"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[6217],{782607:(e,a,t)=>{t.d(a,{Z:()=>s});var n=t(751995),o=t(978573),l=t(135944);const s=(0,n.iK)((e=>(0,l.tZ)(o.Z,{...e})))`
  ${({theme:e,color:a,count:t})=>`\n    & > sup,\n    & > sup.antd5-badge-count {\n      ${void 0!==t?`background: ${a||e.colors.primary.base};`:""}\n    }\n  `}
`},73995:(e,a,t)=>{t.d(a,{Z:()=>S});var n=t(667294),o=t(751995),l=t(431069),s=t(61988),r=t(115926),i=t.n(r),d=t(104715),c=t(737921),u=t(49238),h=t(940277),p=t(414114),m=t(708743),b=t(135944);const v=o.iK.div`
  ${({theme:e})=>`\n    .refresh {\n      display: flex;\n      align-items: center;\n      width: 30px;\n      margin-left: ${e.gridUnit}px;\n      margin-top: ${5*e.gridUnit}px;\n    }\n\n    .section {\n      display: flex;\n      flex-direction: row;\n      align-items: center;\n    }\n\n    .select {\n      width: calc(100% - 30px - ${e.gridUnit}px);\n      flex: 1;\n    }\n\n    & > div {\n      margin-bottom: ${4*e.gridUnit}px;\n    }\n  `}
`,g=o.iK.div`
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-left: ${({theme:e})=>e.gridUnit-2}px;

  .backend {
    overflow: visible;
  }

  .name {
    overflow: hidden;
    text-overflow: ellipsis;
  }
