"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[4502],{95731:(e,a,t)=>{t.r(a),t.d(a,{default:()=>z});var l=t(75049),n=t(51995),o=t(61988),s=t(31069),d=t(93185),r=t(67294),i=t(15926),c=t.n(i),u=t(28216),b=t(35755),p=t(61337),m=t(38703),_=t(34858),h=t(40768),Z=t(14114),f=t(86074),g=t(17198),v=t(23525),w=t(27600),S=t(58593),C=t(70707),y=t(22318),E=t(93139),D=t(32228),x=t(1315),k=t(11965);const N=(0,l.I)(),A=N.get("database.delete.related"),L=N.get("databaseconnection.extraOption"),T=(0,n.iK)(C.Z.Check)`
  color: ${e=>{let{theme:a}=e;return a.colors.grayscale.dark1}};
`,H=(0,n.iK)(C.Z.CancelX)`
  color: ${e=>{let{theme:a}=e;return a.colors.grayscale.light1}};
`,q=n.iK.div`
  color: ${e=>{let{theme:a}=e;return a.colors.grayscale.base}};

  .action-button {
    display: inline-block;
    height: 100%;
  }
`;function O(e){let{value:a}=e;return a?(0,k.tZ)(T,null):(0,k.tZ)(H,null)}const z=(0,Z.ZP)((function(e){let{addDangerToast:a,addSuccessToast:t}=e;const{state:{loading:l,resourceCount:n,resourceCollection:i},hasPerm:Z,fetchData:N,refreshData:T}=(0,_.Yi)("database",(0,o.t)("database"),a),H=(0,u.v9)((e=>e.user)),z=(0,v.eY)(w.KD.showDatabaseModal),[U,I]=(0,b.Kx)({databaseAdded:b.dJ}),[$,X]=(0,r.useState)(z||!1),[M,V]=(0,r.useState)(null),[K,Q]=(0,r.useState)(null),[j,B]=(0,r.useState)(!1),P=(0,y.i5)(H),R=j||P,[Y,F]=(0,r.useState)(!1),{roles:J}=H,{CSV_EXTENSIONS:W,COLUMNAR_EXTENSIONS:G,EXCEL_EXTENSIONS:ee,ALLOWED_EXTENSIONS:ae}=(0,u.v9)((e=>e.common.conf));function te(e){let{database:a=null,modalOpen:t=!1}=void 0===e?{}:e;Q(a),X(t)}(0,r.useEffect)((()=>{null!=U&&U.databaseAdded&&(I({databaseAdded:void 0}),T())}),[U,I,T]);const le=Z("can_write"),ne=Z("can_write"),oe=Z("can_write"),se=Z("can_export")&&(0,d.cr)(d.TT.VERSIONED_EXPORT),{canUploadCSV:de,canUploadColumnar:re,canUploadExcel:ie}=(0,h.Mc)(J,W,G,ee,ae),ce=P&&!j,ue=[{label:(0,o.t)("Upload file to database"),childs:[{label:(0,o.t)("Upload CSV"),name:"Upload CSV file",url:"/csvtodatabaseview/form",perm:de&&R,disable:ce},{label:(0,o.t)("Upload columnar file"),name:"Upload columnar file",url:"/columnartodatabaseview/form",perm:re&&R,disable:ce},{label:(0,o.t)("Upload Excel file"),name:"Upload Excel file",url:"/exceltodatabaseview/form",perm:ie&&R,disable:ce}]}];(0,r.useEffect)((()=>{s.Z.get({endpoint:`/api/v1/database/?q=${c().encode({filters:[{col:"allow_file_upload",opr:"upload_is_enabled",value:!0}]})}`}).then((e=>{var a;let{json:t}=e;const l=(null==t||null==(a=t.result)?void 0:a.filter((e=>{var a;return null==e||null==(a=e.engine_information)?void 0:a.supports_file_upload})))||[];B((null==l?void 0:l.length)>=1)}))}),[$]);const be={activeChild:"Databases",dropDownLinks:ue.reduce(((e,a)=>(a.childs=a.childs.filter((e=>e.perm)),a.childs.length?(e.push(a),e):e)),[]),name:(0,o.t)("Databases")};le&&(be.buttons=[{"data-test":"btn-create-database",name:(0,k.tZ)(r.Fragment,null,(0,k.tZ)("i",{className:"fa fa-plus"})," ",(0,o.t)("Database")," "),buttonStyle:"primary",onClick:()=>{te({modalOpen:!0})}}]);const pe=(0,r.useMemo)((()=>[{accessor:"database_name",Header:(0,o.t)("Database")},{accessor:"backend",Header:(0,o.t)("Backend"),size:"lg",disableSortBy:!0},{accessor:"allow_run_async",Header:(0,k.tZ)(S.u,{id:"allow-run-async-header-tooltip",title:(0,o.t)("Asynchronous query execution"),placement:"top"},(0,k.tZ)("span",null,(0,o.t)("AQE"))),Cell:e=>{let{row:{original:{allow_run_async:a}}}=e;return(0,k.tZ)(O,{value:a})},size:"sm"},{accessor:"allow_dml",Header:(0,k.tZ)(S.u,{id:"allow-dml-header-tooltip",title:(0,o.t)("Allow data manipulation language"),placement:"top"},(0,k.tZ)("span",null,(0,o.t)("DML"))),Cell:e=>{let{row:{original:{allow_dml:a}}}=e;return(0,k.tZ)(O,{value:a})},size:"sm"},{accessor:"allow_file_upload",Header:(0,o.t)("CSV upload"),Cell:e=>{let{row:{original:{allow_file_upload:a}}}=e;return(0,k.tZ)(O,{value:a})},size:"md"},{accessor:"expose_in_sqllab",Header:(0,o.t)("Expose in SQL Lab"),Cell:e=>{let{row:{original:{expose_in_sqllab:a}}}=e;return(0,k.tZ)(O,{value:a})},size:"md"},{accessor:"created_by",disableSortBy:!0,Header:(0,o.t)("Created by"),Cell:e=>{let{row:{original:{created_by:a}}}=e;return a?`${a.first_name} ${a.last_name}`:""},size:"xl"},{Cell:e=>{let{row:{original:{changed_on_delta_humanized:a}}}=e;return a},Header:(0,o.t)("Last modified"),accessor:"changed_on_delta_humanized",size:"xl"},{Cell:e=>{let{row:{original:a}}=e;return ne||oe||se?(0,k.tZ)(q,{className:"actions"},oe&&(0,k.tZ)("span",{role:"button",tabIndex:0,className:"action-button",onClick:()=>{return e=a,s.Z.get({endpoint:`/api/v1/database/${e.id}/related_objects/`}).then((a=>{let{json:t={}}=a;V({...e,chart_count:t.charts.count,dashboard_count:t.dashboards.count,sqllab_tab_count:t.sqllab_tab_states.count})})).catch((0,h.v$)((e=>(0,o.t)("An error occurred while fetching database related data: %s",e))));var e}},(0,k.tZ)(S.u,{id:"delete-action-tooltip",title:(0,o.t)("Delete database"),placement:"bottom"},(0,k.tZ)(C.Z.Trash,null))),se&&(0,k.tZ)(S.u,{id:"export-action-tooltip",title:(0,o.t)("Export"),placement:"bottom"},(0,k.tZ)("span",{role:"button",tabIndex:0,className:"action-button",onClick:()=>{var e;void 0!==(e=a).id&&((0,D.Z)("database",[e.id],(()=>{F(!1)})),F(!0))}},(0,k.tZ)(C.Z.Share,null))),ne&&(0,k.tZ)(S.u,{id:"edit-action-tooltip",title:(0,o.t)("Edit"),placement:"bottom"},(0,k.tZ)("span",{role:"button",tabIndex:0,className:"action-button",onClick:()=>te({database:a,modalOpen:!0})},(0,k.tZ)(C.Z.EditAlt,null)))):null},Header:(0,o.t)("Actions"),id:"actions",hidden:!ne&&!oe,disableSortBy:!0}]),[oe,ne,se]),me=(0,r.useMemo)((()=>[{Header:(0,o.t)("Expose in SQL Lab"),key:"expose_in_sql_lab",id:"expose_in_sqllab",input:"select",operator:E.p.equals,unfilteredLabel:(0,o.t)("All"),selects:[{label:(0,o.t)("Yes"),value:!0},{label:(0,o.t)("No"),value:!1}]},{Header:(0,k.tZ)(S.u,{id:"allow-run-async-filter-header-tooltip",title:(0,o.t)("Asynchronous query execution"),placement:"top"},(0,k.tZ)("span",null,(0,o.t)("AQE"))),key:"allow_run_async",id:"allow_run_async",input:"select",operator:E.p.equals,unfilteredLabel:(0,o.t)("All"),selects:[{label:(0,o.t)("Yes"),value:!0},{label:(0,o.t)("No"),value:!1}]},{Header:(0,o.t)("Search"),key:"search",id:"database_name",input:"search",operator:E.p.contains}]),[]);return(0,k.tZ)(r.Fragment,null,(0,k.tZ)(f.Z,be),(0,k.tZ)(x.ZP,{databaseId:null==K?void 0:K.id,show:$,onHide:te,onDatabaseAdd:()=>{T()}}),M&&(0,k.tZ)(g.Z,{description:(0,k.tZ)(r.Fragment,null,(0,k.tZ)("p",null,(0,o.t)("The database %s is linked to %s charts that appear on %s dashboards and users have %s SQL Lab tabs using this database open. Are you sure you want to continue? Deleting the database will break those objects.",M.database_name,M.chart_count,M.dashboard_count,M.sqllab_tab_count)),A&&(0,k.tZ)(A,{database:M})),onConfirm:()=>{M&&function(e){const{id:l,database_name:n}=e;s.Z.delete({endpoint:`/api/v1/database/${l}`}).then((()=>{T(),t((0,o.t)("Deleted: %s",n)),null!=L&&L.onDelete&&L.onDelete(e),(0,p.LS)(p.dR.db,null),V(null)}),(0,h.v$)((e=>a((0,o.t)("There was an issue deleting %s: %s",n,e)))))}(M)},onHide:()=>V(null),open:!0,title:(0,o.t)("Delete Database?")}),(0,k.tZ)(E.Z,{className:"database-list-view",columns:pe,count:n,data:i,fetchData:N,filters:me,initialSort:[{id:"changed_on_delta_humanized",desc:!0}],loading:l,addDangerToast:a,addSuccessToast:t,refreshData:()=>{},pageSize:25}),Y&&(0,k.tZ)(m.Z,null))}))}}]);
//# sourceMappingURL=67eac0b0995264fa677d.chunk.js.map