datajunction-ui
Version:
DataJunction UI
3 lines (2 loc) • 49.4 kB
JavaScript
"use strict";const e=require("react/jsx-runtime"),u=require("react"),Qe=require("react-router-dom"),de=require("./index-h1A5IisM.cjs"),Ne={hljs:{display:"block",overflowX:"auto",padding:"0.5em",color:"#383a42",background:"#fafafa"},"hljs-comment":{color:"#a0a1a7",fontStyle:"italic"},"hljs-quote":{color:"#a0a1a7",fontStyle:"italic"},"hljs-doctag":{color:"#a626a4"},"hljs-keyword":{color:"#a626a4"},"hljs-formula":{color:"#a626a4"},"hljs-section":{color:"#e45649"},"hljs-name":{color:"#e45649"},"hljs-selector-tag":{color:"#e45649"},"hljs-deletion":{color:"#e45649"},"hljs-subst":{color:"#e45649"},"hljs-literal":{color:"#0184bb"},"hljs-string":{color:"#50a14f"},"hljs-regexp":{color:"#50a14f"},"hljs-addition":{color:"#50a14f"},"hljs-attribute":{color:"#50a14f"},"hljs-meta-string":{color:"#50a14f"},"hljs-built_in":{color:"#c18401"},"hljs-class .hljs-title":{color:"#c18401"},"hljs-attr":{color:"#986801"},"hljs-variable":{color:"#986801"},"hljs-template-variable":{color:"#986801"},"hljs-type":{color:"#986801"},"hljs-selector-class":{color:"#986801"},"hljs-selector-attr":{color:"#986801"},"hljs-selector-pseudo":{color:"#986801"},"hljs-number":{color:"#986801"},"hljs-symbol":{color:"#4078f2"},"hljs-bullet":{color:"#4078f2"},"hljs-link":{color:"#4078f2",textDecoration:"underline"},"hljs-meta":{color:"#4078f2"},"hljs-selector-id":{color:"#4078f2"},"hljs-title":{color:"#4078f2"},"hljs-emphasis":{fontStyle:"italic"},"hljs-strong":{fontWeight:"bold"}};function ns(l){const h=l.split("[")[0],o=h.split(".");return o.length>1?o.slice(0,-1).join("."):h}function ts(l){return(l||[]).map(h=>h.split(".").pop()).sort().join(",")}function Ge(l){if(!l)return null;const h=l.split(" ");if(h.length<5)return l;const[o,p,j,x,N]=h;if(j==="*"&&x==="*"&&N==="*"){const f=parseInt(p,10),b=parseInt(o,10);if(!isNaN(f)&&!isNaN(b)){const D=f>=12?"pm":"am",q=f>12?f-12:f||12,Q=b.toString().padStart(2,"0");return`Daily @ ${q}:${Q}${D}`}}if(j==="*"&&x==="*"&&N!=="*"){const f=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b=parseInt(N,10);if(!isNaN(b)&&b>=0&&b<=6)return`Weekly on ${f[b]}`}return l}function is(l){var h,o,p;if(!l||((h=l.workflow_urls)==null?void 0:h.length)===0)return{icon:"○",text:"Not planned",className:"status-not-planned",color:"#94a3b8"};if(l._isCompatible){const j=(o=l.grain_columns)==null?void 0:o.map(x=>x.split(".").pop()).join(", ");return l.availability||l.status==="active"?{icon:"✓",text:`Covered (${j})`,className:"status-compatible-materialized",color:"#059669",isCompatible:!0}:{icon:"◐",text:`Covered (${j})`,className:"status-compatible",color:"#d97706",isCompatible:!0}}return l.status==="running"?{icon:"◉",text:"Running",className:"status-running",color:"#2563eb"}:l.availability||l.status==="active"?{icon:"●",text:"Materialized",className:"status-materialized",color:"#059669"}:l.workflow_status==="active"?{icon:"◐",text:"Workflow Active",className:"status-workflow-active",color:"#2563eb"}:l.workflow_status==="paused"?{icon:"◐",text:"Workflow Paused",className:"status-workflow-paused",color:"#94a3b8"}:((p=l.workflow_urls)==null?void 0:p.length)>0?{icon:"◐",text:"Pending",className:"status-pending",color:"#d97706"}:{icon:"○",text:"Not planned",className:"status-not-planned",color:"#94a3b8"}}function cs(l){switch(l==null?void 0:l.toUpperCase()){case"HOUR":return{cron:"0 * * * *",label:"Hourly"};case"DAY":default:return{cron:"0 6 * * *",label:"Daily at 6:00 AM"}}}function rs(l){for(const h of l||[])for(const o of h.grain||[])if(o.split(".").pop().toLowerCase().includes("hour"))return"HOUR";return"DAY"}function ge(l){if(!l||l===0)return"0 B";const h=1024,o=["B","KB","MB","GB","TB","PB"],p=Math.floor(Math.log(l)/Math.log(h));return Math.round(l/Math.pow(h,p)*100)/100+" "+o[p]}function os(l){return l>de.SCAN_CRITICAL_THRESHOLD?"critical":l>de.SCAN_WARNING_THRESHOLD?"warning":"ok"}function Re(l){if(!l||!l.sources||l.sources.length===0)return null;const h=l.sources.some(j=>j.total_bytes===null||j.total_bytes===void 0);let o="unknown",p="ℹ️";return l.total_bytes!==null&&l.total_bytes!==void 0&&(o=os(l.total_bytes),p=o==="critical"?"⚠️":o==="warning"?"⚡":"✓"),{icon:p,level:o,totalBytes:l.total_bytes,sources:l.sources||[],hasMissingData:h}}function ds({onClose:l,onSubmit:h,loading:o}){const p=new Date().toISOString().split("T")[0],j=new Date(Date.now()-7*24*60*60*1e3).toISOString().split("T")[0],[x,N]=u.useState(j),[f,b]=u.useState(p);return e.jsx("div",{className:"backfill-modal-overlay",onClick:l,children:e.jsxs("div",{className:"backfill-modal",onClick:D=>D.stopPropagation(),children:[e.jsxs("div",{className:"backfill-modal-header",children:[e.jsx("h3",{children:"Run Cube Backfill"}),e.jsx("button",{className:"modal-close",onClick:l,children:"×"})]}),e.jsxs("div",{className:"backfill-modal-body",children:[e.jsx("p",{className:"backfill-description",children:"Run a backfill for the specified date range:"}),e.jsxs("div",{className:"backfill-date-inputs",children:[e.jsxs("div",{className:"date-input-group",children:[e.jsx("label",{htmlFor:"backfill-start",children:"Start Date"}),e.jsx("input",{id:"backfill-start",type:"date",value:x,onChange:D=>N(D.target.value),disabled:o})]}),e.jsxs("div",{className:"date-input-group",children:[e.jsx("label",{htmlFor:"backfill-end",children:"End Date"}),e.jsx("input",{id:"backfill-end",type:"date",value:f,onChange:D=>b(D.target.value),disabled:o})]})]})]}),e.jsxs("div",{className:"backfill-modal-actions",children:[e.jsx("button",{className:"action-btn action-btn-secondary",onClick:l,disabled:o,children:"Cancel"}),e.jsx("button",{className:"action-btn action-btn-primary",disabled:o||!x,onClick:()=>h(x,f||null),children:o?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Starting..."]}):"Start Backfill"})]})]})})}function ms({measuresResult:l,metricsResult:h,selectedMetrics:o,selectedDimensions:p,plannedPreaggs:j={},onPlanMaterialization:x,onUpdateConfig:N,onCreateWorkflow:f,onRunBackfill:b,onRunAdhoc:D,onFetchRawSql:q,onSetPartition:Q,onRefreshMeasures:y,onFetchNodePartitions:F,materializationError:Z,onClearError:z,workflowUrls:G=[],onClearWorkflowUrls:ps,loadedCubeName:V=null,cubeMaterialization:d=null,onUpdateCubeConfig:me,onRefreshCubeWorkflow:be,onRunCubeBackfill:ye,onDeactivatePreaggWorkflow:ve,onDeactivateCubeWorkflow:ke}){var Oe,Ee,He;const we=u.useCallback(()=>{if(o&&o.length>0){const a=o[0].split(".");if(a.length>1)return a.slice(0,-1).join(".")}return"default"},[o]),[M,Ce]=u.useState({}),[he,ee]=u.useState(null),[Ue,se]=u.useState(null),[Ve,ae]=u.useState(!1),[Ye,ue]=u.useState(!1),[R,Y]=u.useState({strategy:"incremental_time",schedule:"0 6 * * *",lookbackWindow:"1 DAY"}),[_e,Se]=u.useState(!1),[Je,De]=u.useState(!1),[Ke,le]=u.useState({}),[Xe,Te]=u.useState(null),[Ze,pe]=u.useState({}),[A,fe]=u.useState({}),[Fe,Be]=u.useState(!1),[t,g]=u.useState({strategy:"incremental_time",backfillFrom:"",backfillTo:"today",backfillToDate:"",continueAfterBackfill:!0,schedule:"",scheduleType:"auto",lookbackWindow:"1 day",enableDruidCube:!0,druidCubeNamespace:"",druidCubeName:""}),[ne,te]=u.useState(!1),[w,C]=u.useState(null),[U,I]=u.useState(null),[Pe,O]=u.useState(null),[ie,ze]=u.useState("optimized"),[E,Me]=u.useState(null),[Le,We]=u.useState(!1),$e=async s=>{if(ze(s),s==="raw"&&!E&&q){We(!0);const a=await q();Me(a),We(!1)}},P=u.useCallback(()=>{const s=(l==null?void 0:l.grain_groups)||[],a=new Set;return s.forEach(i=>{i.parent_name&&a.add(i.parent_name)}),Array.from(a)},[l==null?void 0:l.grain_groups]),qe=u.useCallback(async()=>{const s=P();if(s.length===0||!F)return fe({}),{};Be(!0);try{const a={},i=s.map(async c=>{try{const n=await F(c);a[c]=n}catch(n){console.error(`Failed to fetch partitions for ${c}:`,n),a[c]={columns:[],temporalPartitions:[]}}});return await Promise.all(i),console.log("[fetchAllNodePartitions] results:",a),fe(a),a}catch(a){return console.error("Failed to fetch node partitions:",a),fe({}),{}}finally{Be(!1)}},[P,F]),ce=u.useCallback(()=>{const s=P();if(s.length===0)return!1;const a=s.every(i=>{var n;const c=A[i];return((n=c==null?void 0:c.temporalPartitions)==null?void 0:n.length)>0});return console.log("[hasActualTemporalPartitions]",{parentNodes:s,allNodePartitions:A,allHaveTemporal:a}),a},[P,A]);u.useCallback(()=>P().filter(a=>{var c;const i=A[a];return!((c=i==null?void 0:i.temporalPartitions)!=null&&c.length)}),[P,A]);const es=async()=>{const s=(l==null?void 0:l.grain_groups)||[],a=rs(s),i=cs(a),c=new Date(Date.now()-30*24*60*60*1e3).toISOString().split("T")[0],n=await qe(),_=P(),L=_.every(v=>{var r,S;return((S=(r=n[v])==null?void 0:r.temporalPartitions)==null?void 0:S.length)>0});console.log("[openConfigForm] allHaveTemporal:",L,"partitionResults:",n);const B=/date|time|day|month|year|hour|ds|dt|dateint|timestamp/i,W={};_.forEach(v=>{var S,J;const r=n[v];if(!((S=r==null?void 0:r.temporalPartitions)!=null&&S.length)){const oe=[...((r==null?void 0:r.columns)||[]).filter(H=>!H.partition)].sort((H,K)=>{const X=B.test(H.name),m=B.test(K.name);return X&&!m?-1:!X&&m?1:H.name.localeCompare(K.name)});W[v]={column:((J=oe[0])==null?void 0:J.name)||"",granularity:"day",format:"yyyyMMdd"}}}),le(W),pe({}),g({strategy:L?"incremental_time":"full",runBackfill:!0,backfillFrom:c,backfillTo:"today",backfillToDate:"",continueAfterBackfill:!0,schedule:i.cron,scheduleType:"auto",lookbackWindow:"1 day",_recommendedSchedule:i,_granularity:a,enableDruidCube:!0,druidCubeNamespace:we(),druidCubeName:""}),ee("__all__")},ss=(s,a)=>{g({strategy:a.strategy||"incremental_time",backfillFrom:"",backfillTo:"today",backfillToDate:"",continueAfterBackfill:!0,schedule:a.schedule||"",scheduleType:a.schedule?"custom":"auto",lookbackWindow:a.lookback_window||""}),se(s)},as=s=>{Ce(a=>({...a,[s]:!a[s]}))};if(!(o!=null&&o.length)||!(p!=null&&p.length))return e.jsx("div",{className:"details-panel details-panel-empty",children:e.jsxs("div",{className:"empty-hint",children:[e.jsx("div",{className:"empty-icon",children:"⊞"}),e.jsx("h4",{children:"Query Planner"}),e.jsx("p",{children:"Select metrics and dimensions from the left panel to see the generated SQL and pre-aggregation plan"})]})});if(!l||!h)return e.jsx("div",{className:"details-panel details-panel-empty",children:e.jsxs("div",{className:"empty-hint",children:[e.jsx("div",{className:"loading-spinner"}),e.jsx("p",{children:"Building query plan..."})]})});const re=l.grain_groups||[],je=l.metric_formulas||[],Ae=h.sql||"",Ie=G.length>0||Object.values(j).some(s=>{var a;return((a=s==null?void 0:s.workflow_urls)==null?void 0:a.length)>0});return e.jsxs("div",{className:"details-panel",children:[e.jsxs("div",{className:"details-header",children:[e.jsx("h2",{className:"details-title",children:"Query Plan"}),e.jsxs("p",{className:"details-full-name",children:[o.length," metric",o.length!==1?"s":""," ×"," ",p.length," dimension",p.length!==1?"s":""]})]}),Z&&e.jsxs("div",{className:"materialization-error global-error",children:[e.jsxs("div",{className:"error-content",children:[e.jsx("span",{className:"error-icon",children:"⚠"}),e.jsx("span",{className:"error-message",children:Z})]}),e.jsx("button",{className:"error-dismiss",onClick:z,"aria-label":"Dismiss error",children:"×"})]}),re.length>0&&x&&(!Ie||he==="__all__")&&e.jsxs("div",{className:"details-section",children:[!Ie&&he!=="__all__"&&e.jsxs("div",{className:"plan-materialization-cta",children:[e.jsxs("div",{className:"cta-content",children:[e.jsx("div",{className:"cta-icon",children:"⚡"}),e.jsxs("div",{className:"cta-text",children:[e.jsx("strong",{children:"Ready to materialize?"}),e.jsx("span",{children:"Configure scheduled materialization for faster queries"})]})]}),e.jsx("button",{className:"action-btn action-btn-primary",type:"button",onClick:es,children:"Configure"})]}),he==="__all__"&&e.jsxs("div",{className:"materialization-config-form section-level-config",children:[e.jsxs("div",{className:"config-form-header",children:[e.jsx("span",{children:"Configure Materialization"}),e.jsx("button",{className:"config-close-btn",type:"button",onClick:()=>ee(null),children:"×"})]}),e.jsxs("div",{className:"config-form-body",children:[e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Strategy"}),e.jsxs("div",{className:"config-form-options",children:[e.jsxs("label",{className:"radio-option",children:[e.jsx("input",{type:"radio",name:"strategy-all",value:"full",checked:t.strategy==="full",onChange:s=>g(a=>({...a,strategy:s.target.value}))}),e.jsx("span",{children:"Full"})]}),e.jsxs("label",{className:"radio-option",children:[e.jsx("input",{type:"radio",name:"strategy-all",value:"incremental_time",checked:t.strategy==="incremental_time",onChange:s=>{g(a=>({...a,strategy:s.target.value})),!ce()&&!Fe&&De(!0)}}),e.jsx("span",{children:"Incremental"}),t.strategy==="incremental_time"&&(Fe?e.jsx("span",{className:"option-hint",children:"(checking...)"}):ce()?e.jsx("span",{className:"partition-badge",children:P().map(s=>{var a,i,c;return(c=(i=(a=A[s])==null?void 0:a.temporalPartitions)==null?void 0:i[0])==null?void 0:c.name}).filter(Boolean).join(", ")}):null)]})]})]}),Je&&t.strategy==="incremental_time"&&!ce()&&e.jsxs("div",{className:"partition-setup-form",children:[e.jsxs("div",{className:"partition-setup-header",children:[e.jsx("span",{className:"partition-setup-icon",children:"⚠️"}),e.jsx("span",{children:"Set up temporal partitions for incremental builds"})]}),e.jsx("div",{className:"partition-setup-body",children:P().map(s=>{var B,W;const a=A[s],i=((B=a==null?void 0:a.temporalPartitions)==null?void 0:B.length)>0,c=Ke[s]||{column:"",granularity:"day",format:"yyyyMMdd"},n=Ze[s],_=Xe===s,L=s.split(".").pop();return i?e.jsxs("div",{className:"partition-node-section partition-node-done",children:[e.jsx("div",{className:"partition-node-header",children:e.jsxs("span",{className:"partition-node-name",children:[e.jsx("span",{className:"partition-node-icon",children:"✓"}),L]})}),e.jsx("div",{className:"partition-node-status",children:e.jsx("span",{className:"partition-badge",children:(W=a.temporalPartitions[0])==null?void 0:W.name})})]},s):e.jsxs("div",{className:"partition-node-section",children:[e.jsx("div",{className:"partition-node-header",children:e.jsxs("span",{className:"partition-node-name",children:[e.jsx("span",{className:"partition-node-icon",children:"📦"}),L]})}),n&&e.jsx("div",{className:"partition-setup-error",children:n}),e.jsxs("div",{className:"partition-node-form",children:[e.jsxs("div",{className:"partition-field",children:[e.jsx("label",{children:"Column"}),e.jsxs("select",{value:c.column,onChange:v=>le(r=>({...r,[s]:{...c,column:v.target.value}})),children:[e.jsx("option",{value:"",children:"Select..."}),(()=>{const v=/date|time|day|month|year|hour|ds|dt|dateint|timestamp/i;return((a==null?void 0:a.columns)||[]).filter(r=>!r.partition).map(r=>({...r,isDateLike:v.test(r.name)})).sort((r,S)=>r.isDateLike&&!S.isDateLike?-1:!r.isDateLike&&S.isDateLike?1:r.name.localeCompare(S.name)).map(r=>e.jsxs("option",{value:r.name,children:[r.name,r.isDateLike?" ★":""]},r.name))})()]})]}),e.jsxs("div",{className:"partition-field partition-field-small",children:[e.jsx("label",{children:"Granularity"}),e.jsxs("select",{value:c.granularity,onChange:v=>le(r=>({...r,[s]:{...c,granularity:v.target.value}})),children:[e.jsx("option",{value:"day",children:"Day"}),e.jsx("option",{value:"hour",children:"Hour"}),e.jsx("option",{value:"month",children:"Month"})]})]}),e.jsxs("div",{className:"partition-field partition-field-small",children:[e.jsx("label",{children:"Format"}),e.jsx("input",{type:"text",placeholder:"yyyyMMdd",value:c.format,onChange:v=>le(r=>({...r,[s]:{...c,format:v.target.value}}))})]}),e.jsx("button",{type:"button",className:"partition-set-btn",disabled:!c.column||_,onClick:async()=>{var v;if(c.column){Te(s),pe(r=>({...r,[s]:null}));try{const r=await Q(s,c.column,"temporal",c.format||"yyyyMMdd",c.granularity);if((r==null?void 0:r.status)>=400)throw new Error(((v=r.json)==null?void 0:v.message)||"Failed to set partition");await qe(),ce()&&De(!1)}catch(r){pe(S=>({...S,[s]:r.message||"Failed to set partition"}))}finally{Te(null)}}},children:_?"...":"Set"})]})]},s)})})]}),t.strategy==="incremental_time"&&e.jsxs("div",{className:"config-form-row",children:[e.jsxs("label",{className:"checkbox-option",children:[e.jsx("input",{type:"checkbox",checked:t.runBackfill,onChange:s=>g(a=>({...a,runBackfill:s.target.checked}))}),e.jsx("span",{children:"Run initial backfill"})]}),e.jsx("span",{className:"config-form-hint",children:"Populate historical data. Uncheck to only set up ongoing materialization."})]}),t.strategy==="incremental_time"&&t.runBackfill&&e.jsxs("div",{className:"config-form-section",children:[e.jsx("label",{className:"config-form-section-label",children:"Backfill Date Range"}),e.jsxs("div",{className:"backfill-range",children:[e.jsxs("div",{className:"backfill-field",children:[e.jsx("label",{children:"From"}),e.jsx("input",{type:"date",value:t.backfillFrom,onChange:s=>g(a=>({...a,backfillFrom:s.target.value}))})]}),e.jsxs("div",{className:"backfill-field",children:[e.jsx("label",{children:"To"}),e.jsxs("select",{value:t.backfillTo,onChange:s=>g(a=>({...a,backfillTo:s.target.value})),children:[e.jsx("option",{value:"today",children:"Today"}),e.jsx("option",{value:"specific",children:"Specific date"})]}),t.backfillTo==="specific"&&e.jsx("input",{type:"date",value:t.backfillToDate,onChange:s=>g(a=>({...a,backfillToDate:s.target.value})),style:{marginTop:"6px"}})]})]})]}),e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Schedule"}),e.jsxs("select",{className:"config-form-select",value:t.scheduleType,onChange:s=>{const a=s.target.value;g(i=>{var c;return{...i,scheduleType:a,schedule:a==="auto"?((c=i._recommendedSchedule)==null?void 0:c.cron)||"0 6 * * *":i.schedule}})},children:[e.jsxs("option",{value:"auto",children:[((Oe=t._recommendedSchedule)==null?void 0:Oe.label)||"Daily at 6:00 AM"," ","(recommended)"]}),e.jsx("option",{value:"hourly",children:"Hourly"}),e.jsx("option",{value:"custom",children:"Custom cron..."})]}),t.scheduleType==="custom"&&e.jsx("input",{type:"text",className:"config-form-input",placeholder:"0 6 * * *",value:t.schedule,onChange:s=>g(a=>({...a,schedule:s.target.value})),style:{marginTop:"6px"}}),t.scheduleType==="auto"&&e.jsxs("span",{className:"config-form-hint",children:["Based on"," ",((Ee=t._granularity)==null?void 0:Ee.toLowerCase())||"daily"," ","partition granularity"]})]}),t.strategy==="incremental_time"&&e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Lookback Window"}),e.jsx("input",{type:"text",className:"config-form-input",placeholder:"1 day",value:t.lookbackWindow,onChange:s=>g(a=>({...a,lookbackWindow:s.target.value}))}),e.jsx("span",{className:"config-form-hint",children:'For late-arriving data (e.g., "1 day", "3 days")'})]}),e.jsx("div",{className:"config-form-divider",children:e.jsx("span",{children:"Cube Materialization (Druid)"})}),e.jsxs("div",{className:"config-form-row",children:[e.jsxs("label",{className:"checkbox-option",children:[e.jsx("input",{type:"checkbox",checked:t.enableDruidCube,onChange:s=>g(a=>({...a,enableDruidCube:s.target.checked}))}),"Enable Druid cube materialization"]}),e.jsx("span",{className:"config-form-hint",children:"Combines pre-aggs into a single Druid datasource for fast interactive queries"})]}),t.enableDruidCube&&!V&&e.jsxs("div",{className:"config-form-section druid-cube-config",children:[V?e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Using Cube"}),e.jsxs("div",{className:"existing-cube-name",children:[e.jsx("span",{className:"cube-badge",children:"📦"}),e.jsx("code",{children:V})]}),e.jsx("span",{className:"config-form-hint",children:"Materialization will be added to this existing cube"})]}):e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Cube Name"}),e.jsxs("div",{className:"cube-name-input-group",children:[e.jsx("input",{type:"text",className:"config-form-input namespace-input",placeholder:"users.myname",value:t.druidCubeNamespace,onChange:s=>g(a=>({...a,druidCubeNamespace:s.target.value}))}),e.jsx("span",{className:"namespace-separator",children:"."}),e.jsx("input",{type:"text",className:"config-form-input name-input",placeholder:"my_cube",value:t.druidCubeName,onChange:s=>g(a=>({...a,druidCubeName:s.target.value}))})]}),e.jsxs("span",{className:"config-form-hint",children:["Full name:"," ",e.jsxs("code",{children:[t.druidCubeNamespace,".",t.druidCubeName||"my_cube"]})]})]}),e.jsxs("div",{className:"druid-cube-preview",children:[e.jsx("div",{className:"preview-label",children:"Pre-aggregations to combine:"}),e.jsx("div",{className:"preview-list",children:((l==null?void 0:l.grain_groups)||[]).map((s,a)=>{var i;return e.jsxs("div",{className:"preview-item",children:[e.jsx("span",{className:"preview-source",children:(i=s.parent_name)==null?void 0:i.split(".").pop()}),e.jsxs("span",{className:"preview-grain",children:["(",(s.grain||[]).map(c=>c.split(".").pop()).join(", "),")"]})]},a)})}),e.jsxs("div",{className:"preview-info",children:[e.jsx("span",{className:"info-icon",children:"ℹ️"}),"Pre-aggs will be combined with FULL OUTER JOIN on shared dimensions and ingested to Druid"]})]})]})]}),e.jsxs("div",{className:"config-form-actions",children:[e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:()=>ee(null),children:"Cancel"}),e.jsx("button",{className:"action-btn action-btn-primary",type:"button",disabled:ne,onClick:async()=>{var s;te(!0);try{let a=t.schedule;t.scheduleType==="auto"?a=((s=t._recommendedSchedule)==null?void 0:s.cron)||"0 6 * * *":t.scheduleType==="hourly"&&(a="0 * * * *");let i=null;t.strategy==="incremental_time"&&(i=t.backfillTo==="today"?new Date().toISOString().split("T")[0]:t.backfillToDate);const c={strategy:t.strategy,schedule:a,lookbackWindow:t.strategy==="incremental_time"?t.lookbackWindow:null,runBackfill:t.runBackfill,backfillFrom:t.strategy==="incremental_time"&&t.runBackfill?t.backfillFrom:null,backfillTo:t.strategy==="incremental_time"&&t.runBackfill?i:null,enableDruidCube:t.enableDruidCube,druidCubeName:t.enableDruidCube&&t.druidCubeName?`${t.druidCubeNamespace}.${t.druidCubeName}`:null};await x(null,c),ee(null),g({strategy:"incremental_time",runBackfill:!0,backfillFrom:"",backfillTo:"today",backfillToDate:"",continueAfterBackfill:!0,schedule:"",scheduleType:"auto",lookbackWindow:"1 day",enableDruidCube:!0,druidCubeNamespace:we(),druidCubeName:""})}catch(a){console.error("Failed to plan:",a)}te(!1)},children:ne?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Creating..."]}):t.enableDruidCube?"Create Pre-Agg Workflows & Schedule Cube":t.strategy==="incremental_time"&&t.runBackfill?"Create Workflow & Start Backfill":"Create Workflow"})]})]})]}),G.length>0&&e.jsxs("div",{className:"details-section",children:[e.jsx("div",{className:"section-header-row",children:e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon cube-icon",children:"◆"}),"Druid Cube"]})}),e.jsx("div",{className:"preagg-summary-card cube-card",children:Ve?e.jsxs("div",{className:"materialization-config-form",children:[e.jsxs("div",{className:"config-form-header",children:[e.jsx("span",{children:"Edit Materialization Config"}),e.jsx("button",{className:"config-close-btn",type:"button",onClick:()=>ae(!1),children:"×"})]}),e.jsxs("div",{className:"config-form-body",children:[e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Strategy"}),e.jsxs("div",{className:"config-form-options",children:[e.jsxs("label",{className:"radio-option",children:[e.jsx("input",{type:"radio",name:"cube-strategy",value:"full",checked:R.strategy==="full",onChange:s=>Y(a=>({...a,strategy:s.target.value}))}),e.jsx("span",{children:"Full"})]}),e.jsxs("label",{className:"radio-option",children:[e.jsx("input",{type:"radio",name:"cube-strategy",value:"incremental_time",checked:R.strategy==="incremental_time",onChange:s=>Y(a=>({...a,strategy:s.target.value}))}),e.jsx("span",{children:"Incremental (Time)"})]})]})]}),e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Schedule (cron)"}),e.jsx("input",{type:"text",className:"config-form-input",placeholder:"0 6 * * * (daily at 6am)",value:R.schedule,onChange:s=>Y(a=>({...a,schedule:s.target.value}))})]}),R.strategy==="incremental_time"&&e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Lookback Window"}),e.jsx("input",{type:"text",className:"config-form-input",placeholder:"3 days",value:R.lookbackWindow,onChange:s=>Y(a=>({...a,lookbackWindow:s.target.value}))})]})]}),e.jsxs("div",{className:"config-form-actions",children:[e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:()=>ae(!1),children:"Cancel"}),e.jsx("button",{className:"action-btn action-btn-primary",type:"button",disabled:_e,onClick:async()=>{Se(!0);try{me&&await me(R),ae(!1)}catch(s){console.error("Failed to save cube config:",s)}Se(!1)},children:_e?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Saving..."]}):"Save"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"preagg-summary-header",children:[e.jsx("span",{className:"preagg-summary-name cube-name",children:(d==null?void 0:d.druidDatasource)||(V?`dj__${V.replace(/\./g,"_")}`:"dj__cube")}),e.jsx("span",{className:"status-pill status-active",children:"● Active"})]}),e.jsxs("div",{className:"materialization-header clickable",onClick:()=>Ce(s=>({...s,cube:!s.cube})),children:[e.jsxs("div",{className:"materialization-status",children:[e.jsx("span",{className:"status-indicator status-materialized",style:{color:"#059669"},children:"●"}),e.jsx("span",{className:"status-text",children:"Workflow active"}),(d==null?void 0:d.schedule)&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-separator",children:"|"}),e.jsx("span",{className:"schedule-summary",children:Ge(d.schedule)})]})]}),e.jsx("button",{className:"expand-toggle",type:"button","aria-label":M.cube?"Collapse":"Expand",children:M.cube?"▲":"▼"})]}),M.cube&&e.jsxs("div",{className:"materialization-details",children:[e.jsxs("div",{className:"materialization-config",children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Strategy:"}),e.jsx("span",{className:"config-value",children:(d==null?void 0:d.strategy)==="incremental_time"?"Incremental (Time-based)":(d==null?void 0:d.strategy)==="full"?"Full":(d==null?void 0:d.strategy)||"Not set"})]}),(d==null?void 0:d.schedule)&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Schedule:"}),e.jsx("span",{className:"config-value config-mono",children:d.schedule})]}),(d==null?void 0:d.lookbackWindow)&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Lookback:"}),e.jsx("span",{className:"config-value",children:d.lookbackWindow})]}),e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Dependencies:"}),e.jsxs("span",{className:"config-value",children:[((He=d==null?void 0:d.preaggTables)==null?void 0:He.length)||Object.keys(j).length||re.length," ","pre-agg(s)"]})]}),G.length>0&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Workflows:"}),e.jsx("div",{className:"workflow-links",children:G.map((s,a)=>{const i=typeof s=="string"?s:s.url,c=typeof s=="string"?s.includes("adhoc")||s.includes("backfill")?"Backfill":"Scheduled":s.label||"Workflow";return e.jsx("a",{href:i,target:"_blank",rel:"noopener noreferrer",className:"action-btn action-btn-secondary",children:c==="backfill"?"Backfill":c==="scheduled"?"Scheduled":c},a)})})]})]}),e.jsxs("div",{className:"materialization-actions",children:[me&&e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:s=>{s.stopPropagation(),Y({strategy:(d==null?void 0:d.strategy)||"incremental_time",schedule:(d==null?void 0:d.schedule)||"0 6 * * *",lookbackWindow:(d==null?void 0:d.lookbackWindow)||"1 DAY"}),ae(!0)},children:"Edit Config"}),be&&e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",title:"Refresh workflow (re-push to scheduler)",onClick:async s=>{s.stopPropagation(),C("refresh-cube");try{await be()}finally{C(null)}},disabled:w==="refresh-cube",children:w==="refresh-cube"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Refreshing..."]}):"↻ Refresh"}),ye&&e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:s=>{s.stopPropagation(),ue(!0)},children:"Run Backfill"}),ke&&e.jsx("button",{className:"action-btn action-btn-danger",type:"button",title:"Deactivate this cube materialization",onClick:async s=>{if(s.stopPropagation(),window.confirm("Are you sure you want to deactivate this cube materialization? The workflow will be stopped.")){C("deactivate-cube");try{await ke()}finally{C(null)}}},disabled:w==="deactivate-cube",children:w==="deactivate-cube"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Deactivating..."]}):"⏹ Deactivate"})]})]})]})})]}),e.jsxs("div",{className:"details-section",children:[e.jsx("div",{className:"section-header-row",children:e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"◫"}),"Pre-Aggregations (",re.length,")"]})}),e.jsx("div",{className:"preagg-summary-list",children:re.map((s,a)=>{var S,J,xe,oe,H,K,X;const i=((S=s.parent_name)==null?void 0:S.split(".").pop())||"Unknown";je.filter(m=>{var k;return(k=m.components)==null?void 0:k.some(T=>{var $;return($=s.components)==null?void 0:$.some(ls=>ls.name===T)})});const c=`${s.parent_name}|${ts(s.grain)}`,n=j[c],_=is(n),L=M[c]||!1,B=n!=null&&n.schedule?Ge(n.schedule):null,W=(n==null?void 0:n.strategy)&&(n==null?void 0:n.schedule),v=W?"status-active":"status-not-set",r=W?"● Active":"○ Not Set";return e.jsxs("div",{className:"preagg-summary-card",children:[e.jsxs("div",{className:"preagg-summary-header",children:[e.jsx("span",{className:"preagg-summary-name",children:i}),e.jsx("span",{className:`status-pill ${v}`,children:r})]}),e.jsxs("div",{className:"preagg-summary-details",children:[e.jsxs("div",{className:"preagg-summary-row",children:[e.jsx("span",{className:"label",children:"Grain:"}),e.jsx("span",{className:"value",children:((J=s.grain)==null?void 0:J.join(", "))||"None"})]}),W&&B&&e.jsxs("div",{className:"preagg-summary-row",children:[e.jsx("span",{className:"label",children:"Schedule:"}),e.jsx("span",{className:"value",children:B})]})]}),Ue===c?e.jsxs("div",{className:"materialization-config-form",children:[e.jsxs("div",{className:"config-form-header",children:[e.jsx("span",{children:"Edit Materialization Config"}),e.jsx("button",{className:"config-close-btn",type:"button",onClick:()=>{se(null)},children:"×"})]}),e.jsxs("div",{className:"config-form-body",children:[e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Strategy"}),e.jsxs("div",{className:"config-form-options",children:[e.jsxs("label",{className:"radio-option",children:[e.jsx("input",{type:"radio",name:`strategy-${a}`,value:"full",checked:t.strategy==="full",onChange:m=>g(k=>({...k,strategy:m.target.value}))}),e.jsx("span",{children:"Full"})]}),e.jsxs("label",{className:"radio-option",children:[e.jsx("input",{type:"radio",name:`strategy-${a}`,value:"incremental_time",checked:t.strategy==="incremental_time",onChange:m=>g(k=>({...k,strategy:m.target.value}))}),e.jsx("span",{children:"Incremental (Time)"})]})]})]}),e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Schedule (cron)"}),e.jsx("input",{type:"text",className:"config-form-input",placeholder:"0 6 * * * (daily at 6am)",value:t.schedule,onChange:m=>g(k=>({...k,schedule:m.target.value}))})]}),t.strategy==="incremental_time"&&e.jsxs("div",{className:"config-form-row",children:[e.jsx("label",{className:"config-form-label",children:"Lookback Window"}),e.jsx("input",{type:"text",className:"config-form-input",placeholder:"3 days",value:t.lookbackWindow,onChange:m=>g(k=>({...k,lookbackWindow:m.target.value}))})]})]}),e.jsxs("div",{className:"config-form-actions",children:[e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:()=>se(null),children:"Cancel"}),e.jsx("button",{className:"action-btn action-btn-primary",type:"button",disabled:ne,onClick:async()=>{te(!0);try{N&&(n!=null&&n.id)&&await N(n.id,t),se(null),g({strategy:"full",schedule:"",lookbackWindow:""})}catch(m){console.error("Failed to save:",m)}te(!1)},children:ne?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Saving..."]}):"Save"})]})]}):n?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"materialization-header clickable",onClick:()=>as(c),children:[e.jsxs("div",{className:"materialization-status",children:[e.jsx("span",{className:`status-indicator ${_.className}`,style:{color:_.color},children:_.icon}),e.jsx("span",{className:"status-text",children:_.text}),B&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"status-separator",children:"|"}),e.jsx("span",{className:"schedule-summary",children:B})]})]}),e.jsx("button",{className:"expand-toggle",type:"button","aria-label":L?"Collapse":"Expand",children:L?"▲":"▼"})]}),L&&e.jsxs("div",{className:"materialization-details",children:[n._isCompatible&&e.jsxs("div",{className:"compatible-preagg-note",children:[e.jsx("span",{className:"note-icon",children:"ℹ️"}),e.jsxs("span",{children:["This query can use an existing pre-agg with finer grain:",e.jsxs("strong",{children:[" ",(xe=n.grain_columns)==null?void 0:xe.map(m=>m.split(".").pop()).join(", ")]})]})]}),e.jsxs("div",{className:"materialization-config",children:[e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Strategy:"}),e.jsx("span",{className:"config-value",children:n.strategy==="incremental_time"?"Incremental (Time-based)":n.strategy==="full"?"Full":n.strategy||"Not set"})]}),n.schedule&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Schedule:"}),e.jsx("span",{className:"config-value config-mono",children:n.schedule})]}),n.lookback_window&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Lookback:"}),e.jsx("span",{className:"config-value",children:n.lookback_window})]}),((oe=n.availability)==null?void 0:oe.updated_at)&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Last Run:"}),e.jsxs("span",{className:"config-value",children:[new Date(n.availability.updated_at).toLocaleString()," ",e.jsx("span",{className:"run-status success",children:"✓"})]})]}),((H=n.workflow_urls)==null?void 0:H.length)>0&&e.jsxs("div",{className:"config-row",children:[e.jsx("span",{className:"config-label",children:"Workflows:"}),e.jsx("div",{className:"workflow-links",children:n.workflow_urls.map((m,k)=>{const T=typeof m=="string"?m:m.url,$=typeof m=="string"?m.includes("backfill")||m.includes("adhoc")?"backfill":"scheduled":m.label||"workflow";return e.jsx("a",{href:T,target:"_blank",rel:"noopener noreferrer",className:"action-btn action-btn-secondary",children:$==="scheduled"?"Scheduled":$==="backfill"?"Backfill":$},k)})})]})]}),e.jsxs("div",{className:"materialization-actions",children:[N&&n.id&&e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:m=>{m.stopPropagation(),ss(c,n)},children:"Edit Config"}),n.strategy&&n.schedule&&e.jsxs(e.Fragment,{children:[(!n.workflow_urls||n.workflow_urls.length===0)&&f&&e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",disabled:w===`workflow-${n.id}`,onClick:async m=>{var k;m.stopPropagation(),C(`workflow-${n.id}`);try{const T=await f(n.id);if(((k=T==null?void 0:T.workflow_urls)==null?void 0:k.length)>0){const $=typeof T.workflow_urls[0]=="string"?T.workflow_urls[0]:T.workflow_urls[0].url;O(`Workflow created: ${$}`),setTimeout(()=>O(null),5e3)}}finally{C(null)}},children:w===`workflow-${n.id}`?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Creating..."]}):"Create Workflow"}),((K=n.workflow_urls)==null?void 0:K.length)>0&&e.jsx(e.Fragment,{children:e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",title:"Refresh workflow (re-push to scheduler)",disabled:w===`refresh-${n.id}`,onClick:async m=>{m.stopPropagation(),C(`refresh-${n.id}`);try{await f(n.id,!0)}finally{C(null)}},children:w===`refresh-${n.id}`?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," ","Refreshing..."]}):"↻ Refresh"})})]}),n.strategy&&b&&e.jsx("button",{className:"action-btn action-btn-secondary",type:"button",onClick:m=>{m.stopPropagation();const k=new Date().toISOString().split("T")[0],T=new Date(Date.now()-7*24*60*60*1e3).toISOString().split("T")[0];I({preaggId:n.id,startDate:T,endDate:k})},children:"Run Backfill"}),((X=n.workflow_urls)==null?void 0:X.length)>0&&ve&&e.jsx("button",{className:"action-btn action-btn-danger",type:"button",title:"Deactivate (pause) this workflow",onClick:async m=>{if(m.stopPropagation(),window.confirm("Are you sure you want to deactivate this workflow? It will be paused and can be re-activated later.")){C(`deactivate-${n.id}`);try{await ve(n.id)}finally{C(null)}}},disabled:w===`deactivate-${n.id}`,children:w===`deactivate-${n.id}`?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Deactivating..."]}):"⏹ Deactivate"})]})]})]}):e.jsx("div",{className:"materialization-header",children:e.jsxs("div",{className:"materialization-status",children:[e.jsx("span",{className:`status-indicator ${_.className}`,style:{color:_.color},children:_.icon}),e.jsx("span",{className:"status-text",children:_.text})]})})]},a)})})]}),Ae&&e.jsxs("div",{className:"details-section details-section-full details-sql-section",children:[e.jsxs("div",{className:"section-header-row",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"⌘"}),"Generated SQL"]}),e.jsxs("div",{className:"sql-view-toggle",children:[e.jsx("button",{className:`sql-toggle-btn ${ie==="optimized"?"active":""}`,onClick:()=>$e("optimized"),type:"button",title:"SQL using pre-aggregations (when available)",children:"Optimized"}),e.jsx("button",{className:`sql-toggle-btn ${ie==="raw"?"active":""}`,onClick:()=>$e("raw"),type:"button",title:"SQL computed directly from source tables",disabled:Le,children:Le?"...":"Raw"})]})]}),(()=>{const s=ie==="raw"?E==null?void 0:E.scan_estimate:h==null?void 0:h.scan_estimate,a=Re(s);return a?e.jsxs("div",{className:`scan-estimate-banner scan-estimate-${a.level}`,children:[e.jsx("span",{className:"scan-estimate-icon",children:a.icon}),e.jsxs("div",{className:"scan-estimate-content",children:[e.jsxs("div",{className:"scan-estimate-header",children:[e.jsx("strong",{children:"Scan Cost:"})," ",a.totalBytes!==null&&a.totalBytes!==void 0?(a.hasMissingData?"≥ ":"")+ge(a.totalBytes):"Unknown"]}),e.jsx("div",{className:"scan-estimate-sources",children:a.sources.map((i,c)=>{let n=i.source_name;return i.schema_&&i.table?n=`${i.schema_}.${i.table}`:i.table&&(n=i.table),e.jsxs("div",{className:"scan-source-item",children:[e.jsx("span",{className:"scan-source-name",title:i.source_name,children:n}),e.jsx("span",{className:"scan-source-size",children:i.total_bytes!==null&&i.total_bytes!==void 0?ge(i.total_bytes):"no size data"})]},c)})})]})]}):null})(),e.jsx("div",{className:"sql-code-wrapper",children:e.jsx(de.SyntaxHighlighter,{language:"sql",style:Ne,customStyle:{margin:0,borderRadius:"6px",fontSize:"11px",background:"#f8fafc",border:"1px solid #e2e8f0"},children:ie==="raw"?(E==null?void 0:E.sql)||"Loading...":Ae})})]}),e.jsxs("div",{className:"details-section",children:[e.jsx("div",{className:"section-header-row",children:e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"◈"}),"Selection Summary"]})}),e.jsxs("div",{className:"selection-summary-grid",children:[e.jsxs("div",{className:"selection-summary-column",children:[e.jsxs("div",{className:"selection-summary-label",children:["Metrics (",je.length,")"]}),e.jsx("div",{className:"selection-summary-list",children:je.map((s,a)=>e.jsxs(Qe.Link,{to:`/nodes/${s.name}`,className:"selection-summary-item metric clickable",children:[e.jsx("span",{className:"selection-summary-name",children:s.short_name}),s.is_derived&&e.jsx("span",{className:"compact-node-badge",children:"Derived"})]},a))})]}),e.jsxs("div",{className:"selection-summary-column",children:[e.jsxs("div",{className:"selection-summary-label",children:["Dimensions (",p.length,")"]}),e.jsx("div",{className:"selection-summary-list",children:p.map((s,a)=>{const i=s.split(".").pop().split("[")[0],c=ns(s);return e.jsx(Qe.Link,{to:`/nodes/${c}`,className:"selection-summary-item dimension clickable",children:e.jsx("span",{className:"selection-summary-name",children:i})},a)})})]})]})]}),U&&e.jsx("div",{className:"backfill-modal-overlay",onClick:()=>I(null),children:e.jsxs("div",{className:"backfill-modal",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"backfill-modal-header",children:[e.jsx("h3",{children:"Run Backfill"}),e.jsx("button",{className:"modal-close",onClick:()=>I(null),children:"×"})]}),e.jsxs("div",{className:"backfill-modal-body",children:[e.jsxs("div",{className:"backfill-form-row",children:[e.jsx("label",{children:"Start Date"}),e.jsx("input",{type:"date",value:U.startDate,onChange:s=>I(a=>({...a,startDate:s.target.value}))})]}),e.jsxs("div",{className:"backfill-form-row",children:[e.jsx("label",{children:"End Date"}),e.jsx("input",{type:"date",value:U.endDate,onChange:s=>I(a=>({...a,endDate:s.target.value}))})]})]}),e.jsxs("div",{className:"backfill-modal-actions",children:[e.jsx("button",{className:"action-btn action-btn-secondary",onClick:()=>I(null),disabled:w==="backfill-modal",children:"Cancel"}),e.jsx("button",{className:"action-btn action-btn-primary",disabled:w==="backfill-modal",onClick:async()=>{C("backfill-modal");try{const s=await b(U.preaggId,U.startDate,U.endDate);I(null),s!=null&&s.job_url&&(O(e.jsxs("span",{children:["Backfill started:"," ",e.jsx("a",{href:s.job_url,target:"_blank",rel:"noopener noreferrer",children:"View Job ↗"})]})),setTimeout(()=>O(null),1e4))}finally{C(null)}},children:w==="backfill-modal"?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner"})," Starting..."]}):"Start Backfill"})]})]})}),Ye&&e.jsx(ds,{onClose:()=>ue(!1),onSubmit:async(s,a)=>{C("cube-backfill");try{const i=await ye(s,a);ue(!1),i!=null&&i.job_url&&(O(e.jsxs("span",{children:["Backfill started:"," ",e.jsx("a",{href:i.job_url,target:"_blank",rel:"noopener noreferrer",children:"View Job ↗"})]})),setTimeout(()=>O(null),1e4))}finally{C(null)}},loading:w==="cube-backfill"}),Pe&&e.jsxs("div",{className:"toast-message",children:[Pe,e.jsx("button",{className:"toast-close",onClick:()=>O(null),children:"×"})]})]})}function hs({preAgg:l,metricFormulas:h,onClose:o,highlightedComponent:p}){var D,q,Q;const j=u.useRef(null);if(u.useEffect(()=>{p&&j.current&&j.current.scrollIntoView({behavior:"smooth",block:"start"})},[p]),!l)return null;const x=l.parent_name||"Pre-aggregation",N=x.split(".").pop(),f=(h==null?void 0:h.filter(y=>{var F;return(F=y.components)==null?void 0:F.some(Z=>{var z;return(z=l.components)==null?void 0:z.some(G=>G.name===Z)})}))||[],b=y=>{navigator.clipboard.writeText(y)};return e.jsxs("div",{className:"details-panel",children:[e.jsxs("div",{className:"details-header",children:[e.jsxs("div",{className:"details-title-row",children:[e.jsx("div",{className:"details-type-badge preagg",children:"Pre-aggregation"}),e.jsx("button",{className:"details-close",onClick:o,title:"Close panel",children:"×"})]}),e.jsx("h2",{className:"details-title",children:N}),e.jsx("p",{className:"details-full-name",children:x})]}),e.jsxs("div",{className:"details-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"⊞"}),"Grain (GROUP BY)"]}),e.jsx("div",{className:"grain-pills",children:((D=l.grain)==null?void 0:D.length)>0?l.grain.map(y=>e.jsx("code",{className:"grain-pill",children:y},y)):e.jsx("span",{className:"empty-text",children:"No grain columns"})})]}),e.jsxs("div",{className:"details-section details-section-full",ref:j,children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"⚙"}),"Components (",((q=l.components)==null?void 0:q.length)||0,")"]}),e.jsx("div",{className:"components-table-wrapper",children:e.jsxs("table",{className:"details-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Expression"}),e.jsx("th",{children:"Agg"}),e.jsx("th",{children:"Re-agg"})]})}),e.jsx("tbody",{children:(Q=l.components)==null?void 0:Q.map((y,F)=>e.jsxs("tr",{className:p===y.name?"component-row-highlighted":"",children:[e.jsx("td",{className:"comp-name-cell",children:e.jsx("code",{children:y.name})}),e.jsx("td",{className:"comp-expr-cell",children:e.jsx("code",{children:y.expression})}),e.jsx("td",{className:"comp-agg-cell",children:e.jsx("span",{className:"agg-func",children:y.aggregation||"—"})}),e.jsx("td",{className:"comp-merge-cell",children:e.jsx("span",{className:"merge-func",children:y.merge||"—"})})]},y.name||F))})]})})]}),e.jsxs("div",{className:"details-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"◈"}),"Metrics Using This"]}),e.jsx("div",{className:"metrics-list",children:f.length>0?f.map((y,F)=>e.jsxs("div",{className:"related-metric",children:[e.jsx("span",{className:"metric-name",children:y.short_name}),y.is_derived&&e.jsx("span",{className:"derived-badge",children:"Derived"})]},F)):e.jsx("span",{className:"empty-text",children:"No metrics found"})})]}),l.sql&&e.jsxs("div",{className:"details-section details-section-full details-sql-section",children:[e.jsxs("div",{className:"section-header-row",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"⌘"}),"Pre-Aggregation SQL"]}),e.jsx("button",{className:"copy-sql-btn",onClick:()=>b(l.sql),type:"button",children:"Copy SQL"})]}),e.jsx("div",{className:"sql-code-wrapper",children:e.jsx(de.SyntaxHighlighter,{language:"sql",style:Ne,customStyle:{margin:0,borderRadius:"6px",fontSize:"11px",background:"#f8fafc",border:"1px solid #e2e8f0"},children:l.sql})})]})]})}function us({metric:l,grainGroups:h,onClose:o}){var j;if(!l)return null;const p=(h==null?void 0:h.filter(x=>{var N;return(N=l.components)==null?void 0:N.some(f=>{var b;return(b=x.components)==null?void 0:b.some(D=>D.name===f)})}))||[];return e.jsxs("div",{className:"details-panel",children:[e.jsxs("div",{className:"details-header",children:[e.jsxs("div",{className:"details-title-row",children:[e.jsx("div",{className:`details-type-badge ${l.is_derived?"derived":"metric"}`,children:l.is_derived?"Derived Metric":"Metric"}),e.jsx("button",{className:"details-close",onClick:o,title:"Close panel",children:"×"})]}),e.jsx("h2",{className:"details-title",children:l.short_name}),e.jsx("p",{className:"details-full-name",children:l.name})]}),e.jsxs("div",{className:"details-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"⌘"}),"Definition"]}),e.jsx("div",{className:"formula-display",children:e.jsx("code",{children:l.query})})]}),e.jsxs("div",{className:"details-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"∑"}),"Combiner Formula"]}),e.jsx("div",{className:"formula-display",children:e.jsx("code",{children:l.combiner})})]}),e.jsxs("div",{className:"details-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"⚙"}),"Components Used"]}),e.jsx("div",{className:"component-tags",children:(j=l.components)==null?void 0:j.map((x,N)=>e.jsx("span",{className:"component-tag",children:x},N))})]}),e.jsxs("div",{className:"details-section",children:[e.jsxs("h3",{className:"section-title",children:[e.jsx("span",{className:"section-icon",children:"◫"}),"Source Pre-aggregations"]}),e.jsx("div",{className:"preagg-sources",children:p.length>0?p.map((x,N)=>{var f;return e.jsxs("div",{className:"preagg-source-item",children:[e.jsx("span",{className:"preagg-source-name",children:(f=x.parent_name)==null?void 0:f.split(".").pop()}),e.jsx("span",{className:"preagg-source-full",children:x.parent_name})]},N)}):e.jsx("span",{className:"empty-text",children:"No source found"})})]})]})}exports.MetricDetailsPanel=us;exports.PreAggDetailsPanel=hs;exports.QueryOverviewPanel=ms;exports.atomOneLight=Ne;exports.formatBytes=ge;exports.formatScanEstimate=Re;
//# sourceMappingURL=PreAggDetailsPanel-DbHqhxEA.cjs.map