`,f=({backend:e,databaseName:a})=>(0,b.BX)(g,{children:[(0,b.tZ)(c.Z,{className:"backend",children:e||""}),(0,b.tZ)("span",{className:"name",title:a,children:a})]}),y=[],Z=[];function S({db:e,formMode:a=!1,emptyState:t,getDbList:o,handleError:r,isDatabaseSelectEnabled:c=!0,onDbChange:g,onEmptyResults:S,onCatalogChange:C,catalog:w,onSchemaChange:_,schema:x,readOnly:$=!1,sqlLabMode:k=!1}){const E=!(null==e||!e.allow_multi_catalog),[L,N]=(0,n.useState)(),[q,T]=(0,n.useState)(w?{label:w,value:w,title:w}:void 0),D=(0,n.useRef)(w);D.current=w;const[I,R]=(0,n.useState)(x?{label:x,value:x,title:x}:void 0),X=(0,n.useRef)(x);X.current=x;const{addSuccessToast:z}=(0,p.e1)(),M=(0,n.useCallback)(((e,a)=>e.order-a.order),[]),O=(0,n.useMemo)((()=>async(e,t,n)=>{const s=`/api/v1/database/?q=${i().encode({order_column:"database_name",order_direction:"asc",page:t,page_size:n,...a||!k?{filters:[{col:"database_name",opr:"ct",value:e}]}:{filters:[{col:"database_name",opr:"ct",value:e},{col:"expose_in_sqllab",opr:"eq",value:!0}]}})}`;return l.Z.get({endpoint:s}).then((({json:a})=>{const{result:t,count:n}=a;o&&o(t),0===t.length&&S&&S(e);const l=t.map(((e,a)=>({label:(0,b.tZ)(f,{backend:e.backend,databaseName:e.database_name}),value:e.id,id:e.id,database_name:e.database_name,backend:e.backend,allow_multi_catalog:e.allow_multi_catalog,order:a})));return{data:l,totalCount:null!=n?n:l.length}}))}),[a,o,k,S]);function j(e){R(e),_&&(null==e?void 0:e.value)!==X.current&&_(null==e?void 0:e.value)}(0,n.useEffect)((()=>{N((a=>(null==a?void 0:a.id)!==(null==e?void 0:e.id)?e?{label:(0,b.tZ)(f,{backend:e.backend,databaseName:e.database_name}),value:e.id,...e}:void 0:a))}),[e]);const{currentData:F,isFetching:U,refetch:A}=(0,m.Xx)({dbId:null==L?void 0:L.value,catalog:null==q?void 0:q.value,onSuccess:(e,a)=>{1===e.length?j(e[0]):e.find((e=>X.current===e.value))||j(void 0),a&&z("List refreshed")},onError:()=>r((0,s.t)("There was an error loading the schemas"))}),P=F||Z;function Q(e){T(e),R(void 0),C&&(null==e?void 0:e.value)!==D.current&&C(null==e?void 0:e.value)}const{data:B,isFetching:J,refetch:V}=(0,m.$O)({dbId:E?null==L?void 0:L.value:void 0,onSuccess:(e,a)=>{E?1===e.length?Q(e[0]):e.find((e=>D.current===e.value))||Q(void 0):Q(null),E&&a&&z("List refreshed")},onError:()=>{E&&r((0,s.t)("There was an error loading the catalogs"))}}),K=B||y;function Y(e,a){return(0,b.BX)("div",{className:"section",children:[(0,b.tZ)("span",{className:"select",children:e}),(0,b.tZ)("span",{className:"refresh",children:a})]})}return(0,b.BX)(v,{children:[Y((0,b.tZ)(d.qb,{ariaLabel:(0,s.t)("Select database or type to search databases"),optionFilterProps:["database_name","value"],header:(0,b.tZ)(u.lX,{children:(0,s.t)("Database")}),lazyLoading:!1,notFoundContent:t,onChange:function(e,a){N(a),T(void 0),R(void 0),g&&g(a),C&&C(void 0),_&&_(void 0)},value:L,placeholder:(0,s.t)("Select database or type to search databases"),disabled:!c||$,options:O,sortComparator:M}),null),E&&function(){const e=!$&&(0,b.tZ)(h.Z,{onClick:V,tooltipContent:(0,s.t)("Force refresh catalog list")});return Y((0,b.tZ)(d.Ph,{ariaLabel:(0,s.t)("Select catalog or type to search catalogs"),disabled:!L||$,header:(0,b.tZ)(u.lX,{children:(0,s.t)("Catalog")}),labelInValue:!0,loading:J,name:"select-catalog",notFoundContent:(0,s.t)("No compatible catalog found"),placeholder:(0,s.t)("Select catalog or type to search catalogs"),onChange:e=>Q(e),options:K,showSearch:!0,value:q||void 0}),e)}(),function(){const e=!$&&(0,b.tZ)(h.Z,{onClick:A,tooltipContent:(0,s.t)("Force refresh schema list")});return Y((0,b.tZ)(d.Ph,{ariaLabel:(0,s.t)("Select schema or type to search schemas"),disabled:!L||$,header:(0,b.tZ)(u.lX,{children:(0,s.t)("Schema")}),labelInValue:!0,loading:U,name:"select-schema",notFoundContent:(0,s.t)("No compatible schema found"),placeholder:(0,s.t)("Select schema or type to search schemas"),onChange:e=>j(e),options:P,showSearch:!0,value:I}),e)}()]})}},940277:(e,a,t)=>{t.d(a,{Z:()=>r});var n=t(667294),o=t(358593),l=t(313322),s=t(135944);const r=({onClick:e,tooltipContent:a})=>{const t=(0,n.forwardRef)(((e,a)=>(0,s.tZ)(l.Z.Refresh,{...e})));return(0,s.tZ)(o.u,{title:a,children:(0,s.tZ)(t,{role:"button",onClick:e,css:e=>({cursor:"pointer",color:e.colors.grayscale.base,"&:hover":{color:e.colors.primary.base}})})})}},517982:(e,a,t)=>{t.d(a,{PH:()=>S,ZP:()=>C,ez:()=>y});var n=t(667294),o=t(751995),l=t(61988),s=t(844818),r=t(104715),i=t(49238),d=t(313322),c=t(73995),u=t(940277),h=t(679789),p=t(486057),m=t(414114),b=t(708743),v=t(135944);const g=o.iK.div`
  ${({theme:e})=>`\n    .refresh {\n      display: flex;\n      align-items: center;\n      width: 30px;\n      margin-left: ${e.gridUnit}px;\n      margin-top: ${5*e.gridUnit}px;\n    }\n\n    .section {\n      display: flex;\n      flex-direction: row;\n      align-items: center;\n    }\n\n    .divider {\n      border-bottom: 1px solid ${e.colors.secondary.light5};\n      margin: 15px 0;\n    }\n\n    .table-length {\n      color: ${e.colors.grayscale.light1};\n    }\n\n    .select {\n      flex: 1;\n      max-width: calc(100% - ${e.gridUnit+30}px)\n    }\n  `}
