react-semaphor 0.1.435 → 0.1.437
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-BSHDErvU.js → dashboard--OqogTLn.js} +23217 -23170
- package/dist/chunks/{dashboard-Bp3M6YmS.js → dashboard-BJr7m1TP.js} +208 -208
- package/dist/chunks/dashboard-briefing-launcher-BRjtoHFz.js +31 -0
- package/dist/chunks/{dashboard-briefing-launcher-D-QS3bYN.js → dashboard-briefing-launcher-Cegf8sog.js} +752 -740
- package/dist/chunks/{dashboard-controls-BKaTTk-y.js → dashboard-controls-BjWzQbOT.js} +884 -874
- package/dist/chunks/dashboard-controls-DbOKYwbJ.js +36 -0
- package/dist/chunks/{dashboard-json-BkL6Xf10.js → dashboard-json-BYHE2Xi7.js} +1 -1
- package/dist/chunks/{dashboard-json-DrOZ5EP1.js → dashboard-json-D3rtzp8l.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-DOFAJpQh.js → edit-dashboard-visual-3rc-aeNO.js} +2 -2
- package/dist/chunks/{edit-dashboard-visual-BcV0QmRp.js → edit-dashboard-visual-BKTpoR38.js} +702 -699
- package/dist/chunks/{report-preferences-dialog-BiCnXwKt.js → report-preferences-dialog-CoYKKbFc.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-Nib_Yl_j.js → report-preferences-dialog-VVM61k5R.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-CG5Se5yF.js → use-create-flow-overlay-state-CpH9832I.js} +1 -1
- package/dist/chunks/{use-create-flow-overlay-state-CNdny3Z2.js → use-create-flow-overlay-state-Doo8NeYf.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +2 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/surfboard.d.ts +2 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/chunks/dashboard-briefing-launcher-C9phmdyP.js +0 -31
- package/dist/chunks/dashboard-controls-Znhp6MTa.js +0 -36
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./code-editor-BSENCZwR.js"),s=require("./dashboard-BJr7m1TP.js"),T=require("./index-jSrCwPQz.js");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");const f=require("react");require("./index-Dpm_VET4.js");require("./comparison-document-migration-DbU_BTxR.js");const ss=require("react-dom");require("../briefings/index.cjs");const q=require("./dashboard-briefing-launcher-BRjtoHFz.js"),wt=require("./search-Dcud9ajy.js"),Dt=require("./index-D7KJindZ.js"),rs=require("./report-preferences-dialog-CoYKKbFc.js"),as=require("./use-debounced-dirty-check-XHSwAefL.js"),Ge=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),bt=require("./save-Xdc4pnys.js"),ns=require("./palette-C0yjT5Tv.js"),os=require("./braces-CbO-aIwH.js");function is(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 A=is(f);/**
|
|
2
|
+
* @license lucide-react v0.453.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const ds=T.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
|
|
7
|
+
* @license lucide-react v0.453.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/const ls=T.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
|
|
12
|
+
* @license lucide-react v0.453.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const cs=T.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
|
|
17
|
+
* @license lucide-react v0.453.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const us=T.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
|
|
22
|
+
* @license lucide-react v0.453.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const ms=T.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);/**
|
|
27
|
+
* @license lucide-react v0.453.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const hs=T.createLucideIcon("UserPlus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);/**
|
|
32
|
+
* @license lucide-react v0.453.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const Nt=T.createLucideIcon("UserRound",[["circle",{cx:"12",cy:"8",r:"5",key:"1hypcn"}],["path",{d:"M20 21a8 8 0 0 0-16 0",key:"rfgkzh"}]]),ke=["light","dark","system"];function ps(){const{theme:t,setTheme:n}=s.useTheme(),a=l.useDashboardStore(p=>p.actions.setDashboardTheme);function r(){const p=ke.includes(t)?t:"system",c=ke[(ke.indexOf(p)+1)%ke.length];n(c),a(c)}const o=t==="light"?ms:t==="dark"?cs:ls,u=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(l.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:r,"aria-label":u,title:u,children:e.jsx(o,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}function St(t){const n=new Date().toISOString(),a=s.buildDashboardSheetsInputExecutionSnapshot({dashboard:t.dashboard,sheetIds:(t.dashboard.sheets||[]).filter(r=>r.kind!=="document").map(r=>r.id),sheetKind:"dashboard",mode:"dashboard",generatedAt:n,runtimeValues:{dashboardInputValues:t.dashboardInputValues,filterValues:t.filterValues,controlValues:t.controlValues,inlineFilterValuesMap:t.inlineFilterValuesMap,cardControlValuesMap:t.cardControlValuesMap}}).snapshot;return{generatedAt:n,dashboardInputValues:a.dashboardInputValues}}async function xs(t,n,a,r,o,u){if(!u)return null;const p=JSON.stringify(a),c=`${t}/v1/lens`;return await l.postRequest(c,u,{name:n,template:p,filterValues:r,inputValues:o,operation:"create"})}async function ze(t,n,a){if(!a)return null;const{id:r,template:o,filterValues:u,inputValues:p,isDefault:c,shared:v}=n,y=`${t}/v1/lens`;return await l.postRequest(y,a,{lensId:r,template:o,filterValues:u,inputValues:p,isDefault:c,shared:v,operation:"update"})}async function fs(t,n,a){if(!a)return null;const r=`${t}/v1/lens`;return await l.postRequest(r,a,{operation:"delete",lensId:n})}const gs="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function bs({open:t,onOpenChange:n}={}){const[a,r]=f.useState(""),[o,u]=f.useState(!1),p=l.useDashboardStore(w=>w.lenses),{setLenses:c,setSelectedLensId:v}=l.useDashboardActions(),[y,d]=f.useState(!1),[m,b]=f.useState(!1),x=t!==void 0,j=x?t:m,D=w=>{x||b(w),n==null||n(w)},N=l.useDashboardStore(w=>w.dashboard),C=l.useDashboardStore(w=>w.filterValues),{authToken:h,tokenProps:F}=s.useSemaphorContext();async function P(){d(!0);const w=l.useDashboardStore.getState(),k=St({dashboard:N,dashboardInputValues:w.dashboardInputValues,filterValues:C,controlValues:w.controlValues,inlineFilterValuesMap:w.inlineFilterValuesMap,cardControlValuesMap:w.cardControlValuesMap}),S=await xs(F.apiServiceUrl,a,N,C,k,h==null?void 0:h.accessToken);S&&(c([...p||[],S]),v(S.id),D(!1)),d(!1)}return e.jsxs(s.Dialog,{open:j,onOpenChange:D,children:[x?null:e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(l.Button,{variant:"secondary",size:"xs",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[420px] sm:rounded-control",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{className:"text-[15px]",children:"Create lens"}),e.jsx(s.DialogDescription,{className:"text-[13px] leading-5",children:"Lenses are private by default and are only visible to you."})]}),e.jsxs("div",{className:"space-y-1.5 py-1",children:[e.jsx(l.Label,{htmlFor:"lens-name",className:gs,children:"Name"}),e.jsx(l.Input,{id:"lens-name",size:"xs",value:a,placeholder:"Monthly review, West region, …",onChange:w=>r(w.target.value)}),o&&e.jsx("p",{className:"text-[12px] text-destructive",children:"A lens with this name already exists. Pick a different one."})]}),e.jsxs(s.DialogFooter,{children:[e.jsx(l.Button,{variant:"outline",size:"xs",onClick:()=>D(!1),children:"Cancel"}),e.jsx(l.Button,{size:"xs",type:"submit",onClick:P,disabled:y||!a.trim(),children:y?"Creating…":"Create"})]})]})]})}function vs({includeLabel:t=!1}={}){const n=l.useDashboardStore(d=>d.lenses),a=l.useDashboardStore(d=>d.selectedLensId),{setLenses:r,setSelectedLensId:o}=l.useDashboardActions(),{authToken:u,tokenProps:p}=s.useSemaphorContext();async function c(d){o(d)}async function v(d){if(await fs(p.apiServiceUrl,d,u==null?void 0:u.accessToken)){const b=n==null?void 0:n.filter(x=>x.id!==d);r(b||[]),o("original")}}async function y(d){const m=n==null?void 0:n.map(j=>j.id===d.id?{...j,isDefault:!d.isDefault}:{...j,isDefault:!1});r(m||[]);const b={...d,isDefault:!d.isDefault};await ze(p.apiServiceUrl,b,u==null?void 0:u.accessToken);const x=n==null?void 0:n.find(j=>j.isDefault);if(x&&x.id!==d.id){const j={...x,isDefault:!1};await ze(p.apiServiceUrl,j,u==null?void 0:u.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:a,onValueChange:c,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:m=>{m.preventDefault(),y(d)},className:l.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:m=>{m.preventDefault(),v(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})}function ys(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),o=f.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),u=f.useMemo(()=>c=>o&&o[c]!==void 0&&o[c]===!1?!1:n(c),[o,n,t]),p=f.useMemo(()=>{var c,v,y,d,m;return{canEdit:((c=r==null?void 0:r.permissions)==null?void 0:c.canEdit)??s.canUserEdit(a),canUseFilters:((v=r==null?void 0:r.permissions)==null?void 0:v.canEdit)??s.canUserUseFilters(a),canManageDashboards:((y=r==null?void 0:r.permissions)==null?void 0:y.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((d=r==null?void 0:r.permissions)==null?void 0:d.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((m=r==null?void 0:r.permissions)==null?void 0:m.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:u,permissions:p,currentUser:a}}var _e="Avatar",[js]=l.createContextScope(_e),ws=[0,()=>{}],[Ds,Ct]=js(_e),He=A.forwardRef((t,n)=>{const{__scopeAvatar:a,...r}=t,[o,u]=A.useState("idle"),[p,c]=Ss();return e.jsx(Ds,{scope:a,imageLoadingStatus:o,setImageLoadingStatus:u,imageCount:p,setImageCount:c,children:e.jsx(l.Primitive.span,{...r,ref:n})})});He.displayName=_e;var kt="AvatarImage",Ke=A.forwardRef((t,n)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:o,...u}=t,p=Ct(kt,a);Cs(p.setImageCount);const c=Ns(r,{referrerPolicy:u.referrerPolicy,crossOrigin:u.crossOrigin,loadingStatus:p.imageLoadingStatus,setLoadingStatus:p.setImageLoadingStatus}),v=l.useCallbackRef(d=>{o==null||o(d)}),y=A.useRef(c);return l.useLayoutEffect2(()=>{const d=y.current;y.current=c,c!==d&&v(c)},[c,v]),c==="loaded"?e.jsx(l.Primitive.img,{...u,ref:n,src:r}):null});Ke.displayName=kt;var Mt="AvatarFallback",Qe=A.forwardRef((t,n)=>{const{__scopeAvatar:a,delayMs:r,...o}=t,u=Ct(Mt,a),[p,c]=A.useState(r===void 0);return A.useEffect(()=>{if(r!==void 0){const v=window.setTimeout(()=>c(!0),r);return()=>window.clearTimeout(v)}},[r]),p&&u.imageLoadingStatus!=="loaded"?e.jsx(l.Primitive.span,{...o,ref:n}):null});Qe.displayName=Mt;function Ns(t,{loadingStatus:n,setLoadingStatus:a,referrerPolicy:r,crossOrigin:o}){return l.useLayoutEffect2(()=>{if(!t){a("error");return}const u=new window.Image,p=v=>{const y=v.currentTarget;a(vt(y))},c=()=>a("error");return u.addEventListener("load",p),u.addEventListener("error",c),r&&(u.referrerPolicy=r),u.crossOrigin=o??null,u.src=t,a(vt(u)),()=>{u.removeEventListener("load",p),u.removeEventListener("error",c),a("idle")}},[t,o,r,a]),n}function vt(t){return t.complete?t.naturalWidth>0?"loaded":"error":"loading"}function Ss(){let t=ws;{t=A.useState(0);const[n]=t,a=A.useRef(!1);A.useEffect(()=>{n>1&&!a.current&&(a.current=!0,console.warn("Avatar: Only one `Avatar.Image` component should be rendered per `Avatar.Root`, but multiple were detected. This will lead to unexpected behavior."))},[n])}return t}function Cs(t){A.useEffect(()=>(t(n=>n+1),()=>{t(n=>n-1)}),[t])}const It=A.forwardRef(({className:t,...n},a)=>e.jsx(He,{ref:a,className:l.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));It.displayName=He.displayName;const ks=A.forwardRef(({className:t,...n},a)=>e.jsx(Ke,{ref:a,className:l.cn("aspect-square h-full w-full",t),...n}));ks.displayName=Ke.displayName;const Lt=A.forwardRef(({className:t,...n},a)=>e.jsx(Qe,{ref:a,className:l.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));Lt.displayName=Qe.displayName;const Ms=async(t,n,a)=>{const r=`${t}/management/v1/groups`;return await l.postRequestRegular(r,n,a)},Is=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}`;return l.requestJsonRegular(o,n,"PATCH",r)},Ls=async(t,n,a)=>{const r=`${t}/management/v1/groups/${a}`;await l.requestJsonRegular(r,n,"DELETE")},Es=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;return await l.postRequestRegular(o,n,r)},As=async(t,n,a,r)=>{const o=`${t}/management/v1/groups/${a}/members`;await l.requestJsonRegular(o,n,"DELETE",r)};function Ps(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Ms(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),s.ue.error("Failed to create group",{description:l.getRequestErrorMessage(r,"Failed to create group")})}})}function Rs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>Is(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group updated successfully")},onError:r=>{console.error("Failed to update group:",r),s.ue.error("Failed to update group",{description:l.getRequestErrorMessage(r,"Failed to update group")})}})}function Us(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Ls(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",o]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:l.getRequestErrorMessage(r,"Failed to delete group")})}})}function Fs(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>Es(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:l.getRequestErrorMessage(r,"Failed to add members")})}})}function Ts(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:o})=>As(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,o),onSuccess:(r,o)=>{a.invalidateQueries({queryKey:["group",o.groupId]}),a.invalidateQueries({queryKey:["group-members",o.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:l.getRequestErrorMessage(r,"Failed to remove members")})}})}const Os=[];function Vs({open:t,onOpenChange:n}){var h,F,P;const{tokenProps:a}=s.useSemaphorContext(),{currentUser:r}=s.useCurrentUserInfo(),o=(r==null?void 0:r.type)==="tenant",u=a==null?void 0:a.tenantId,{groups:p,isLoading:c,error:v,refetch:y}=s.useGroups({type:o?"TENANT_GROUP":"all",tenantId:o?u:void 0,includeMembers:!1}),d=v?Et(v,"Unable to load groups."):null,[m,b]=f.useState({kind:"list"}),[x,j]=f.useState(null),D=Us();f.useEffect(()=>{t||(b({kind:"list"}),j(null))},[t]);const N=m.kind==="members"&&p.find(w=>w.id===m.groupId)||null,C=async()=>{if(x)try{await D.mutateAsync(x.id),j(null),b({kind:"list"}),y()}catch{}};return e.jsx(s.Dialog,{open:t,onOpenChange:n,children:e.jsxs(s.DialogContent,{className:"flex max-h-[640px] w-[720px] max-w-[92vw] flex-col gap-0 overflow-hidden p-0",children:[m.kind==="list"?e.jsxs("div",{className:"shrink-0 border-b border-border px-5 pt-4 pb-3.5",children:[e.jsx(s.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"Group management"}),e.jsx(s.DialogDescription,{className:"mt-1 text-[12px] leading-[1.5] text-muted-foreground",children:"Organize people into groups for shared access."})]}):m.kind==="create"?e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:()=>b({kind:"list"}),"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),e.jsx(s.DialogTitle,{className:"truncate text-[13px] font-medium",children:"New group"}),e.jsx(s.DialogDescription,{className:"sr-only",children:"Create a new group to organize members."})]}):null,m.kind==="list"&&e.jsx(qs,{groups:p,isLoading:c,errorMessage:d,onRetry:()=>y(),currentUserId:r==null?void 0:r.id,onOpenGroup:w=>b({kind:"members",groupId:w}),onCreate:()=>b({kind:"create"}),onDeleteRequest:w=>j(w)}),m.kind==="members"&&N&&e.jsx(Gs,{group:N,isTenantViewer:o,canEdit:((h=N.permissions)==null?void 0:h.canEdit)??N.createdBy===(r==null?void 0:r.id),canDelete:((F=N.permissions)==null?void 0:F.canDelete)??N.createdBy===(r==null?void 0:r.id),canManageMembers:((P=N.permissions)==null?void 0:P.canManageMembers)??N.createdBy===(r==null?void 0:r.id),onBack:()=>b({kind:"list"}),onMembersChanged:y,onUpdated:y,onRequestDelete:()=>j(N)},N.id),m.kind==="create"&&e.jsx(zs,{isTenantUser:o,tenantId:u,onCancel:()=>b({kind:"list"}),onCreated:w=>{y(),b({kind:"members",groupId:w})}}),x&&e.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-3 border-t border-border bg-muted/40 px-5 py-2.5",children:[e.jsxs("div",{className:"min-w-0 text-[12px] text-foreground",children:["Delete ",e.jsx("span",{className:"font-medium",children:x.name}),"?",e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Members lose any access granted via this group."})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>j(null),disabled:D.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-background",children:"Cancel"}),e.jsxs("button",{type:"button",onClick:C,disabled:D.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-rose-600 px-2.5 text-[12px] font-medium text-white hover:bg-rose-700 disabled:opacity-60",children:[D.isPending?e.jsx(l.LoaderCircle,{className:"h-3 w-3 animate-spin"}):e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})]})]})]})})}function qs({groups:t,isLoading:n,errorMessage:a,onRetry:r,currentUserId:o,onOpenGroup:u,onCreate:p,onDeleteRequest:c}){const[v,y]=f.useState(""),d=f.useMemo(()=>t.filter(m=>!v.trim()||m.name.toLowerCase().includes(v.toLowerCase())||(m.description||"").toLowerCase().includes(v.toLowerCase())),[t,v]);return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex shrink-0 items-center gap-2 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{className:"flex flex-1 items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(wt.Search,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:v,onChange:m=>y(m.target.value),placeholder:"Search groups…",className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none"}),v&&e.jsx("button",{type:"button",onClick:()=>y(""),className:"flex h-4 w-4 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(T.X,{className:"h-2.5 w-2.5"})})]}),e.jsxs("button",{type:"button",onClick:p,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:n?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(m=>e.jsx("div",{className:"h-12 animate-pulse rounded-[4px] bg-muted/60"},m))}):a?e.jsx(At,{title:"Can't load groups",message:a,onRetry:r}):d.length===0&&t.length===0?e.jsx($s,{onCreate:p}):d.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsxs("div",{className:"text-[12px] text-foreground",children:['No groups match "',v,'"']}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Try a different search."})]}):d.map(m=>{var b;return e.jsx(Bs,{group:m,canDelete:((b=m.permissions)==null?void 0:b.canDelete)??m.createdBy===o,onClick:()=>u(m.id),onDelete:()=>c(m)},m.id)})})]})}function Bs({group:t,canDelete:n,onClick:a,onDelete:r}){let o="";try{o=Dt.format(new Date(t.createdAt),"MMM d, yyyy")}catch{o=""}return e.jsxs("button",{type:"button",onClick:a,className:"group flex w-full items-center gap-3 border-b border-border/60 px-5 py-2.5 text-left hover:bg-accent/40",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-[4px] border border-border bg-background text-muted-foreground",children:e.jsx(s.UsersRound,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[13px] font-medium text-foreground",children:t.name}),e.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(Nt,{className:"h-2.5 w-2.5"}),t.memberCount," member",t.memberCount===1?"":"s"]}),o&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(s.Calendar,{className:"h-2.5 w-2.5"}),o]})]}),t.description&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-border",children:"·"}),e.jsx("span",{className:"truncate text-muted-foreground",children:t.description})]})]})]}),e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100",children:[n&&e.jsx("span",{role:"button",tabIndex:0,onClick:u=>{u.stopPropagation(),r()},onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),u.stopPropagation(),r())},"aria-label":`Delete ${t.name}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.Trash2,{className:"h-3 w-3"})}),e.jsx(wt.ChevronRight,{className:"h-3.5 w-3.5 text-muted-foreground"})]})]})}function $s({onCreate:t}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 py-12 text-center",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full border border-border bg-muted/40 text-muted-foreground",children:e.jsx(s.Users,{className:"h-4 w-4"})}),e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:"No groups yet"}),e.jsx("div",{className:"max-w-[320px] text-[11.5px] leading-[1.55] text-muted-foreground",children:"Groups let you grant shared access to dashboards. Create one and add members."}),e.jsxs("button",{type:"button",onClick:t,className:"mt-1 inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90",children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"New group"]})]})}function Gs({group:t,isTenantViewer:n,canEdit:a,canDelete:r,canManageMembers:o,onBack:u,onMembersChanged:p,onUpdated:c,onRequestDelete:v}){const{data:y,isLoading:d,error:m,refetch:b}=s.useGroupMembers(t.id),x=(y==null?void 0:y.members)??Os,j=m?Et(m,"Unable to load members for this group."):null,D=t.type==="TENANT_GROUP"?"tenant":"organization",{users:N}=s.useUnifiedUsers({type:D,tenantId:t.tenantId||void 0,active:!0,limit:200}),C=f.useMemo(()=>new Set(x.map(g=>g.userId)),[x]),h=Fs(),F=Ts(),P=Rs(),[w,k]=f.useState(!1),[S,Q]=f.useState(t.name),[Me,B]=f.useState(!1),[X,$]=f.useState(t.description||""),[Y,Z]=f.useState(""),[Ie,ee]=f.useState(!1),me=f.useMemo(()=>{const g=Y.trim().toLowerCase();return N.filter(R=>!C.has(R.id)).filter(R=>!g||(R.name||"").toLowerCase().includes(g)||(R.email||"").toLowerCase().includes(g)).slice(0,50)},[N,C,Y]),W=async()=>{const g=S.trim();if(k(!1),g.length>=3&&g!==t.name)try{await P.mutateAsync({groupId:t.id,data:{name:g}}),c()}catch{}},he=async()=>{const g=X.trim();if(B(!1),g!==(t.description||""))try{await P.mutateAsync({groupId:t.id,data:{description:g}}),c()}catch{}},pe=async g=>{if(o){Z(""),ee(!1);try{await h.mutateAsync({groupId:t.id,data:{userIds:[g.id],userType:D==="tenant"?"tenant":"org"}}),b(),p()}catch{}}},Le=async g=>{if(o)try{await F.mutateAsync({groupId:t.id,data:{userIds:[g]}}),b(),p()}catch{}};let G="";try{G=Dt.format(new Date(t.createdAt),"MMM d, yyyy")}catch{G=""}return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex h-10 shrink-0 items-center gap-1.5 border-b border-border px-5",children:[e.jsx("button",{type:"button",onClick:u,"aria-label":"Back",className:"-ml-1 flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground hover:bg-accent hover:text-foreground",children:e.jsx(s.ArrowLeft,{className:"h-3.5 w-3.5"})}),w?e.jsx("input",{autoFocus:!0,value:S,onChange:g=>Q(g.target.value),onBlur:W,onKeyDown:g=>{g.key==="Enter"&&W(),g.key==="Escape"&&(Q(t.name),k(!1))},className:"h-6 min-w-0 flex-1 rounded-[3px] border border-border bg-background px-1.5 text-[13px] font-medium text-foreground focus:border-foreground/40 focus:outline-none"}):e.jsx("button",{type:"button",onClick:()=>{a&&(Q(t.name),k(!0))},title:a?"Click to rename":t.name,disabled:!a,className:"truncate rounded-[3px] px-1 text-[13px] font-medium text-foreground enabled:hover:bg-accent disabled:cursor-default",children:t.name}),e.jsxs("span",{className:"ml-1 inline-flex shrink-0 items-center gap-1 text-[10.5px] text-muted-foreground",children:[e.jsx(Nt,{className:"h-2.5 w-2.5"}),x.length," member",x.length===1?"":"s"]})]}),e.jsx("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:Me?e.jsxs("div",{children:[e.jsx("textarea",{autoFocus:!0,rows:2,value:X,onChange:g=>$(g.target.value),maxLength:200,onKeyDown:g=>{g.key==="Escape"&&($(t.description||""),B(!1)),g.key==="Enter"&&(g.metaKey||g.ctrlKey)&&he()},placeholder:"What is this group for?",className:"block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-between",children:[e.jsxs("span",{className:"text-[10.5px] text-muted-foreground",children:[X.length,"/200 · Esc to cancel · ⌘↩ to save"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>{$(t.description||""),B(!1)},className:"h-6 rounded-[5px] px-2 text-[11px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:he,className:"inline-flex h-6 items-center rounded-[5px] bg-foreground px-2 text-[11px] font-medium text-background hover:opacity-90",children:"Save"})]})]})]}):e.jsxs("button",{type:"button",onClick:()=>{a&&($(t.description||""),B(!0))},disabled:!a,title:a?"Click to edit description":void 0,className:"block w-full rounded-[3px] px-1 py-0.5 text-left enabled:hover:bg-accent/40 disabled:cursor-default",children:[t.description?e.jsx("p",{className:"text-[12px] leading-[1.55] text-foreground/90",children:t.description}):e.jsx("p",{className:"text-[12px] leading-[1.55] text-muted-foreground",children:a?"Add a description…":"No description"}),e.jsxs("p",{className:"mt-1 text-[10.5px] text-muted-foreground",children:[G?`Created ${G}`:"Recently created",a?" · You can edit this group":""]})]})}),o&&e.jsx(_s,{query:Y,setQuery:Z,open:Ie,setOpen:ee,candidates:me,showKindChip:!n,onAdd:pe,busy:h.isPending}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:d?e.jsx("div",{className:"space-y-px p-3",children:[1,2,3].map(g=>e.jsx("div",{className:"h-10 animate-pulse rounded-[4px] bg-muted/60"},g))}):j?e.jsx(At,{title:"Can't load members",message:j,onRetry:()=>b()}):x.length===0?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-1 py-10 text-center",children:[e.jsx("div",{className:"text-[12px] text-foreground",children:"No members yet"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:o?"Search above to add people to this group.":"This group does not have any members."})]}):x.map(g=>{var R,z,_,te,H,se;return e.jsxs("div",{className:"group flex items-center gap-2 border-b border-border/60 px-5 py-2",children:[e.jsx(Pt,{name:((R=g.user)==null?void 0:R.name)||((z=g.user)==null?void 0:z.email)||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12.5px] font-medium text-foreground",children:((_=g.user)==null?void 0:_.name)||((te=g.user)==null?void 0:te.email)||"Unknown"}),((H=g.user)==null?void 0:H.email)&&g.user.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:g.user.email})]}),!n&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:g.userType}),e.jsx("button",{type:"button",onClick:()=>Le(g.userId),disabled:!o||F.isPending,"aria-label":`Remove ${((se=g.user)==null?void 0:se.name)||"member"}`,className:"flex h-6 w-6 items-center justify-center rounded-[3px] text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-foreground group-hover:opacity-100 disabled:opacity-30",children:e.jsx(T.X,{className:"h-3 w-3"})})]},g.id)})}),r&&e.jsx("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:e.jsxs("button",{type:"button",onClick:v,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] border border-rose-200 bg-background px-2.5 text-[12px] font-medium text-rose-600 hover:bg-rose-50 dark:border-rose-900/60 dark:text-rose-400 dark:hover:bg-rose-950/30",children:[e.jsx(s.Trash2,{className:"h-3 w-3"}),"Delete group"]})})]})}function zs({isTenantUser:t,tenantId:n,onCancel:a,onCreated:r}){const[o,u]=f.useState(""),[p,c]=f.useState(""),[v,y]=f.useState(null),d=Ps(),m=o.trim().length>=3&&o.trim().length<=50,b=async()=>{if(!m)return;y(null);const x={name:o.trim(),description:p.trim()||void 0,type:t?"TENANT_GROUP":"ORG_GROUP",...t&&n?{tenantId:n}:{}};try{const j=await d.mutateAsync(x),D=j==null?void 0:j.id;D?r(D):a()}catch(j){y(j instanceof Error?j.message:"Failed to create group")}};return e.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[e.jsx(yt,{children:"Name"}),e.jsx("input",{autoFocus:!0,value:o,onChange:x=>u(x.target.value),placeholder:"Marketing leads, North America sales, …",maxLength:50,className:"mt-1 block h-7 w-full rounded-[5px] border border-border bg-background px-2 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsx("div",{className:"mt-1 text-[10.5px] text-muted-foreground",children:"3–50 characters."}),e.jsxs("div",{className:"mt-4",children:[e.jsx(yt,{children:"Description (optional)"}),e.jsx("textarea",{rows:2,value:p,onChange:x=>c(x.target.value),maxLength:200,placeholder:"What is this group for?",className:"mt-1 block w-full resize-none rounded-[5px] border border-border bg-background px-2 py-1.5 text-[12px] text-foreground placeholder:text-muted-foreground focus:border-foreground/40 focus:outline-none"}),e.jsxs("div",{className:"mt-1 flex justify-end text-[10.5px] text-muted-foreground",children:[p.length,"/200"]})]}),v&&e.jsx("div",{className:"mt-3 rounded-[5px] border border-rose-200 bg-rose-50 px-2 py-1.5 text-[11.5px] text-rose-700 dark:border-rose-900/60 dark:bg-rose-950/30 dark:text-rose-300",children:v})]}),e.jsxs("div",{className:"flex shrink-0 items-center justify-end gap-1.5 border-t border-border bg-muted/30 px-5 py-2.5",children:[e.jsx("button",{type:"button",onClick:a,disabled:d.isPending,className:"h-7 rounded-[5px] px-2.5 text-[12px] font-medium text-foreground/80 hover:bg-accent",children:"Cancel"}),e.jsx("button",{type:"button",onClick:b,disabled:!m||d.isPending,className:"inline-flex h-7 items-center gap-1.5 rounded-[5px] bg-foreground px-2.5 text-[12px] font-medium text-background hover:opacity-90 disabled:cursor-not-allowed disabled:opacity-60",children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(l.LoaderCircle,{className:"h-3 w-3 animate-spin"}),"Creating…"]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Plus,{className:"h-3 w-3"}),"Create group"]})})]})]})}function _s({query:t,setQuery:n,open:a,setOpen:r,candidates:o,showKindChip:u,onAdd:p,busy:c}){const v=f.useRef(null),y=f.useRef(null),[d,m]=f.useState(null);f.useLayoutEffect(()=>{if(!a){m(null);return}const x=()=>{const j=v.current;if(!j)return;const D=j.getBoundingClientRect(),N=240,h=window.innerHeight-D.bottom<N+16&&D.top>N;m({left:D.left,top:h?D.top-6:D.bottom+6,width:D.width,above:h})};return x(),window.addEventListener("resize",x),window.addEventListener("scroll",x,!0),()=>{window.removeEventListener("resize",x),window.removeEventListener("scroll",x,!0)}},[a,o.length]),f.useEffect(()=>{if(!a)return;const x=j=>{var N,C;const D=j.target;(N=v.current)!=null&&N.contains(D)||(C=y.current)!=null&&C.contains(D)||r(!1)};return document.addEventListener("mousedown",x),()=>document.removeEventListener("mousedown",x)},[a,r]);const b=a&&o.length>0&&d;return e.jsxs("div",{className:"shrink-0 border-b border-border px-5 py-2.5",children:[e.jsxs("div",{ref:v,className:"flex items-center gap-2 rounded-[5px] border border-border bg-background px-2 focus-within:border-foreground/40",children:[e.jsx(hs,{className:"h-3 w-3 text-muted-foreground"}),e.jsx("input",{value:t,onChange:x=>{n(x.target.value),r(!0)},onFocus:()=>r(!0),placeholder:"Add a member by name or email…",disabled:c,className:"h-7 flex-1 bg-transparent text-[12px] text-foreground placeholder:text-muted-foreground focus:outline-none disabled:cursor-not-allowed"})]}),b&&typeof document<"u"&&ss.createPortal(e.jsx("div",{ref:y,style:{position:"fixed",left:d.left,top:d.top,width:d.width,transform:d.above?"translateY(-100%)":void 0},className:"z-[60] max-h-[240px] overflow-y-auto rounded-[5px] border border-border bg-background shadow-[0_8px_24px_-12px_rgba(0,0,0,0.18)]",children:o.map(x=>e.jsxs("button",{type:"button",onClick:()=>p(x),className:"flex w-full items-center gap-2 border-b border-border/60 px-2.5 py-2 text-left last:border-b-0 hover:bg-accent",children:[e.jsx(Pt,{name:x.name||x.email||"?"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"truncate text-[12px] font-medium text-foreground",children:x.name||x.email||"Unknown"}),x.email&&x.name&&e.jsx("div",{className:"truncate text-[10.5px] text-muted-foreground",children:x.email})]}),u&&x.type&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:x.type==="tenant"?"tenant":"org"})]},x.id))}),document.body)]})}function Et(t,n){if(!t)return n;if(t instanceof Error){const a=t.message||"",r=a.match(/\{[\s\S]*"error"\s*:\s*"([^"]+)"[\s\S]*\}/);return r?r[1]:a||n}return typeof t=="string"?t:n}function At({title:t,message:n,onRetry:a}){return e.jsxs("div",{className:"flex h-full flex-col items-center justify-center gap-2 px-6 py-10 text-center",children:[e.jsx("div",{className:"text-[12.5px] font-medium text-foreground",children:t}),e.jsx("div",{className:"max-w-[360px] text-[11.5px] leading-[1.55] text-muted-foreground",children:n}),a&&e.jsx("button",{type:"button",onClick:a,className:"mt-1 inline-flex h-7 items-center rounded-[5px] border border-border bg-background px-2.5 text-[11.5px] font-medium text-foreground hover:bg-accent",children:"Try again"})]})}function yt({children:t}){return e.jsx("label",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:t})}function Pt({name:t}){const n=t.split(" ").map(a=>a[0]).filter(Boolean).slice(0,2).join("").toUpperCase();return e.jsx(It,{className:"h-6 w-6 shrink-0",children:e.jsx(Lt,{className:"text-[9px] font-semibold",children:n||"?"})})}function ce(t,n,a){var u,p;const r=(t.controls||[]).find(c=>c.id===a);if(r)return r.label;const o=(p=(u=l.findCardById(t,n))==null?void 0:u.controls)==null?void 0:p.find(c=>c.id===a);return(o==null?void 0:o.label)||a}function ue(t,n){var a;return((a=l.findCardById(t,n))==null?void 0:a.title)||n}function Hs(t){const{errors:n,dashboard:a}=t;if(!a)return n;const r=new Map;for(const o of n){const u=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(u){const[,d,m]=u,b=`${d}:${m}:missing-metric`;r.has(b)||r.set(b,`"${ue(a,d)}" has an outdated "${ce(a,d,m)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const p=o.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(p){const[,d,m]=p,b=`${d}:${m}:missing-group-by`;r.has(b)||r.set(b,`"${ue(a,d)}" has an outdated "${ce(a,d,m)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const c=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(c){const[,d,m]=c,b=`${d}:${m}:invalid-metric`;r.has(b)||r.set(b,`"${ue(a,d)}" has an invalid "${ce(a,d,m)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const v=o.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(v){const[,d,m]=v,b=`${d}:${m}:invalid-group-by`;r.has(b)||r.set(b,`"${ue(a,d)}" has an invalid "${ce(a,d,m)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const y=o.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(y){const[,d,m]=y,b=`${d}:${m}:missing-temporal-group-by`;r.has(b)||r.set(b,`"${ue(a,d)}" can no longer use "${ce(a,d,m)}" for time grain because the card does not currently group by a date field.`);continue}r.set(o,o)}return Array.from(r.values())}function Ks({visible:t,onSelect:n}){return t?e.jsxs(s.DropdownMenuItem,{onSelect:n,children:[e.jsx(s.CalendarClock,{className:"h-3.5 w-3.5"}),"Schedule email report"]}):null}function Qs({scheduleReportVisible:t,analyticalBriefingVisible:n,onScheduleReport:a,onCreateAnalyticalBriefing:r}){return e.jsxs(e.Fragment,{children:[e.jsx(Ks,{visible:t,onSelect:a}),n?e.jsxs(s.DropdownMenuItem,{onSelect:r,children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Create analytical briefing"]}):null]})}function jt(t,n){return{dashboard:s.cloneDeep(t),semanticExecutionPayload:s.cloneDeep(n)}}function Ws(){var lt,ct,ut,mt,ht,pt,xt,ft;q.useExportRecovery(),q.useExportPolling();const{authToken:t,tokenProps:n,id:a,showBriefings:r}=s.useSemaphorContext(),o=s.useBriefingUiCapabilities(),{isLocalDev:u,preferences:p}=s.useDashboardPreferences(),c=((lt=p==null?void 0:p.uiMode)==null?void 0:lt.inspection)===!0,{openBrandStudioPreview:v}=s.useBrandStudioPreview(),{permissions:y}=ys(),d=s.useHasDashboardId(),{isLoading:m}=s.useDashboardQuery(),b=l.useDashboardStore(i=>i.theme),x=l.useDashboardStore(i=>i.isDownloadingPdf),j=l.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),D=l.useDashboardStore(i=>i.lenses),N=l.useDashboardStore(i=>i.selectedLensId),C=D==null?void 0:D.find(i=>i.id===N),h=l.useDashboardStore(i=>i.dashboard),F=l.useDashboardStore(i=>i.selectedSheetId),P=(ct=h==null?void 0:h.sheets)==null?void 0:ct.find(i=>i.id===F),w=l.isDocumentSheet(P),k=w?(ut=P==null?void 0:P.document)==null?void 0:ut.page:void 0,S=l.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:Q}=l.useDashboardStore(i=>i.actions),[Me,B]=f.useState(!1),[X,$]=f.useState(!1),[Y,Z]=f.useState(!1),[Ie,ee]=f.useState(!1),[me,W]=f.useState(null),[he,pe]=f.useState(!1),[Le,G]=f.useState(!1),[g,R]=f.useState(!1),[z,_]=f.useState(null),[te,H]=f.useState([]),[se,xe]=f.useState(!1),[Rt,We]=f.useState(!1),Je=l.useDashboardStore(i=>i.filterValues),L=l.useDashboardStore(i=>i.isVisualEditing);l.useEditorStore(i=>i.card);const re=s.useManagementStore(i=>i.selectedDashboard),fe=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),l.useDashboardStore(i=>i.selectedFrameId),l.useEditorStore(i=>i.frame);const ge=re?(ht=re==null?void 0:re.permissions)==null?void 0:ht.canEdit:(mt=fe==null?void 0:fe.permissions)==null?void 0:mt.canEdit,Xe=l.useDashboardStore(i=>i.showDashboardJSON),Ee=l.useDashboardStore(i=>i.onSaveFunction),{setIsDashboardEditing:Ye,setShowDashboardJSON:Ze}=l.useDashboardStore(i=>i.actions),{setInitialDashboard:et,clearSelectedDashboard:Ae}=s.useManagementStore(i=>i.actions),ae=!!n.orgUserId||!!(n.tenantId&&n.endUserId&&n.endUserEmail),{resources:be}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:Pe}=s.useUserPreferences(),Ut=((pt=Pe==null?void 0:Pe.preference)==null?void 0:pt.defaultDashboardId)||null,{mutate:Ft,isPending:Tt}=s.useDefaultDashboardMutation(),{currentUser:Ot}=s.useCurrentUserInfo(),Vt=s.canUserManageGroups(Ot),O=re||fe,J=s.resolveDashboardControlsVisibility({config:n.config,canNavigateDashboardHub:ae,canShareDashboard:((xt=O==null?void 0:O.permissions)==null?void 0:xt.canShare)===!0,canManageGroups:Vt}),tt=O?{id:O.id,title:(h==null?void 0:h.title)||O.title||"Dashboard"}:null,{handleAddNewFrame:qt}=s.useAddNewFrame(),[Re,Ue]=f.useState(!1),[Bt,ne]=f.useState(!1),[Fe,ve]=f.useState("close"),oe=s.useUpdateResource(s.ResourceType.DASHBOARD),[I,ye]=f.useState(null),$t=async(i,M)=>{if(!c){if(!(h!=null&&h.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:h.id,newTitle:i,previousTitle:M}),oe.mutate({resourceId:h.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:U=>{console.error("Failed to update dashboard title:",U),s.ue.error("Failed to update dashboard title"),Q(M)}})}};f.useEffect(()=>{if(be&&be.length>0){const i=h==null?void 0:h.id;if(i){const M=be.find(U=>U.id===i);M&&et(M)}}},[be,h==null?void 0:h.id,et]);const ie=n.orgUserId||n.tenantId,Te=f.useMemo(()=>Js({accessToken:t==null?void 0:t.accessToken,dashboardId:(h==null?void 0:h.id)||a||n.dashboard_id,selectedSheetId:w?F:void 0,pageSize:k==null?void 0:k.size,orientation:k==null?void 0:k.orientation,theme:b}),[t==null?void 0:t.accessToken,a,h==null?void 0:h.id,w,k==null?void 0:k.orientation,k==null?void 0:k.size,F,b,n.dashboard_id]),st=S&&!L&&!c&&ie&&ge,{setDashboard:Oe}=l.useDashboardStore(i=>i.actions),rt=l.useDashboardStore(i=>i.semanticExecutionPayload),Gt=()=>{Ye(!0)},je=()=>{Ye(!1),Ze(!1),ye(null)};f.useEffect(()=>{if(!S){I&&ye(null);return}I||!h||m||ye(jt(h,rt))},[h,I,S,m,rt]);const we=(I==null?void 0:I.dashboard)??null,{isDirty:at,isDirtyPending:zt,resetDirty:de}=as.useDebouncedDirtyCheck(h,we,300,1e3,Ge.serializeDashboardForDirtyCheck),nt=f.useCallback(()=>we?Ge.serializeDashboardForDirtyCheck(h)!==Ge.serializeDashboardForDirtyCheck(we):!1,[h,we]),ot=at||zt,De=Re||oe.isPending,_t=()=>{if(c){I&&Oe(I.dashboard,{semanticExecutionPayload:I.semanticExecutionPayload}),je(),de();return}nt()?(ve("close"),ne(!0)):(je(),de())},Ht=async()=>{await Ve({closeAfterSave:!0,navigateHomeAfterSave:Fe==="home"})},Kt=()=>{const i=Fe==="home"&&!!ae;I&&Oe(I.dashboard,{semanticExecutionPayload:I.semanticExecutionPayload}),je(),i&&Ae(),ve("close"),ne(!1),de()},Qt=()=>{I&&(Oe(I.dashboard,{semanticExecutionPayload:I.semanticExecutionPayload}),de())},Wt=()=>{if(ae){if(S&&nt()){ve("home"),ne(!0);return}Ae()}};async function Ve(i){if(c)return;const M=l.useDashboardStore.getState().dashboard;if(!M)return;const U=(i==null?void 0:i.closeAfterSave)??se,qe=(i==null?void 0:i.navigateHomeAfterSave)??!1;xe(U),U&&ne(!1);const Be=s.cloneDeep(M);R(!0),_(null),H([]),Ue(!0);const ts={template:M};oe.mutate({resourceId:M.id,data:ts},{onSuccess:E=>{var Ne,Se,gt;const K=(E==null?void 0:E.id)||((Ne=E==null?void 0:E.dashboard)==null?void 0:Ne.id)||((Se=E==null?void 0:E.resource)==null?void 0:Se.id)||((gt=E==null?void 0:E.template)==null?void 0:gt.id)||null;if(!M.id&&K){const $e=l.useAIInteractionStore.getState(),Ce=$e.pendingDashboardDraftMigration;(Ce==null?void 0:Ce.scopeKey)===j?$e.actions.setPendingDashboardDraftMigrationExpectedDashboardId(K):Ce&&$e.actions.clearPendingDashboardDraftMigration()}Ue(!1),s.ue.success("Dashboard saved!"),ye(jt(Be,l.useDashboardStore.getState().semanticExecutionPayload)),R(!1),xe(!1),U&&(je(),de(),qe&&ae&&Ae()),ve("close")},onError:E=>{Ue(!1),_("Failed to save dashboard. Please try again.");const K=E.details,Ne=Array.isArray(K==null?void 0:K.errors)?(K.errors||[]).filter(Se=>typeof Se=="string"):[];H(Hs({errors:Ne,dashboard:M||void 0})),s.ue.error("Failed to save dashboard")}})}async function Jt(){if(c||(B(!0),!N||!C))return;const i=l.useDashboardStore.getState().dashboard;if(!i){B(!1);return}const M=JSON.stringify(i),U=l.useDashboardStore.getState(),qe=St({dashboard:i,dashboardInputValues:U.dashboardInputValues,filterValues:Je,controlValues:U.controlValues,inlineFilterValuesMap:U.inlineFilterValuesMap,cardControlValuesMap:U.cardControlValuesMap}),Be={...C,template:M,filterValues:Je,inputValues:qe};await ze(n.apiServiceUrl,Be,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),Ee==null||Ee(i),B(!1)}const it=(C==null?void 0:C.name)||h.title;oe.isPending&&console.log("Title during update:",{title:it,dashboardStateTitle:h.title,dashboardId:h==null?void 0:h.id,currentLensName:C==null?void 0:C.name});const Xt=ae&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl),Yt=!c&&J.showDashboardHub&&Xt,Zt=!c&&d&&J.showDashboardHub,V=(h==null?void 0:h.id)||null,dt=s.resolveDashboardBriefingsVisibility((ft=n.config)==null?void 0:ft.showBriefings,r),le=!!V&&Ut===V,es=()=>{!V||c||Ft({dashboardId:le?null:V})};return!d&&!L?null:e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[Zt&&!L&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Wt,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})}),!L&&d&&(m?e.jsx("div",{className:"h-4 w-28 animate-pulse rounded-md bg-muted/70","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:it||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:ge,dashboardId:h==null?void 0:h.id});const M=(h==null?void 0:h.title)||"";Q(i),$t(i,M)},isEditable:s.resolveDashboardTitleEditability({isDashboardEditing:S,canEditDashboard:ge===!0&&!c,hasCurrentLens:!!C}),displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:oe.isPending}),J.showDashboardHub&&le&&e.jsx("span",{className:"shrink-0 rounded-[4px] border border-border/60 px-1.5 py-px text-[10px] font-medium uppercase tracking-[0.06em] text-muted-foreground",title:"Default dashboard",children:"Default"}),Yt&&V&&e.jsx(l.TooltipProvider,{children:e.jsxs(l.Tooltip,{children:[e.jsx(l.TooltipTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"ghost",size:"xs",onClick:es,disabled:Tt||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0 text-muted-foreground hover:text-foreground","aria-label":le?"Clear default dashboard":"Set as default dashboard",children:le?e.jsx(s.PinOff,{className:"h-3.5 w-3.5"}):e.jsx(s.Pin,{className:"h-3.5 w-3.5"})})}),e.jsx(l.TooltipContent,{children:e.jsx("p",{children:le?"Clear default":"Set as default"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[L&&e.jsxs(e.Fragment,{children:[e.jsx(q.AdvancedModeToggle,{}),e.jsx(q.VisualEditingControls,{})]}),!L&&d&&!c&&J.showDashboardSharing&&e.jsxs(l.Button,{variant:"outline",size:"xs",onClick:()=>$(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!L&&S&&!c&&y.canUseFilters&&d&&e.jsx(q.DashboardFilterControlsLauncher,{}),S&&!L&&!c&&ie&&C&&u&&d&&e.jsxs(l.Button,{variant:"secondary",size:"xs",disabled:Me,onClick:Jt,children:[e.jsx(bt.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),S&&!L&&!c&&d&&!w&&e.jsxs("div",{className:"inline-flex h-7 items-stretch overflow-hidden rounded-control border border-input bg-background",children:[e.jsxs(l.Button,{variant:"ghost",size:"xs",disabled:!S,onClick:()=>void qt(),className:"h-full rounded-none border-0 shadow-none hover:bg-accent",children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),e.jsxs(s.DropdownMenu,{modal:!1,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(l.Button,{variant:"ghost",size:"xs",className:"h-full w-7 rounded-none border-0 border-l border-border/60 px-0 shadow-none hover:bg-accent","aria-label":"Open visual options",disabled:!S,children:e.jsx(T.ChevronDown,{className:"h-3.5 w-3.5"})})}),e.jsx(s.DropdownMenuContent,{align:"end",className:"z-[60] w-48 rounded-[6px] border-border/60 p-1 shadow-sm",children:e.jsxs(s.DropdownMenuItem,{onClick:()=>We(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"From library..."]})})]}),e.jsx(q.VisualsLibraryDialog,{open:Rt,onOpenChange:We})]}),!L&&!S&&(ge||c)&&d&&e.jsxs(l.Button,{size:"xs",onClick:Gt,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),c?"Inspect":"Edit"]}),st&&d&&at&&e.jsxs(l.Button,{variant:"outline",size:"xs",onClick:Qt,disabled:De,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),st&&d&&e.jsxs(l.Button,{size:"xs",className:l.cn(!ot&&"opacity-60"),disabled:De||!ot,onClick:()=>Ve(),children:[De?e.jsx(l.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(bt.Save,{className:"h-3.5 w-3.5"}),De?"Saving...":"Save"]}),S&&!L&&d&&e.jsxs(l.Button,{variant:"outline",size:"xs",onClick:_t,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!L&&d&&e.jsx("div",{className:"ml-2",children:e.jsx(q.NotificationBell,{})}),!L&&u&&e.jsx(ps,{}),!L&&d&&!c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-control border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports & briefings"}),e.jsxs(s.DropdownMenuItem,{disabled:x,onSelect:()=>G(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsx(Qs,{scheduleReportVisible:!!(dt&&o.surfaceVisible&&V&&!S),analyticalBriefingVisible:!!(dt&&o.surfaceVisible&&V&&!S),onScheduleReport:()=>W("scheduled_report"),onCreateAnalyticalBriefing:()=>W("analytical_briefing")}),e.jsx(s.DropdownMenuSeparator,{}),J.showGroupManagement&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>Z(!0),children:[e.jsx(s.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>ee(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Report preferences"]}),u&&d&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),w&&e.jsxs(s.DropdownMenuItem,{disabled:!Te,onSelect:()=>{var i;if(!Te){s.ue.error("Open a document sheet with a token to copy the local PDF URL");return}(i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(Te).then(()=>s.ue.success("Local document PDF URL copied to clipboard")).catch(()=>s.ue.error("Unable to copy local document PDF URL")):s.ue.error("Clipboard not available")},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy local document PDF URL"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>l.invalidateToken(n.apiServiceUrl),children:[e.jsx(us,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:v,children:[e.jsx(ns.Palette,{className:"h-3.5 w-3.5"}),"Brand Studio"]}),S&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Ze(!Xe),children:[e.jsx(os.Braces,{className:"h-3.5 w-3.5"}),Xe?"Hide dashboard JSON":"Show dashboard JSON"]}),ie&&S&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>pe(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),ie&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(ds,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(vs,{})})]})]})]})]}),X&&tt&&e.jsx(s.ShareDialog,{resource:tt,resourceType:s.ResourceType.DASHBOARD,onClose:()=>$(!1)}),J.showGroupManagement&&e.jsx(Vs,{open:Y,onOpenChange:Z}),e.jsx(rs.ReportPreferencesDialog,{open:Ie,onOpenChange:ee}),V&&me?e.jsx(q.DashboardBriefingLauncher,{dashboardId:V,dashboardTitle:(h==null?void 0:h.title)||(O==null?void 0:O.title),open:!0,onOpenChange:i=>{i||W(null)},hideTrigger:!0,workflowIntent:me}):null,u&&ie&&d&&e.jsx(bs,{open:he,onOpenChange:pe}),d&&e.jsx(s.DownloadPdf,{open:Le,onOpenChange:G}),e.jsx(s.AlertDialog,{open:g,onOpenChange:i=>{!i&&Re&&!z||(R(i),i||(_(null),H([]),xe(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:z?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:z?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),te.length>0&&e.jsxs("div",{className:"space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:"What needs attention"}),e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs text-muted-foreground",children:te.slice(0,5).map(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:z?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{R(!1),_(null),H([]),xe(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Ve({closeAfterSave:se,navigateHomeAfterSave:Fe==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(l.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(q.UnsavedChangesAlert,{open:Bt,onOpenChange:i=>{ne(i)},onSave:Ht,onDiscard:Kt,isSaving:Re,saveLabel:"Save",discardLabel:"Discard"})]})]})}function Js({accessToken:t,dashboardId:n,selectedSheetId:a,pageSize:r,orientation:o,theme:u}){if(!t||!a)return null;const p=new URL("http://localhost:5173/print-document");p.searchParams.set("token",t),n&&p.searchParams.set("dashboardId",n),p.searchParams.set("selectedSheetId",a),u&&p.searchParams.set("theme",u);const c=new URL("http://127.0.0.1:3002/");return c.searchParams.set("pdfMode","document"),c.searchParams.set("pageSize",r||"letter"),c.searchParams.set("orientation",o||"portrait"),c.searchParams.set("url",p.toString()),c.toString()}exports.default=Ws;
|
|
@@ -4,7 +4,7 @@ import { X as S } from "./index-xHCrHprY.js";
|
|
|
4
4
|
import { u as o, B as N, C as D, c as J } from "./code-editor-C8zzmSgt.js";
|
|
5
5
|
import "./analyze-result-contract-CfOBEwaC.js";
|
|
6
6
|
import "../value-format-preferences/index.js";
|
|
7
|
-
import "./dashboard
|
|
7
|
+
import "./dashboard--OqogTLn.js";
|
|
8
8
|
import "./index-If0wlXGi.js";
|
|
9
9
|
import "./comparison-document-migration-Dj6xZMCb.js";
|
|
10
10
|
import "react-dom";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),o=require("react"),b=require("./index-jSrCwPQz.js"),s=require("./code-editor-BSENCZwR.js");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");require("./dashboard-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),o=require("react"),b=require("./index-jSrCwPQz.js"),s=require("./code-editor-BSENCZwR.js");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");require("./dashboard-BJr7m1TP.js");require("./index-Dpm_VET4.js");require("./comparison-document-migration-DbU_BTxR.js");require("react-dom");require("../briefings/index.cjs");function S(){const t=s.useDashboardStore(e=>e.dashboard),u=s.useDashboardStore(e=>e.actions.setDashboard),c=s.useDashboardStore(e=>e.showDashboardJSON),h=s.useDashboardStore(e=>e.actions.setShowDashboardJSON),r=o.useMemo(()=>t?JSON.stringify(t,null,2):"",[t]),[l,i]=o.useState(r),n=o.useRef(r);return o.useEffect(()=>{r!==n.current&&(i(r),n.current=r)},[r]),a.jsxs("div",{className:s.cn("relative p-2",{hidden:!c}),children:[a.jsxs(s.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>h(!1),children:[a.jsx(b.X,{className:"mr-2 h-4 w-4"}),"Close"]}),a.jsx("div",{className:"h-[550px] overflow-hidden",children:a.jsx(s.CodeEditor,{value:l,onValueChange:e=>{i(e);try{const d=JSON.parse(e);n.current=JSON.stringify(d,null,2),u(d)}catch{}},language:"json"})})]})}exports.default=S;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("react"),n=require("./dashboard-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("react"),n=require("./dashboard-BJr7m1TP.js"),ae=require("./index-jSrCwPQz.js"),t=require("./code-editor-BSENCZwR.js");require("./analyze-result-contract-BswhsmWT.js");const Es=require("../value-format-preferences/index.cjs"),Ue=require("./search-Dcud9ajy.js"),ke=require("./use-create-flow-overlay-state-Doo8NeYf.js"),Lt=require("./card-config-utils-15sRtebL.js"),er=require("react-dom");require("./index-Dpm_VET4.js");require("./comparison-document-migration-DbU_BTxR.js");require("../briefings/index.cjs");const ta=require("./numeric-presentation-Dlb-Dk4c.js"),In=require("./metric-comparison-DVy3fll_.js"),tr=require("./palette-C0yjT5Tv.js"),sr=require("./common-types-C73-Ud1-.js");function nr(s){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const r in s)if(r!=="default"){const o=Object.getOwnPropertyDescriptor(s,r);Object.defineProperty(a,r,o.get?o:{enumerable:!0,get:()=>s[r]})}}return a.default=s,Object.freeze(a)}const ar=nr(v);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -154,7 +154,7 @@ ${w.joinType} JOIN ${F.name}
|
|
|
154
154
|
ON ${S}`}),R},isValidConfiguration:()=>!(!r.baseEntity.name||r.joins.some(w=>!w.source.name||!w.target.name)||r.joins.some(w=>w.joinKeyGroups.some(F=>F.keys.length===0))||r.joins.some(w=>w.joinKeyGroups.some(F=>F.keys.some(L=>!L.source.name||!L.target.name||!L.operator))))}}const Lr=[{value:"LEFT",label:"Keep rows without a match"},{value:"INNER",label:"Only matching rows"},{value:"RIGHT",label:"Keep all target rows"},{value:"FULL",label:"Keep all rows"}],Mr={one_to_one:"One to one",one_to_many:"One to many",many_to_one:"Many to one",many_to_many:"Many to many"},Fr={one_to_one:"1 : 1",one_to_many:"1 : N",many_to_one:"N : 1",many_to_many:"N : N"},Rr=["=","<",">","<=",">="];function Pr({joinPlan:s,availableDataSources:a,onSave:r,onRemove:o,onCancel:d}){const{columnGroups:i}=n.useColumns(),l=i.filter(M=>M.entityName!==t.CALCULATED_FIELDS_GROUP_NAME),{joinPlan:c,expandedJoins:u,setJoinPlan:x,addJoin:m,removeJoin:f,updateJoin:p,moveJoinUp:h,moveJoinDown:b,toggleJoinExpansion:E,getAvailableSourceEntities:C,getAvailableTargetEntities:g,addJoinKeyGroup:I,updateGroupOperator:P,removeJoinKeyGroup:N,addJoinKey:j,updateJoinKey:A,removeJoinKey:k,generateSQLPreview:R,isValidConfiguration:w}=Ar({initialJoinPlan:s,availableDataSources:a}),[F,L]=v.useState(new Set),[S,O]=v.useState(!1),V=M=>{const B=l.find(z=>z.entityName===M);return(B==null?void 0:B.columns)||[]},y=M=>L(B=>{const z=new Set(B);return z.has(M)?z.delete(M):z.add(M),z}),T=[];c.baseEntity.name&&T.push(c.baseEntity.name);for(const M of[...c.joins].sort((B,z)=>B.sequence-z.sequence))M.target.name&&!T.includes(M.target.name)&&T.push(M.target.name);const D=M=>{const B=M.joinKeyGroups.flatMap(q=>q.keys),z=B.find(q=>{var U,H;return((U=q.source)==null?void 0:U.name)&&((H=q.target)==null?void 0:H.name)});if(!z)return null;const _=B.length>1?` +${B.length-1}`:"";return`${z.source.name} ${z.operator||"="} ${z.target.name}${_}`};return e.jsxs("div",{className:"min-w-0 space-y-5",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Start from"}),e.jsxs(t.Select,{value:c.baseEntity.name,onValueChange:M=>{const B=a.find(z=>z.name===M);x({...c,baseEntity:{connectionId:(B==null?void 0:B.connectionId)||"",connectionType:(B==null?void 0:B.connectionType)||"none",type:(B==null?void 0:B.type)||"table",name:M,database:B==null?void 0:B.database,schema:B==null?void 0:B.schema}})},children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{placeholder:"Select the dataset to start from..."})}),e.jsx(t.SelectContent,{children:a.map(M=>e.jsx(t.SelectItem,{value:M.name,className:"text-[12px]",children:M.name},M.name))})]}),e.jsx("p",{className:"text-[11px] leading-relaxed text-muted-foreground",children:"Every other dataset connects back to this one."})]}),T.length>0&&e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Join path"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5",children:T.map((M,B)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[B>0&&e.jsx(n.ArrowRight,{className:"h-3 w-3 text-muted-foreground"}),e.jsxs("span",{className:`inline-flex max-w-[220px] items-center gap-1.5 rounded-[4px] border px-2 py-1 leading-none ${B===0?"border-border bg-muted font-medium text-foreground":"border-border/60 text-muted-foreground"}`,children:[e.jsx(n.Database,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"min-w-0 truncate text-[11.5px] leading-none",children:M}),B===0&&e.jsx("span",{className:"shrink-0 text-[9.5px] uppercase leading-none tracking-[0.06em] text-muted-foreground",children:"BASE"})]})]},M))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:["How datasets connect (",c.joins.length,")"]}),e.jsxs(t.Button,{variant:"outline",size:"xs",className:"gap-1.5",onClick:m,children:[e.jsx(n.Plus,{className:"h-3.5 w-3.5"}),"Add join"]})]}),c.joins.length===0?e.jsxs("div",{className:"rounded-[6px] border border-dashed border-border px-4 py-8 text-center",children:[e.jsx("p",{className:"text-[12.5px] font-medium text-foreground",children:"No joins yet"}),e.jsxs("p",{className:"mx-auto mt-1 max-w-[360px] text-[11.5px] leading-relaxed text-muted-foreground",children:["Add a join to connect another dataset to"," ",c.baseEntity.name||"your base dataset","."]})]}):e.jsx("div",{className:"max-h-[340px] space-y-1.5 overflow-y-auto",children:c.joins.map(M=>{var $;const B=a.find(Y=>Y.name===M.source.name),z=a.find(Y=>Y.name===M.target.name),_=u.has(M.id),q=F.has(M.id)||M.joinKeyGroups.length>1||M.joinKeyGroups.some(Y=>Y.operator!=="AND"),U=D(M),H=M.relationshipCardinality;return e.jsxs("div",{className:`rounded-[6px] border ${_?"border-border":"border-border/60"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("button",{type:"button",onClick:()=>E(M.id),className:"flex min-w-0 flex-1 items-center gap-2 text-left",children:[_?e.jsx(ae.ChevronDown,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(Ue.ChevronRight,{className:"h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-[12.5px] font-medium text-foreground",children:[e.jsx("span",{className:"truncate",children:M.source.name||"source"}),e.jsx(n.ArrowRight,{className:"h-3 w-3 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"truncate",children:M.target.name||"target"})]}),U&&e.jsx("code",{className:"hidden max-w-[180px] shrink-0 truncate rounded-[4px] bg-muted px-1.5 py-0.5 font-mono text-[10.5px] text-muted-foreground lg:inline-block",children:U})]}),e.jsxs("span",{className:"flex shrink-0 items-center gap-0.5",children:[e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>h(M.id),disabled:M.sequence===1,"aria-label":"Move join earlier",children:e.jsx(Or,{})}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>b(M.id),disabled:M.sequence===c.joins.length,"aria-label":"Move join later",children:e.jsx(Vr,{})}),e.jsxs(t.Button,{variant:"ghost",size:"sm",className:"h-6 gap-1 px-1.5 text-[11px] font-medium text-muted-foreground",onClick:()=>E(M.id),children:[e.jsx(n.Pencil,{className:"h-3 w-3"}),_?"Editing":"Edit"]}),e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0 text-muted-foreground",onClick:()=>f(M.id),"aria-label":"Remove join",children:e.jsx(ae.X,{className:"h-3.5 w-3.5"})})]})]}),_&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 pb-4 pt-3",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"From"}),e.jsxs(t.Select,{value:M.source.name,onValueChange:Y=>{const Q=a.find(se=>se.name===Y);p(M.id,{source:{connectionId:(Q==null?void 0:Q.connectionId)||"",connectionType:(Q==null?void 0:Q.connectionType)||"none",type:(Q==null?void 0:Q.type)||"table",name:Y,database:Q==null?void 0:Q.database,schema:Q==null?void 0:Q.schema}})},children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{placeholder:"Select source..."})}),e.jsx(t.SelectContent,{children:C(M.id).map(Y=>e.jsx(t.SelectItem,{value:Y.name,className:"text-[12px]",children:Y.name},Y.name))})]})]}),e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"To"}),e.jsxs(t.Select,{value:M.target.name,onValueChange:Y=>{const Q=a.find(se=>se.name===Y);p(M.id,{target:{connectionId:(Q==null?void 0:Q.connectionId)||"",connectionType:(Q==null?void 0:Q.connectionType)||"none",type:(Q==null?void 0:Q.type)||"table",name:Y,database:Q==null?void 0:Q.database,schema:Q==null?void 0:Q.schema}})},disabled:!M.source.name,children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{placeholder:"Select target..."})}),e.jsx(t.SelectContent,{children:M.source.name?g(M.source.name).map(Y=>e.jsx(t.SelectItem,{value:Y.name,className:"text-[12px]",children:Y.name},Y.name)):null})]})]}),e.jsxs("div",{className:"min-w-0 space-y-1.5",children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"When a row has no match"}),e.jsxs(t.Select,{value:M.joinType,onValueChange:Y=>p(M.id,{joinType:Y}),children:[e.jsx(t.SelectTrigger,{className:"h-8 text-[12px]",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Lr.map(Y=>e.jsx(t.SelectItem,{value:Y.value,className:"text-[12px]",children:e.jsxs("span",{className:"flex w-full min-w-0 items-center justify-between gap-3",children:[e.jsx("span",{className:"truncate",children:Y.label}),e.jsx("span",{className:"shrink-0 font-mono text-[10px] tracking-[0.04em] text-muted-foreground",children:Y.value})]})},Y.value))})]})]})]}),H&&e.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-[5px] border border-border/60 bg-muted/40 px-2.5 py-1.5 text-[11.5px]",children:[e.jsx("span",{className:"shrink-0 rounded-[3px] bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground",children:Fr[H]}),e.jsx("span",{className:"text-muted-foreground",children:Mr[H]}),e.jsxs("span",{className:"truncate text-muted-foreground/70",children:["(",M.source.name||"source"," →"," ",M.target.name||"target",")"]})]}),M.source.name&&M.target.name&&B&&z&&e.jsx("div",{className:"space-y-2",children:q?e.jsx(Br,{join:M,getColumnsForEntity:V,addJoinKey:j,addJoinKeyGroup:I,updateGroupOperator:P,removeJoinKeyGroup:N,updateJoinKey:A,removeJoinKey:k,canCollapse:M.joinKeyGroups.length<=1&&M.joinKeyGroups.every(Y=>Y.operator==="AND"),onCollapse:()=>y(M.id)}):e.jsxs(e.Fragment,{children:[e.jsx(t.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Match on"}),($=M.joinKeyGroups[0])!=null&&$.keys.length?e.jsx("div",{className:"min-w-0 space-y-1.5",children:M.joinKeyGroups[0].keys.map((Y,Q)=>e.jsx(la,{join:M,groupIndex:0,keyIndex:Q,conditionKey:Y,getColumnsForEntity:V,updateJoinKey:A,removeJoinKey:k,showRemove:M.joinKeyGroups[0].keys.length>1},Y.id||Q))}):e.jsx("p",{className:"rounded-[5px] border border-border/60 px-3 py-2 text-[11.5px] text-muted-foreground",children:"No match condition yet. Add one to define how these connect."}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",className:"gap-1.5",onClick:()=>j(M.id,0),children:[e.jsx(n.Plus,{className:"h-3 w-3"})," Add condition"]}),e.jsxs("button",{type:"button",onClick:()=>y(M.id),className:"inline-flex items-center gap-1 text-[11px] font-medium text-muted-foreground hover:text-foreground",children:[e.jsx(n.Settings2,{className:"h-3 w-3"}),"Advanced"]})]})]})})]})]},M.id)})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("button",{type:"button",onClick:()=>O(M=>!M),className:"inline-flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground hover:text-foreground",children:[S?e.jsx(ae.ChevronDown,{className:"h-3 w-3"}):e.jsx(Ue.ChevronRight,{className:"h-3 w-3"}),"View SQL"]}),S&&e.jsx("div",{className:"rounded-[5px] border border-border/60 bg-muted/40 p-3",children:e.jsx("code",{className:"block whitespace-pre-wrap break-all font-mono text-[11px] text-muted-foreground",children:R()})})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 border-t border-border pt-4",children:[e.jsxs(t.Button,{variant:"ghost",size:"xs",className:"gap-1.5 text-muted-foreground",onClick:()=>{o(),d()},children:[e.jsx(n.Trash2,{className:"h-3.5 w-3.5"}),"Remove all"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(t.Button,{variant:"outline",size:"xs",onClick:d,children:"Cancel"}),e.jsxs(t.Button,{size:"xs",className:"gap-1.5",onClick:()=>r(c),disabled:!w(),children:["Save joins",e.jsx(n.ArrowRight,{className:"h-3.5 w-3.5"})]})]})]})]})}function Or(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m18 15-6-6-6 6"})})}function Vr(){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}function la({join:s,groupIndex:a,keyIndex:r,conditionKey:o,getColumnsForEntity:d,updateJoinKey:i,removeJoinKey:l,showRemove:c,showOperator:u=!1}){const x=u||(o.operator||"=")!=="=";return e.jsxs("div",{className:"flex items-center gap-2 rounded-[5px] border border-border/60 p-2",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs(t.Select,{value:o.source.name,onValueChange:m=>i(s.id,a,r,"sourceColumnName",m),children:[e.jsx(t.SelectTrigger,{className:"h-7 font-mono text-[11px]",children:e.jsx(t.SelectValue,{placeholder:"Source column"})}),e.jsx(t.SelectContent,{children:d(s.source.name).map(m=>e.jsx(t.SelectItem,{value:m.name,children:e.jsxs("span",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx("span",{className:"font-mono",children:m.name}),m.dataType&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:m.dataType})]})},m.name))})]})}),x?e.jsx("div",{className:"w-16 shrink-0",children:e.jsxs(t.Select,{value:o.operator,onValueChange:m=>i(s.id,a,r,"operator",m),children:[e.jsx(t.SelectTrigger,{className:"h-7 justify-center px-1 font-mono text-[11px]",children:e.jsx(t.SelectValue,{})}),e.jsx(t.SelectContent,{children:Rr.map(m=>e.jsx(t.SelectItem,{value:m,children:m},m))})]})}):e.jsx("span",{className:"shrink-0 px-1 font-mono text-[12px] text-muted-foreground",children:"="}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs(t.Select,{value:o.target.name,onValueChange:m=>i(s.id,a,r,"targetColumnName",m),children:[e.jsx(t.SelectTrigger,{className:"h-7 font-mono text-[11px]",children:e.jsx(t.SelectValue,{placeholder:"Target column"})}),e.jsx(t.SelectContent,{children:d(s.target.name).map(m=>e.jsx(t.SelectItem,{value:m.name,children:e.jsxs("span",{className:"flex w-full items-center justify-between gap-2",children:[e.jsx("span",{className:"font-mono",children:m.name}),m.dataType&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:m.dataType})]})},m.name))})]})}),c&&e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>l(s.id,a,r),"aria-label":"Remove condition",children:e.jsx(ae.X,{className:"h-3.5 w-3.5"})})]})}function Br({join:s,getColumnsForEntity:a,addJoinKey:r,addJoinKeyGroup:o,updateGroupOperator:d,removeJoinKeyGroup:i,updateJoinKey:l,removeJoinKey:c,canCollapse:u,onCollapse:x}){return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(t.Label,{className:"flex items-center gap-1.5 text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:[e.jsx(n.Settings2,{className:"h-3 w-3"}),"Advanced conditions"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[u&&e.jsx("button",{type:"button",onClick:x,className:"text-[11px] font-medium text-muted-foreground hover:text-foreground",children:"Use simple"}),e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",className:"gap-1.5",onClick:()=>o(s.id),children:[e.jsx(n.Plus,{className:"h-3 w-3"})," Add OR group"]})]})]}),s.joinKeyGroups.map((m,f)=>e.jsxs("div",{className:"space-y-2 rounded-[5px] border border-border/60 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("span",{className:"text-[11px] font-medium text-foreground",children:["Group ",f+1]}),f>0&&e.jsx("span",{className:"rounded-[3px] bg-muted px-1.5 py-0.5 text-[10px] font-medium text-muted-foreground",children:"OR with previous"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.06em] text-muted-foreground",children:"within group"}),e.jsxs(t.Select,{value:m.operator,onValueChange:p=>d(s.id,f,p),children:[e.jsx(t.SelectTrigger,{className:"h-7 w-[76px] text-[11px]",children:e.jsx(t.SelectValue,{})}),e.jsxs(t.SelectContent,{children:[e.jsx(t.SelectItem,{value:"AND",children:"AND"}),e.jsx(t.SelectItem,{value:"OR",children:"OR"})]})]}),e.jsx(t.Button,{type:"button",variant:"ghost",size:"sm",className:"h-7 w-7 p-0 text-muted-foreground",onClick:()=>i(s.id,f),"aria-label":"Remove group",children:e.jsx(n.Trash2,{className:"h-3.5 w-3.5"})})]})]}),m.keys.length===0?e.jsx("p",{className:"rounded-[5px] border border-dashed border-border/60 px-3 py-2 text-center text-[11.5px] text-muted-foreground",children:"No conditions in this group."}):e.jsx("div",{className:"min-w-0 space-y-1.5",children:m.keys.map((p,h)=>e.jsxs("div",{className:"flex items-center gap-2",children:[h>0&&e.jsx("span",{className:"w-9 shrink-0 text-center text-[10px] font-medium text-muted-foreground",children:m.operator}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(la,{join:s,groupIndex:f,keyIndex:h,conditionKey:p,getColumnsForEntity:a,updateJoinKey:l,removeJoinKey:c,showRemove:!0,showOperator:!0})})]},p.id||h))}),e.jsxs(t.Button,{type:"button",variant:"outline",size:"xs",className:"gap-1.5",onClick:()=>r(s.id,f),children:[e.jsx(n.Plus,{className:"h-3 w-3"})," Add condition"]})]},m.id))]})}function ia({children:s,open:a,onOpenChange:r,joinPlan:o,availableDataSources:d,onRemove:i,onSave:l,onCancel:c}){return e.jsxs(n.Dialog,{open:a,onOpenChange:r,children:[e.jsxs(n.DialogContent,{className:"max-h-[88vh] w-[calc(100vw-2rem)] max-w-4xl overflow-y-auto overflow-x-hidden",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{className:"text-[15px] font-semibold tracking-tight",children:"How datasets connect"}),e.jsx(n.DialogDescription,{className:"text-[12px] text-muted-foreground",children:"Datasets joined together so a card can use fields from all of them."})]}),e.jsx(Pr,{joinPlan:o,availableDataSources:d,onSave:l,onCancel:c,onRemove:i})]}),s]})}function _r({joins:s,baseEntityId:a,availableDataSources:r,generateSQLPreview:o}){return e.jsxs("div",{className:"my-2 max-h-[400px] divide-y divide-border overflow-y-auto",children:[s.length>0&&e.jsxs("div",{className:"px-4 py-2",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 d=[...s].sort((l,c)=>l.sequence-c.sequence),i=r.find(l=>l.name===a);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(n.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}),e.jsx(n.Badge,{variant:"outline",className:"text-xs text-green-600",children:"BASE"})]}),d.map(l=>{const c=r.find(u=>u.name===l.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(n.Badge,{variant:"outline",className:"text-xs",children:l.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(n.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})]})]},l.id)})]})})()})]}),e.jsxs("div",{className:"p-4",children:[e.jsxs("h3",{className:"mb-3 text-left text-sm font-medium",children:["Configured Joins (",s.length,")"]}),e.jsx("div",{className:"space-y-2",children:[...s].sort((d,i)=>d.sequence-i.sequence).map((d,i)=>{const l=r.find(x=>x.name===d.source.name),c=r.find(x=>x.name===d.target.name),u=d.joinKeyGroups.reduce((x,m)=>x+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(n.Badge,{variant:"secondary",className:"shrink-0 text-xs",children:i+1}),e.jsx(n.Badge,{variant:"outline",className:"shrink-0 text-xs",children:d.joinType}),e.jsxs(n.Badge,{variant:"outline",className:"ml-auto shrink-0 text-xs",children:[u," condition",u>1?"s":""]})]}),e.jsxs("div",{className:"mt-1 truncate pl-1 text-xs text-muted-foreground",children:[l==null?void 0:l.name," → ",c==null?void 0:c.name]})]},d.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:o()})})]})]})}function zr({open:s,onOpenChange:a,variant:r="button"}={}){var I,P;const o=t.useEditorStore(N=>N.card),{autoJoinMetadata:d}=n.useEditorCardQuery(o),i=t.useEditorStore(N=>N.actions.updateCardConfig),l=((I=o==null?void 0:o.config)==null?void 0:I.joinPlan)||{baseEntity:{type:"table",name:"",database:"",schema:"",connectionId:"",connectionType:"none",dialect:"none"},joins:[]},[c,u]=v.useState(!1),x=s!==void 0,m=x?s:c,f=x?a:u,p=((P=o==null?void 0:o.dataSource)==null?void 0:P.selectedEntities)||[],h=N=>{i(o.id,{...o==null?void 0:o.config,joinPlan:N}),f(!1)},b=()=>{i(o.id,{...o==null?void 0:o.config,joinPlan:void 0})},E=()=>{f(!1)},C=()=>{const N=[...l.joins].sort((k,R)=>k.sequence-R.sequence),j=l.baseEntity;if(!j.name)return"SELECT * FROM table -- Please select a base entity";let A=`SELECT *
|
|
155
155
|
FROM ${j.name}`;return N.forEach(k=>{const R=p.find(L=>L.name===k.target.name);if(!R)return;const w=k.joinKeyGroups.filter(L=>L.keys&&L.keys.length>0).map(L=>{const S=L.keys.filter(O=>{var V,y,T,D;return((V=O.source)==null?void 0:V.name)&&((y=O.target)==null?void 0:y.name)&&((T=O.source)==null?void 0:T.entityName)&&((D=O.target)==null?void 0:D.entityName)}).map(O=>`${O.source.entityName}.${O.source.name} ${O.operator} ${O.target.entityName}.${O.target.name}`);return S.length>1?`(${S.join(` ${L.operator} `)})`:S[0]}).filter(Boolean),F=w.length>1?w.join(" OR "):w[0]||"condition_here";A+=`
|
|
156
156
|
${k.joinType} JOIN ${R.name}
|
|
157
|
-
ON ${F}`}),A};if(p.length<2)return null;const g=l.joins.length>0&&e.jsx(t.TooltipContent,{side:"bottom",className:"ml-4 max-w-md overflow-hidden p-0",children:e.jsx(_r,{joins:l.joins,baseEntityId:l.baseEntity.name,availableDataSources:p,generateSQLPreview:C})});return e.jsxs(e.Fragment,{children:[e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:r==="badge"?e.jsxs(n.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:N=>{N.stopPropagation(),f(!0)},children:[e.jsx(n.Link,{className:"h-3 w-3"}),l.joins.length]}):e.jsxs("button",{type:"button",onClick:()=>f(!0),className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(n.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:l.joins.length===0?"Configure joins":`${l.joins.length} ${l.joins.length===1?"join":"joins"}`}),(d==null?void 0:d.autoResolved)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(n.Sparkles,{className:"h-3 w-3",strokeWidth:1.75}),"Auto"]})]})}),g]})}),e.jsx(ia,{open:m,onOpenChange:f,joinPlan:l,availableDataSources:p,onSave:h,onCancel:E,onRemove:b,children:e.jsx("div",{})})]})}function qr(){var F,L,S,O,V,y,T;const[s,a]=v.useState(!1),[r,o]=v.useState(!1),[d,i]=v.useState(!1),l=t.useEditorStore(D=>D.card.dataSource),c=t.useEditorStore(D=>D.card),u=t.useEditorStore(D=>D.isDevMode),{updateCardConfig:x,updateDataSource:m}=t.useEditorActions(),{autoJoinMetadata:f}=n.useEditorCardQuery(c),h={...{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},...l,selectedEntities:(l==null?void 0:l.selectedEntities)||[]},b=n.toEntityArray(h.selectedEntities),E=b.length,C=E===0?"Choose dataset":E===1?fs(b[0]):`${E} datasets`,g=((S=(L=(F=c==null?void 0:c.config)==null?void 0:F.joinPlan)==null?void 0:L.joins)==null?void 0:S.length)??0,I=Dn((O=c==null?void 0:c.config)==null?void 0:O.joinPlan,b),P=I.length>0,N=!u&&(E>1||g>0),j=!!(f!=null&&f.autoResolved);((y=(V=f==null?void 0:f.resolvedJoinPlan)==null?void 0:V.joins)==null?void 0:y.length)??((T=f==null?void 0:f.relationshipsUsed)==null||T.length);const A=g>0?`${g} join${g===1?"":"s"}`:E<2?null:j?"auto":null,k=D=>{var B;const M=b.filter(z=>!n.areContextEntitiesEqual(z,D));c&&Dn((B=c.config)==null?void 0:B.joinPlan,M).length>0&&x(c.id,{...c.config,joinPlan:void 0}),m({...h,selectedEntities:M})},R=()=>{c&&x(c.id,{...c.config,joinPlan:void 0})},w=()=>{m({...h,selectedEntities:n.dedupeContextEntities([...b,...I])})};return e.jsxs(e.Fragment,{children:[e.jsxs(t.Popover,{open:s,onOpenChange:a,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(n.Database,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:C}),A&&e.jsxs("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:["· ",A]}),e.jsx(ae.ChevronDown,{className:t.cn("h-3 w-3 shrink-0 text-muted-foreground transition-transform",s&&"rotate-180")})]})}),e.jsx(t.PopoverContent,{align:"start",sideOffset:4,className:"w-[320px] overflow-hidden rounded-control border border-border bg-popover p-0 shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-3 pb-1.5 pt-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Datasets"}),e.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:E})]}),E===0?e.jsx("div",{className:"px-3 pb-2 text-[12px] text-muted-foreground",children:"No datasets selected."}):e.jsx("ul",{className:"mb-1",children:b.map((D,M)=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-muted/50",children:[e.jsx(n.Database,{className:"mt-[3px] h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] text-foreground",children:fs(D)}),e.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:$r(D)})]}),e.jsx("button",{type:"button",onClick:()=>k(D),"aria-label":`Remove ${fs(D)}`,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(ae.X,{className:"h-3 w-3"})})]},`${D.connectionId}-${D.name}-${M}`))}),e.jsxs("button",{type:"button",onClick:()=>{a(!1),o(!0)},className:"flex w-full items-center gap-1.5 px-3 py-1.5 text-left text-[12px] text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx(n.Plus,{className:"h-3 w-3"}),"Add dataset"]})]}),N&&e.jsxs("div",{className:"border-t border-border/60 px-3 py-2.5",children:[e.jsx("div",{className:"mb-1.5 flex items-center justify-between",children:e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Join"})}),P?e.jsxs("div",{className:"space-y-2 rounded-control border border-amber-300/70 bg-amber-50/70 p-2.5 text-[11px] text-amber-950 dark:border-amber-700/70 dark:bg-amber-950/20 dark:text-amber-100",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(n.TriangleAlert,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-medium",children:[g," saved ",g===1?"join":"joins"," need attention"]}),e.jsxs("p",{className:"mt-0.5 leading-relaxed text-amber-900/80 dark:text-amber-100/80",children:[I.map(D=>D.name).join(", ")," is no longer selected, but the saved join still affects this card."]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:R,className:"rounded-control border border-amber-500/60 bg-background px-2 py-1 text-[11px] font-medium text-foreground transition-colors hover:bg-amber-100 dark:bg-background dark:hover:bg-amber-950/60",children:"Remove saved join"}),e.jsx("button",{type:"button",onClick:w,className:"rounded-control px-1 py-1 text-[11px] font-medium text-amber-900 transition-colors hover:underline dark:text-amber-100",children:"Re-add dataset"})]})]}):e.jsxs("button",{type:"button",onClick:()=>{a(!1),i(!0)},className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(n.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:g>0?`${g} ${g===1?"join":"joins"}`:"Configure joins"}),j&&g===0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(n.Sparkles,{className:"h-3 w-3",strokeWidth:1.75}),"Auto"]})]})]}),e.jsx("div",{className:"flex items-center justify-end border-t border-border/60 px-2 py-1.5",children:e.jsx("button",{type:"button",onClick:()=>a(!1),className:"inline-flex h-6 items-center rounded-control px-2 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:"Done"})})]})})]}),e.jsx(n.AddDataPicker,{incomingSelectedEntities:(l==null?void 0:l.selectedEntities)||[],dialogMode:"dataSource",open:r,onOpenChange:o,dataSource:h}),N&&!P&&e.jsx("div",{className:"hidden",children:e.jsx(zr,{open:d,onOpenChange:i})})]})}function fs(s){return"label"in s&&s.label?s.label:s.name||"Dataset"}function $r(s){const a=[];return s.connectionType&&a.push(String(s.connectionType)),s.database&&a.push(s.database),s.schema&&a.push(s.schema),a.join(" · ")}function ca({isVisible:s}){ke.useSyncLegacyEditorState();const[a,r]=v.useState(!1);return e.jsxs("div",{className:t.cn("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",{"w-[290px]":s,"min-w-[290px]":s,"w-0 border-r-0":!s,"min-w-0":!s}),children:[e.jsx("div",{className:"px-4 pt-4",children:e.jsx(qr,{})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(n.FieldsSection,{})}),e.jsx(Er,{open:a,onOpenChange:r})]})}function da({storeValue:s,defaultValue:a="",onStoreUpdate:r,delay:o=300}){const[d,i]=v.useState(s??a),l=v.useRef(null),c=v.useRef(d),u=v.useRef(s),x=v.useRef(!1),m=v.useCallback(()=>{l.current&&(clearTimeout(l.current),l.current=null),x.current&&c.current!==(u.current??a)&&(r(c.current),u.current=c.current)},[a,r]);v.useEffect(()=>{if(s!==u.current){l.current&&(clearTimeout(l.current),l.current=null);const p=s??a;i(p),c.current=p,u.current=s,x.current=!1}},[s,a]),v.useEffect(()=>{if(x.current)return l.current=setTimeout(()=>{m()},o),()=>{l.current&&(clearTimeout(l.current),l.current=null)}},[o,m,d]),v.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]);const f=v.useCallback(p=>{const h=p??a;x.current=!0,c.current=h,i(h)},[a]);return{value:d,onChange:f,flush:m}}const Kr=300;function Ur(){const s=t.useEditorStore(g=>g.card.sql),a=t.useEditorStore(g=>g.sqlGen),r=t.useEditorStore(g=>g.card),o=ke.useEffectiveEditorCardType(),{setCardSql:d,setSqlGen:i,setRunSql:l}=t.useEditorActions(),c=v.useMemo(()=>o!==r.type?{...r,type:o}:r,[r,o]),{queryKey:u}=n.useEditorCardQuery(c),x=n.useQueryClient(),m=v.useRef(u);m.current=u;const f=v.useRef(a);f.current=a;const p=v.useCallback(g=>{d(g)},[d]),{value:h,onChange:b,flush:E}=da({storeValue:s,defaultValue:"",onStoreUpdate:p,delay:Kr});v.useEffect(()=>ke.registerPendingEditorDraftFlusher(E),[E]);function C(g){b(g),t.isObjectEmpty(f.current)||i({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!h&&e.jsx("div",{className:"pointer-events-none absolute left-[56px] top-4 z-10 font-mono text-[12px] leading-[1.55] text-muted-foreground",children:"Write your SQL here"}),e.jsx(t.CodeEditor,{value:h??"",onValueChange:C,language:"sql-jinja",embedded:!0,flushGutter:!0,wrapLines:!0,onKeyDown:g=>{g.key==="Enter"&&g.shiftKey&&(g.preventDefault(),ke.flushPendingEditorDrafts(),setTimeout(()=>{x.removeQueries({queryKey:m.current,exact:!0}),l(!0)},0))}})]})}const Gr=300;function Hr(){const s=t.useEditorStore(p=>p.card.python),a=t.useEditorStore(p=>p.card),r=ke.useEffectiveEditorCardType(),{setCardPython:o,setRunSql:d}=t.useEditorActions(),i=v.useMemo(()=>r!==a.type?{...a,type:r}:a,[a,r]),{queryKey:l}=n.useEditorCardQuery(i),c=n.useQueryClient(),u=v.useRef(l);u.current=l;const{value:x,onChange:m,flush:f}=da({storeValue:s,defaultValue:n.PYTHON_DEFAULT_CODE,onStoreUpdate:o,delay:Gr});return v.useEffect(()=>ke.registerPendingEditorDraftFlusher(f),[f]),e.jsx(t.CodeEditor,{value:x??"",onValueChange:m,language:"python",embedded:!0,flushGutter:!0,wrapLines:!0,onKeyDown:p=>{p.key==="Enter"&&p.shiftKey&&(p.preventDefault(),ke.flushPendingEditorDrafts(),setTimeout(()=>{c.removeQueries({queryKey:u.current,exact:!0}),d(!0)},0))}})}const Qr=/\{\{-?\s*filters\s*\|\s*where\s*-?\}\}/i,Wr=/\{\{-?\s*filters\s*\|\s*and\s*-?\}\}/i,Yr=/\bwhere\b/i;function Jr(s){return s!=null&&s.trim()?Qr.test(s)||Wr.test(s):!1}function Xr(s){return!(s!=null&&s.trim())||Jr(s)?null:Yr.test(s)?{helper:"{{ filters | and }}",description:"Use this inside your existing WHERE clause to append dashboard filters."}:{helper:"{{ filters | where }}",description:"Use this when the query does not already have a WHERE clause."}}function Zr(s){const{request:a,mode:r="draft",currentSql:o,selectedTableName:d,selectedSchemaName:i,selectedDatabaseName:l}=s,c=[l?`Database: ${l}`:"",i?`Schema: ${i}`:"",d?`Table: ${d}`:""].filter(Boolean);return["You are an expert SQL writing assistant embedded in a query editor.",`Write SQL only. You may call only read-only tools when needed: ${n.INLINE_ALLOWED_TOOL_LIST}.`,"Do not call mutation tools or chart-creation tools; those require Full Assistant.","Return exactly one SQL statement inside a single ```sql fenced block.","After the code block, optionally include one short sentence.",r==="refine"&&o?"Mode: Refine existing SQL. Keep the current query structure and only apply the requested changes unless the current query is invalid.":"Mode: Draft new SQL from the request.",c.length>0?`Context:
|
|
157
|
+
ON ${F}`}),A};if(p.length<2)return null;const g=l.joins.length>0&&e.jsx(t.TooltipContent,{side:"bottom",className:"ml-4 max-w-md overflow-hidden p-0",children:e.jsx(_r,{joins:l.joins,baseEntityId:l.baseEntity.name,availableDataSources:p,generateSQLPreview:C})});return e.jsxs(e.Fragment,{children:[e.jsx(t.TooltipProvider,{children:e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:r==="badge"?e.jsxs(n.Badge,{variant:"secondary",className:"h-5 cursor-pointer gap-1 px-1.5 text-xs transition-colors hover:bg-secondary/80",onClick:N=>{N.stopPropagation(),f(!0)},children:[e.jsx(n.Link,{className:"h-3 w-3"}),l.joins.length]}):e.jsxs("button",{type:"button",onClick:()=>f(!0),className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(n.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:l.joins.length===0?"Configure joins":`${l.joins.length} ${l.joins.length===1?"join":"joins"}`}),(d==null?void 0:d.autoResolved)&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(n.Sparkles,{className:"h-3 w-3",strokeWidth:1.75}),"Auto"]})]})}),g]})}),e.jsx(ia,{open:m,onOpenChange:f,joinPlan:l,availableDataSources:p,onSave:h,onCancel:E,onRemove:b,children:e.jsx("div",{})})]})}function qr(){var F,L,S,O,V,y,T;const[s,a]=v.useState(!1),[r,o]=v.useState(!1),[d,i]=v.useState(!1),l=t.useEditorStore(D=>D.card.dataSource),c=t.useEditorStore(D=>D.card),u=t.useEditorStore(D=>D.isDevMode),{updateCardConfig:x,updateDataSource:m}=t.useEditorActions(),{autoJoinMetadata:f}=n.useEditorCardQuery(c),h={...{connectionId:"",connectionType:"",mode:"database",selectedEntities:[]},...l,selectedEntities:(l==null?void 0:l.selectedEntities)||[]},b=n.toEntityArray(h.selectedEntities),E=b.length,C=E===0?"Choose dataset":E===1?fs(b[0]):`${E} datasets`,g=((S=(L=(F=c==null?void 0:c.config)==null?void 0:F.joinPlan)==null?void 0:L.joins)==null?void 0:S.length)??0,I=Dn((O=c==null?void 0:c.config)==null?void 0:O.joinPlan,b),P=I.length>0,N=!u&&(E>1||g>0),j=!!(f!=null&&f.autoResolved);((y=(V=f==null?void 0:f.resolvedJoinPlan)==null?void 0:V.joins)==null?void 0:y.length)??((T=f==null?void 0:f.relationshipsUsed)==null||T.length);const A=g>0?`${g} join${g===1?"":"s"}`:E<2?null:j?"auto":null,k=D=>{var B;const M=b.filter(z=>!n.areContextEntitiesEqual(z,D));c&&Dn((B=c.config)==null?void 0:B.joinPlan,M).length>0&&x(c.id,{...c.config,joinPlan:void 0}),m({...h,...h.mode==="semanticDomain"?{semanticDomainId:n.inferSemanticDomainIdFromSelectedEntities(M)}:{},selectedEntities:M})},R=()=>{c&&x(c.id,{...c.config,joinPlan:void 0})},w=()=>{m({...h,selectedEntities:n.dedupeContextEntities([...b,...I])})};return e.jsxs(e.Fragment,{children:[e.jsxs(t.Popover,{open:s,onOpenChange:a,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs("button",{type:"button",className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(n.Database,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:C}),A&&e.jsxs("span",{className:"shrink-0 text-[11px] text-muted-foreground",children:["· ",A]}),e.jsx(ae.ChevronDown,{className:t.cn("h-3 w-3 shrink-0 text-muted-foreground transition-transform",s&&"rotate-180")})]})}),e.jsx(t.PopoverContent,{align:"start",sideOffset:4,className:"w-[320px] overflow-hidden rounded-control border border-border bg-popover p-0 shadow-[0_4px_16px_rgba(0,0,0,0.08)]",children:e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between px-3 pb-1.5 pt-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Datasets"}),e.jsx("span",{className:"font-mono text-[10px] tabular-nums text-muted-foreground/70",children:E})]}),E===0?e.jsx("div",{className:"px-3 pb-2 text-[12px] text-muted-foreground",children:"No datasets selected."}):e.jsx("ul",{className:"mb-1",children:b.map((D,M)=>e.jsxs("li",{className:"flex items-start gap-2 px-3 py-1.5 hover:bg-muted/50",children:[e.jsx(n.Database,{className:"mt-[3px] h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] text-foreground",children:fs(D)}),e.jsx("p",{className:"truncate text-[11px] text-muted-foreground",children:$r(D)})]}),e.jsx("button",{type:"button",onClick:()=>k(D),"aria-label":`Remove ${fs(D)}`,className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded-control text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:e.jsx(ae.X,{className:"h-3 w-3"})})]},`${D.connectionId}-${D.name}-${M}`))}),e.jsxs("button",{type:"button",onClick:()=>{a(!1),o(!0)},className:"flex w-full items-center gap-1.5 px-3 py-1.5 text-left text-[12px] text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground",children:[e.jsx(n.Plus,{className:"h-3 w-3"}),"Add dataset"]})]}),N&&e.jsxs("div",{className:"border-t border-border/60 px-3 py-2.5",children:[e.jsx("div",{className:"mb-1.5 flex items-center justify-between",children:e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Join"})}),P?e.jsxs("div",{className:"space-y-2 rounded-control border border-amber-300/70 bg-amber-50/70 p-2.5 text-[11px] text-amber-950 dark:border-amber-700/70 dark:bg-amber-950/20 dark:text-amber-100",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(n.TriangleAlert,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"font-medium",children:[g," saved ",g===1?"join":"joins"," need attention"]}),e.jsxs("p",{className:"mt-0.5 leading-relaxed text-amber-900/80 dark:text-amber-100/80",children:[I.map(D=>D.name).join(", ")," is no longer selected, but the saved join still affects this card."]})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx("button",{type:"button",onClick:R,className:"rounded-control border border-amber-500/60 bg-background px-2 py-1 text-[11px] font-medium text-foreground transition-colors hover:bg-amber-100 dark:bg-background dark:hover:bg-amber-950/60",children:"Remove saved join"}),e.jsx("button",{type:"button",onClick:w,className:"rounded-control px-1 py-1 text-[11px] font-medium text-amber-900 transition-colors hover:underline dark:text-amber-100",children:"Re-add dataset"})]})]}):e.jsxs("button",{type:"button",onClick:()=>{a(!1),i(!0)},className:"flex h-7 w-full items-center gap-2 rounded-control border border-input bg-background px-2 text-left transition-colors hover:bg-muted focus:outline-none focus-visible:border-ring",children:[e.jsx(n.Link,{className:"h-3 w-3 shrink-0 text-muted-foreground",strokeWidth:1.75}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-[13px] text-foreground",children:g>0?`${g} ${g===1?"join":"joins"}`:"Configure joins"}),j&&g===0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground",children:[e.jsx(n.Sparkles,{className:"h-3 w-3",strokeWidth:1.75}),"Auto"]})]})]}),e.jsx("div",{className:"flex items-center justify-end border-t border-border/60 px-2 py-1.5",children:e.jsx("button",{type:"button",onClick:()=>a(!1),className:"inline-flex h-6 items-center rounded-control px-2 text-[11px] font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground",children:"Done"})})]})})]}),e.jsx(n.AddDataPicker,{incomingSelectedEntities:(l==null?void 0:l.selectedEntities)||[],dialogMode:"dataSource",open:r,onOpenChange:o,dataSource:h}),N&&!P&&e.jsx("div",{className:"hidden",children:e.jsx(zr,{open:d,onOpenChange:i})})]})}function fs(s){return"label"in s&&s.label?s.label:s.name||"Dataset"}function $r(s){const a=[];return s.connectionType&&a.push(String(s.connectionType)),s.database&&a.push(s.database),s.schema&&a.push(s.schema),a.join(" · ")}function ca({isVisible:s}){ke.useSyncLegacyEditorState();const[a,r]=v.useState(!1);return e.jsxs("div",{className:t.cn("flex shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-all duration-300 ease-in-out",{"w-[290px]":s,"min-w-[290px]":s,"w-0 border-r-0":!s,"min-w-0":!s}),children:[e.jsx("div",{className:"px-4 pt-4",children:e.jsx(qr,{})}),e.jsx("div",{className:"min-h-0 flex-1",children:e.jsx(n.FieldsSection,{})}),e.jsx(Er,{open:a,onOpenChange:r})]})}function da({storeValue:s,defaultValue:a="",onStoreUpdate:r,delay:o=300}){const[d,i]=v.useState(s??a),l=v.useRef(null),c=v.useRef(d),u=v.useRef(s),x=v.useRef(!1),m=v.useCallback(()=>{l.current&&(clearTimeout(l.current),l.current=null),x.current&&c.current!==(u.current??a)&&(r(c.current),u.current=c.current)},[a,r]);v.useEffect(()=>{if(s!==u.current){l.current&&(clearTimeout(l.current),l.current=null);const p=s??a;i(p),c.current=p,u.current=s,x.current=!1}},[s,a]),v.useEffect(()=>{if(x.current)return l.current=setTimeout(()=>{m()},o),()=>{l.current&&(clearTimeout(l.current),l.current=null)}},[o,m,d]),v.useEffect(()=>()=>{l.current&&clearTimeout(l.current)},[]);const f=v.useCallback(p=>{const h=p??a;x.current=!0,c.current=h,i(h)},[a]);return{value:d,onChange:f,flush:m}}const Kr=300;function Ur(){const s=t.useEditorStore(g=>g.card.sql),a=t.useEditorStore(g=>g.sqlGen),r=t.useEditorStore(g=>g.card),o=ke.useEffectiveEditorCardType(),{setCardSql:d,setSqlGen:i,setRunSql:l}=t.useEditorActions(),c=v.useMemo(()=>o!==r.type?{...r,type:o}:r,[r,o]),{queryKey:u}=n.useEditorCardQuery(c),x=n.useQueryClient(),m=v.useRef(u);m.current=u;const f=v.useRef(a);f.current=a;const p=v.useCallback(g=>{d(g)},[d]),{value:h,onChange:b,flush:E}=da({storeValue:s,defaultValue:"",onStoreUpdate:p,delay:Kr});v.useEffect(()=>ke.registerPendingEditorDraftFlusher(E),[E]);function C(g){b(g),t.isObjectEmpty(f.current)||i({})}return e.jsxs("div",{className:"relative h-full w-full",children:[!h&&e.jsx("div",{className:"pointer-events-none absolute left-[56px] top-4 z-10 font-mono text-[12px] leading-[1.55] text-muted-foreground",children:"Write your SQL here"}),e.jsx(t.CodeEditor,{value:h??"",onValueChange:C,language:"sql-jinja",embedded:!0,flushGutter:!0,wrapLines:!0,onKeyDown:g=>{g.key==="Enter"&&g.shiftKey&&(g.preventDefault(),ke.flushPendingEditorDrafts(),setTimeout(()=>{x.removeQueries({queryKey:m.current,exact:!0}),l(!0)},0))}})]})}const Gr=300;function Hr(){const s=t.useEditorStore(p=>p.card.python),a=t.useEditorStore(p=>p.card),r=ke.useEffectiveEditorCardType(),{setCardPython:o,setRunSql:d}=t.useEditorActions(),i=v.useMemo(()=>r!==a.type?{...a,type:r}:a,[a,r]),{queryKey:l}=n.useEditorCardQuery(i),c=n.useQueryClient(),u=v.useRef(l);u.current=l;const{value:x,onChange:m,flush:f}=da({storeValue:s,defaultValue:n.PYTHON_DEFAULT_CODE,onStoreUpdate:o,delay:Gr});return v.useEffect(()=>ke.registerPendingEditorDraftFlusher(f),[f]),e.jsx(t.CodeEditor,{value:x??"",onValueChange:m,language:"python",embedded:!0,flushGutter:!0,wrapLines:!0,onKeyDown:p=>{p.key==="Enter"&&p.shiftKey&&(p.preventDefault(),ke.flushPendingEditorDrafts(),setTimeout(()=>{c.removeQueries({queryKey:u.current,exact:!0}),d(!0)},0))}})}const Qr=/\{\{-?\s*filters\s*\|\s*where\s*-?\}\}/i,Wr=/\{\{-?\s*filters\s*\|\s*and\s*-?\}\}/i,Yr=/\bwhere\b/i;function Jr(s){return s!=null&&s.trim()?Qr.test(s)||Wr.test(s):!1}function Xr(s){return!(s!=null&&s.trim())||Jr(s)?null:Yr.test(s)?{helper:"{{ filters | and }}",description:"Use this inside your existing WHERE clause to append dashboard filters."}:{helper:"{{ filters | where }}",description:"Use this when the query does not already have a WHERE clause."}}function Zr(s){const{request:a,mode:r="draft",currentSql:o,selectedTableName:d,selectedSchemaName:i,selectedDatabaseName:l}=s,c=[l?`Database: ${l}`:"",i?`Schema: ${i}`:"",d?`Table: ${d}`:""].filter(Boolean);return["You are an expert SQL writing assistant embedded in a query editor.",`Write SQL only. You may call only read-only tools when needed: ${n.INLINE_ALLOWED_TOOL_LIST}.`,"Do not call mutation tools or chart-creation tools; those require Full Assistant.","Return exactly one SQL statement inside a single ```sql fenced block.","After the code block, optionally include one short sentence.",r==="refine"&&o?"Mode: Refine existing SQL. Keep the current query structure and only apply the requested changes unless the current query is invalid.":"Mode: Draft new SQL from the request.",c.length>0?`Context:
|
|
158
158
|
${c.join(`
|
|
159
159
|
`)}`:"",o?r==="refine"?`Current SQL (must refine):
|
|
160
160
|
${o}`:`Current SQL (revise if useful):
|