"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[6217],{82607:(e,t,a)=>{a.d(t,{Z:()=>i});var n=a(73126),l=(a(67294),a(51995)),s=a(62529),o=a(11965);const i=(0,l.iK)((({textColor:e,color:t,text:a,...l})=>(0,o.tZ)(s.Z,(0,n.Z)({text:a,color:a?t:void 0},l))))`
  & > sup {
    padding: 0 ${({theme:e})=>2*e.gridUnit}px;
    background: ${({theme:e,color:t})=>t||e.colors.primary.base};
    color: ${({theme:e,textColor:t})=>t||e.colors.grayscale.light5};
  }
`},73995:(e,t,a)=>{a.d(t,{Z:()=>y});var n=a(67294),l=a(51995),s=a(31069),o=a(61988),i=a(15926),r=a.n(i),d=a(4715),c=a(37921),u=a(49238),m=a(40277),p=a(14114),h=a(67417),b=a(11965);const v=l.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=l.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:t})=>(0,b.tZ)(g,null,(0,b.tZ)(c.Z,{className:"backend"},e||""),(0,b.tZ)("span",{className:"name",title:t},t)),Z=[];function y({db:e,formMode:t=!1,emptyState:a,getDbList:l,handleError:i,isDatabaseSelectEnabled:c=!0,onDbChange:g,onEmptyResults:y,onSchemaChange:S,readOnly:x=!1,schema:w,sqlLabMode:_=!1}){const[C,$]=(0,n.useState)(),[k,E]=(0,n.useState)(w?{label:w,value:w,title:w}:void 0),N=(0,n.useRef)(w);N.current=w;const{addSuccessToast:L}=(0,p.e1)(),q=(0,n.useMemo)((()=>async(e,a,n)=>{const o=`/api/v1/database/?q=${r().encode({order_columns:"database_name",order_direction:"asc",page:a,page_size:n,...t||!_?{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 s.Z.get({endpoint:o}).then((({json:t})=>{const{result:a}=t;l&&l(a),0===a.length&&y&&y(e);const n=a.map((e=>({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})));return{data:n,totalCount:n.length}}))}),[t,l,_]);function M(e){E(e),S&&(null==e?void 0:e.value)!==N.current&&S(null==e?void 0:e.value)}(0,n.useEffect)((()=>{$((t=>(null==t?void 0:t.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:t))}),[e]);const{data:T,isFetching:D,refetch:U}=(0,h.Xx)({dbId:null==C?void 0:C.value,onSuccess:(e,t)=>{1===e.length?M(e[0]):e.find((e=>N.current===e.value))||M(void 0),t&&L("List refreshed")},onError:()=>i((0,o.t)("There was an error loading the schemas"))}),z=T||Z;function O(e,t){return(0,b.tZ)("div",{className:"section"},(0,b.tZ)("span",{className:"select"},e),(0,b.tZ)("span",{className:"refresh"},t))}return(0,b.tZ)(v,null,O((0,b.tZ)(d.qb,{ariaLabel:(0,o.t)("Select database or type to search databases"),optionFilterProps:["database_name","value"],header:(0,b.tZ)(u.lX,null,(0,o.t)("Database")),lazyLoading:!1,notFoundContent:a,onChange:function(e,t){$(t),E(void 0),g&&g(t),S&&S(void 0)},value:C,placeholder:(0,o.t)("Select database or type to search databases"),disabled:!c||x,options:q}),null),function(){const e=!x&&(0,b.tZ)(m.Z,{onClick:()=>U(),tooltipContent:(0,o.t)("Force refresh schema list")});return O((0,b.tZ)(d.Ph,{ariaLabel:(0,o.t)("Select schema or type to search schemas"),disabled:!C||x,header:(0,b.tZ)(u.lX,null,(0,o.t)("Schema")),labelInValue:!0,loading:D,name:"select-schema",notFoundContent:(0,o.t)("No compatible schema found"),placeholder:(0,o.t)("Select schema or type to search schemas"),onChange:e=>M(e),options:z,showSearch:!0,value:k}),e)}())}},40277:(e,t,a)=>{a.d(t,{Z:()=>i});var n=a(67294),l=a(58593),s=a(70707),o=a(11965);const i=({onClick:e,tooltipContent:t})=>{const a=(0,n.forwardRef)(((e,t)=>(0,o.tZ)(s.Z.Refresh,e)));return(0,o.tZ)(l.u,{title:t},(0,o.tZ)(a,{role:"button",onClick:e,css:e=>({cursor:"pointer",color:e.colors.grayscale.base,"&:hover":{color:e.colors.primary.base}})}))}},17982:(e,t,a)=>{a.d(t,{PH:()=>x,ZP:()=>w,ez:()=>y});var n=a(73126),l=a(67294),s=a(51995),o=a(61988),i=a(4715),r=a(49238),d=a(70707),c=a(73995),u=a(40277),m=a(79789),p=a(86057),h=a(14114),b=a(67417),v=a(98286),g=a(11965);const f=s.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  `}
`,Z=s.iK.span`
  align-items: center;
  display: flex;
  white-space: nowrap;

  svg,
  small {
    margin-right: ${({theme:e})=>e.gridUnit}px;
  }
`,y=({table:e})=>{const{value:t,type:a,extra:n}=e;return(0,g.tZ)(Z,{title:t},"view"===a?(0,g.tZ)(d.Z.Eye,{iconSize:"m"}):(0,g.tZ)(d.Z.Table,{iconSize:"m"}),(null==n?void 0:n.certification)&&(0,g.tZ)(m.Z,{certifiedBy:n.certification.certified_by,details:n.certification.details,size:"l"}),(null==n?void 0:n.warning_markdown)&&(0,g.tZ)(p.Z,{warningMarkdown:n.warning_markdown,size:"l",marginRight:4}),t)},S=({database:e,emptyState:t,formMode:a=!1,getDbList:n,handleError:s,isDatabaseSelectEnabled:d=!0,onDbChange:m,onSchemaChange:p,readOnly:Z=!1,onEmptyResults:S,schema:x,sqlLabMode:w=!0,tableSelectMode:_="single",tableValue:C,onTableSelectChange:$,customTableOptionLabelRenderer:k})=>{const{addSuccessToast:E}=(0,h.e1)(),[N,L]=(0,l.useState)(x),[q,M]=(0,l.useState)(void 0),{data:T,isFetching:D,refetch:U}=(0,b.zA)({dbId:null==e?void 0:e.id,schema:N,onSuccess:(e,t)=>{t&&E((0,o.t)("List updated"))},onError:e=>{(0,v.O$)(e).then((e=>{s((0,v.d7)((0,o.t)("There was an error loading the tables"),e))}))}}),z=(0,l.useMemo)((()=>T?T.options.map((e=>({value:e.value,label:(0,g.tZ)(y,{table:e}),text:e.value,...k&&{customLabel:k(e)}}))):[]),[T,k]);(0,l.useEffect)((()=>{void 0===e&&(L(void 0),M(void 0))}),[e,_]),(0,l.useEffect)((()=>{M("single"===_?z.find((e=>e.value===C)):(null==z?void 0:z.filter((e=>e&&(null==C?void 0:C.includes(e.value)))))||[])}),[z,C,_]);const O=e=>{N?null==$||$(Array.isArray(e)?e.map((e=>null==e?void 0:e.value)):null==e?void 0:e.value,N):M(e)},R=(0,l.useMemo)((()=>(e,t)=>{const a=e.trim().toLowerCase(),{value:n}=t;return n.toLowerCase().includes(a)}),[]);return(0,g.tZ)(f,null,(0,g.tZ)(c.Z,{db:e,emptyState:t,formMode:a,getDbList:n,handleError:s,onDbChange:Z?void 0:e=>{m&&m(e)},onEmptyResults:S,onSchemaChange:Z?void 0:e=>{L(e),p&&p(e),O("single"===_?void 0:[])},schema:N,sqlLabMode:w,isDatabaseSelectEnabled:d&&!Z,readOnly:Z}),w&&!a&&(0,g.tZ)("div",{className:"divider"}),function(){const e=N&&!a&&Z||!N,t=w?(0,g.tZ)(r.lX,null,(0,o.t)("See table schema")):(0,g.tZ)(r.lX,null,(0,o.t)("Table"));return n=(0,g.tZ)(i.Ph,{ariaLabel:(0,o.t)("Select table or type to search tables"),disabled:e,filterOption:R,header:t,labelInValue:!0,loading:D,name:"select-table",onChange:e=>O(e),options:z,placeholder:(0,o.t)("Select table or type to search tables"),showSearch:!0,mode:_,value:q,allowClear:"multiple"===_,allowSelectAll:!1}),l=!Z&&(0,g.tZ)(u.Z,{onClick:()=>U(),tooltipContent:(0,o.t)("Force refresh table list")}),(0,g.tZ)("div",{className:"section"},(0,g.tZ)("span",{className:"select"},n),(0,g.tZ)("span",{className:"refresh"},l));var n,l}())},x=e=>(0,g.tZ)(S,(0,n.Z)({tableSelectMode:"multiple"},e)),w=S},67417:(e,t,a)=>{a.d(t,{schemaEndpoints:()=>p.Kt,CN:()=>n.CN,tableEndpoints:()=>m.QD,hb:()=>r,QU:()=>d,Es:()=>c,JL:()=>u,L8:()=>b,Xx:()=>p.Xx,SJ:()=>m.SJ,uY:()=>m.uY,zA:()=>m.zA});var n=a(45673),l=a(42190),s=a(15926);function o({owners:e}){return e?e.map((e=>`${e.first_name} ${e.last_name}`)):null}const i=a.n(s)().encode({columns:["owners.first_name","owners.last_name"],keys:["none"]});function r(e){return(0,l.l6)((0,l.s_)(`/api/v1/chart/${e}?q=${i}`),o)}const d=e=>(0,l.l6)((0,l.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||[]}))),c=e=>(0,l.s_)(`/api/v1/dashboard/${e}/charts`),u=e=>(0,l.s_)(`/api/v1/dashboard/${e}/datasets`);var m=a(23936),p=a(69279);const h=a(10362).h.injectEndpoints({endpoints:e=>({queryValidations:e.query({providesTags:["QueryValidations"],query:({dbId:e,schema:t,sql:a,templateParams:n})=>{let l=n;try{l=JSON.parse(n||"")}catch(e){l=void 0}const s={schema:t,sql:a,...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:b}=h}}]);
//# sourceMappingURL=3298c61b189181f3c063.chunk.js.map