`,f=o.iK.span`
  align-items: center;
  display: flex;
  white-space: nowrap;

  svg,
  small {
    margin-right: ${({theme:e})=>e.gridUnit}px;
  }
`,y=({table:e})=>{const{value:a,type:t,extra:n}=e;return(0,v.BX)(f,{title:a,children:["view"===t?(0,v.tZ)(d.Z.Eye,{iconSize:"m"}):(0,v.tZ)(d.Z.Table,{iconSize:"m"}),(null==n?void 0:n.certification)&&(0,v.tZ)(h.Z,{certifiedBy:n.certification.certified_by,details:n.certification.details,size:"l"}),(null==n?void 0:n.warning_markdown)&&(0,v.tZ)(p.Z,{warningMarkdown:n.warning_markdown,size:"l",marginRight:4}),a]})},Z=({database:e,emptyState:a,formMode:t=!1,getDbList:o,handleError:d,isDatabaseSelectEnabled:h=!0,onDbChange:p,onCatalogChange:f,onSchemaChange:Z,readOnly:S=!1,onEmptyResults:C,catalog:w,schema:_,sqlLabMode:x=!0,tableSelectMode:$="single",tableValue:k,onTableSelectChange:E,customTableOptionLabelRenderer:L})=>{const{addSuccessToast:N}=(0,m.e1)(),[q,T]=(0,n.useState)(w),[D,I]=(0,n.useState)(_),[R,X]=(0,n.useState)(void 0),{currentData:z,isFetching:M,refetch:O}=(0,b.zA)({dbId:null==e?void 0:e.id,catalog:q,schema:D,onSuccess:(e,a)=>{a&&N((0,l.t)("List updated"))},onError:e=>{(0,s.O$)(e).then((e=>{d((0,s.d7)((0,l.t)("There was an error loading the tables"),e))}))}}),j=(0,n.useMemo)((()=>z?z.options.map((e=>({value:e.value,label:(0,v.tZ)(y,{table:e}),text:e.value,...L&&{customLabel:L(e)}}))):[]),[z,L]);(0,n.useEffect)((()=>{void 0===e&&(T(void 0),I(void 0),X(void 0))}),[e,$]),(0,n.useEffect)((()=>{X("single"===$?j.find((e=>e.value===k)):(null==j?void 0:j.filter((e=>e&&(null==k?void 0:k.includes(e.value)))))||[])}),[j,k,$]);const F=(0,n.useMemo)((()=>(e,a)=>{const t=e.trim().toLowerCase(),{value:n}=a;return n.toLowerCase().includes(t)}),[]);return(0,v.BX)(g,{children:[(0,v.tZ)(c.Z,{db:e,emptyState:a,formMode:t,getDbList:o,handleError:d,onDbChange:S?void 0:e=>{p&&p(e),T(void 0),I(void 0),X("single"===$?void 0:[])},onEmptyResults:C,onCatalogChange:S?void 0:e=>{T(e),f&&f(e),I(void 0),X("single"===$?void 0:[])},catalog:q,onSchemaChange:S?void 0:e=>{I(e),Z&&Z(e),X("single"===$?void 0:[])},schema:D,sqlLabMode:x,isDatabaseSelectEnabled:h&&!S,readOnly:S}),x&&!t&&(0,v.tZ)("div",{className:"divider"}),function(){const e=D&&!t&&S||!D,a=x?(0,v.tZ)(i.lX,{children:(0,l.t)("See table schema")}):(0,v.tZ)(i.lX,{children:(0,l.t)("Table")});return n=(0,v.tZ)(r.Ph,{ariaLabel:(0,l.t)("Select table or type to search tables"),disabled:e,filterOption:F,header:a,labelInValue:!0,loading:M,name:"select-table",onChange:e=>{return a=e,void(D?null==E||E(Array.isArray(a)?a.map((e=>null==e?void 0:e.value)):null==a?void 0:a.value,q,D):X(a));var a},options:j,placeholder:(0,l.t)("Select table or type to search tables"),showSearch:!0,mode:$,value:R,allowClear:"multiple"===$,allowSelectAll:!1}),o=!S&&(0,v.tZ)(u.Z,{onClick:()=>O(),tooltipContent:(0,l.t)("Force refresh table list")}),(0,v.BX)("div",{className:"section",children:[(0,v.tZ)("span",{className:"select",children:n}),(0,v.tZ)("span",{className:"refresh",children:o})]});var n,o}()]})},S=e=>(0,v.tZ)(Z,{tableSelectMode:"multiple",...e}),C=Z},708743:(e,a,t)=>{t.d(a,{schemaEndpoints:()=>w.Kt,CN:()=>n.CN,tableEndpoints:()=>C.QD,$O:()=>m,hb:()=>f,QU:()=>y,Es:()=>Z,JL:()=>S,L8:()=>x,Xx:()=>w.Xx,SJ:()=>C.SJ,uY:()=>C.uY,zA:()=>C.zA});var n=t(845673),o=t(242190),l=t(667294),s=t(938325),r=t(610362);const i=r.h.injectEndpoints({endpoints:e=>({catalogs:e.query({providesTags:[{type:"Catalogs",id:"LIST"}],query:({dbId:e,forceRefresh:a})=>({endpoint:`/api/v1/database/${e}/catalogs/`,urlParams:{force:a},transformResponse:({json:e})=>e.result.sort().map((e=>({value:e,label:e,title:e})))}),serializeQueryArgs:({queryArgs:{dbId:e}})=>({dbId:e})})})}),{useLazyCatalogsQuery:d,useCatalogsQuery:c,endpoints:u,util:h}=i,p=[];function m(e){const{dbId:a,onSuccess:t,onError:n}=e||{},[o]=d(),r=c({dbId:a,forceRefresh:!1},{skip:!a}),i=(0,s.Z)(((e,a=!1)=>{!e||r.currentData&&!a||o({dbId:e,forceRefresh:a}).then((({isSuccess:e,isError:o,data:l})=>{e&&(null==t||t(l||p,a)),o&&(null==n||n())}))})),u=(0,l.useCallback)((()=>{i(a,!0)}),[a,i]);return(0,l.useEffect)((()=>{i(a,!1)}),[a,i]),{...r,refetch:u}}var b=t(115926);function v({owners:e}){return e?e.map((e=>`${e.first_name} ${e.last_name}`)):null}const g=t.n(b)().encode({columns:["owners.first_name","owners.last_name"],keys:["none"]});function f(e){return(0,o.l6)((0,o.s_)(`/api/v1/chart/${e}?q=${g}`),v)}const y=e=>(0,o.l6)((0,o.s_)(`/api/v1/dashboard/${e}`),(e=>({...e,metadata:e.json_metadata&&JSON.parse(e.json_metadata)||{},position_data:e.position_json&&JSON.parse(e.position_json),owners:e.owners||[]}))),Z=e=>(0,o.s_)(`/api/v1/dashboard/${e}/charts`),S=e=>(0,o.s_)(`/api/v1/dashboard/${e}/datasets`);var C=t(123936),w=t(469279);const _=r.h.injectEndpoints({endpoints:e=>({queryValidations:e.query({providesTags:["QueryValidations"],query:({dbId:e,catalog:a,schema:t,sql:n,templateParams:o})=>{let l=o;try{l=JSON.parse(o||"")}catch(e){l=void 0}const s={catalog:a,schema:t,sql:n,...l&&{template_params:l}};return{method:"post",endpoint:`/api/v1/database/${e}/validate_sql/`,headers:{"Content-Type":"application/json"},body:JSON.stringify(s),transformResponse:({json:e})=>e.result}}})})}),{useQueryValidationsQuery:x}=_}}]);
//# sourceMappingURL=1b6d9772983c77145a4c.chunk.js.map