"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[4502],{95731:(e,a,t)=>{t.r(a),t.d(a,{default:()=>U});var l=t(75049),n=t(51995),o=t(55867),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(91877),h=t(34858),Z=t(40768),f=t(14114),g=t(86074),v=t(17198),w=t(23525),S=t(27600),C=t(58593),y=t(70163),E=t(22318),x=t(18782),D=t(32228),k=t(1315),N=t(11965);const A=(0,l.I)(),L=A.get("database.delete.related"),H=A.get("databaseconnection.extraOption"),T=(0,n.iK)(y.Z.Check)`
  color: ${e=>{let{theme:a}=e;return a.colors.grayscale.dark1}};
`,q=(0,n.iK)(y.Z.CancelX)`
  color: ${e=>{let{theme:a}=e;return a.colors.grayscale.light1}};
`,O=n.iK.div`
  color: ${e=>{let{theme:a}=e;return a.colors.grayscale.base}};

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