"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[4502],{452630:(e,a,t)=>{a.iB=a.YM=void 0;var n=Object.assign||function(e){for(var a=1;a<arguments.length;a++){var t=arguments[a];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},l=r(t(667294)),o=r(t(45697)),i=t(402371);function r(e){return e&&e.__esModule?e:{default:e}}a.YM=function(e){var a=e.itemTypeToComponent,t=e.WrapperComponent,r=void 0===t?"div":t,s=function(e){var t=e.currentPage,o=e.totalPages,s=e.boundaryPagesRange,d=e.siblingPagesRange,u=e.hideEllipsis,c=e.hidePreviousAndNextPageLinks,g=e.hideFirstAndLastPageLinks,p=e.onChange,b=e.disabled,h=function(e,a){var t={};for(var n in e)a.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t}(e,["currentPage","totalPages","boundaryPagesRange","siblingPagesRange","hideEllipsis","hidePreviousAndNextPageLinks","hideFirstAndLastPageLinks","onChange","disabled"]),E=(0,i.getPaginationModel)({currentPage:t,totalPages:o,boundaryPagesRange:s,siblingPagesRange:d,hideEllipsis:u,hidePreviousAndNextPageLinks:c,hideFirstAndLastPageLinks:g}),_=function(e,a,t){return function(o){var i,r,s,d=e[o.type],u=(r=(i=o).value,s=i.isDisabled,function(){!s&&t&&a!==r&&t(r)});return l.default.createElement(d,n({onClick:u},o))}}(a,t,p);return l.default.createElement(r,h,E.map((function(e){return _(n({},e,{isDisabled:!!b}))})))};return s.propTypes={currentPage:o.default.number.isRequired,totalPages:o.default.number.isRequired,boundaryPagesRange:o.default.number,siblingPagesRange:o.default.number,hideEllipsis:o.default.bool,hidePreviousAndNextPageLinks:o.default.bool,hideFirstAndLastPageLinks:o.default.bool,onChange:o.default.func,disabled:o.default.bool},s},a.iB=i.ITEM_TYPES},554070:(e,a,t)=>{t.d(a,{w:()=>r});var n=t(358593),l=t(83379),o=t(61988),i=t(135944);const r=({user:e,date:a})=>{const t=(0,i.tZ)("span",{className:"no-wrap",children:a});if(e){const a=(0,l.Z)(e),r=(0,o.t)("Modified by: %s",a);return(0,i.tZ)(n.u,{title:r,placement:"bottom",children:t})}return t}},395731:(e,a,t)=>{t.r(a),t.d(a,{default:()=>Y});var n=t(175049),l=t(751995),o=t(61988),i=t(431069),r=t(667294),s=t(115926),d=t.n(s),u=t(828216),c=t(535755),g=t(961337),p=t(838703),b=t(34858),h=t(440768),E=t(414114),_=t(586074),P=t(217198),m=t(23525),S=t(427600),v=t(358593),f=t(313322),L=t(922318),I=t(593139),y=t(232228),T=t(719235),N=t(493628),w=t(554070),A=t(400012),Z=t(135944);const k=(0,n.I)(),M=k.get("database.delete.related"),C=k.get("databaseconnection.extraOption"),R=(0,l.iK)(f.Z.Check)`
  color: ${({theme:e})=>e.colors.grayscale.dark1};
`,x=(0,l.iK)(f.Z.CancelX)`
  color: ${({theme:e})=>e.colors.grayscale.light1};
`,K=l.iK.div`
  color: ${({theme:e})=>e.colors.grayscale.base};

  .action-button {
    display: inline-block;
    height: 100%;
  }
