(window.webpackJsonp=window.webpackJsonp||[]).push([[69],{1929:function(e,t,a){"use strict";a.d(t,"a",(function(){return h}));a(41);var s=a(115),n=a.n(s),l=a(0),o=a(5),i=a.n(o),c=a(13),r=a(51),d=a(1);function h({canEdit:e=!1,editing:t=!1,extraClasses:a,multiLine:s=!1,noPermitTooltip:o,onSaveTitle:h,showTooltip:b=!0,style:u,title:m="",defaultTitle:j="",placeholder:p=""}){const[g,O]=Object(l.useState)(t),[x,f]=Object(l.useState)(m),[y,C]=Object(l.useState)(m),[v,_]=Object(l.useState)(null),w=Object(l.useRef)();function S(){if(!e||g)return;const t=w.current?w.current.getBoundingClientRect():null;O(!0),_(t)}function E(){const t=n()(x).call(x);e&&(O(!1),t.length?(y!==t&&C(t),m!==t&&h(t)):f(y))}function T(e){" "===e.key&&e.stopPropagation(),"Enter"===e.key&&(e.preventDefault(),E())}function k(t){e&&f(t.target.value)}function D(e){"Enter"===e.key&&(e.preventDefault(),E())}let I;Object(l.useEffect)(()=>{m!==x&&(C(x),f(m))},[m]),Object(l.useEffect)(()=>{if(g&&(w.current.focus(),w.current.setSelectionRange)){const{length:e}=w.current.value;w.current.setSelectionRange(e,e),w.current.scrollLeft=w.current.scrollWidth,w.current.scrollTop=w.current.scrollHeight}},[g]),I=x,g||x||(I=j||m);const M=g&&v?{height:`${v.height}px`}:void 0;let A=s&&g?Object(d.jsx)("textarea",{ref:w,value:I,className:m?void 0:"text-muted",onKeyDown:T,onChange:k,onBlur:E,onClick:S,onKeyPress:D,placeholder:p,style:M}):Object(d.jsx)("input",{ref:w,type:g?"text":"button",value:I,className:m?void 0:"text-muted",onKeyDown:T,onChange:k,onBlur:E,onClick:S,onKeyPress:D,placeholder:p});return b&&!g&&(A=Object(d.jsx)(r.a,{id:"title-tooltip",title:e?Object(c.e)("Click to edit"):o||Object(c.e)("You don't have the rights to alter this title.")},A)),e||(A=Object(d.jsx)("span",{title:I},I)),Object(d.jsx)("span",{className:i()("editable-title",a,e&&"editable-title--editable",g&&"editable-title--editing"),style:u},A)}},2295:function(e,t,a){"use strict";a.r(t);a(41);var s=a(161),n=a.n(s),l=a(62),o=a.n(l),i=a(86),c=a.n(i),r=a(32),d=a.n(r),h=a(50),b=a.n(h),u=a(23),m=a.n(u),j=a(35),p=a.n(j),g=a(11),O=a.n(g),x=a(26),f=a.n(x),y=a(111),C=a.n(y),v=a(0),_=a.n(v),w=a(2),S=a.n(w),E=a(19),T=a(199),k=a(309),D=a(213),I=a(278),M=a(98),A=a.n(M),N=a(40),L=a(13),K=a(66),P=a(45),q=a(169),R=a(1938),F=a(726),U=a(1947),$=a(123),B=a(171),G=a(1946),H=a(1929),W=a(65),z=a(352),J=a(351),Q=a(442),Y=a(1295),V=a(1305),Z=a(1306),X=a(624),ee=a.n(X),te=a(158),ae=a.n(te),se=a(39),ne=a.n(se),le=a(31),oe=a(74);function ie(e,t,a){var s;return O()(s=_.a.Children).call(s,e,e=>{let s=e;return e&&e.type.name===t.name&&(s=_.a.cloneElement(e,a(e))),s&&s.props.children&&(s=_.a.cloneElement(s,{children:ie(s.props.children,t,a)})),s})}var ce=a(1),re=a(51);a(4827);const de=ce.css`
  .ant-form-item-control-input-content {
    display: flex;
    flex-direction: row;
  }
`;function he({fieldKey:e,value:t,label:a,description:s,control:n,onChange:l,compact:o,inline:i}){const c=Object(v.useCallback)(t=>{l(e,t)},[l,e]),r=_.a.cloneElement(n,{value:t,onChange:c});return Object(ce.jsx)(oe.b,{label:Object(ce.jsx)(oe.c,{className:"m-r-5"},a||e,o&&s&&Object(ce.jsx)(re.a,{id:"field-descr",placement:"right",title:s},Object(ce.jsx)("i",{className:"fa fa-info-circle m-l-5"}))),css:i&&de},r,!o&&s&&Object(ce.jsx)("div",{css:e=>({color:e.colors.grayscale.base,[i?"marginLeft":"marginTop"]:e.gridUnit})},s))}const be={children:S.a.node.isRequired,onChange:S.a.func,item:S.a.object,title:S.a.node,compact:S.a.bool};class ue extends _.a.PureComponent{constructor(e){var t;super(e),this.onChange=m()(t=this.onChange).call(t,this)}onChange(e,t){return this.props.onChange({...this.props.item,[e]:t})}render(){const{title:e}=this.props;return Object(ce.jsx)(oe.a,{componentClass:"fieldset",className:"CRUD",layout:"vertical"},e&&Object(ce.jsx)("legend",null,e),ie(this.props.children,he,e=>({onChange:this.onChange,value:this.props.item[e.props.fieldKey],compact:this.props.compact})))}}var me;function je(e){const t=O()(e).call(e,e=>({...e,id:e.id||A.a.generate()})),a={};return f()(t).call(t,e=>{a[e.id]=e}),{collection:a,collectionArray:t}}ue.propTypes=be,ue.defaultProps={compact:!1,title:null},function(e){e[e.asc=1]="asc",e[e.desc=2]="desc",e[e.unsort=0]="unsort"}(me||(me={}));const pe=N.g.div`
  ${({stickyHeader:e})=>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    "}
  th span {
    vertical-align: ${({theme:e})=>-2*e.gridUnit}px;
  }
`,ge=N.g.div`
  text-align: right;
  ${({theme:e})=>`margin-bottom: ${2*e.gridUnit}px`}
`;class Oe extends _.a.PureComponent{constructor(e){var t,a,s,n,l,o,i,c,r;super(e);const{collection:d,collectionArray:h}=je(e.collection);this.state={expandedColumns:{},collection:d,collectionArray:h,sortColumn:"",sort:0},this.renderItem=m()(t=this.renderItem).call(t,this),this.onAddItem=m()(a=this.onAddItem).call(a,this),this.renderExpandableSection=m()(s=this.renderExpandableSection).call(s,this),this.getLabel=m()(n=this.getLabel).call(n,this),this.onFieldsetChange=m()(l=this.onFieldsetChange).call(l,this),this.renderTableBody=m()(o=this.renderTableBody).call(o,this),this.changeCollection=m()(i=this.changeCollection).call(i,this),this.sortColumn=m()(c=this.sortColumn).call(c,this),this.renderSortIcon=m()(r=this.renderSortIcon).call(r,this)}UNSAFE_componentWillReceiveProps(e){if(e.collection!==this.props.collection){const{collection:t,collectionArray:a}=je(e.collection);this.setState({collection:t,collectionArray:a})}}onCellChange(e,t,a){this.changeCollection({...this.state.collection,[e]:{...this.state.collection[e],[t]:a}})}onAddItem(){if(this.props.itemGenerator){let e=this.props.itemGenerator();e.id||(e={...e,id:A.a.generate()}),this.changeCollection(this.state.collection,e)}}onFieldsetChange(e){this.changeCollection({...this.state.collection,[e.id]:e})}getLabel(e){const{columnLabels:t}=this.props;let a=t&&t[e]?t[e]:e;return ae()(a).call(a,"__")&&(a=""),a}changeCollection(e,t){if(this.setState({collection:e}),this.props.onChange){var a,s;const n=p()(a=O()(s=this.state.collectionArray).call(s,t=>e[t.id])).call(a,e=>void 0!==e);t&&n.unshift(t),this.props.onChange(n)}}deleteItem(e){const t={...this.state.collection};delete t[e],this.changeCollection(t)}effectiveTableColumns(){var e;const{tableColumns:t,allowDeletes:a,expandFieldset:s}=this.props,n=a?o()(t).call(t,["__actions"]):t;return s?o()(e=["__expand"]).call(e,n):n}toggleExpand(e){this.onCellChange(e,"__expanded",!1),this.setState(t=>({expandedColumns:{...t.expandedColumns,[e]:!t.expandedColumns[e]}}))}sortColumn(e,t=me.unsort){const{sortColumns:a}=this.props;return()=>{if(null!=a&&d()(a).call(a,e)){var s;if(t===me.unsort){const{collection:e}=je(this.props.collection),a=function(e){var t;return O()(t=ne()(e)).call(t,t=>e[t])}(e);return void this.setState({collectionArray:a,sortColumn:"",sort:t})}const a=n()(s=[...this.state.collectionArray]).call(s,(t,a)=>{return s=t[e],n=a[e],"string"==typeof s?(s||" ").localeCompare(n):s-n;var s,n}),l=t===me.asc?a:ee()(a).call(a);this.setState(a=>({...a,collectionArray:l,sortColumn:e,sort:t}))}}}renderSortIcon(e){return this.state.sortColumn===e&&n()(this.state)===me.asc?Object(ce.jsx)(le.a.SortAsc,{onClick:this.sortColumn(e,2)}):this.state.sortColumn===e&&n()(this.state)===me.desc?Object(ce.jsx)(le.a.SortDesc,{onClick:this.sortColumn(e,0)}):Object(ce.jsx)(le.a.Sort,{onClick:this.sortColumn(e,1)})}renderHeaderRow(){const e=this.effectiveTableColumns(),{allowDeletes:t,expandFieldset:a,extraButtons:s,sortColumns:n}=this.props;return Object(ce.jsx)("thead",null,Object(ce.jsx)("tr",null,a&&Object(ce.jsx)("th",{"aria-label":"Expand",className:"tiny-cell"}),O()(e).call(e,e=>Object(ce.jsx)("th",{key:e},this.getLabel(e),(null==n?void 0:d()(n).call(n,e))&&this.renderSortIcon(e))),s,t&&Object(ce.jsx)("th",{key:"delete-item","aria-label":"Delete",className:"tiny-cell"})))}renderExpandableSection(e){return ie(this.props.expandFieldset,ue,()=>({item:e,onChange:this.onFieldsetChange}))}renderCell(e,t){var a;const s=this.props.itemRenderers&&this.props.itemRenderers[t],n=e[t],l=m()(a=this.onCellChange).call(a,this,e.id,t);return s?s(n,l,this.getLabel(t),e):n}renderItem(e){const{allowAddItem:t,allowDeletes:a,expandFieldset:s,tableColumns:n}=this.props,l=!!this.state.expandedColumns[e.id]||e.__expanded;let i=[];var c,r;s&&i.push(Object(ce.jsx)("td",{key:"__expand",className:"expand"},Object(ce.jsx)("i",{role:"button","aria-label":"Toggle expand",tabIndex:0,className:`fa fa-caret-${l?"down":"right"} text-primary pointer`,onClick:m()(c=this.toggleExpand).call(c,this,e.id)})));(i=o()(i).call(i,O()(n).call(n,t=>Object(ce.jsx)("td",{key:t},this.renderCell(e,t)))),t&&i.push(Object(ce.jsx)("td",{key:"add"})),a)&&i.push(Object(ce.jsx)("td",{key:"__actions",className:"text-primary"},Object(ce.jsx)(le.a.Trash,{"aria-label":"Delete item",className:"pointer",role:"button",tabIndex:0,onClick:m()(r=this.deleteItem).call(r,this,e.id)})));const d=[Object(ce.jsx)("tr",{"data-test":"table-row",className:"row",key:e.id},i)];return l&&d.push(Object(ce.jsx)("tr",{className:"exp",key:`exp__${e.id}`},Object(ce.jsx)("td",{colSpan:this.effectiveTableColumns().length,className:"expanded"},Object(ce.jsx)("div",null,this.renderExpandableSection(e))))),d}renderEmptyCell(){return Object(ce.jsx)("tr",null,Object(ce.jsx)("td",{className:"empty-collection"},this.props.emptyMessage))}renderTableBody(){const e=this.state.collectionArray,t=e.length?O()(e).call(e,e=>this.renderItem(e)):this.renderEmptyCell();return Object(ce.jsx)("tbody",null,t)}render(){return Object(ce.jsx)(_.a.Fragment,null,Object(ce.jsx)(ge,null,this.props.allowAddItem&&Object(ce.jsx)("span",{className:"m-t-10 m-r-10"},Object(ce.jsx)(P.a,{buttonSize:"small",buttonStyle:"tertiary",onClick:this.onAddItem},Object(ce.jsx)("i",{className:"fa fa-plus"})," ",Object(L.e)("Add item")))),Object(ce.jsx)(pe,{className:"CRUD",stickyHeader:this.props.stickyHeader},Object(ce.jsx)("table",{className:"table"},this.renderHeaderRow(),this.renderTableBody())))}}var xe=a(142),fe=a(42);const ye=N.g.div`
  .change-warning {
    margin: 16px 10px 0;
    color: ${({theme:e})=>e.colors.warning.base};
  }

  .change-warning .bold {
    font-weight: ${({theme:e})=>e.typography.weights.bold};
  }

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

  .form-group.form-group-md {
    margin-bottom: 8px;
  }
`,Ce=N.g.div`
  align-items: center;
  display: flex;

  svg {
    margin-right: ${({theme:e})=>e.gridUnit}px;
  }
`,ve=Object(N.g)(q.c)`
  overflow: visible;
  .ant-tabs-content-holder {
    overflow: visible;
  }
`,_e=Object(N.g)(I.a)`
  .ant-badge-count {
    line-height: ${({theme:e})=>4*e.gridUnit}px;
    height: ${({theme:e})=>4*e.gridUnit}px;
    margin-left: ${({theme:e})=>e.gridUnit}px;
  }
`,we=N.g.div`
  font-size: ${N.h.typography.sizes.s}px;
  display: flex;
  align-items: center;
  a {
    padding: 0 10px;
  }
`,Se=N.g.div`
  text-align: right;
  ${({theme:e})=>`margin-bottom: ${2*e.gridUnit}px`}
`,Ee=(e,t)=>Object(ce.jsx)(z.a,{value:e,onChange:t}),Te=["STRING","NUMERIC","DATETIME","BOOLEAN"],ke=[{key:"physical",label:Object(L.e)("Physical (table or view)")},{key:"virtual",label:Object(L.e)("Virtual (SQL)")}],De={};f()(ke).call(ke,e=>{De[e.key]=e});var Ie={name:"s5xdrg",styles:"display:flex;align-items:center"};function Me({title:e,collection:t}){return Object(ce.jsx)("div",{css:Ie},e," ",Object(ce.jsx)(_e,{count:t?t.length:0,showZero:!0}))}function Ae({columns:e,onChange:t,editableColumnName:a,showExpression:s,allowAddItem:n,allowEditDataType:l,itemGenerator:o}){return Object(ce.jsx)(Oe,{collection:e,tableColumns:["column_name","type","is_dttm","filterable","groupby"],sortColumns:["column_name","type","is_dttm","filterable","groupby"],allowDeletes:!0,allowAddItem:n,itemGenerator:o,stickyHeader:!0,expandFieldset:Object(ce.jsx)(Le,null,Object(ce.jsx)(ue,{compact:!0},s&&Object(ce.jsx)(he,{fieldKey:"expression",label:Object(L.e)("SQL expression"),control:Object(ce.jsx)(Y.a,{language:"markdown",offerEditInModal:!1})}),Object(ce.jsx)(he,{fieldKey:"verbose_name",label:Object(L.e)("Label"),control:Object(ce.jsx)(J.a,{controlId:"verbose_name",placeholder:Object(L.e)("Label")})}),Object(ce.jsx)(he,{fieldKey:"description",label:Object(L.e)("Description"),control:Object(ce.jsx)(J.a,{controlId:"description",placeholder:Object(L.e)("Description")})}),l&&Object(ce.jsx)(he,{fieldKey:"type",label:Object(L.e)("Data type"),control:Object(ce.jsx)(Q.a,{choices:Te,name:"type",freeForm:!0})}),Object(ce.jsx)(he,{fieldKey:"python_date_format",label:Object(L.e)("Datetime format"),description:Object(ce.jsx)("div",null,Object(L.e)("The pattern of timestamp format. For strings use "),Object(ce.jsx)("a",{href:"https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior"},Object(L.e)("Python datetime string pattern")),Object(L.e)(" expression which needs to adhere to the "),Object(ce.jsx)("a",{href:"https://en.wikipedia.org/wiki/ISO_8601"},Object(L.e)("ISO 8601")),Object(L.e)(" 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:Object(ce.jsx)(J.a,{controlId:"python_date_format",placeholder:"%Y/%m/%d"})}))),columnLabels:{column_name:Object(L.e)("Column"),type:Object(L.e)("Data type"),groupby:Object(L.e)("Is dimension"),is_dttm:Object(L.e)("Is temporal"),filterable:Object(L.e)("Is filterable")},onChange:t,itemRenderers:{column_name:(e,t)=>a?Object(ce.jsx)(H.a,{canEdit:!0,title:e,onSaveTitle:t}):e,type:e=>e?Object(ce.jsx)($.a,null,e):null,is_dttm:Ee,filterable:Ee,groupby:Ee}})}function Ne({label:e,formElement:t}){return Object(ce.jsx)("div",null,Object(ce.jsx)("div",null,Object(ce.jsx)("strong",null,e)),Object(ce.jsx)("div",null,t))}function Le({children:e}){return Object(ce.jsx)(k.a,{padded:!0},e)}Me.propTypes={title:S.a.string,collection:S.a.array},Ae.propTypes={columns:S.a.array.isRequired,onChange:S.a.func.isRequired,editableColumnName:S.a.bool,showExpression:S.a.bool,allowAddItem:S.a.bool,allowEditDataType:S.a.bool,itemGenerator:S.a.func},Ae.defaultProps={editableColumnName:!1,showExpression:!1,allowAddItem:!1,allowEditDataType:!1,itemGenerator:()=>({column_name:"<new column>",filterable:!0,groupby:!0})},Ne.propTypes={label:S.a.string,formElement:S.a.node},Le.propTypes={children:S.a.node};const Ke={datasource:S.a.object.isRequired,onChange:S.a.func,addSuccessToast:S.a.func.isRequired,addDangerToast:S.a.func.isRequired};class Pe extends _.a.PureComponent{constructor(e){var t,a,s,n,l,o,i,c,r,d,h,b;super(e),this.state={datasource:{...e.datasource,metrics:null==(t=e.datasource.metrics)?void 0:O()(t).call(t,e=>{const{certification:{details:t,certified_by:a}={},warning_markdown:s}=JSON.parse(e.extra||"{}")||{};return{...e,certification_details:t||"",warning_markdown:s||"",certified_by:a}})},errors:[],isDruid:"druid"===e.datasource.type||"druid"===e.datasource.datasource_type,isSqla:"table"===e.datasource.datasource_type||"table"===e.datasource.type,isEditMode:!1,databaseColumns:p()(a=e.datasource.columns).call(a,e=>!e.expression),calculatedColumns:p()(s=e.datasource.columns).call(s,e=>!!e.expression),metadataLoading:!1,activeTabKey:0,datasourceType:e.datasource.sql?De.virtual.key:De.physical.key},this.onChange=m()(n=this.onChange).call(n,this),this.onChangeEditMode=m()(l=this.onChangeEditMode).call(l,this),this.onDatasourcePropChange=m()(o=this.onDatasourcePropChange).call(o,this),this.onDatasourceChange=m()(i=this.onDatasourceChange).call(i,this),this.tableChangeAndSyncMetadata=m()(c=this.tableChangeAndSyncMetadata).call(c,this),this.syncMetadata=m()(r=this.syncMetadata).call(r,this),this.setColumns=m()(d=this.setColumns).call(d,this),this.validateAndChange=m()(h=this.validateAndChange).call(h,this),this.handleTabSelect=m()(b=this.handleTabSelect).call(b,this),this.allowEditSource=!Object(fe.c)(fe.a.DISABLE_DATASET_SOURCE_EDIT)}onChange(){const{datasourceType:e,datasource:t}=this.state,a=e===De.physical.key?"":t.sql,s={...this.state.datasource,sql:a,columns:[...this.state.databaseColumns,...this.state.calculatedColumns]};this.props.onChange(s,this.state.errors)}onChangeEditMode(){this.setState(e=>({isEditMode:!e.isEditMode}))}onDatasourceChange(e,t=this.validateAndChange){this.setState({datasource:e},t)}onDatasourcePropChange(e,t){const a={...this.state.datasource,[e]:t};this.setState(a=>({datasource:{...a.datasource,[e]:t}}),"table_name"===e?this.onDatasourceChange(a,this.tableChangeAndSyncMetadata):this.onDatasourceChange(a,this.validateAndChange))}onDatasourceTypeChange(e){this.setState({datasourceType:e})}setColumns(e){this.setState(e,this.validateAndChange)}validateAndChange(){this.validate(this.onChange)}tableChangeAndSyncMetadata(){this.validate(()=>{this.syncMetadata(),this.onChange()})}updateColumns(e){var t;const{databaseColumns:a}=this.state,s=O()(e).call(e,e=>e.name),n=b()(a).call(a,(e,t)=>({...e,[t.column_name]:t}),{}),l=[],o={added:[],modified:[],removed:p()(t=O()(a).call(a,e=>e.column_name)).call(t,e=>!d()(s).call(s,e))};return f()(e).call(e,e=>{const t=n[e.name];t?t.type!==e.type||!t.is_dttm&&e.is_dttm?(l.push({...t,type:e.type,is_dttm:t.is_dttm||e.is_dttm}),o.modified.push(e.name)):l.push(t):(l.push({id:A.a.generate(),column_name:e.name,type:e.type,groupby:!0,filterable:!0,is_dttm:e.is_dttm}),o.added.push(e.name))}),(o.added.length||o.modified.length||o.removed.length)&&this.setColumns({databaseColumns:l}),o}syncMetadata(){var e;const{datasource:t}=this.state,a={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};f()(e=c()(a)).call(e,([e,t])=>{void 0===t&&(a[e]=null)});const s=`/datasource/external_metadata_by_name/?q=${C.a.encode(a)}`;this.setState({metadataLoading:!0}),K.a.get({endpoint:s}).then(({json:e})=>{const t=this.updateColumns(e);t.modified.length&&this.props.addSuccessToast(Object(L.e)("Modified columns: %s",t.modified.join(", "))),t.removed.length&&this.props.addSuccessToast(Object(L.e)("Removed columns: %s",t.removed.join(", "))),t.added.length&&this.props.addSuccessToast(Object(L.e)("New columns added: %s",t.added.join(", "))),this.props.addSuccessToast(Object(L.e)("Metadata has been synced")),this.setState({metadataLoading:!1})}).catch(e=>Object(W.a)(e).then(({error:e,statusText:t})=>{this.props.addDangerToast(e||t||Object(L.e)("An error has occurred")),this.setState({metadataLoading:!1})}))}findDuplicates(e,t){const a={},s=[];return f()(e).call(e,e=>{const n=t(e);n in a?s.push(n):a[n]=null}),s}validate(e){var t;let a,s=[];const{datasource:n}=this.state;a=this.findDuplicates(n.columns,e=>e.column_name),s=o()(s).call(s,O()(a).call(a,e=>Object(L.e)("Column name [%s] is duplicated",e))),a=this.findDuplicates(n.metrics,e=>e.metric_name),s=o()(s).call(s,O()(a).call(a,e=>Object(L.e)("Metric name [%s] is duplicated",e)));const l=p()(t=this.state.calculatedColumns).call(t,e=>!e.expression&&!e.json);s=o()(s).call(s,O()(l).call(l,e=>Object(L.e)("Calculated column [%s] requires an expression",e.column_name))),this.setState({errors:s},e)}handleTabSelect(e){this.setState({activeTabKey:e})}sortMetrics(e){return n()(e).call(e,({id:e},{id:t})=>t-e)}renderSettingsFieldset(){const{datasource:e}=this.state;return Object(ce.jsx)(ue,{title:Object(L.e)("Basic"),item:e,onChange:this.onDatasourceChange},Object(ce.jsx)(he,{fieldKey:"description",label:Object(L.e)("Description"),control:Object(ce.jsx)(Y.a,{language:"markdown",offerEditInModal:!1})}),Object(ce.jsx)(he,{fieldKey:"default_endpoint",label:Object(L.e)("Default URL"),description:Object(L.e)("Default URL to redirect to when accessing from the dataset list page"),control:Object(ce.jsx)(J.a,{controlId:"default_endpoint"})}),Object(ce.jsx)(he,{inline:!0,fieldKey:"filter_select_enabled",label:Object(L.e)("Autocomplete filters"),description:Object(L.e)("Whether to populate autocomplete filters options"),control:Object(ce.jsx)(z.a,null)}),this.state.isSqla&&Object(ce.jsx)(he,{fieldKey:"fetch_values_predicate",label:Object(L.e)("Autocomplete query predicate"),description:Object(L.e)('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:Object(ce.jsx)(Y.a,{language:"sql",controlId:"fetch_values_predicate",minLines:5})}),this.state.isSqla&&Object(ce.jsx)(he,{fieldKey:"extra",label:Object(L.e)("Extra"),description:Object(L.e)('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:Object(ce.jsx)(Y.a,{controlId:"extra",language:"json",offerEditInModal:!1})}),Object(ce.jsx)(he,{fieldKey:"owners",label:Object(L.e)("Owners"),description:Object(L.e)("Owners of the dataset"),control:Object(ce.jsx)(V.a,{dataEndpoint:"api/v1/dataset/related/owners",multi:!0,mutator:e=>{var t;return O()(t=e.result).call(t,e=>({value:e.value,label:`${e.text}`}))}}),controlProps:{}}))}renderAdvancedFieldset(){const{datasource:e}=this.state;return Object(ce.jsx)(ue,{title:Object(L.e)("Advanced"),item:e,onChange:this.onDatasourceChange},Object(ce.jsx)(he,{fieldKey:"cache_timeout",label:Object(L.e)("Cache timeout"),description:Object(L.e)("The duration of time in seconds before the cache is invalidated"),control:Object(ce.jsx)(J.a,{controlId:"cache_timeout"})}),Object(ce.jsx)(he,{fieldKey:"offset",label:Object(L.e)("Hours offset"),control:Object(ce.jsx)(J.a,{controlId:"offset"}),description:Object(L.e)("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&&Object(ce.jsx)(he,{fieldKey:"template_params",label:Object(L.e)("Template parameters"),description:Object(L.e)("A set of parameters that become available in the query using Jinja templating syntax"),control:Object(ce.jsx)(J.a,{controlId:"template_params"})}))}renderSpatialTab(){var e;const{datasource:t}=this.state,{spatials:a,all_cols:s}=t;return Object(ce.jsx)(q.c.TabPane,{tab:Object(ce.jsx)(Me,{collection:a,title:Object(L.e)("Spatial")}),key:4},Object(ce.jsx)(Oe,{tableColumns:["name","config"],onChange:m()(e=this.onDatasourcePropChange).call(e,this,"spatials"),itemGenerator:()=>({name:"<new spatial>",type:"<no type>",config:null}),collection:a,allowDeletes:!0,itemRenderers:{name:(e,t)=>Object(ce.jsx)(H.a,{canEdit:!0,title:e,onSaveTitle:t}),config:(e,t)=>Object(ce.jsx)(Z.a,{value:e,onChange:t,choices:s})}}))}renderSourceFieldset(){const{datasource:e}=this.state;return Object(ce.jsx)("div",null,Object(ce.jsx)("div",{className:"m-l-10 m-t-20 m-b-10"},O()(ke).call(ke,e=>{var t;return Object(ce.jsx)(T.a,{key:e.key,value:e.key,inline:!0,onChange:m()(t=this.onDatasourceTypeChange).call(t,this,e.key),checked:this.state.datasourceType===e.key,disabled:!this.state.isEditMode},e.label)})),Object(ce.jsx)("hr",null),Object(ce.jsx)(ue,{item:e,onChange:this.onDatasourceChange,compact:!0},this.state.datasourceType===De.virtual.key&&Object(ce.jsx)("div",null,this.state.isSqla&&Object(ce.jsx)(_.a.Fragment,null,Object(ce.jsx)(he,{fieldKey:"databaseSelector",label:Object(L.e)("virtual"),control:Object(ce.jsx)(U.a,{dbId:e.database.id,schema:e.schema,onSchemaChange:e=>this.state.isEditMode&&this.onDatasourcePropChange("schema",e),onDbChange:e=>this.state.isEditMode&&this.onDatasourcePropChange("database",e),formMode:!1,handleError:this.props.addDangerToast,readOnly:!this.state.isEditMode})}),Object(ce.jsx)(he,{fieldKey:"table_name",label:Object(L.e)("Dataset name"),control:Object(ce.jsx)(J.a,{controlId:"table_name",onChange:e=>{this.onDatasourcePropChange("table_name",e)},placeholder:Object(L.e)("Dataset name"),disabled:!this.state.isEditMode})}),Object(ce.jsx)(he,{fieldKey:"sql",label:Object(L.e)("SQL"),description:Object(L.e)("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:Object(ce.jsx)(Y.a,{language:"sql",offerEditInModal:!1,minLines:20,maxLines:20,readOnly:!this.state.isEditMode})})),this.state.isDruid&&Object(ce.jsx)(he,{fieldKey:"json",label:Object(L.e)("JSON"),description:Object(ce.jsx)("div",null,Object(L.e)("The JSON metric or post aggregation definition.")),control:Object(ce.jsx)(Y.a,{language:"json",offerEditInModal:!1})})),this.state.datasourceType===De.physical.key&&Object(ce.jsx)(E.g,{xs:24,md:12},this.state.isSqla&&Object(ce.jsx)(he,{fieldKey:"tableSelector",label:Object(L.e)("Physical"),control:Object(ce.jsx)(G.a,{clearable:!1,dbId:e.database.id,handleError:this.props.addDangerToast,schema:e.schema,sqlLabMode:!1,tableName:e.table_name,onSchemaChange:this.state.isEditMode?e=>this.onDatasourcePropChange("schema",e):void 0,onDbChange:this.state.isEditMode?e=>this.onDatasourcePropChange("database",e):void 0,onTableChange:this.state.isEditMode?e=>this.onDatasourcePropChange("table_name",e):void 0,readOnly:!this.state.isEditMode}),description:Object(L.e)("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.")}))),this.allowEditSource&&Object(ce.jsx)(we,null,Object(ce.jsx)("span",{role:"button",tabIndex:0,onClick:this.onChangeEditMode},this.state.isEditMode?Object(ce.jsx)(le.a.LockUnlocked,{iconColor:N.h.colors.grayscale.base}):Object(ce.jsx)(le.a.LockLocked,{iconColor:N.h.colors.grayscale.base})),!this.state.isEditMode&&Object(ce.jsx)("div",null,Object(L.e)("Click the lock to make changes.")),this.state.isEditMode&&Object(ce.jsx)("div",null,Object(L.e)("Click the lock to prevent further changes."))))}renderErrors(){var e;return this.state.errors.length>0?Object(ce.jsx)(D.a,{css:e=>({marginBottom:4*e.gridUnit}),type:"error",message:Object(ce.jsx)(_.a.Fragment,null,O()(e=this.state.errors).call(e,e=>Object(ce.jsx)("div",{key:e},e)))}):null}renderMetricCollection(){var e;const{datasource:t}=this.state,{metrics:a}=t,s=null!=a&&a.length?this.sortMetrics(a):[];return Object(ce.jsx)(Oe,{tableColumns:["metric_name","verbose_name","expression"],sortColumns:["metric_name","verbose_name","expression"],columnLabels:{metric_name:Object(L.e)("Metric"),verbose_name:Object(L.e)("Label"),expression:Object(L.e)("SQL expression")},expandFieldset:Object(ce.jsx)(Le,null,Object(ce.jsx)(ue,{compact:!0},Object(ce.jsx)(he,{fieldKey:"verbose_name",label:Object(L.e)("Label"),control:Object(ce.jsx)(J.a,{controlId:"verbose_name"})}),Object(ce.jsx)(he,{fieldKey:"description",label:Object(L.e)("Description"),control:Object(ce.jsx)(J.a,{controlId:"description",placeholder:Object(L.e)("Description")})}),Object(ce.jsx)(he,{fieldKey:"d3format",label:Object(L.e)("D3 format"),control:Object(ce.jsx)(J.a,{controlId:"d3format",placeholder:"%y/%m/%d"})}),Object(ce.jsx)(he,{label:Object(L.e)("Certified by"),fieldKey:"certified_by",description:Object(L.e)("Person or group that has certified this metric"),control:Object(ce.jsx)(J.a,{controlId:"certified_by",placeholder:Object(L.e)("Certified by")})}),Object(ce.jsx)(he,{label:Object(L.e)("Certification details"),fieldKey:"certification_details",description:Object(L.e)("Details of the certification"),control:Object(ce.jsx)(J.a,{controlId:"certification_details",placeholder:Object(L.e)("Certification details")})}),Object(ce.jsx)(he,{label:Object(L.e)("Warning"),fieldKey:"warning_markdown",description:Object(L.e)("Optional warning about use of this metric"),control:Object(ce.jsx)(Y.a,{controlId:"warning_markdown",language:"markdown",offerEditInModal:!1})}))),collection:s,allowAddItem:!0,onChange:m()(e=this.onDatasourcePropChange).call(e,this,"metrics"),itemGenerator:()=>({metric_name:"<new metric>",verbose_name:"",expression:""}),itemRenderers:{metric_name:(e,t,a,s)=>Object(ce.jsx)(Ce,null,s.is_certified&&Object(ce.jsx)(R.a,{certifiedBy:s.certified_by,details:s.certification_details}),s.warning_markdown&&Object(ce.jsx)(F.a,{warningMarkdown:s.warning_markdown}),Object(ce.jsx)(H.a,{canEdit:!0,title:e,onSaveTitle:t})),verbose_name:(e,t)=>Object(ce.jsx)(H.a,{canEdit:!0,title:e,onSaveTitle:t}),expression:(e,t)=>Object(ce.jsx)(H.a,{canEdit:!0,title:e,onSaveTitle:t,extraClasses:["datasource-sql-expression"],multiLine:!0}),description:(e,t,a)=>Object(ce.jsx)(Ne,{label:a,formElement:Object(ce.jsx)(J.a,{value:e,onChange:t})}),d3format:(e,t,a)=>Object(ce.jsx)(Ne,{label:a,formElement:Object(ce.jsx)(J.a,{value:e,onChange:t})})},allowDeletes:!0,stickyHeader:!0})}render(){const{datasource:e,activeTabKey:t}=this.state,{metrics:a}=e,s=null!=a&&a.length?this.sortMetrics(a):[];return Object(ce.jsx)(ye,null,this.renderErrors(),Object(ce.jsx)(D.a,{css:e=>({marginBottom:4*e.gridUnit}),type:"warning",message:Object(ce.jsx)(_.a.Fragment,null," ",Object(ce.jsx)("strong",null,Object(L.e)("Be careful.")," "),Object(L.e)("Changing these settings will affect all charts using this dataset, including charts owned by other people."))}),Object(ce.jsx)(ve,{fullWidth:!1,id:"table-tabs",onChange:this.handleTabSelect,defaultActiveKey:t},Object(ce.jsx)(q.c.TabPane,{key:0,tab:Object(L.e)("Source")},this.renderSourceFieldset()),Object(ce.jsx)(q.c.TabPane,{tab:Object(ce.jsx)(Me,{collection:s,title:Object(L.e)("Metrics")}),key:1},this.renderMetricCollection()),Object(ce.jsx)(q.c.TabPane,{tab:Object(ce.jsx)(Me,{collection:this.state.databaseColumns,title:Object(L.e)("Columns")}),key:2},Object(ce.jsx)("div",null,Object(ce.jsx)(Se,null,Object(ce.jsx)("span",{className:"m-t-10 m-r-10"},Object(ce.jsx)(P.a,{buttonSize:"small",buttonStyle:"tertiary",onClick:this.syncMetadata,className:"sync-from-source",disabled:this.state.isEditMode},Object(ce.jsx)("i",{className:"fa fa-database"})," ",Object(L.e)("Sync columns from source")))),Object(ce.jsx)(Ae,{className:"columns-table",columns:this.state.databaseColumns,onChange:e=>this.setColumns({databaseColumns:e})}),this.state.metadataLoading&&Object(ce.jsx)(B.a,null))),Object(ce.jsx)(q.c.TabPane,{tab:Object(ce.jsx)(Me,{collection:this.state.calculatedColumns,title:Object(L.e)("Calculated columns")}),key:3},Object(ce.jsx)(Ae,{columns:this.state.calculatedColumns,onChange:e=>this.setColumns({calculatedColumns:e}),editableColumnName:!0,showExpression:!0,allowAddItem:!0,allowEditDataType:!0,itemGenerator:()=>({column_name:"<new column>",filterable:!0,groupby:!0,expression:"<enter SQL expression here>",__expanded:!0})})),Object(ce.jsx)(q.c.TabPane,{key:4,tab:Object(L.e)("Settings")},Object(ce.jsx)(E.t,{gutter:16},Object(ce.jsx)(E.g,{xs:24,md:12},Object(ce.jsx)(Le,null,this.renderSettingsFieldset())),Object(ce.jsx)(E.g,{xs:24,md:12},Object(ce.jsx)(Le,null,this.renderAdvancedFieldset()))))))}}Pe.defaultProps={onChange:()=>{}},Pe.propTypes=Ke;t.default=Object(xe.a)(Pe)},4827:function(e,t,a){}}]);