react-semaphor 0.1.111 → 0.1.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{dashboard-controls-i6Wbe7nf.js → dashboard-controls-5qgjTVv6.js} +1 -1
- package/dist/chunks/{dashboard-controls-au5vGH7o.js → dashboard-controls-DHd_P52F.js} +3 -3
- package/dist/chunks/{dashboard-json-DzFuErre.js → dashboard-json-BYwq46z_.js} +1 -1
- package/dist/chunks/{dashboard-json-RDd6wMsW.js → dashboard-json-CfUq5kTZ.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-BrJPT6U4.js → edit-dashboard-visual-Djr8EWh1.js} +2 -2
- package/dist/chunks/{edit-dashboard-visual-zQT9UpcS.js → edit-dashboard-visual-fWBf3zeR.js} +180 -182
- package/dist/chunks/{editor-action-buttons-B6bgTDgU.js → editor-action-buttons-CD7cFr1q.js} +2 -7
- package/dist/chunks/{editor-action-buttons-BehEDUE0.js → editor-action-buttons-DLVVxKAG.js} +47 -64
- package/dist/chunks/{index--DLrWJ82.js → index-B39f8U4D.js} +61 -61
- package/dist/chunks/{index-BjaJfJko.js → index-Cfbj8EdC.js} +1 -1
- package/dist/chunks/{resource-management-panel-59R5lAiD.js → resource-management-panel-BgAjrKoZ.js} +1 -1
- package/dist/chunks/{resource-management-panel-DSlY17bM.js → resource-management-panel-CTKDFvEI.js} +49 -49
- package/dist/chunks/{schedule-dashboard-CTX2mzOI.js → schedule-dashboard-Ct9dmSTU.js} +1 -1
- package/dist/chunks/{schedule-dashboard-DXKqgTXP.js → schedule-dashboard-DqGegSJM.js} +3 -3
- package/dist/chunks/{use-visual-utils-Dcb72nce.js → use-visual-utils-CuHcin-_.js} +54 -54
- package/dist/chunks/{use-visual-utils-BuSSJYD4.js → use-visual-utils-llIwfZ_J.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +22 -22
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-Cfbj8EdC.js"),f=require("react");require("react-dom");const O=require("./schedule-dashboard-Ct9dmSTU.js"),ne=require("./editor-action-buttons-CD7cFr1q.js");function Ce(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const D=Ce(f);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { jsxs as r, jsx as e, Fragment as E } from "react/jsx-runtime";
|
|
2
|
-
import { b as J, bp as vs, bq as Ns, u as y, aC as Ce, aD as Se, B as k, aF as Me, aG as W, br as ke,
|
|
2
|
+
import { b as J, bp as vs, bq as Ns, u as y, aC as Ce, aD as Se, B as k, aF as Me, aG as W, br as ke, g as Ve, aj as R, ao as oe, bs as ys, aU as Le, ap as ie, aq as le, ar as ce, as as Pe, at as te, bt as Q, ax as Qe, I as V, bu as ws, aW as xs, bv as Ds, bw as qe, bx as He, c as X, by as Be, bz as Cs, bA as Ss, bB as Ms, bC as ks, bD as Ls, l as C, O as ze, h as de, bE as ue, bF as Ke, av as Ps, bG as As, L as H, aR as $, bH as Is, bI as Es, bJ as Fs, bK as We, bL as Je, bM as re, bN as ne, bj as be, aM as ve, bO as Ne, aX as Xe, bP as ye, aw as Ye, a$ as Ze, bQ as Ts, b3 as Gs, b4 as Rs, b5 as Os, b6 as Us, b7 as qs, b8 as zs, b9 as $s, ba as js, bR as _s, aO as Vs, be as Qs, bS as Hs, bT as Bs, f as $e, aA as se, bU as Ks, R as fe, bV as Ws, bW as Js, bX as Xs, bY as Ys, N as Zs, bZ as ea, b_ as sa, b$ as aa, c0 as ta, J as ra } from "./index-B39f8U4D.js";
|
|
3
3
|
import * as S from "react";
|
|
4
4
|
import { useState as w, useMemo as ae, useEffect as na } from "react";
|
|
5
5
|
import "react-dom";
|
|
6
|
-
import { g as we, A as oa, V as ia, S as la } from "./schedule-dashboard-
|
|
7
|
-
import { S as je } from "./editor-action-buttons-
|
|
6
|
+
import { g as we, A as oa, V as ia, S as la } from "./schedule-dashboard-DqGegSJM.js";
|
|
7
|
+
import { S as je } from "./editor-action-buttons-DLVVxKAG.js";
|
|
8
8
|
/**
|
|
9
9
|
* @license lucide-react v0.453.0 - ISC
|
|
10
10
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-Cfbj8EdC.js");require("react");require("react-dom");function i(){const o=a.useDashboardStore(e=>e.dashboard),r=a.useDashboardStore(e=>e.actions.setDashboard),t=a.useDashboardStore(e=>e.showDashboardJSON),n=a.useDashboardStore(e=>e.actions.setShowDashboardJSON);return s.jsxs("div",{className:a.cn("relative p-2",{hidden:!t}),children:[s.jsxs(a.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>n(!1),children:[s.jsx(a.X,{className:"mr-2 h-4 w-4"}),"Close"]}),s.jsx(a.de,{onChange:e=>{if(e)try{JSON.parse(e),r(JSON.parse(e))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(o,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}exports.default=i;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as o, jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { u as s, c as l, B as h, X as d, d as c } from "./index
|
|
2
|
+
import { u as s, c as l, B as h, X as d, d as c } from "./index-B39f8U4D.js";
|
|
3
3
|
import "react";
|
|
4
4
|
import "react-dom";
|
|
5
5
|
function N() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-Cfbj8EdC.js"),E=require("react"),Je=require("./editor-action-buttons-CD7cFr1q.js"),Xs=require("react-dom"),Zs=require("./use-visual-utils-llIwfZ_J.js"),et=require("./use-click-outside-B9T3lmcw.js");function st(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const Ue=st(E);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
*/const Ct=s.createLucideIcon("Wand",[["path",{d:"M15 4V2",key:"z1p9b7"}],["path",{d:"M15 16v-2",key:"px0unx"}],["path",{d:"M8 9h2",key:"1g203m"}],["path",{d:"M20 9h2",key:"19tzq7"}],["path",{d:"M17.8 11.8 19 13",key:"yihg8r"}],["path",{d:"M15 9h.01",key:"x1ddxp"}],["path",{d:"M17.8 6.2 19 5",key:"fd4us0"}],["path",{d:"m3 21 9-9",key:"1jfql5"}],["path",{d:"M12.2 6.2 11 5",key:"i3da3b"}]]);function St({initialJoinPlan:t,availableDataSources:n}){const[a,r]=E.useState(t),[l,c]=E.useState(new Set),d=()=>{const k=a.joins.length>0?Math.max(...a.joins.map(f=>f.sequence))+1:1,h={id:`join-${Date.now()}`,source:{type:"table",name:"",database:"",schema:""},target:{type:"table",name:"",database:"",schema:""},joinType:"INNER",sequence:k,joinKeyGroups:[{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}]};r({...a,joins:[...a.joins,h]}),c(new Set([...l,h.id]))},i=k=>{r({...a,joins:a.joins.filter(h=>h.id!==k)}),c(new Set([...l].filter(h=>h!==k)))},o=(k,h)=>{var N,I,O,w,L;const f=a.joins.find(P=>P.id===k);if(!f)return;const C={...f,...h};if((N=C.source)!=null&&N.name&&((I=C.target)!=null&&I.name)&&C.source.name===C.target.name){s.ue.error("Self-joins are not yet supported",{description:`Joining ${C.source.name} to itself is not currently supported. Please select a different target table.`});return}const D=a.joins.filter(P=>{var z;return P.id!==k&&P.target.name===((z=C.target)==null?void 0:z.name)});if((O=C.target)!=null&&O.name&&D.length>0){s.ue.error("Duplicate join targets are not supported",{description:`The table ${C.target.name} is already used as a target in another join. Each table can only be joined once.`});return}const v=a.joins.map(P=>P.id===k?C:P);if((w=C.source)!=null&&w.name&&((L=C.target)!=null&&L.name)&&C.joinKeyGroups[0].keys.length===0){const P=n.find(R=>{var K;return R.name===((K=C.source)==null?void 0:K.name)}),z=n.find(R=>{var K;return R.name===((K=C.target)==null?void 0:K.name)}),G={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(P==null?void 0:P.name)||"",entityName:(P==null?void 0:P.name)||"",entityType:(P==null?void 0:P.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(z==null?void 0:z.name)||"",entityName:(z==null?void 0:z.name)||"",entityType:(z==null?void 0:z.type)||"table"},operator:"="},$=[...C.joinKeyGroups];$[0]={...$[0],keys:[G]},C.joinKeyGroups=$,v[v.findIndex(R=>R.id===k)]=C}r({...a,joins:v})};return{joinPlan:a,expandedJoins:l,setJoinPlan:r,addJoin:d,removeJoin:i,updateJoin:o,moveJoinUp:k=>{const h=a.joins.findIndex(f=>f.id===k);if(h>0){const f=[...a.joins],C={...f[h]},D={...f[h-1]};f[h]=D,f[h-1]=C,f.forEach((N,I)=>{N.sequence=I+1});const v={...a,joins:f};r(v)}},moveJoinDown:k=>{const h=a.joins.findIndex(f=>f.id===k);if(h<a.joins.length-1){const f=[...a.joins],C={...f[h]},D={...f[h+1]};f[h]=D,f[h+1]=C,f.forEach((N,I)=>{N.sequence=I+1});const v={...a,joins:f};r(v)}},toggleJoinExpansion:k=>{const h=new Set(l);h.has(k)?h.delete(k):h.add(k),c(h)},getAvailableSourceEntities:k=>{if(a.joins.length===0)return n;const h=a.joins.findIndex(C=>C.id===k);if(h===0)return n.filter(C=>C.name===a.baseEntity.name);const f=new Set;return a.baseEntity.name&&f.add(a.baseEntity.name),a.joins.slice(0,h).forEach(C=>{f.add(C.source.name),f.add(C.target.name)}),n.filter(C=>f.has(C.name))},getAvailableTargetEntities:k=>n.filter(h=>h.name!==k),addJoinKeyGroup:k=>{const h=a.joins.find(C=>C.id===k);if(!h)return;const f=[...h.joinKeyGroups,{id:"group-"+Date.now()+"-"+Math.random().toString(36).substr(2,9),operator:"AND",keys:[]}];o(k,{joinKeyGroups:f})},updateGroupOperator:(k,h,f)=>{const C=a.joins.find(v=>v.id===k);if(!C)return;const D=[...C.joinKeyGroups];D[h]={...D[h],operator:f},o(k,{joinKeyGroups:D})},removeJoinKeyGroup:(k,h)=>{const f=a.joins.find(D=>D.id===k);if(!f)return;const C=[...f.joinKeyGroups];C.splice(h,1),o(k,{joinKeyGroups:C})},addJoinKey:(k,h)=>{const f=a.joins.find(I=>I.id===k);if(!f)return;const C=n.find(I=>I.name===f.source.name),D=n.find(I=>I.name===f.target.name),v=[...f.joinKeyGroups],N={id:`key-${Date.now()}`,source:{id:`source-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(C==null?void 0:C.name)||"",entityName:(C==null?void 0:C.name)||"",entityType:(C==null?void 0:C.type)||"table"},target:{id:`target-${Date.now()}`,name:"",dataType:"",label:"",qualifiedFieldName:"",entityId:(D==null?void 0:D.name)||"",entityName:(D==null?void 0:D.name)||"",entityType:(D==null?void 0:D.type)||"table"},operator:"="};v[h]={...v[h],keys:[...v[h].keys,N]},o(k,{joinKeyGroups:v})},updateJoinKey:(k,h,f,C,D)=>{const v=a.joins.find(L=>L.id===k);if(!v)return;const N=n.find(L=>L.name===v.source.name),I=n.find(L=>L.name===v.target.name),O=[...v.joinKeyGroups],w=O[h].keys[f];C==="sourceColumnName"&&N?O[h].keys[f]={...w,source:{...w.source,name:D}}:C==="targetColumnName"&&I?O[h].keys[f]={...w,target:{...w.target,name:D}}:C==="operator"&&(O[h].keys[f]={...w,operator:D}),o(k,{joinKeyGroups:O})},removeJoinKey:(k,h,f)=>{const C=a.joins.find(v=>v.id===k);if(!C)return;const D=[...C.joinKeyGroups];D[h].keys.splice(f,1),o(k,{joinKeyGroups:D})},generateSQLPreview:()=>{const k=[...a.joins].sort((C,D)=>C.sequence-D.sequence),h=a.baseEntity;if(!h.name)return"SELECT * FROM table -- Please select a base entity";let f=`SELECT *
|
|
147
147
|
FROM ${h.name}`;return k.forEach(C=>{const D=n.find(I=>I.name===C.target.name);if(!D)return;const v=C.joinKeyGroups.filter(I=>I.keys&&I.keys.length>0).map(I=>{const O=I.keys.filter(w=>{var L,P,z,G;return((L=w.source)==null?void 0:L.name)&&((P=w.target)==null?void 0:P.name)&&((z=w.source)==null?void 0:z.entityName)&&((G=w.target)==null?void 0:G.entityName)}).map(w=>`${w.source.entityName}.${w.source.name} ${w.operator} ${w.target.entityName}.${w.target.name}`);return O.length>1?`(${O.join(` ${I.operator} `)})`:O[0]}).filter(Boolean),N=v.length>1?v.join(" OR "):v[0]||"condition_here";f+=`
|
|
148
148
|
${C.joinType} JOIN ${D.name}
|
|
149
|
-
ON ${N}`}),f},isValidConfiguration:()=>!(!a.baseEntity.name||a.joins.some(C=>!C.source.name||!C.target.name)||a.joins.some(C=>C.joinKeyGroups.some(D=>D.keys.length===0))||a.joins.some(C=>C.joinKeyGroups.some(D=>D.keys.some(v=>!v.source.name||!v.target.name||!v.operator))))}}function wt({joinPlan:t,availableDataSources:n,onSave:a,onRemove:r,onCancel:l}){const{setCardConfig:c}=s.useEditorActions();s.useEditorStore(v=>v.card.config);const{columnGroups:d}=s.useColumns(),{joinPlan:i,expandedJoins:o,setJoinPlan:u,addJoin:m,removeJoin:p,updateJoin:g,moveJoinUp:x,moveJoinDown:j,toggleJoinExpansion:b,getAvailableSourceEntities:y,getAvailableTargetEntities:S,addJoinKeyGroup:T,updateGroupOperator:B,removeJoinKeyGroup:M,addJoinKey:A,updateJoinKey:k,removeJoinKey:h,generateSQLPreview:f,isValidConfiguration:C}=St({initialJoinPlan:t,availableDataSources:n}),D=v=>{const N=d.find(I=>I.entityName===v);return(N==null?void 0:N.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(s.Select,{value:i.baseEntity.name,onValueChange:v=>{const N=n.find(I=>I.name===v);u({...i,baseEntity:{connectionId:(N==null?void 0:N.connectionId)||"",connectionType:(N==null?void 0:N.connectionType)||"none",type:(N==null?void 0:N.type)||"table",name:v,database:N==null?void 0:N.database,schema:N==null?void 0:N.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:n.map(v=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:v.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:v.type}),v.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},v.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This entity will be used as the base table in the FROM clause of the SQL query."})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:f()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{children:["Joins Configuration (",i.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:m,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),i.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-muted-foreground",children:e.jsx("p",{children:"No joins configured. Add a join to connect multiple data sources."})}):e.jsx("div",{className:"max-h-[300px] space-y-4 overflow-y-auto",children:i.joins.map(v=>{const N=n.find(w=>w.name===v.source.name),I=n.find(w=>w.name===v.target.name),O=o.has(v.id);return e.jsxs(s.Card,{className:"border",children:[e.jsx(s.CardHeader,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{children:v.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",v.sequence,N&&I&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",N.name," → ",I.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>x(v.id),disabled:v.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>j(v.id),disabled:v.sequence===i.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>b(v.id),children:O?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(v.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),O&&e.jsxs(s.CardContent,{className:"space-y-4 pb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Source"}),e.jsxs(s.Select,{value:v.source.name,onValueChange:w=>{const L=n.find(P=>P.name===w);g(v.id,{source:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:w,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:y(v.id).map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name]})},w.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:v.joinType,onValueChange:w=>g(v.id,{joinType:w}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:v.target.name,onValueChange:w=>{const L=n.find(P=>P.name===w);g(v.id,{target:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:w,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},disabled:!v.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:v.source.name?S(v.source.name).map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name,w.name===v.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},w.name)):[]})]})]})]}),v.source.name&&v.target.name&&N&&I&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Join Conditions"}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>T(v.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),v.joinKeyGroups.length===0?e.jsx("div",{className:"rounded-md border p-3 text-center text-sm text-gray-500",children:"No join conditions defined. Add condition groups to specify how data sources should be joined."}):e.jsx("div",{className:"space-y-4",children:v.joinKeyGroups.map((w,L)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",L+1]}),L>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:w.operator,onValueChange:P=>B(v.id,L,P),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>M(v.id,L),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[w.keys.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-center text-sm text-gray-500",children:"No conditions in this group. Add conditions to specify join criteria."}):e.jsx("div",{className:"space-y-2",children:w.keys.map((P,z)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[z>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:w.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:P.source.name,onValueChange:G=>k(v.id,L,z,"sourceColumnName",G),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:D(v.source.name).map(G=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:G.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:G.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:G.dataType})]})},G.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:P.operator,onValueChange:G=>k(v.id,L,z,"operator",G),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"=",children:"="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<",children:"<"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">",children:">"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<=",children:"<="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:P.target.name,onValueChange:G=>k(v.id,L,z,"targetColumnName",G),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:D(v.target.name).map(G=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:G.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:G.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:G.dataType})]})},G.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>h(v.id,L,z),children:e.jsx(s.X,{className:"size-3.5"})})]},P.id||z))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>A(v.id,L),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},w.id))})]})]})]},v.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),l()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>a(i),disabled:!C(),children:"Save"})]})]})}function Ss({children:t,open:n,onOpenChange:a,joinPlan:r,availableDataSources:l,onRemove:c,onSave:d,onCancel:i}){return e.jsxs(s.Dialog,{open:n,onOpenChange:a,children:[e.jsxs(s.DialogContent,{className:"max-w-4xl",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Join Configuration"}),e.jsx(s.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(wt,{joinPlan:r,availableDataSources:l,onSave:d,onCancel:i,onRemove:c})]}),t]})}function kt({joins:t,baseEntityId:n,availableDataSources:a,generateSQLPreview:r}){return e.jsxs("div",{className:"divide-y divide-border",children:[t.length>0&&e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const l=[...t].sort((d,i)=>d.sequence-i.sequence),c=a.find(d=>d.name===n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:c==null?void 0:c.type}),e.jsx("span",{className:"text-xs font-medium",children:c==null?void 0:c.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),l.map(d=>{const i=a.find(o=>o.name===d.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:d.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:i==null?void 0:i.type}),e.jsx("span",{className:"text-xs font-medium",children:i==null?void 0:i.name})]})]},d.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((l,c)=>l.sequence-c.sequence).map((l,c)=>{const d=a.find(o=>o.name===l.source.name),i=a.find(o=>o.name===l.target.name);return e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-muted p-2 text-left",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:c+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:l.joinType}),e.jsxs("span",{className:"text-xs font-medium",children:[d==null?void 0:d.name," → ",i==null?void 0:i.name]}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto text-xs",children:[l.joinKeyGroups.reduce((o,u)=>o+u.keys.length,0)," ","condition",l.joinKeyGroups.reduce((o,u)=>o+u.keys.length,0)>1?"s":""]})]},l.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function rs({open:t,onOpenChange:n,variant:a="button"}={}){var T,B;const r=s.useEditorStore(M=>M.card),{autoJoinMetadata:l}=s.useDashboardCardQuery(r),c=s.useEditorStore(M=>M.actions.updateCardConfig),d=((T=r==null?void 0:r.config)==null?void 0:T.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[i,o]=E.useState(!1),u=t!==void 0,m=u?t:i,p=u?n:o,g=((B=r==null?void 0:r.dataSource)==null?void 0:B.selectedEntities)||[],x=M=>{c(r.id,{...r==null?void 0:r.config,joinPlan:M}),p(!1)},j=()=>{c(r.id,{...r==null?void 0:r.config,joinPlan:void 0})},b=()=>{p(!1)},y=()=>{const M=[...d.joins].sort((h,f)=>h.sequence-f.sequence),A=d.baseEntity;if(!A.name)return"SELECT * FROM table -- Please select a base entity";let k=`SELECT *
|
|
149
|
+
ON ${N}`}),f},isValidConfiguration:()=>!(!a.baseEntity.name||a.joins.some(C=>!C.source.name||!C.target.name)||a.joins.some(C=>C.joinKeyGroups.some(D=>D.keys.length===0))||a.joins.some(C=>C.joinKeyGroups.some(D=>D.keys.some(v=>!v.source.name||!v.target.name||!v.operator))))}}function wt({joinPlan:t,availableDataSources:n,onSave:a,onRemove:r,onCancel:l}){const{setCardConfig:c}=s.useEditorActions();s.useEditorStore(v=>v.card.config);const{columnGroups:d}=s.useColumns(),{joinPlan:i,expandedJoins:o,setJoinPlan:u,addJoin:m,removeJoin:p,updateJoin:g,moveJoinUp:x,moveJoinDown:j,toggleJoinExpansion:b,getAvailableSourceEntities:y,getAvailableTargetEntities:S,addJoinKeyGroup:T,updateGroupOperator:B,removeJoinKeyGroup:M,addJoinKey:A,updateJoinKey:k,removeJoinKey:h,generateSQLPreview:f,isValidConfiguration:C}=St({initialJoinPlan:t,availableDataSources:n}),D=v=>{const N=d.find(I=>I.entityName===v);return(N==null?void 0:N.columns)||[]};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Base Entity (FROM clause)"}),e.jsxs(s.Select,{value:i.baseEntity.name,onValueChange:v=>{const N=n.find(I=>I.name===v);u({...i,baseEntity:{connectionId:(N==null?void 0:N.connectionId)||"",connectionType:(N==null?void 0:N.connectionType)||"none",type:(N==null?void 0:N.type)||"table",name:v,database:N==null?void 0:N.database,schema:N==null?void 0:N.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select base entity..."})}),e.jsx(s.SelectContent,{children:n.map(v=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:v.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:v.type}),v.name,e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]})},v.name))})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This entity will be used as the base table in the FROM clause of the SQL query."})]}),e.jsxs("div",{className:"rounded-md border p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"Join SQL Preview"}),e.jsx("code",{className:"block whitespace-pre-wrap break-all text-xs",children:f()})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(s.Label,{children:["Joins Configuration (",i.joins.length,")"]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs(s.Button,{variant:"outline",size:"sm",onClick:m,children:[e.jsx(s.Plus,{className:"mr-1 h-4 w-4"}),"Add Join"]})})]}),i.joins.length===0?e.jsx("div",{className:"rounded-lg border border-dashed py-8 text-center text-muted-foreground",children:e.jsx("p",{children:"No joins configured. Add a join to connect multiple data sources."})}):e.jsx("div",{className:"max-h-[300px] space-y-4 overflow-y-auto",children:i.joins.map(v=>{const N=n.find(w=>w.name===v.source.name),I=n.find(w=>w.name===v.target.name),O=o.has(v.id);return e.jsxs(s.Card,{className:"border",children:[e.jsx(s.CardHeader,{className:"pb-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{children:v.sequence}),e.jsxs(s.CardTitle,{className:"text-sm",children:["Join ",v.sequence,N&&I&&e.jsxs("span",{className:"ml-2 font-normal text-gray-600",children:["(",N.name," → ",I.name,")"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>x(v.id),disabled:v.sequence===1,children:e.jsx(s.ArrowUp,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>j(v.id),disabled:v.sequence===i.joins.length,children:e.jsx(s.ArrowDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>b(v.id),children:O?e.jsx(s.ChevronUp,{className:"h-4 w-4"}):e.jsx(s.ChevronDown,{className:"h-4 w-4"})}),e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:()=>p(v.id),children:e.jsx(s.X,{className:"h-4 w-4"})})]})]})}),O&&e.jsxs(s.CardContent,{className:"space-y-4 pb-6",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Source"}),e.jsxs(s.Select,{value:v.source.name,onValueChange:w=>{const L=n.find(P=>P.name===w);g(v.id,{source:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:w,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select source..."})}),e.jsx(s.SelectContent,{children:y(v.id).map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name]})},w.name))})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Join Type"}),e.jsxs(s.Select,{value:v.joinType,onValueChange:w=>g(v.id,{joinType:w}),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"INNER",children:"INNER JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"LEFT",children:"LEFT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"RIGHT",children:"RIGHT JOIN"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"FULL",children:"FULL JOIN"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(s.Label,{children:"Target"}),e.jsxs(s.Select,{value:v.target.name,onValueChange:w=>{const L=n.find(P=>P.name===w);g(v.id,{target:{connectionId:(L==null?void 0:L.connectionId)||"",connectionType:(L==null?void 0:L.connectionType)||"none",type:(L==null?void 0:L.type)||"table",name:w,database:L==null?void 0:L.database,schema:L==null?void 0:L.schema}})},disabled:!v.source.name,children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Select target..."})}),e.jsx(s.SelectContent,{children:v.source.name?S(v.source.name).map(w=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:w.name,children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:w.type}),w.name,w.name===v.source.name&&e.jsx(s.Badge,{variant:"outline",className:"text-xs text-yellow-600",children:"(Self-join)"})]})},w.name)):[]})]})]})]}),v.source.name&&v.target.name&&N&&I&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(s.Label,{children:"Join Conditions"}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>T(v.id),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition Group"]})]}),v.joinKeyGroups.length===0?e.jsx("div",{className:"rounded-md border p-3 text-center text-sm text-gray-500",children:"No join conditions defined. Add condition groups to specify how data sources should be joined."}):e.jsx("div",{className:"space-y-4",children:v.joinKeyGroups.map((w,L)=>e.jsxs("div",{className:"space-y-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Label,{children:["Group ",L+1]}),L>0&&e.jsxs("div",{className:"flex items-center gap-2 rounded-md bg-gray-100 px-2 py-1",children:[e.jsx(s.Label,{className:"text-xs font-normal",children:"Join with:"}),e.jsx("span",{className:"text-sm font-medium",children:"OR"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(s.Select,{value:w.operator,onValueChange:P=>B(v.id,L,P),children:[e.jsx(s.SelectTrigger,{className:"w-[100px]",children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"AND",children:"AND"}),e.jsx(s.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>M(v.id,L),children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[w.keys.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-center text-sm text-gray-500",children:"No conditions in this group. Add conditions to specify join criteria."}):e.jsx("div",{className:"space-y-2",children:w.keys.map((P,z)=>e.jsxs("div",{className:"flex flex-col items-start gap-2 rounded-md border p-2 sm:flex-row sm:items-center",children:[z>0&&e.jsx("div",{className:"self-center rounded-md bg-gray-100 px-2 py-1 text-xs font-medium",children:w.operator}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:P.source.name,onValueChange:G=>k(v.id,L,z,"sourceColumnName",G),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Source column"})}),e.jsx(s.SelectContent,{children:D(v.source.name).map(G=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:G.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("span",{children:G.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:G.dataType})]})},G.name))})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:w-20",children:e.jsxs(s.Select,{value:P.operator,onValueChange:G=>k(v.id,L,z,"operator",G),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{})}),e.jsxs(s.SelectContent,{children:[e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"=",children:"="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<",children:"<"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">",children:">"}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:"<=",children:"<="}),e.jsx(s.SelectItem,{className:"hover:bg-muted",value:">=",children:">="})]})]})}),e.jsx("div",{className:"mb-2 w-full sm:mb-0 sm:flex-1",children:e.jsxs(s.Select,{value:P.target.name,onValueChange:G=>k(v.id,L,z,"targetColumnName",G),children:[e.jsx(s.SelectTrigger,{children:e.jsx(s.SelectValue,{placeholder:"Target column"})}),e.jsx(s.SelectContent,{children:D(v.target.name).map(G=>e.jsx(s.SelectItem,{className:"hover:bg-muted",value:G.name,children:e.jsxs("div",{className:"flex w-full items-center justify-between hover:bg-muted",children:[e.jsx("span",{children:G.name}),e.jsx(s.Badge,{variant:"outline",className:"ml-2 text-xs",children:G.dataType})]})},G.name))})]})}),e.jsx(s.Button,{type:"button",variant:"ghost",size:"sm",className:"self-center",onClick:()=>h(v.id,L,z),children:e.jsx(s.X,{className:"size-3.5"})})]},P.id||z))}),e.jsxs(s.Button,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>A(v.id,L),children:[e.jsx(s.Plus,{className:"mr-1 h-3 w-3"})," Add Condition"]})]})]},w.id))})]})]})]},v.id)})})]}),e.jsxs("div",{className:"flex justify-end gap-2 border-t pt-4",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>{r(),l()},children:"Remove All"}),e.jsx(s.Button,{variant:"outline",onClick:l,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>a(i),disabled:!C(),children:"Save"})]})]})}function Ss({children:t,open:n,onOpenChange:a,joinPlan:r,availableDataSources:l,onRemove:c,onSave:d,onCancel:i}){return e.jsxs(s.Dialog,{open:n,onOpenChange:a,children:[e.jsxs(s.DialogContent,{className:"max-w-4xl",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Join Configuration"}),e.jsx(s.DialogDescription,{children:"Configure the join between the two entities to combine the fields."})]}),e.jsx(wt,{joinPlan:r,availableDataSources:l,onSave:d,onCancel:i,onRemove:c})]}),t]})}function kt({joins:t,baseEntityId:n,availableDataSources:a,generateSQLPreview:r}){return e.jsxs("div",{className:"max-h-[400px] divide-y divide-border overflow-y-auto",children:[t.length>0&&e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left font-semibold",children:"Join Chain"}),e.jsx("div",{className:"flex flex-wrap items-center gap-2",children:(()=>{const l=[...t].sort((d,i)=>d.sequence-i.sequence),c=a.find(d=>d.name===n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:c==null?void 0:c.type}),e.jsx("span",{className:"text-xs font-medium",children:c==null?void 0:c.name}),e.jsx(s.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),l.map(d=>{const i=a.find(o=>o.name===d.target.name);return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"mx-1 flex items-center gap-1",children:[e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:d.joinType}),e.jsx("span",{className:"text-muted-foreground",children:"→"})]}),e.jsxs("div",{className:"flex items-center gap-1 rounded-md border bg-muted px-2 py-1",children:[e.jsx(s.Badge,{variant:"secondary",className:"text-xs",children:i==null?void 0:i.type}),e.jsx("span",{className:"text-xs font-medium",children:i==null?void 0:i.name})]})]},d.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",t.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...t].sort((l,c)=>l.sequence-c.sequence).map((l,c)=>{const d=a.find(u=>u.name===l.source.name),i=a.find(u=>u.name===l.target.name),o=l.joinKeyGroups.reduce((u,m)=>u+m.keys.length,0);return e.jsxs("div",{className:"rounded-md bg-muted p-2 text-left",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:c+1}),e.jsx(s.Badge,{variant:"outline",className:"shrink-0 text-xs",children:l.joinType}),e.jsxs(s.Badge,{variant:"outline",className:"ml-auto shrink-0 text-xs",children:[o," condition",o>1?"s":""]})]}),e.jsxs("div",{className:"mt-1 truncate pl-1 text-xs text-muted-foreground",children:[d==null?void 0:d.name," → ",i==null?void 0:i.name]})]},l.id)})})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"mb-3 text-left text-sm font-medium",children:"SQL Query"}),e.jsx("div",{className:"overflow-x-auto rounded-md border bg-muted p-3",children:e.jsx("pre",{className:"whitespace-pre-wrap break-all text-left font-mono text-xs text-muted-foreground",children:r()})})]})]})}function rs({open:t,onOpenChange:n,variant:a="button"}={}){var T,B;const r=s.useEditorStore(M=>M.card),{autoJoinMetadata:l}=s.useDashboardCardQuery(r),c=s.useEditorStore(M=>M.actions.updateCardConfig),d=((T=r==null?void 0:r.config)==null?void 0:T.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[i,o]=E.useState(!1),u=t!==void 0,m=u?t:i,p=u?n:o,g=((B=r==null?void 0:r.dataSource)==null?void 0:B.selectedEntities)||[],x=M=>{c(r.id,{...r==null?void 0:r.config,joinPlan:M}),p(!1)},j=()=>{c(r.id,{...r==null?void 0:r.config,joinPlan:void 0})},b=()=>{p(!1)},y=()=>{const M=[...d.joins].sort((h,f)=>h.sequence-f.sequence),A=d.baseEntity;if(!A.name)return"SELECT * FROM table -- Please select a base entity";let k=`SELECT *
|
|
150
150
|
FROM ${A.name}`;return M.forEach(h=>{const f=g.find(v=>v.name===h.target.name);if(!f)return;const C=h.joinKeyGroups.filter(v=>v.keys&&v.keys.length>0).map(v=>{const N=v.keys.filter(I=>{var O,w,L,P;return((O=I.source)==null?void 0:O.name)&&((w=I.target)==null?void 0:w.name)&&((L=I.source)==null?void 0:L.entityName)&&((P=I.target)==null?void 0:P.entityName)}).map(I=>`${I.source.entityName}.${I.source.name} ${I.operator} ${I.target.entityName}.${I.target.name}`);return N.length>1?`(${N.join(` ${v.operator} `)})`:N[0]}).filter(Boolean),D=C.length>1?C.join(" OR "):C[0]||"condition_here";k+=`
|
|
151
151
|
${h.joinType} JOIN ${f.name}
|
|
152
152
|
ON ${D}`}),k};if(g.length<2)return null;const S=d.joins.length>0&&e.jsx(s.TooltipContent,{side:"bottom",className:"ml-4 max-w-md overflow-hidden p-0",children:e.jsx(kt,{joins:d.joins,baseEntityId:d.baseEntity.name,availableDataSources:g,generateSQLPreview:y})});return e.jsxs(e.Fragment,{children:[e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:a==="badge"?e.jsxs(s.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:M=>{M.stopPropagation(),p(!0)},children:[e.jsx(s.Link,{className:"h-3 w-3"}),d.joins.length]}):e.jsxs(s.Button,{onClick:()=>p(!0),variant:"outline",className:"w-full bg-muted/50",children:[e.jsx(s.Link,{className:"mr-2 h-3.5 w-3.5"}),d.joins.length===0?"Configure Joins":d.joins.length===1?"Join":"Joins",d.joins.length>0&&e.jsx("span",{className:"ml-2 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-medium text-primary-foreground",children:d.joins.length}),(l==null?void 0:l.autoResolved)&&e.jsxs(s.Badge,{variant:"secondary",className:"ml-2 h-5 gap-1 bg-blue-50 text-blue-700 dark:bg-blue-950 dark:text-blue-300",children:[e.jsx(s.Sparkles,{className:"h-3 w-3"}),"Auto"]})]})}),S]})}),e.jsx(Ss,{open:m,onOpenChange:p,joinPlan:d,availableDataSources:g,onSave:x,onCancel:b,onRemove:j,children:e.jsx("div",{})})]})}function Tt({open:t,onOpenChange:n}){const[a,r]=E.useState([]),{updateDataSource:l}=s.useEditorActions(),c=s.useDashboardStore(j=>j.dashboard.aiContext),d=(c==null?void 0:c.selectedEntities)||[];E.useEffect(()=>{t&&r([])},[t]);const i=j=>{r(b=>b.some(S=>S.name===j.name&&S.type===j.type)?b.filter(S=>!(S.name===j.name&&S.type===j.type)):[...b,j])},o=()=>{r([...d])},u=()=>{r([])},m=()=>{if(a.length===0)return;const j=a[0],b=j.connectionId||"",y=j.connectionType||"",T=a.some(M=>M.type==="dataset")?"semanticDomain":"database";l({connectionId:b,connectionType:y,mode:T,selectedEntities:a}),n(!1)},p=j=>"label"in j&&j.label?j.label:j.name,g=j=>{if("description"in j&&j.description)return j.description;const b=[];return j.database&&b.push(j.database),j.schema&&b.push(j.schema),j.name&&b.push(j.name),b.join(".")},x=j=>a.some(b=>b.name===j.name&&b.type===j.type);return d.length===0?e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"max-w-md",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"No Data Available"}),e.jsx(s.DialogDescription,{children:"No entities are currently available in the AI context. Please add some data sources to the dashboard first."})]}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{onClick:()=>n(!1),children:"Close"})})]})}):e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"flex max-w-2xl flex-col",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Select Data to Analyze"}),e.jsx(s.DialogDescription,{children:"Choose entities from the dashboard's context"})]}),e.jsxs("div",{className:"flex-1 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{variant:"outline",size:"sm",onClick:o,disabled:a.length===d.length,children:"Select All"}),e.jsx(s.Button,{variant:"outline",size:"sm",onClick:u,disabled:a.length===0,children:"Clear All"})]}),e.jsxs(s.Badge,{variant:"secondary",children:[a.length," of ",d.length," selected"]})]}),e.jsx(s.Separator,{}),e.jsx(s.ScrollArea,{className:"h-64",children:e.jsx("div",{className:"space-y-2",children:d.map((j,b)=>e.jsxs("div",{className:s.cn("flex items-center gap-3 rounded-lg border p-3 transition-colors hover:bg-muted/50",x(j)&&"border-primary bg-primary/5"),children:[e.jsx(s.Checkbox,{checked:x(j),onCheckedChange:()=>i(j)}),e.jsx("div",{className:"flex items-center gap-2 text-muted-foreground",children:s.getEntityIcon(j.type)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate font-medium",children:p(j)}),e.jsx("div",{className:"truncate text-sm text-muted-foreground",children:g(j)})]}),e.jsx(s.Badge,{variant:"outline",className:"text-xs",children:j.type})]},`${j.type}-${j.name}-${b}`))})})]}),e.jsx(s.DialogFooter,{children:e.jsx("div",{className:"flex w-full justify-between",children:e.jsxs("div",{className:"flex grow justify-end gap-2",children:[e.jsx(s.Button,{variant:"outline",onClick:()=>n(!1),children:"Cancel"}),e.jsxs(s.Button,{onClick:m,disabled:a.length===0,children:["Select"," ",a.length>0?`(${a.length})`:""]})]})})})]})})}function ls({entities:t,title:n}){const{isConsoleMode:a}=s.useDashboardPreferences();return e.jsx(s.TooltipContent,{side:"top",className:"ml-5 max-w-xs",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-sm font-medium",children:n??`${t.length} more entities`}),e.jsx("div",{className:"space-y-1",children:t.map((r,l)=>{const c=s.getEntityDetails(r),d=c.find(o=>o.label==="Description"&&o.value),i=c.filter(o=>o.label==="Description"?!1:a?!0:!["Connection","Database","Schema"].includes(o.label)).slice(0,3);return e.jsxs("div",{className:"border-b border-border pb-1 last:border-b-0",children:[e.jsx("div",{className:"text-xs font-medium",children:s.getDisplayName(r)}),d&&e.jsxs("div",{className:"mb-1 mt-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Description:"}),e.jsx("div",{className:"text-xs leading-relaxed",children:d.value})]}),i.length>0&&e.jsx("div",{className:"mt-1 space-y-0.5",children:i.map((o,u)=>e.jsxs("div",{className:"flex justify-between text-xs",children:[e.jsxs("span",{className:"mr-2 text-muted-foreground",children:[o.label,":"]}),e.jsx("span",{className:"font-mono",children:o.value})]},u))})]},`remaining-${r.type}-${r.name}-${l}`)})})]})})}function Ve(t,n){const[a,r]=E.useState(()=>{const l=localStorage.getItem(t);return l?JSON.parse(l):n});return E.useEffect(()=>{localStorage.setItem(t,JSON.stringify(a))},[a,t]),[a,r]}function ws({isVisible:t}){var b,y;const n=s.useEditorStore(S=>S.isDevMode);s.useSyncLegacyEditorState();const[a,r]=E.useState(!1),[l,c]=E.useState(!1),[d,i]=Ve("semaphor:data-source-collapsed",!1),o=s.useEditorStore(S=>S.card.dataSource),u=s.useEditorStore(S=>{var T,B;return(B=(T=S.card)==null?void 0:T.config)==null?void 0:B.joinPlan}),{updateDataSource:m}=s.useEditorActions(),p=((b=o==null?void 0:o.selectedEntities)==null?void 0:b.length)||0,g=((y=u==null?void 0:u.joins)==null?void 0:y.length)||0,j={...{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},...o,selectedEntities:(o==null?void 0:o.selectedEntities)||[]};return e.jsxs("div",{className:s.cn("flex flex-col overflow-hidden bg-background transition-all duration-300 ease-in-out",{"w-[325px]":t,"w-0":!t}),children:[p===0&&g===0?e.jsx("div",{className:"p-4 px-6",children:e.jsxs(s.Button,{className:"w-full bg-muted/50",variant:"outline",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),"Choose Dataset"]})}):e.jsxs("div",{children:[e.jsxs("div",{className:s.cn("flex cursor-pointer items-center justify-between px-6 pt-3",!d&&"pb-3"),onClick:()=>i(!d),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:"Data Source"}),d&&e.jsxs("div",{className:"flex items-center gap-1.5",onClick:S=>S.stopPropagation(),children:[p>0&&e.jsx(s.TooltipProvider,{delayDuration:100,children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"h-3 w-3"}),p]})}),e.jsx(ls,{entities:j.selectedEntities,title:`${p} selected ${p===1?"entity":"entities"}`})]})}),g>0&&!n&&e.jsx(rs,{variant:"badge"})]})]}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:S=>{S.stopPropagation(),i(!d)},children:d?e.jsx(s.ChevronDown,{className:"h-4 w-4"}):e.jsx(s.ChevronUp,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:s.cn("overflow-hidden transition-all duration-200 ease-in-out",d?"max-h-0 opacity-0":"max-h-96 opacity-100"),children:[e.jsx("div",{className:"px-6 pb-2",children:e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(s.Button,{className:"w-full bg-muted/50",variant:"outline",onClick:()=>r(!0),children:[e.jsx(s.Database,{className:"mr-2 h-3.5 w-3.5"}),p===1?"Dataset":"Datasets",e.jsx("span",{className:"ml-2 flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-xs font-medium text-primary-foreground",children:p})]})}),e.jsx(ls,{entities:j.selectedEntities,title:`${p} selected ${p===1?"entity":"entities"}`})]})})}),!n&&e.jsx("div",{className:"px-6 pb-2",children:e.jsx(rs,{})})]})]}),e.jsx(s.FieldsSection,{}),e.jsx(s.DataSourceDialog,{incomingSelectedEntities:(o==null?void 0:o.selectedEntities)||[],dialogMode:"dataSource",open:a,onOpenChange:r,dataSource:j}),e.jsx(Tt,{open:l,onOpenChange:c})]})}function He({error:t,errorSql:n,onSendFeedback:a,onOpenInEditor:r,className:l,showFeedbackButton:c=!0,errorTitle:d="Query Error"}){const[i,o]=E.useState(!1);return e.jsx("div",{className:s.cn("rounded-lg border border-destructive/30 bg-destructive/5 p-4",l),children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(s.CircleAlert,{className:"mt-0.5 h-5 w-5 flex-shrink-0 text-destructive"}),e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-destructive",children:d}),e.jsxs("div",{className:"relative rounded-md bg-background/60 p-3",children:[e.jsx(s.CopyButton,{text:t,className:"absolute right-2 top-2 h-6 w-6 z-10"}),e.jsx("div",{className:"max-h-40 overflow-auto pr-10",children:e.jsx("p",{className:"font-mono text-xs text-foreground/80 break-all",children:t})})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.jsx(s.Collapsible,{open:i,onOpenChange:o,children:e.jsx(s.CollapsibleTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"sm",className:"h-8",children:i?e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronUp,{className:"mr-1.5 h-3.5 w-3.5"}),"Hide Details"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.ChevronDown,{className:"mr-1.5 h-3.5 w-3.5"}),"Show Details"]})})})}),r&&n&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:r,children:[e.jsx(Ns,{className:"mr-1.5 h-3.5 w-3.5"}),"Open in Editor"]}),c&&a&&e.jsxs(s.Button,{variant:"outline",size:"sm",className:"h-8",onClick:a,children:[e.jsx(s.MessageSquareWarning,{className:"mr-1.5 h-3.5 w-3.5"}),"Send Feedback"]})]}),n&&e.jsx(s.Collapsible,{open:i,onOpenChange:o,children:e.jsx(s.CollapsibleContent,{className:"space-y-2",children:e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:"Error SQL Query"}),e.jsx(s.CopyButton,{text:n,className:"h-6 w-6"})]}),e.jsx("div",{className:"rounded-md bg-background/60 p-2 max-h-80 overflow-auto",children:e.jsx(s.CodeHighlighter,{code:n,language:"sql"})})]})})})]})]})})}function ks({sql:t,error:n,errorSql:a,onDebugWithAssistant:r}){const l=s.useEditorStore(b=>b.isDevMode),{setIsDevMode:c,setCardSql:d,setRunSql:i}=s.useEditorActions(),[o,u]=E.useState(!1),m=s.useEditorStore(b=>b.card),p=s.useEditorStore(b=>b.frame),g=s.useDashboardStore(b=>b.selectedSheetId),x=s.useDashboardStore(b=>{var y;return(y=b.dashboard)==null?void 0:y.id});function j(b){c(!0),d(b||t),setTimeout(()=>{i(!0)},100)}return e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col pt-4",children:[!l&&t&&!n&&e.jsxs("div",{className:"mb-3 flex items-center gap-2",children:[e.jsxs(s.Button,{onClick:()=>j(),variant:"secondary",size:"sm",children:[e.jsx(Ns,{className:"mr-2 h-4 w-4"}),"View in SQL Editor"]}),e.jsxs(s.Button,{onClick:()=>u(!o),variant:"outline",size:"sm",children:[e.jsx(s.Info,{className:"mr-2 h-4 w-4"}),"Card Details"]})]}),o&&e.jsx("div",{className:"mb-3 rounded-lg border border-border bg-muted/30 p-4",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:"Card Information"}),e.jsx(s.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>u(!1),children:e.jsx(ys,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Card ID"}),e.jsx("code",{className:"text-xs font-mono",children:m.id||"N/A"})]}),e.jsx(s.CopyButton,{text:m.id||"",className:"h-6 w-6"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Frame ID"}),e.jsx("code",{className:"text-xs font-mono",children:p.id||"N/A"})]}),e.jsx(s.CopyButton,{text:p.id||"",className:"h-6 w-6"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Sheet ID"}),e.jsx("code",{className:"text-xs font-mono",children:g||"N/A"})]}),e.jsx(s.CopyButton,{text:g||"",className:"h-6 w-6"})]}),e.jsxs("div",{className:"flex items-center justify-between rounded-md bg-background/60 px-3 py-2",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Dashboard ID"}),e.jsx("code",{className:"text-xs font-mono",children:x||"N/A"})]}),e.jsx(s.CopyButton,{text:x||"",className:"h-6 w-6"})]})]})]})}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-auto text-xs leading-relaxed text-foreground/80",children:[n&&e.jsx(He,{error:n,errorSql:a,showFeedbackButton:!1,onOpenInEditor:()=>j(a)}),!n&&t&&e.jsx("div",{className:"flex flex-col space-y-1.5",children:e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute right-2 top-2 z-10",children:e.jsx(s.CopyButton,{text:t,className:"h-6 w-6"})}),e.jsx(s.CodeHighlighter,{code:t,language:"sql"})]})})]}),n&&r&&e.jsx("div",{className:"mt-3",children:e.jsxs(s.Button,{onClick:r,size:"sm",variant:"outline",children:[e.jsx(ut,{className:"mr-2 h-4 w-4"}),"Debug with Assistant"]})})]})}function Et({sql:t,error:n,errorSql:a,onDebugWithAssistant:r}){return e.jsxs(s.HoverCard,{openDelay:n?0:500,children:[e.jsx(s.HoverCardTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"link",className:"h-5 p-0",children:n?e.jsx(ys,{className:"h-4 w-4 text-red-500"}):e.jsx(s.Info,{className:"h-4 w-4 text-muted-foreground"})})}),e.jsx(s.HoverCardContent,{align:"start",className:"flex w-[700px]",children:e.jsx(ks,{errorSql:a,sql:t,error:n,onDebugWithAssistant:r})})]})}function At(t){return s.GenIcon({attr:{viewBox:"0 0 448 512"},child:[{tag:"path",attr:{d:"M439.8 200.5c-7.7-30.9-22.3-54.2-53.4-54.2h-40.1v47.4c0 36.8-31.2 67.8-66.8 67.8H172.7c-29.2 0-53.4 25-53.4 54.3v101.8c0 29 25.2 46 53.4 54.3 33.8 9.9 66.3 11.7 106.8 0 26.9-7.8 53.4-23.5 53.4-54.3v-40.7H226.2v-13.6h160.2c31.1 0 42.6-21.7 53.4-54.2 11.2-33.5 10.7-65.7 0-108.6zM286.2 404c11.1 0 20.1 9.1 20.1 20.3 0 11.3-9 20.4-20.1 20.4-11 0-20.1-9.2-20.1-20.4.1-11.3 9.1-20.3 20.1-20.3zM167.8 248.1h106.8c29.7 0 53.4-24.5 53.4-54.3V91.9c0-29-24.4-50.7-53.4-55.6-35.8-5.9-74.7-5.6-106.8.1-45.2 8-53.4 24.7-53.4 55.6v40.7h106.9v13.6h-147c-31.1 0-58.3 18.7-66.8 54.2-9.8 40.7-10.2 66.1 0 108.6 7.6 31.6 25.7 54.2 56.8 54.2H101v-48.8c0-35.3 30.5-66.4 66.8-66.4zm-6.7-142.6c-11.1 0-20.1-9.1-20.1-20.3.1-11.3 9-20.4 20.1-20.4 11 0 20.1 9.2 20.1 20.4s-9 20.3-20.1 20.3z"},child:[]}]})(t)}function Ts(t){const{theme:n}=s.useTheme(),a=s.useDashboardStore(b=>b.theme),r=s.useEditorStore(b=>b.frame),l=s.useEditorStore(b=>b.card),c=s.useEditorStore(b=>b.activeTabCardId),d=s.Le(),{refetch:i}=s.useDashboardCardQuery(l),{updateCardTab:o,setRunSql:u}=s.useEditorActions(),m=E.useRef(),p=E.useRef({}),g=r.cards.find(b=>b.id===c),x=E.useCallback(()=>{let b="";return t==="python"&&(b=(g==null?void 0:g.python)||s.PYTHON_DEFAULT_CODE),t==="sql"&&(b=(g==null?void 0:g.sql)||""),b},[t,g]);E.useEffect(()=>{if(c&&l.id&&l.id!==c){if(m.current&&d){const b=m.current.getModel();b&&(p.current[l.id]=b);let y=p.current[c];if(!y){const S=x();y=d.editor.createModel(S,t),p.current[c]=y}m.current.setModel(y)}o(c,l),u(!0)}},[c,l,o,d,u,t,x]),E.useEffect(()=>{if(!d)return;const b=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light",y=a==="system"?b:a;d.editor.defineTheme("default",{base:y==="light"?"vs":"vs-dark",inherit:!0,rules:[],colors:{"editor.background":y==="light"?"#ffffff":s.hslStringToHex("240 10% 10%")}}),d.editor.setTheme("default")},[n,a,d]),E.useEffect(()=>{const b=m.current;b&&d&&l&&b.addCommand(d.KeyMod.Shift|d.KeyCode.Enter,function(){return i(),!1})},[d,i,l]);function j(b,y){if(m.current=b,!p.current[l.id]){const S=b.getModel(),T=x();p.current[l.id]=S||(y==null?void 0:y.editor.createModel(T,t))||b.getModel()}b.setModel(p.current[l.id])}return{handleEditorDidMount:j}}function It(){const t=s.useEditorStore(d=>d.card.sql),n=s.useEditorStore(d=>d.sqlGen),{setCardSql:a,setSqlGen:r}=s.useEditorActions(),{handleEditorDidMount:l}=Ts("sql");function c(d){a(d),s.isObjectEmpty(n)||r({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!t&&e.jsx("div",{className:"pointer-events-none absolute left-[65px] top-3 z-10 font-mono text-sm text-muted-foreground",children:"Write your SQL here"}),e.jsx(s.Ft,{theme:"default",className:"pt-3",onChange:c,value:t||"",options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"sql",onMount:l})]})}function Dt(){const t=s.useEditorStore(l=>l.card.python),{setCardPython:n}=s.useEditorActions(),{handleEditorDidMount:a}=Ts("python");function r(l){n(l)}return e.jsx(s.Ft,{className:"pt-3",theme:"default",onChange:r,value:t||s.PYTHON_DEFAULT_CODE,options:{minimap:{enabled:!1},wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:13,renderLineHighlight:"none"},defaultLanguage:"python",onMount:a})}function Lt(){const t=s.useQueryClient(),{isConsoleMode:n}=s.useDashboardPreferences(),[a,r]=E.useState(!1);s.useEditorStore(R=>R.frame);const l=s.useEditorStore(R=>R.card);s.useEditorStore(R=>R.isShowingVisual),s.useEditorStore(R=>R.selectedConnectionId),s.useEditorStore(R=>R.tempQueryData),s.useEditorStore(R=>R.selectedDatabaseName),s.useEditorStore(R=>R.selectedDatamodelId),s.useEditorStore(R=>R.selectedSchemaName);const c=s.useEditorStore(R=>R.showAIDialog);s.useEditorStore(R=>R.selectedTableName);const d=s.useEditorStore(R=>{var K;return(K=R==null?void 0:R.card)==null?void 0:K.sql}),i=s.useEditorStore(R=>{var K;return(K=R==null?void 0:R.card)==null?void 0:K.python}),{cardFilterValues:o}=s.useCardFilterValues((l==null?void 0:l.id)??""),{setCardCustomCfg:u,setQueryResultColumns:m,setCardSql:p,setTempQueryData:g,setPythonStdOut:x,setCardPreferences:j,setCardType:b,setCardPython:y,runAssistant:S,setShowAIDialog:T,setCard:B,updateCardInFrame:M}=s.useEditorActions();s.useEditorStore(R=>R.onSave),s.useEditorStore(R=>R.onClose),s.useEditorStore(R=>R.actions.setSqlGen);const A=s.useEditorStore(R=>R.runSql),k=s.useEditorStore(R=>R.actions.setRunSql),h=s.useEditorStore(R=>R.actions.setIsSqlRunning),{data:f,isLoading:C,isFetching:D,isSuccess:v,isError:N,error:I,errorSql:O,queryKey:w,refetch:L,errorMessage:P}=s.useDashboardCardQuery(l);E.useEffect(()=>{if(f&&(f.rowLimitExceeded&&s.ue.error("Row limit (10,000) exceeded. Refine your query.",{position:"top-center",richColors:!0}),x((f==null?void 0:f.output)||""),f.records.length>0)){const{dimensionKeys:R}=s.getKeys(f.records);m(R)}},[f,m,x]),E.useEffect(()=>{(C||D)&&h(!0),(N||v)&&h(!1),N&&(m([]),x(""))},[C,D,f,x,N,v,h,m,I]),E.useEffect(()=>{A&&(t.getQueryData(w)||L(),k(!1))},[A,L,k,w,t]);async function z(){const R=`Can you help me debug this query?
|