`;function D({value:e}){return e?(0,Z.tZ)(R,{}):(0,Z.tZ)(x,{})}const Y=(0,E.ZP)((function({addDangerToast:e,addSuccessToast:a,user:t}){const{state:{loading:n,resourceCount:l,resourceCollection:s},hasPerm:E,fetchData:k,refreshData:R}=(0,b.Yi)("database",(0,o.t)("database"),e),x=(0,u.v9)((e=>e.user)),Y=(0,m.eY)(S.KD.showDatabaseModal),[O,G]=(0,c.Kx)({databaseAdded:c.dJ}),[F,H]=(0,r.useState)(Y||!1),[U,X]=(0,r.useState)(null),[q,B]=(0,r.useState)(null),[z,V]=(0,r.useState)(!1),[$,j]=(0,r.useState)(!1),[Q,J]=(0,r.useState)(!1),[W,ee]=(0,r.useState)(!1),ae=(0,L.i5)(x),te=W||ae,[ne,le]=(0,r.useState)(!1),{roles:oe}=x,{CSV_EXTENSIONS:ie,COLUMNAR_EXTENSIONS:re,EXCEL_EXTENSIONS:se,ALLOWED_EXTENSIONS:de}=(0,u.v9)((e=>e.common.conf));function ue({database:e=null,modalOpen:a=!1}={}){B(e),H(a)}(0,r.useEffect)((()=>{null!=O&&O.databaseAdded&&(G({databaseAdded:void 0}),R())}),[O,G,R]);const ce=E("can_write"),ge=E("can_write"),pe=E("can_write"),be=E("can_export"),{canUploadCSV:he,canUploadColumnar:Ee,canUploadExcel:_e}=(0,h.Mc)(oe,ie,re,se,de),Pe=ae&&!W,me=[{label:(0,o.t)("Upload file to database"),childs:[{label:(0,o.t)("Upload CSV"),name:"Upload CSV file",url:"#",onClick:()=>{V(!0)},perm:he&&te,disable:Pe},{label:(0,o.t)("Upload Excel"),name:"Upload Excel file",url:"#",onClick:()=>{j(!0)},perm:_e&&te,disable:Pe},{label:(0,o.t)("Upload Columnar"),name:"Upload columnar file",url:"#",onClick:()=>{J(!0)},perm:Ee&&te,disable:Pe}]}];(0,r.useEffect)((()=>{i.Z.get({endpoint:`/api/v1/database/?q=${d().encode({filters:[{col:"allow_file_upload",opr:"upload_is_enabled",value:!0}]})}`}).then((({json:e})=>{var a;const t=(null==e||null==(a=e.result)?void 0:a.filter((e=>{var a;return null==e||null==(a=e.engine_information)?void 0:a.supports_file_upload})))||[];ee((null==t?void 0:t.length)>=1)}))}),[F]);const Se={activeChild:"Databases",dropDownLinks:me.reduce(((e,a)=>(a.childs=a.childs.filter((e=>e.perm)),a.childs.length?(e.push(a),e):e)),[]),name:(0,o.t)("Databases")};ce&&(Se.buttons=[{name:(0,Z.BX)(Z.HY,{children:[(0,Z.tZ)("i",{className:"fa fa-plus"})," ",(0,o.t)("Database")," "]}),buttonStyle:"primary",onClick:()=>{ue({modalOpen:!0})}}]);const ve=(0,r.useMemo)((()=>[{accessor:"database_name",Header:(0,o.t)("Name")},{accessor:"backend",Header:(0,o.t)("Backend"),size:"lg",disableSortBy:!0},{accessor:"allow_run_async",Header:(0,Z.tZ)(v.u,{id:"allow-run-async-header-tooltip",title:(0,o.t)("Asynchronous query execution"),placement:"top",children:(0,Z.tZ)("span",{children:(0,o.t)("AQE")})}),Cell:({row:{original:{allow_run_async:e}}})=>(0,Z.tZ)(D,{value:e}),size:"sm"},{accessor:"allow_dml",Header:(0,Z.tZ)(v.u,{id:"allow-dml-header-tooltip",title:(0,o.t)("Allow data manipulation language"),placement:"top",children:(0,Z.tZ)("span",{children:(0,o.t)("DML")})}),Cell:({row:{original:{allow_dml:e}}})=>(0,Z.tZ)(D,{value:e}),size:"sm"},{accessor:"allow_file_upload",Header:(0,o.t)("File upload"),Cell:({row:{original:{allow_file_upload:e}}})=>(0,Z.tZ)(D,{value:e}),size:"md"},{accessor:"expose_in_sqllab",Header:(0,o.t)("Expose in SQL Lab"),Cell:({row:{original:{expose_in_sqllab:e}}})=>(0,Z.tZ)(D,{value:e}),size:"md"},{Cell:({row:{original:{changed_by:e,changed_on_delta_humanized:a}}})=>(0,Z.tZ)(w.w,{date:a,user:e}),Header:(0,o.t)("Last modified"),accessor:"changed_on_delta_humanized",size:"xl"},{Cell:({row:{original:e}})=>ge||pe||be?(0,Z.BX)(K,{className:"actions",children:[pe&&(0,Z.tZ)("span",{role:"button",tabIndex:0,className:"action-button",onClick:()=>{return a=e,i.Z.get({endpoint:`/api/v1/database/${a.id}/related_objects/`}).then((({json:e={}})=>{X({...a,chart_count:e.charts.count,dashboard_count:e.dashboards.count,sqllab_tab_count:e.sqllab_tab_states.count})})).catch((0,h.v$)((e=>(0,o.t)("An error occurred while fetching database related data: %s",e))));var a},children:(0,Z.tZ)(v.u,{id:"delete-action-tooltip",title:(0,o.t)("Delete database"),placement:"bottom",children:(0,Z.tZ)(f.Z.Trash,{})})}),be&&(0,Z.tZ)(v.u,{id:"export-action-tooltip",title:(0,o.t)("Export"),placement:"bottom",children:(0,Z.tZ)("span",{role:"button",tabIndex:0,className:"action-button",onClick:()=>{var a;void 0!==(a=e).id&&((0,y.Z)("database",[a.id],(()=>{le(!1)})),le(!0))},children:(0,Z.tZ)(f.Z.Share,{})})}),ge&&(0,Z.tZ)(v.u,{id:"edit-action-tooltip",title:(0,o.t)("Edit"),placement:"bottom",children:(0,Z.tZ)("span",{role:"button",tabIndex:0,className:"action-button",onClick:()=>ue({database:e,modalOpen:!0}),children:(0,Z.tZ)(f.Z.EditAlt,{})})})]}):null,Header:(0,o.t)("Actions"),id:"actions",hidden:!ge&&!pe,disableSortBy:!0},{accessor:A.J.ChangedBy,hidden:!0}]),[pe,ge,be]),fe=(0,r.useMemo)((()=>[{Header:(0,o.t)("Name"),key:"search",id:"database_name",input:"search",operator:I.p.Contains},{Header:(0,o.t)("Expose in SQL Lab"),key:"expose_in_sql_lab",id:"expose_in_sqllab",input:"select",operator:I.p.Equals,unfilteredLabel:(0,o.t)("All"),selects:[{label:(0,o.t)("Yes"),value:!0},{label:(0,o.t)("No"),value:!1}]},{Header:(0,Z.tZ)(v.u,{id:"allow-run-async-filter-header-tooltip",title:(0,o.t)("Asynchronous query execution"),placement:"top",children:(0,Z.tZ)("span",{children:(0,o.t)("AQE")})}),key:"allow_run_async",id:"allow_run_async",input:"select",operator:I.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)("Modified by"),key:"changed_by",id:"changed_by",input:"select",operator:I.p.RelationOneMany,unfilteredLabel:(0,o.t)("All"),fetchSelects:(0,h.tm)("database","changed_by",(0,h.v$)((e=>(0,o.t)("An error occurred while fetching dataset datasource values: %s",e))),t),paginate:!0}]),[]);return(0,Z.BX)(Z.HY,{children:[(0,Z.tZ)(_.Z,{...Se}),(0,Z.tZ)(T.ZP,{databaseId:null==q?void 0:q.id,show:F,onHide:ue,onDatabaseAdd:()=>{R()}}),(0,Z.tZ)(N.Z,{addDangerToast:e,addSuccessToast:a,onHide:()=>{V(!1)},show:z,allowedExtensions:ie,type:"csv"}),(0,Z.tZ)(N.Z,{addDangerToast:e,addSuccessToast:a,onHide:()=>{j(!1)},show:$,allowedExtensions:se,type:"excel"}),(0,Z.tZ)(N.Z,{addDangerToast:e,addSuccessToast:a,onHide:()=>{J(!1)},show:Q,allowedExtensions:re,type:"columnar"}),U&&(0,Z.tZ)(P.Z,{description:(0,Z.BX)(Z.HY,{children:[(0,Z.tZ)("p",{children:(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.",U.database_name,U.chart_count,U.dashboard_count,U.sqllab_tab_count)}),M&&(0,Z.tZ)(M,{database:U})]}),onConfirm:()=>{U&&function(t){const{id:n,database_name:l}=t;i.Z.delete({endpoint:`/api/v1/database/${n}`}).then((()=>{R(),a((0,o.t)("Deleted: %s",l)),null!=C&&C.onDelete&&C.onDelete(t),(0,g.LS)(g.dR.Database,null),X(null)}),(0,h.v$)((a=>e((0,o.t)("There was an issue deleting %s: %s",l,a)))))}(U)},onHide:()=>X(null),open:!0,title:(0,o.t)("Delete Database?")}),(0,Z.tZ)(I.Z,{className:"database-list-view",columns:ve,count:l,data:s,fetchData:k,filters:fe,initialSort:[{id:"changed_on_delta_humanized",desc:!0}],loading:n,addDangerToast:e,addSuccessToast:a,refreshData:()=>{},pageSize:25}),ne&&(0,Z.tZ)(p.Z,{})]})}))},656590:(e,a)=>{a.ITEM_TYPES={PAGE:"PAGE",ELLIPSIS:"ELLIPSIS",FIRST_PAGE_LINK:"FIRST_PAGE_LINK",PREVIOUS_PAGE_LINK:"PREVIOUS_PAGE_LINK",NEXT_PAGE_LINK:"NEXT_PAGE_LINK",LAST_PAGE_LINK:"LAST_PAGE_LINK"},a.ITEM_KEYS={FIRST_ELLIPSIS:-1,SECOND_ELLIPSIS:-2,FIRST_PAGE_LINK:-3,PREVIOUS_PAGE_LINK:-4,NEXT_PAGE_LINK:-5,LAST_PAGE_LINK:-6}},653804:(e,a,t)=>{var n=t(656590);a.createFirstEllipsis=function(e){return{type:n.ITEM_TYPES.ELLIPSIS,key:n.ITEM_KEYS.FIRST_ELLIPSIS,value:e,isActive:!1}},a.createSecondEllipsis=function(e){return{type:n.ITEM_TYPES.ELLIPSIS,key:n.ITEM_KEYS.SECOND_ELLIPSIS,value:e,isActive:!1}},a.createFirstPageLink=function(e){var a=e.currentPage;return{type:n.ITEM_TYPES.FIRST_PAGE_LINK,key:n.ITEM_KEYS.FIRST_PAGE_LINK,value:1,isActive:1===a}},a.createPreviousPageLink=function(e){var a=e.currentPage;return{type:n.ITEM_TYPES.PREVIOUS_PAGE_LINK,key:n.ITEM_KEYS.PREVIOUS_PAGE_LINK,value:Math.max(1,a-1),isActive:1===a}},a.createNextPageLink=function(e){var a=e.currentPage,t=e.totalPages;return{type:n.ITEM_TYPES.NEXT_PAGE_LINK,key:n.ITEM_KEYS.NEXT_PAGE_LINK,value:Math.min(t,a+1),isActive:a===t}},a.createLastPageLink=function(e){var a=e.currentPage,t=e.totalPages;return{type:n.ITEM_TYPES.LAST_PAGE_LINK,key:n.ITEM_KEYS.LAST_PAGE_LINK,value:t,isActive:a===t}},a.createPageFunctionFactory=function(e){var a=e.currentPage;return function(e){return{type:n.ITEM_TYPES.PAGE,key:e,value:e,isActive:e===a}}}},1158:(e,a)=>{a.createRange=function(e,a){for(var t=[],n=e;n<=a;n++)t.push(n);return t}},402371:(e,a,t)=>{var n=t(1158),l=t(653804);a.getPaginationModel=function(e){if(null==e)throw new Error("getPaginationModel(): options object should be a passed");var a=Number(e.totalPages);if(isNaN(a))throw new Error("getPaginationModel(): totalPages should be a number");if(a<0)throw new Error("getPaginationModel(): totalPages shouldn't be a negative number");var t=Number(e.currentPage);if(isNaN(t))throw new Error("getPaginationModel(): currentPage should be a number");if(t<0)throw new Error("getPaginationModel(): currentPage shouldn't be a negative number");if(t>a)throw new Error("getPaginationModel(): currentPage shouldn't be greater than totalPages");var o=null==e.boundaryPagesRange?1:Number(e.boundaryPagesRange);if(isNaN(o))throw new Error("getPaginationModel(): boundaryPagesRange should be a number");if(o<0)throw new Error("getPaginationModel(): boundaryPagesRange shouldn't be a negative number");var i=null==e.siblingPagesRange?1:Number(e.siblingPagesRange);if(isNaN(i))throw new Error("getPaginationModel(): siblingPagesRange should be a number");if(i<0)throw new Error("getPaginationModel(): siblingPagesRange shouldn't be a negative number");var r=Boolean(e.hidePreviousAndNextPageLinks),s=Boolean(e.hideFirstAndLastPageLinks),d=Boolean(e.hideEllipsis),u=d?0:1,c=[],g=l.createPageFunctionFactory(e);if(s||c.push(l.createFirstPageLink(e)),r||c.push(l.createPreviousPageLink(e)),1+2*u+2*i+2*o>=a){var p=n.createRange(1,a).map(g);c.push.apply(c,p)}else{var b=o,h=n.createRange(1,b).map(g),E=a+1-o,_=a,P=n.createRange(E,_).map(g),m=Math.min(Math.max(t-i,b+u+1),E-u-2*i-1),S=m+2*i,v=n.createRange(m,S).map(g);if(c.push.apply(c,h),!d){var f=m-1,L=(f===b+1?g:l.createFirstEllipsis)(f);c.push(L)}if(c.push.apply(c,v),!d){var I=S+1,y=(I===E-1?g:l.createSecondEllipsis)(I);c.push(y)}c.push.apply(c,P)}return r||c.push(l.createNextPageLink(e)),s||c.push(l.createLastPageLink(e)),c};var o=t(656590);a.ITEM_TYPES=o.ITEM_TYPES,a.ITEM_KEYS=o.ITEM_KEYS}}]);
//# sourceMappingURL=ed9b08fe9ef03f901d2f.chunk.js.map