"use strict";(globalThis.webpackChunksuperset=globalThis.webpackChunksuperset||[]).push([[1862],{1862:(t,e,a)=>{a.r(e),a.d(e,{default:()=>wt});var n=a(11965),i=a(78580),o=a.n(i),l=a(15926),s=a.n(l),r=a(67294),d=a(45697),c=a.n(d),h=a(87183),u=a(57011),m=a(29487),p=a(82607),g=a(14670),b=a.n(g),f=a(51995),y=a(55867),Z=a(93185),C=a(31069),_=a(55786),v=a(37208),x=a(68135),T=a(4715),E=a(49238),S=a(35932),w=a(71262),D=a(79789),k=a(86057),A=a(73995),I=a(37921),M=a(38703),P=a(17982),L=a(38270),K=a(98286),N=a(79069),q=a(79684),$=a(42878),U=a(665),R=a(14114),B=a(70163),F=a(9870),z=a(5872),O=a.n(z),j=a(9882);function H(t,e,a){return r.Children.map(t,(t=>{let n=t;return t&&t.type.name===e.name&&(n=r.cloneElement(t,a(t))),n&&n.props.children&&(n=r.cloneElement(n,{children:H(n.props.children,e,a)})),n}))}var G=a(58593);const W=n.iv`
  .ant-form-item-control-input-content {
    display: flex;
    flex-direction: row;
  }
`;function Y(t){let{fieldKey:e,value:a,label:i,description:o=null,control:l,onChange:s=(()=>{}),compact:d=!1,inline:c}=t;const h=(0,r.useCallback)((t=>{s(e,t)}),[s,e]),u=r.cloneElement(l,{value:a,onChange:h});return(0,n.tZ)(E.xJ,{label:(0,n.tZ)(E.lX,{className:"m-r-5"},i||e,d&&o&&(0,n.tZ)(G.u,{id:"field-descr",placement:"right",title:o},(0,n.tZ)("i",{className:"fa fa-info-circle m-l-5"}))),css:c&&W},u,!d&&o&&(0,n.tZ)("div",{css:t=>({color:t.colors.grayscale.base,[c?"marginLeft":"marginTop"]:t.gridUnit})},o))}class V extends r.PureComponent{constructor(t){super(t),this.onChange=this.onChange.bind(this)}onChange(t,e){return this.props.onChange({...this.props.item,[t]:e})}render(){const{title:t}=this.props;return(0,n.tZ)(E.l0,{className:"CRUD",layout:"vertical"},t&&(0,n.tZ)("legend",null,t),H(this.props.children,Y,(t=>({onChange:this.onChange,value:this.props.item[t.props.fieldKey],compact:this.props.compact}))))}}var Q;function J(t){const e=t.map((t=>({...t,id:t.id||b().generate()}))),a={};return e.forEach((t=>{a[t.id]=t})),{collection:a,collectionArray:e}}V.defaultProps={compact:!1,title:null},function(t){t[t.asc=1]="asc",t[t.desc=2]="desc",t[t.unsort=0]="unsort"}(Q||(Q={}));const X=f.iK.div`
  ${t=>{let{stickyHeader:e}=t;return e&&"\n      height: 350px;\n      overflow-y: auto;\n      overflow-x: auto;\n\n      .table {\n        min-width: 800px;\n      }\n      thead th {\n        background: #fff;\n        position: sticky;\n        top: 0;\n        z-index: 9;\n        min\n      }\n    "}}
  ${t=>{let{theme:e}=t;return`\n    th span {\n      vertical-align: ${-2*e.gridUnit}px;\n    }\n    .text-right {\n      text-align: right;\n    }\n    .empty-collection {\n      padding: ${2*e.gridUnit+2}px;\n    }\n    .tiny-cell {\n      width: ${e.gridUnit+1}px;\n    }\n    i.fa-caret-down,\n    i.fa-caret-up {\n      width: ${e.gridUnit+1}px;\n    }\n    td.expanded {\n      border-top: 0;\n      padding: 0;\n    }\n  `}}
`,tt=f.iK.div`
  text-align: right;
  ${t=>{let{theme:e}=t;return`margin-bottom: ${2*e.gridUnit}px`}}
`,et=f.iK.span`
  ${t=>{let{theme:e}=t;return`\n    margin-top: ${3*e.gridUnit}px;\n    margin-left: ${3*e.gridUnit}px;\n  `}}
`;class at extends r.PureComponent{constructor(t){super(t);const{collection:e,collectionArray:a}=J(t.collection);this.state={expandedColumns:{},collection:e,collectionArray:a,sortColumn:"",sort:0},this.renderItem=this.renderItem.bind(this),this.onAddItem=this.onAddItem.bind(this),this.renderExpandableSection=this.renderExpandableSection.bind(this),this.getLabel=this.getLabel.bind(this),this.onFieldsetChange=this.onFieldsetChange.bind(this),this.renderTableBody=this.renderTableBody.bind(this),this.changeCollection=this.changeCollection.bind(this),this.sortColumn=this.sortColumn.bind(this),this.renderSortIcon=this.renderSortIcon.bind(this)}UNSAFE_componentWillReceiveProps(t){if(t.collection!==this.props.collection){const{collection:e,collectionArray:a}=J(t.collection);this.setState({collection:e,collectionArray:a})}}onCellChange(t,e,a){this.changeCollection({...this.state.collection,[t]:{...this.state.collection[t],[e]:a}})}onAddItem(){if(this.props.itemGenerator){let t=this.props.itemGenerator();t.id||(t={...t,id:b().generate()}),this.changeCollection(this.state.collection,t)}}onFieldsetChange(t){this.changeCollection({...this.state.collection,[t.id]:t})}getLabel(t){const{columnLabels:e}=this.props;let a=null!=e&&e[t]?e[t]:t;return a.startsWith("__")&&(a=""),a}getTooltip(t){const{columnLabelTooltips:e}=this.props;return null==e?void 0:e[t]}changeCollection(t,e){if(this.setState({collection:t}),this.props.onChange){const a=this.state.collectionArray.map((e=>t[e.id])).filter((t=>void 0!==t));e&&a.unshift(e),this.props.onChange(a)}}deleteItem(t){const e={...this.state.collection};delete e[t],this.changeCollection(e)}effectiveTableColumns(){const{tableColumns:t,allowDeletes:e,expandFieldset:a}=this.props,n=e?t.concat(["__actions"]):t;return a?["__expand"].concat(n):n}toggleExpand(t){this.onCellChange(t,"__expanded",!1),this.setState((e=>({expandedColumns:{...e.expandedColumns,[t]:!e.expandedColumns[t]}})))}sortColumn(t,e){void 0===e&&(e=Q.unsort);const{sortColumns:a}=this.props;return()=>{if(null!=a&&o()(a).call(a,t)){if(e===Q.unsort){const{collection:t}=J(this.props.collection),a=function(t){return Object.keys(t).map((e=>t[e]))}(t);return void this.setState({collectionArray:a,sortColumn:"",sort:e})}const a=[...this.state.collectionArray].sort(((e,a)=>{return n=e[t],i=a[t],"string"==typeof n?(n||" ").localeCompare(i):n-i;var n,i})),n=e===Q.asc?a:a.reverse();this.setState((a=>({...a,collectionArray:n,sortColumn:t,sort:e})))}}}renderSortIcon(t){return this.state.sortColumn===t&&this.state.sort===Q.asc?(0,n.tZ)(B.Z.SortAsc,{onClick:this.sortColumn(t,2)}):this.state.sortColumn===t&&this.state.sort===Q.desc?(0,n.tZ)(B.Z.SortDesc,{onClick:this.sortColumn(t,0)}):(0,n.tZ)(B.Z.Sort,{onClick:this.sortColumn(t,1)})}renderTH(t,e){const a=this.getTooltip(t);return(0,n.tZ)("th",{key:t,className:"no-wrap"},this.getLabel(t),a&&(0,n.tZ)(r.Fragment,null," ",(0,n.tZ)(j.V,{label:(0,y.t)("description"),tooltip:a})),(null==e?void 0:o()(e).call(e,t))&&this.renderSortIcon(t))}renderHeaderRow(){const t=this.effectiveTableColumns(),{allowDeletes:e,expandFieldset:a,extraButtons:i,sortColumns:o}=this.props;return(0,n.tZ)("thead",null,(0,n.tZ)("tr",null,a&&(0,n.tZ)("th",{"aria-label":"Expand",className:"tiny-cell"}),t.map((t=>this.renderTH(t,o))),i,e&&(0,n.tZ)("th",{key:"delete-item","aria-label":"Delete",className:"tiny-cell"})))}renderExpandableSection(t){return H(this.props.expandFieldset,V,(()=>({item:t,onChange:this.onFieldsetChange})))}getCellProps(t,e){var a;const n=null==(a=this.props.itemCellProps)?void 0:a[e],i=t[e];return n?n(i,this.getLabel(e),t):{}}renderCell(t,e){var a;const n=null==(a=this.props.itemRenderers)?void 0:a[e],i=t[e],o=this.onCellChange.bind(this,t.id,e);return n?n(i,o,this.getLabel(e),t):i}renderItem(t){const{allowAddItem:e,allowDeletes:a,expandFieldset:i,tableColumns:o}=this.props,l=!!this.state.expandedColumns[t.id]||t.__expanded;let s=[];i&&s.push((0,n.tZ)("td",{key:"__expand",className:"expand"},(0,n.tZ)("i",{role:"button","aria-label":"Toggle expand",tabIndex:0,className:`fa fa-caret-${l?"down":"right"} text-primary pointer`,onClick:this.toggleExpand.bind(this,t.id)}))),s=s.concat(o.map((e=>(0,n.tZ)("td",O()({},this.getCellProps(t,e),{key:e}),this.renderCell(t,e))))),e&&s.push((0,n.tZ)("td",{key:"add"})),a&&s.push((0,n.tZ)("td",{key:"__actions",className:"text-primary"},(0,n.tZ)(B.Z.Trash,{"aria-label":"Delete item",className:"pointer",role:"button",tabIndex:0,onClick:this.deleteItem.bind(this,t.id)})));const r=[(0,n.tZ)("tr",{"data-test":"table-row",className:"row",key:t.id},s)];return l&&r.push((0,n.tZ)("tr",{className:"exp",key:`exp__${t.id}`},(0,n.tZ)("td",{colSpan:this.effectiveTableColumns().length,className:"expanded"},(0,n.tZ)("div",null,this.renderExpandableSection(t))))),r}renderEmptyCell(){return(0,n.tZ)("tr",null,(0,n.tZ)("td",{className:"empty-collection"},this.props.emptyMessage))}renderTableBody(){const t=this.state.collectionArray,e=t.length?t.map((t=>this.renderItem(t))):this.renderEmptyCell();return(0,n.tZ)("tbody",null,e)}render(){return(0,n.tZ)(r.Fragment,null,(0,n.tZ)(tt,null,this.props.allowAddItem&&(0,n.tZ)(et,null,(0,n.tZ)(S.Z,{buttonSize:"small",buttonStyle:"tertiary",onClick:this.onAddItem},(0,n.tZ)("i",{className:"fa fa-plus"})," ",(0,y.t)("Add item")))),(0,n.tZ)(X,{className:"CRUD",stickyHeader:this.props.stickyHeader},(0,n.tZ)("table",{className:"table"},this.renderHeaderRow(),this.renderTableBody())))}}const nt=f.iK.div`
  .change-warning {
    margin: 16px 10px 0;
    color: ${t=>{let{theme:e}=t;return e.colors.warning.base}};
  }

  .change-warning .bold {
    font-weight: ${t=>{let{theme:e}=t;return e.typography.weights.bold}};
  }

  .form-group.has-feedback > .help-block {
    margin-top: 8px;
  }

  .form-group.form-group-md {
    margin-bottom: 8px;
  }
`,it=f.iK.div`
  align-items: center;
  display: flex;

  svg {
    margin-right: ${t=>{let{theme:e}=t;return e.gridUnit}}px;
  }
`,ot=(0,f.iK)(w.ZP)`
  overflow: visible;
  .ant-tabs-content-holder {
    overflow: visible;
  }
`,lt=(0,f.iK)(p.Z)`
  .ant-badge-count {
    line-height: ${t=>{let{theme:e}=t;return 4*e.gridUnit}}px;
    height: ${t=>{let{theme:e}=t;return 4*e.gridUnit}}px;
    margin-left: ${t=>{let{theme:e}=t;return e.gridUnit}}px;
  }
`,st=f.iK.div`
  font-size: ${t=>{let{theme:e}=t;return e.typography.sizes.s}}px;
  display: flex;
  align-items: center;
  a {
    padding: 0 10px;
  }
`,rt=f.iK.div`
  text-align: right;
  ${t=>{let{theme:e}=t;return`margin-bottom: ${2*e.gridUnit}px`}}
`,dt=f.iK.div`
  display: flex;
  align-items: center;
  span {
    margin-right: ${t=>{let{theme:e}=t;return e.gridUnit}}px;
  }
`,ct=f.iK.div`
  .table > tbody > tr > td {
    vertical-align: middle;
  }

  .ant-tag {
    margin-top: ${t=>{let{theme:e}=t;return e.gridUnit}}px;
  }
`,ht=f.iK.span`
  ${t=>{let{theme:e}=t;return`\n    margin-top: ${3*e.gridUnit}px;\n    margin-left: ${3*e.gridUnit}px;\n  `}}
`,ut=(t,e)=>(0,n.tZ)(N.Z,{value:t,onChange:e}),mt=[{value:"STRING",label:(0,y.t)("STRING")},{value:"NUMERIC",label:(0,y.t)("NUMERIC")},{value:"DATETIME",label:(0,y.t)("DATETIME")},{value:"BOOLEAN",label:(0,y.t)("BOOLEAN")}],pt=[{key:"physical",label:(0,y.t)("Physical (table or view)")},{key:"virtual",label:(0,y.t)("Virtual (SQL)")}],gt={};pt.forEach((t=>{gt[t.key]=t}));var bt={name:"s5xdrg",styles:"display:flex;align-items:center"};function ft(t){let{title:e,collection:a}=t;return(0,n.tZ)("div",{css:bt},e," ",(0,n.tZ)(lt,{count:a?a.length:0,showZero:!0}))}function yt(t){let{columns:e,datasource:a,onColumnsChange:i,onDatasourceChange:o,editableColumnName:l,showExpression:s,allowAddItem:d,allowEditDataType:c,itemGenerator:u,columnLabelTooltips:m}=t;return(0,n.tZ)(at,{tableColumns:(0,Z.cr)(Z.TT.ENABLE_ADVANCED_DATA_TYPES)?["column_name","advanced_data_type","type","is_dttm","main_dttm_col","filterable","groupby"]:["column_name","type","is_dttm","main_dttm_col","filterable","groupby"],sortColumns:(0,Z.cr)(Z.TT.ENABLE_ADVANCED_DATA_TYPES)?["column_name","advanced_data_type","type","is_dttm","main_dttm_col","filterable","groupby"]:["column_name","type","is_dttm","main_dttm_col","filterable","groupby"],allowDeletes:!0,allowAddItem:d,itemGenerator:u,collection:e,columnLabelTooltips:m,stickyHeader:!0,expandFieldset:(0,n.tZ)(Ct,null,(0,n.tZ)(V,{compact:!0},s&&(0,n.tZ)(Y,{fieldKey:"expression",label:(0,y.t)("SQL expression"),control:(0,n.tZ)($.Z,{language:"markdown",offerEditInModal:!1,resize:"vertical"})}),(0,n.tZ)(Y,{fieldKey:"verbose_name",label:(0,y.t)("Label"),control:(0,n.tZ)(q.Z,{controlId:"verbose_name",placeholder:(0,y.t)("Label")})}),(0,n.tZ)(Y,{fieldKey:"description",label:(0,y.t)("Description"),control:(0,n.tZ)(q.Z,{controlId:"description",placeholder:(0,y.t)("Description")})}),c&&(0,n.tZ)(Y,{fieldKey:"type",label:(0,y.t)("Data type"),control:(0,n.tZ)(T.Ph,{ariaLabel:(0,y.t)("Data type"),options:mt,name:"type",allowNewOptions:!0,allowClear:!0})}),(0,Z.cr)(Z.TT.ENABLE_ADVANCED_DATA_TYPES)?(0,n.tZ)(Y,{fieldKey:"advanced_data_type",label:(0,y.t)("Advanced data type"),control:(0,n.tZ)(q.Z,{controlId:"advanced_data_type",placeholder:(0,y.t)("Advanced Data type")})}):(0,n.tZ)(r.Fragment,null),(0,n.tZ)(Y,{fieldKey:"python_date_format",label:(0,y.t)("Datetime format"),description:(0,n.tZ)("div",null,(0,y.t)("The pattern of timestamp format. For strings use "),(0,n.tZ)("a",{href:"https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior"},(0,y.t)("Python datetime string pattern")),(0,y.t)(" expression which needs to adhere to the "),(0,n.tZ)("a",{href:"https://en.wikipedia.org/wiki/ISO_8601"},(0,y.t)("ISO 8601")),(0,y.t)(" standard to ensure that the lexicographical ordering\n                      coincides with the chronological ordering. If the\n                      timestamp format does not adhere to the ISO 8601 standard\n                      you will need to define an expression and type for\n                      transforming the string into a date or timestamp. Note\n                      currently time zones are not supported. If time is stored\n                      in epoch format, put `epoch_s` or `epoch_ms`. If no pattern\n                      is specified we fall back to using the optional defaults on a per\n                      database/column name level via the extra parameter.")),control:(0,n.tZ)(q.Z,{controlId:"python_date_format",placeholder:"%Y/%m/%d"})}),(0,n.tZ)(Y,{fieldKey:"certified_by",label:(0,y.t)("Certified By"),description:(0,y.t)("Person or group that has certified this metric"),control:(0,n.tZ)(q.Z,{controlId:"certified",placeholder:(0,y.t)("Certified by")})}),(0,n.tZ)(Y,{fieldKey:"certification_details",label:(0,y.t)("Certification details"),description:(0,y.t)("Details of the certification"),control:(0,n.tZ)(q.Z,{controlId:"certificationDetails",placeholder:(0,y.t)("Certification details")})}))),columnLabels:(0,Z.cr)(Z.TT.ENABLE_ADVANCED_DATA_TYPES)?{column_name:(0,y.t)("Column"),advanced_data_type:(0,y.t)("Advanced data type"),type:(0,y.t)("Data type"),groupby:(0,y.t)("Is dimension"),is_dttm:(0,y.t)("Is temporal"),main_dttm_col:(0,y.t)("Default datetime"),filterable:(0,y.t)("Is filterable")}:{column_name:(0,y.t)("Column"),type:(0,y.t)("Data type"),groupby:(0,y.t)("Is dimension"),is_dttm:(0,y.t)("Is temporal"),main_dttm_col:(0,y.t)("Default datetime"),filterable:(0,y.t)("Is filterable")},onChange:i,itemRenderers:(0,Z.cr)(Z.TT.ENABLE_ADVANCED_DATA_TYPES)?{column_name:(t,e,a,i)=>l?(0,n.tZ)(dt,null,i.is_certified&&(0,n.tZ)(D.Z,{certifiedBy:i.certified_by,details:i.certification_details}),(0,n.tZ)(L.Z,{canEdit:!0,title:t,onSaveTitle:e})):(0,n.tZ)(dt,null,i.is_certified&&(0,n.tZ)(D.Z,{certifiedBy:i.certified_by,details:i.certification_details}),t),main_dttm_col:(t,i,l,s)=>{const r=a.main_dttm_col===s.column_name,d=!e.find((t=>t.column_name===s.column_name)).is_dttm;return(0,n.tZ)(h.Y,{checked:r,disabled:d,onChange:()=>o({...a,main_dttm_col:s.column_name})})},type:t=>t?(0,n.tZ)(I.Z,null,t):null,advanced_data_type:t=>(0,n.tZ)(I.Z,{onChange:i},t),is_dttm:ut,filterable:ut,groupby:ut}:{column_name:(t,e,a,i)=>l?(0,n.tZ)(dt,null,i.is_certified&&(0,n.tZ)(D.Z,{certifiedBy:i.certified_by,details:i.certification_details}),(0,n.tZ)(q.Z,{value:t,onChange:e})):(0,n.tZ)(dt,null,i.is_certified&&(0,n.tZ)(D.Z,{certifiedBy:i.certified_by,details:i.certification_details}),t),main_dttm_col:(t,i,l,s)=>{const r=a.main_dttm_col===s.column_name,d=!e.find((t=>t.column_name===s.column_name)).is_dttm;return(0,n.tZ)(h.Y,{checked:r,disabled:d,onChange:()=>o({...a,main_dttm_col:s.column_name})})},type:t=>t?(0,n.tZ)(I.Z,null,t):null,is_dttm:ut,filterable:ut,groupby:ut}})}function Zt(t){let{label:e,formElement:a}=t;return(0,n.tZ)("div",null,(0,n.tZ)("div",null,(0,n.tZ)("strong",null,e)),(0,n.tZ)("div",null,a))}function Ct(t){let{children:e}=t;return(0,n.tZ)(u.Z,{padded:!0},e)}ft.propTypes={title:c().string,collection:c().array},yt.propTypes={columns:c().array.isRequired,datasource:c().object.isRequired,onColumnsChange:c().func.isRequired,onDatasourceChange:c().func.isRequired,editableColumnName:c().bool,showExpression:c().bool,allowAddItem:c().bool,allowEditDataType:c().bool,itemGenerator:c().func},yt.defaultProps={editableColumnName:!1,showExpression:!1,allowAddItem:!1,allowEditDataType:!1,itemGenerator:()=>({column_name:(0,y.t)("<new column>"),filterable:!0,groupby:!0})},Zt.propTypes={label:c().string,formElement:c().node},Ct.propTypes={children:c().node};const _t={datasource:c().object.isRequired,onChange:c().func,addSuccessToast:c().func.isRequired,addDangerToast:c().func.isRequired,setIsEditing:c().func};function vt(t){let{datasource:e,onChange:a}=t;const i=(0,r.useCallback)((function(t,e,a){void 0===t&&(t="");const n=s().encode({filter:t,page:e,page_size:a});return C.Z.get({endpoint:`/api/v1/dataset/related/owners?q=${n}`}).then((t=>({data:t.json.result.filter((t=>t.extra.active)).map((t=>({value:t.value,label:t.text}))),totalCount:t.json.count})))}),[]);return(0,n.tZ)(T.qb,{ariaLabel:(0,y.t)("Select owners"),mode:"multiple",name:"owners",value:e.owners,options:i,onChange:a,header:(0,n.tZ)(E.lX,null,(0,y.t)("Owners")),allowClear:!0})}var xt={name:"hkh81z",styles:"margin-top:8px"},Tt={name:"hkh81z",styles:"margin-top:8px"};class Et extends r.PureComponent{constructor(t){var e;super(t),this.state={datasource:{...t.datasource,owners:t.datasource.owners.map((t=>({value:t.value||t.id,label:t.label||`${t.first_name} ${t.last_name}`}))),metrics:null==(e=t.datasource.metrics)?void 0:e.map((t=>{const{certified_by:e,certification_details:a}=t,{certification:{details:n,certified_by:i}={},warning_markdown:o}=JSON.parse(t.extra||"{}")||{};return{...t,certification_details:a||n,warning_markdown:o||"",certified_by:i||e}}))},errors:[],isSqla:"table"===t.datasource.datasource_type||"table"===t.datasource.type,isEditMode:!1,databaseColumns:t.datasource.columns.filter((t=>!t.expression)),calculatedColumns:t.datasource.columns.filter((t=>!!t.expression)),metadataLoading:!1,activeTabKey:0,datasourceType:t.datasource.sql?gt.virtual.key:gt.physical.key},this.onChange=this.onChange.bind(this),this.onChangeEditMode=this.onChangeEditMode.bind(this),this.onDatasourcePropChange=this.onDatasourcePropChange.bind(this),this.onDatasourceChange=this.onDatasourceChange.bind(this),this.tableChangeAndSyncMetadata=this.tableChangeAndSyncMetadata.bind(this),this.syncMetadata=this.syncMetadata.bind(this),this.setColumns=this.setColumns.bind(this),this.validateAndChange=this.validateAndChange.bind(this),this.handleTabSelect=this.handleTabSelect.bind(this),this.allowEditSource=!(0,Z.cr)(Z.TT.DISABLE_DATASET_SOURCE_EDIT),this.currencies=(0,_.Z)(t.currencies).map((t=>({value:t,label:`${(0,v.j)({symbol:t})} (${t})`})))}onChange(){const{datasourceType:t,datasource:e}=this.state,a=t===gt.physical.key?"":e.sql,n={...this.state.datasource,sql:a,columns:[...this.state.databaseColumns,...this.state.calculatedColumns]};this.props.onChange(n,this.state.errors)}onChangeEditMode(){this.props.setIsEditing(!this.state.isEditMode),this.setState((t=>({isEditMode:!t.isEditMode})))}onDatasourceChange(t,e){void 0===e&&(e=this.validateAndChange),this.setState({datasource:t},e)}onDatasourcePropChange(t,e){if(void 0===e)return;const a={...this.state.datasource,[t]:e};this.setState((a=>({datasource:{...a.datasource,[t]:e}})),"table_name"===t?this.onDatasourceChange(a,this.tableChangeAndSyncMetadata):this.onDatasourceChange(a,this.validateAndChange))}onDatasourceTypeChange(t){this.setState({datasourceType:t})}setColumns(t){this.setState(t,this.validateAndChange)}validateAndChange(){this.validate(this.onChange)}tableChangeAndSyncMetadata(){this.validate((()=>{this.syncMetadata(),this.onChange()}))}updateColumns(t){const{databaseColumns:e}=this.state,a=t.map((t=>t.column_name)),n=e.reduce(((t,e)=>({...t,[e.column_name]:e})),{}),i=[],l={added:[],modified:[],removed:e.map((t=>t.column_name)).filter((t=>!o()(a).call(a,t)))};return t.forEach((t=>{const e=n[t.column_name];e?e.type!==t.type||!e.is_dttm&&t.is_dttm?(i.push({...e,type:t.type,is_dttm:e.is_dttm||t.is_dttm}),l.modified.push(t.column_name)):i.push(e):(i.push({id:b().generate(),column_name:t.column_name,type:t.type,groupby:!0,filterable:!0,is_dttm:t.is_dttm}),l.added.push(t.column_name))})),(l.added.length||l.modified.length||l.removed.length)&&this.setColumns({databaseColumns:i}),l}syncMetadata(){const{datasource:t}=this.state,e={datasource_type:t.type||t.datasource_type,database_name:t.database.database_name||t.database.name,schema_name:t.schema,table_name:t.table_name,normalize_columns:t.normalize_columns};Object.entries(e).forEach((t=>{let[a,n]=t;void 0===n&&(e[a]=null)}));const a=`/datasource/external_metadata_by_name/?q=${s().encode_uri(e)}`;this.setState({metadataLoading:!0}),C.Z.get({endpoint:a}).then((t=>{let{json:e}=t;const a=this.updateColumns(e);a.modified.length&&this.props.addSuccessToast((0,y.t)("Modified columns: %s",a.modified.join(", "))),a.removed.length&&this.props.addSuccessToast((0,y.t)("Removed columns: %s",a.removed.join(", "))),a.added.length&&this.props.addSuccessToast((0,y.t)("New columns added: %s",a.added.join(", "))),this.props.addSuccessToast((0,y.t)("Metadata has been synced")),this.setState({metadataLoading:!1})})).catch((t=>(0,K.O$)(t).then((t=>{let{error:e,statusText:a}=t;this.props.addDangerToast(e||a||(0,y.t)("An error has occurred")),this.setState({metadataLoading:!1})}))))}findDuplicates(t,e){const a={},n=[];return t.forEach((t=>{const i=e(t);i in a?n.push(i):a[i]=null})),n}validate(t){let e,a=[];const{datasource:n}=this.state;e=this.findDuplicates(n.columns,(t=>t.column_name)),a=a.concat(e.map((t=>(0,y.t)("Column name [%s] is duplicated",t)))),e=this.findDuplicates(n.metrics,(t=>t.metric_name)),a=a.concat(e.map((t=>(0,y.t)("Metric name [%s] is duplicated",t))));const i=this.state.calculatedColumns.filter((t=>!t.expression&&!t.json));a=a.concat(i.map((t=>(0,y.t)("Calculated column [%s] requires an expression",t.column_name))));try{var o;null==(o=this.state.datasource.metrics)||o.forEach((t=>{var e;return(null==(e=t.currency)?void 0:e.symbol)&&new Intl.NumberFormat("en-US",{style:"currency",currency:t.currency.symbol})}))}catch{a=a.concat([(0,y.t)("Invalid currency code in saved metrics")])}this.setState({errors:a},t)}handleTabSelect(t){this.setState({activeTabKey:t})}sortMetrics(t){return t.sort(((t,e)=>{let{id:a}=t,{id:n}=e;return n-a}))}renderSettingsFieldset(){const{datasource:t}=this.state;return(0,n.tZ)(V,{title:(0,y.t)("Basic"),item:t,onChange:this.onDatasourceChange},(0,n.tZ)(Y,{fieldKey:"description",label:(0,y.t)("Description"),control:(0,n.tZ)($.Z,{language:"markdown",offerEditInModal:!1,resize:"vertical"})}),(0,n.tZ)(Y,{fieldKey:"default_endpoint",label:(0,y.t)("Default URL"),description:(0,y.t)("Default URL to redirect to when accessing from the dataset list page"),control:(0,n.tZ)(q.Z,{controlId:"default_endpoint"})}),(0,n.tZ)(Y,{inline:!0,fieldKey:"filter_select_enabled",label:(0,y.t)("Autocomplete filters"),description:(0,y.t)("Whether to populate autocomplete filters options"),control:(0,n.tZ)(N.Z,null)}),this.state.isSqla&&(0,n.tZ)(Y,{fieldKey:"fetch_values_predicate",label:(0,y.t)("Autocomplete query predicate"),description:(0,y.t)('When using "Autocomplete filters", this can be used to improve performance of the query fetching the values. Use this option to apply a predicate (WHERE clause) to the query selecting the distinct values from the table. Typically the intent would be to limit the scan by applying a relative time filter on a partitioned or indexed time-related field.'),control:(0,n.tZ)($.Z,{language:"sql",controlId:"fetch_values_predicate",minLines:5,resize:"vertical"})}),this.state.isSqla&&(0,n.tZ)(Y,{fieldKey:"extra",label:(0,y.t)("Extra"),description:(0,y.t)('Extra data to specify table metadata. Currently supports metadata of the format: `{ "certification": { "certified_by": "Data Platform Team", "details": "This table is the source of truth." }, "warning_markdown": "This is a warning." }`.'),control:(0,n.tZ)($.Z,{controlId:"extra",language:"json",offerEditInModal:!1,resize:"vertical"})}),(0,n.tZ)(vt,{datasource:t,onChange:e=>{this.onDatasourceChange({...t,owners:e})}}))}renderAdvancedFieldset(){const{datasource:t}=this.state;return(0,n.tZ)(V,{title:(0,y.t)("Advanced"),item:t,onChange:this.onDatasourceChange},(0,n.tZ)(Y,{fieldKey:"cache_timeout",label:(0,y.t)("Cache timeout"),description:(0,y.t)("The duration of time in seconds before the cache is invalidated. Set to -1 to bypass the cache."),control:(0,n.tZ)(q.Z,{controlId:"cache_timeout"})}),(0,n.tZ)(Y,{fieldKey:"offset",label:(0,y.t)("Hours offset"),control:(0,n.tZ)(q.Z,{controlId:"offset"}),description:(0,y.t)("The number of hours, negative or positive, to shift the time column. This can be used to move UTC time to local time.")}),this.state.isSqla&&(0,n.tZ)(Y,{fieldKey:"template_params",label:(0,y.t)("Template parameters"),description:(0,y.t)("A set of parameters that become available in the query using Jinja templating syntax"),control:(0,n.tZ)(q.Z,{controlId:"template_params"})}),(0,n.tZ)(Y,{inline:!0,fieldKey:"normalize_columns",label:(0,y.t)("Normalize column names"),description:(0,y.t)("Allow column names to be changed to case insensitive format, if supported (e.g. Oracle, Snowflake)."),control:(0,n.tZ)(N.Z,{controlId:"normalize_columns"})}))}renderSpatialTab(){const{datasource:t}=this.state,{spatials:e,all_cols:a}=t;return(0,n.tZ)(w.ZP.TabPane,{tab:(0,n.tZ)(ft,{collection:e,title:(0,y.t)("Spatial")}),key:4},(0,n.tZ)(at,{tableColumns:["name","config"],onChange:this.onDatasourcePropChange.bind(this,"spatials"),itemGenerator:()=>({name:(0,y.t)("<new spatial>"),type:(0,y.t)("<no type>"),config:null}),collection:e,allowDeletes:!0,itemRenderers:{name:(t,e)=>(0,n.tZ)(L.Z,{canEdit:!0,title:t,onSaveTitle:e}),config:(t,e)=>(0,n.tZ)(U.Z,{value:t,onChange:e,choices:a})}}))}renderSourceFieldset(t){var e,a,i;const{datasource:o}=this.state;return(0,n.tZ)("div",null,this.allowEditSource&&(0,n.tZ)(st,null,(0,n.tZ)("span",{role:"button",tabIndex:0,onClick:this.onChangeEditMode},this.state.isEditMode?(0,n.tZ)(B.Z.LockUnlocked,{iconColor:t.colors.grayscale.base}):(0,n.tZ)(B.Z.LockLocked,{iconColor:t.colors.grayscale.base})),!this.state.isEditMode&&(0,n.tZ)("div",null,(0,y.t)("Click the lock to make changes.")),this.state.isEditMode&&(0,n.tZ)("div",null,(0,y.t)("Click the lock to prevent further changes."))),(0,n.tZ)("div",{className:"m-l-10 m-t-20 m-b-10"},pt.map((t=>(0,n.tZ)(h.Y,{key:t.key,value:t.key,inline:!0,onChange:this.onDatasourceTypeChange.bind(this,t.key),checked:this.state.datasourceType===t.key,disabled:!this.state.isEditMode},t.label)))),(0,n.tZ)("hr",null),(0,n.tZ)(V,{item:o,onChange:this.onDatasourceChange,compact:!0},this.state.datasourceType===gt.virtual.key&&(0,n.tZ)("div",null,this.state.isSqla&&(0,n.tZ)(r.Fragment,null,(0,n.tZ)(T.JX,{xs:24,md:12},(0,n.tZ)(Y,{fieldKey:"databaseSelector",label:(0,y.t)("virtual"),control:(0,n.tZ)("div",{css:xt},(0,n.tZ)(A.Z,{db:null==o?void 0:o.database,schema:o.schema,onSchemaChange:t=>this.state.isEditMode&&this.onDatasourcePropChange("schema",t),onDbChange:t=>this.state.isEditMode&&this.onDatasourcePropChange("database",t),formMode:!1,handleError:this.props.addDangerToast,readOnly:!this.state.isEditMode}))}),(0,n.tZ)("div",{css:(0,n.iv)({width:"calc(100% - 34px)",marginTop:-16},"","")},(0,n.tZ)(Y,{fieldKey:"table_name",label:(0,y.t)("Dataset name"),control:(0,n.tZ)(q.Z,{controlId:"table_name",onChange:t=>{this.onDatasourcePropChange("table_name",t)},placeholder:(0,y.t)("Dataset name"),disabled:!this.state.isEditMode})}))),(0,n.tZ)(Y,{fieldKey:"sql",label:(0,y.t)("SQL"),description:(0,y.t)("When specifying SQL, the datasource acts as a view. Superset will use this statement as a subquery while grouping and filtering on the generated parent queries."),control:(0,n.tZ)($.Z,{language:"sql",offerEditInModal:!1,minLines:20,maxLines:20,readOnly:!this.state.isEditMode,resize:"both"})}))),this.state.datasourceType===gt.physical.key&&(0,n.tZ)(T.JX,{xs:24,md:12},this.state.isSqla&&(0,n.tZ)(Y,{fieldKey:"tableSelector",label:(0,y.t)("Physical"),control:(0,n.tZ)("div",{css:Tt},(0,n.tZ)(P.ZP,{clearable:!1,database:{...o.database,database_name:(null==(e=o.database)?void 0:e.database_name)||(null==(a=o.database)?void 0:a.name)},dbId:null==(i=o.database)?void 0:i.id,handleError:this.props.addDangerToast,schema:o.schema,sqlLabMode:!1,tableValue:o.table_name,onSchemaChange:this.state.isEditMode?t=>this.onDatasourcePropChange("schema",t):void 0,onDbChange:this.state.isEditMode?t=>this.onDatasourcePropChange("database",t):void 0,onTableSelectChange:this.state.isEditMode?t=>this.onDatasourcePropChange("table_name",t):void 0,readOnly:!this.state.isEditMode})),description:(0,y.t)("The pointer to a physical table (or view). Keep in mind that the chart is associated to this Superset logical table, and this logical table points the physical table referenced here.")}))))}renderErrors(){return this.state.errors.length>0?(0,n.tZ)(m.Z,{css:t=>({marginBottom:4*t.gridUnit}),type:"error",message:(0,n.tZ)(r.Fragment,null,this.state.errors.map((t=>(0,n.tZ)("div",{key:t},t))))}):null}renderMetricCollection(){const{datasource:t}=this.state,{metrics:e}=t,a=null!=e&&e.length?this.sortMetrics(e):[];return(0,n.tZ)(at,{tableColumns:["metric_name","verbose_name","expression"],sortColumns:["metric_name","verbose_name","expression"],columnLabels:{metric_name:(0,y.t)("Metric Key"),verbose_name:(0,y.t)("Label"),expression:(0,y.t)("SQL expression")},columnLabelTooltips:{metric_name:(0,y.t)("This field is used as a unique identifier to attach the metric to charts. It is also used as the alias in the SQL query.")},expandFieldset:(0,n.tZ)(Ct,null,(0,n.tZ)(V,{compact:!0},(0,n.tZ)(Y,{fieldKey:"description",label:(0,y.t)("Description"),control:(0,n.tZ)(q.Z,{controlId:"description",placeholder:(0,y.t)("Description")})}),(0,n.tZ)(Y,{fieldKey:"d3format",label:(0,y.t)("D3 format"),control:(0,n.tZ)(q.Z,{controlId:"d3format",placeholder:"%y/%m/%d"})}),(0,n.tZ)(Y,{fieldKey:"currency",label:(0,y.t)("Metric currency"),control:(0,n.tZ)(F.Z,{currencySelectOverrideProps:{placeholder:(0,y.t)("Select or type currency symbol")},symbolSelectAdditionalStyles:n.iv`
                      max-width: 30%;
                    `})}),(0,n.tZ)(Y,{label:(0,y.t)("Certified by"),fieldKey:"certified_by",description:(0,y.t)("Person or group that has certified this metric"),control:(0,n.tZ)(q.Z,{controlId:"certified_by",placeholder:(0,y.t)("Certified by")})}),(0,n.tZ)(Y,{label:(0,y.t)("Certification details"),fieldKey:"certification_details",description:(0,y.t)("Details of the certification"),control:(0,n.tZ)(q.Z,{controlId:"certification_details",placeholder:(0,y.t)("Certification details")})}),(0,n.tZ)(Y,{label:(0,y.t)("Warning"),fieldKey:"warning_markdown",description:(0,y.t)("Optional warning about use of this metric"),control:(0,n.tZ)($.Z,{controlId:"warning_markdown",language:"markdown",offerEditInModal:!1,resize:"vertical"})}))),collection:a,allowAddItem:!0,onChange:this.onDatasourcePropChange.bind(this,"metrics"),itemGenerator:()=>({metric_name:(0,y.t)("<new metric>"),verbose_name:"",expression:""}),itemCellProps:{expression:()=>({width:"240px"})},itemRenderers:{metric_name:(t,e,a,i)=>(0,n.tZ)(it,null,i.is_certified&&(0,n.tZ)(D.Z,{certifiedBy:i.certified_by,details:i.certification_details}),i.warning_markdown&&(0,n.tZ)(k.Z,{warningMarkdown:i.warning_markdown}),(0,n.tZ)(L.Z,{canEdit:!0,title:t,onSaveTitle:e})),verbose_name:(t,e)=>(0,n.tZ)(q.Z,{canEdit:!0,value:t,onChange:e}),expression:(t,e)=>(0,n.tZ)($.Z,{canEdit:!0,initialValue:t,onChange:e,extraClasses:["datasource-sql-expression"],language:"sql",offerEditInModal:!1,minLines:5,textAreaStyles:{minWidth:"200px",maxWidth:"450px"},resize:"both"}),description:(t,e,a)=>(0,n.tZ)(Zt,{label:a,formElement:(0,n.tZ)(q.Z,{value:t,onChange:e})}),d3format:(t,e,a)=>(0,n.tZ)(Zt,{label:a,formElement:(0,n.tZ)(q.Z,{value:t,onChange:e})})},allowDeletes:!0,stickyHeader:!0})}render(){const{datasource:t,activeTabKey:e}=this.state,{metrics:a}=t,i=null!=a&&a.length?this.sortMetrics(a):[],{theme:o}=this.props;return(0,n.tZ)(nt,null,this.renderErrors(),(0,n.tZ)(m.Z,{css:t=>({marginBottom:4*t.gridUnit}),type:"warning",message:(0,n.tZ)(r.Fragment,null," ",(0,n.tZ)("strong",null,(0,y.t)("Be careful.")," "),(0,y.t)("Changing these settings will affect all charts using this dataset, including charts owned by other people."))}),(0,n.tZ)(ot,{fullWidth:!1,id:"table-tabs",onChange:this.handleTabSelect,defaultActiveKey:e},(0,n.tZ)(w.ZP.TabPane,{key:0,tab:(0,y.t)("Source")},this.renderSourceFieldset(o)),(0,n.tZ)(w.ZP.TabPane,{tab:(0,n.tZ)(ft,{collection:i,title:(0,y.t)("Metrics")}),key:1},this.renderMetricCollection()),(0,n.tZ)(w.ZP.TabPane,{tab:(0,n.tZ)(ft,{collection:this.state.databaseColumns,title:(0,y.t)("Columns")}),key:2},(0,n.tZ)(ct,null,(0,n.tZ)(rt,null,(0,n.tZ)(ht,null,(0,n.tZ)(S.Z,{buttonSize:"small",buttonStyle:"tertiary",onClick:this.syncMetadata,className:"sync-from-source",disabled:this.state.isEditMode},(0,n.tZ)("i",{className:"fa fa-database"})," ",(0,y.t)("Sync columns from source")))),(0,n.tZ)(yt,{className:"columns-table",columns:this.state.databaseColumns,datasource:t,onColumnsChange:t=>this.setColumns({databaseColumns:t}),onDatasourceChange:this.onDatasourceChange}),this.state.metadataLoading&&(0,n.tZ)(M.Z,null))),(0,n.tZ)(w.ZP.TabPane,{tab:(0,n.tZ)(ft,{collection:this.state.calculatedColumns,title:(0,y.t)("Calculated columns")}),key:3},(0,n.tZ)(ct,null,(0,n.tZ)(yt,{columns:this.state.calculatedColumns,onColumnsChange:t=>this.setColumns({calculatedColumns:t}),columnLabelTooltips:{column_name:(0,y.t)("This field is used as a unique identifier to attach the calculated dimension to charts. It is also used as the alias in the SQL query.")},onDatasourceChange:this.onDatasourceChange,datasource:t,editableColumnName:!0,showExpression:!0,allowAddItem:!0,allowEditDataType:!0,itemGenerator:()=>({column_name:(0,y.t)("<new column>"),filterable:!0,groupby:!0,expression:(0,y.t)("<enter SQL expression here>"),__expanded:!0})}))),(0,n.tZ)(w.ZP.TabPane,{key:4,tab:(0,y.t)("Settings")},(0,n.tZ)(T.X2,{gutter:16},(0,n.tZ)(T.JX,{xs:24,md:12},(0,n.tZ)(Ct,null,this.renderSettingsFieldset())),(0,n.tZ)(T.JX,{xs:24,md:12},(0,n.tZ)(Ct,null,this.renderAdvancedFieldset()))))))}}Et.defaultProps={onChange:()=>{},setIsEditing:()=>{}},Et.propTypes=_t;const St=(0,x.b)(Et),wt=(0,R.ZP)(St)},57011:(t,e,a)=>{a.d(e,{Z:()=>s});var n=a(5872),i=a.n(n),o=(a(67294),a(70302)),l=a(11965);const s=t=>{let{padded:e,...a}=t;return(0,l.tZ)(o.Z,i()({},a,{css:t=>({backgroundColor:t.colors.grayscale.light4,borderRadius:t.borderRadius,".ant-card-body":{padding:e?4*t.gridUnit:t.gridUnit}})}))}},79789:(t,e,a)=>{a.d(e,{Z:()=>d});var n=a(67294),i=a(51995),o=a(55867),l=a(70163),s=a(58593),r=a(11965);const d=function(t){let{certifiedBy:e,details:a,size:d="l"}=t;const c=(0,i.Fg)();return(0,r.tZ)(s.u,{id:"certified-details-tooltip",title:(0,r.tZ)(n.Fragment,null,e&&(0,r.tZ)("div",null,(0,r.tZ)("strong",null,(0,o.t)("Certified by %s",e))),(0,r.tZ)("div",null,a))},(0,r.tZ)(l.Z.Certified,{iconColor:c.colors.primary.base,iconSize:d}))}},38270:(t,e,a)=>{a.d(e,{Z:()=>g});var n=a(5872),i=a.n(n),o=a(67294),l=a(73727),s=a(94184),r=a.n(s),d=a(51995),c=a(55867),h=a(11965),u=a(58593),m=a(79789);const p=(0,d.iK)(m.Z)`
  vertical-align: middle;
`;function g(t){let{canEdit:e=!1,editing:a=!1,extraClasses:n,multiLine:s=!1,noPermitTooltip:d,onSaveTitle:m,showTooltip:g=!0,style:b,title:f="",defaultTitle:y="",placeholder:Z="",certifiedBy:C,certificationDetails:_,url:v,...x}=t;const[T,E]=(0,o.useState)(a),[S,w]=(0,o.useState)(f),[D,k]=(0,o.useState)(f),[A,I]=(0,o.useState)(null),M=(0,o.useRef)();function P(){if(!e||T)return;const t=M.current?M.current.getBoundingClientRect():null;E(!0),I(t)}function L(){const t=S.trim();e&&(E(!1),t.length?(D!==t&&k(t),f!==t&&m(t)):w(D))}function K(t){" "===t.key&&t.stopPropagation(),"Enter"===t.key&&(t.preventDefault(),L())}function N(t){e&&w(t.target.value)}function q(t){"Enter"===t.key&&(t.preventDefault(),L())}let $;(0,o.useEffect)((()=>{f!==S&&(k(S),w(f))}),[f]),(0,o.useEffect)((()=>{if(T&&(M.current.focus(),M.current.setSelectionRange)){const{length:t}=M.current.value;M.current.setSelectionRange(t,t),M.current.scrollLeft=M.current.scrollWidth,M.current.scrollTop=M.current.scrollHeight}}),[T]),$=S,T||S||($=y||f);const U=T&&A?{height:`${A.height}px`}:void 0;let R=s&&T?(0,h.tZ)("textarea",{ref:M,value:$,className:f?void 0:"text-muted",onKeyDown:K,onChange:N,onBlur:L,onClick:P,onKeyPress:q,placeholder:Z,style:U}):(0,h.tZ)("input",{ref:M,type:T?"text":"button",value:$,className:f?void 0:"text-muted",onKeyDown:K,onChange:N,onBlur:L,onClick:P,onKeyPress:q,placeholder:Z});return g&&!T&&(R=(0,h.tZ)(u.u,{id:"title-tooltip",title:e?(0,c.t)("Click to edit"):d||(0,c.t)("You don't have the rights to alter this title.")},R)),e||(R=v?(0,h.tZ)(l.rU,{to:v,css:t=>h.iv`
          color: ${t.colors.grayscale.dark1};
          text-decoration: none;
          :hover {
            text-decoration: underline;
          }
        `},$):(0,h.tZ)("span",null,$)),(0,h.tZ)("span",i()({className:r()("editable-title",n,e&&"editable-title--editable",T&&"editable-title--editing"),style:b},x),C&&(0,h.tZ)(o.Fragment,null,(0,h.tZ)(p,{certifiedBy:C,details:_,size:"xl"})," "),R)}}}]);
//# sourceMappingURL=14f8bd0fd1eda39c321e.chunk.js.map