react-semaphor 0.1.441 → 0.1.443
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/brand-studio/index.js +1 -1
- package/dist/chunks/{code-editor-CIWiSltV.js → code-editor-BpADiIlq.js} +26 -26
- package/dist/chunks/{dashboard--bQrQeiz.js → dashboard-Bd1Quco-.js} +4987 -4901
- package/dist/chunks/{dashboard-briefing-launcher-dgTjPWHX.js → dashboard-briefing-launcher-BYMLjZxG.js} +6 -11
- package/dist/chunks/{dashboard-briefing-launcher-xulAb1Oz.js → dashboard-briefing-launcher-C60n8LqW.js} +165 -176
- package/dist/chunks/{dashboard-C-eTAAKs.js → dashboard-cB3xmTNn.js} +77 -77
- package/dist/chunks/{dashboard-controls-D8BDZ5_q.js → dashboard-controls-BH_fZYDU.js} +1 -1
- package/dist/chunks/{dashboard-controls-CWu1wt6_.js → dashboard-controls-ti9Rcel2.js} +4 -4
- package/dist/chunks/{dashboard-json-ZgLCrrSW.js → dashboard-json-Bturr634.js} +2 -2
- package/dist/chunks/{dashboard-json-Bpm-ePrD.js → dashboard-json-Dw_55vSZ.js} +1 -1
- package/dist/chunks/edit-dashboard-visual-BUc3NBQ4.js +182 -0
- package/dist/chunks/{edit-dashboard-visual-DEtVA2re.js → edit-dashboard-visual-DglMds57.js} +8260 -7877
- package/dist/chunks/{use-create-flow-overlay-state-B6a3gmF0.js → editor-action-buttons-CRi0fhVW.js} +887 -870
- package/dist/chunks/editor-action-buttons-Cxo7_tNG.js +16 -0
- package/dist/chunks/{report-preferences-dialog-Ju8DjgyW.js → report-preferences-dialog-CCvFqH4Q.js} +1 -1
- package/dist/chunks/{report-preferences-dialog-Bjj_tIgL.js → report-preferences-dialog-TtwdAuNn.js} +2 -2
- 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 +66 -66
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -6
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunks/edit-dashboard-visual-BCMupXbq.js +0 -182
- package/dist/chunks/use-create-flow-overlay-state-wcIRGLSM.js +0 -11
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";const J=require("./index-jSrCwPQz.js"),v=require("react"),s=require("./code-editor-M7HTUhdF.js"),f=require("./dashboard-cB3xmTNn.js"),e=require("react/jsx-runtime");require("./analyze-result-contract-BswhsmWT.js");require("../value-format-preferences/index.cjs");const ge=require("./search-Dcud9ajy.js"),Se=require("./save-Xdc4pnys.js");/**
|
|
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 Fe=J.createLucideIcon("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]);/**
|
|
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 je=J.createLucideIcon("Library",[["path",{d:"m16 6 4 14",key:"ji33uf"}],["path",{d:"M12 6v14",key:"1n7gus"}],["path",{d:"M8 8v12",key:"1gg7y9"}],["path",{d:"M4 4v16",key:"6qkkli"}]]);/**
|
|
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 ke=J.createLucideIcon("Link2",[["path",{d:"M9 17H7A5 5 0 0 1 7 7h2",key:"8i5ue5"}],["path",{d:"M15 7h2a5 5 0 1 1 0 10h-2",key:"1b9ql8"}],["line",{x1:"8",x2:"16",y1:"12",y2:"12",key:"1jonct"}]]);function Ve(r){const[a,l]=v.useState(null),[n,d]=v.useState(null),u=f.useEnsureReactGlobals();return v.useEffect(()=>{if(!r||r.trim()===""){l(null),d(null);return}if(!u)return;(async()=>{try{if(!r.startsWith("http://")&&!r.startsWith("https://"))throw new Error(`Invalid URL format: ${r}`);try{new URL(r)}catch{throw new Error(`Invalid URL: ${r}`)}const p=`${r.endsWith("/")?r:`${r}/`}index.js`;try{if(!(await fetch(p,{method:"HEAD"})).ok)throw new Error(`Module not found at ${p}`)}catch{}const C=await import(p);if(typeof C.useChartStore!="function")throw new Error("useChartStore is not a function");l(()=>C.useChartStore),d(null)}catch(x){const p=x instanceof Error?x.message:"Unknown error";console.error("Failed to load remote chart store:",p),d(p),l(null)}})()},[r,u]),a}function Ie(r,a){if(r.length===0)return"";const l=r.find(n=>{var d,u;return((d=n.customCardPreferences)==null?void 0:d.visualType)==="multiple"||!!((u=n.customCardPreferences)!=null&&u.dataInputCardIds)});if(l)return l.id;if(a){const n=r.find(d=>d.id===a);if(n){const d=n.tabTitle;if(d=="All__Header")return r[0].id;if(d&&d.endsWith("__Header")){const m=d.split("__")[0],x=r.find(p=>p.tabTitle===m);return x?x.id:r[0].id}return a}}return r[0].id}const Te=r=>{if(!r||!("detailTableBackup"in r))return r;const{detailTableBackup:a,...l}=r;return l};async function be(r,a,l,n,d="Opening library visual..."){if(!a||!l)throw new Error("Missing auth token or visual ID");const u=["resource-by-id","visual",l],m=n.getQueryData(u);if(m)return console.log("Using cached visual data for:",l),{data:m,fromCache:!0};console.log("Fetching visual data from network for:",l);const x=f.ue.loading(d,{position:"top-center"});try{const p=await fetch(`${r}/management/v1/visuals/${l}`,{headers:{Authorization:`Bearer ${a}`}});if(!p.ok)throw new Error("Failed to load visual");const C=await p.json();return n.setQueryData(u,C),f.ue.dismiss(x),{data:C,fromCache:!1}}catch(p){throw f.ue.dismiss(x),p}}function Ne(r){if(typeof r=="string")return JSON.parse(r);if(typeof r=="object")return r;throw new Error("Invalid frame object format")}function Le(r,a){var u,m;const l=(r==null?void 0:r.frameObject)??((u=r==null?void 0:r.visual)==null?void 0:u.frameObject);if(!l)return!1;const n=Ne(l);if(!(n!=null&&n.cards)||n.cards.length===0)return!1;const d=(m=n.cards)==null?void 0:m.find(x=>x.id===n.activeCardId);return d?(f.setupEditorWithCard({...a,frame:n,card:d,visualId:(r==null?void 0:r.id)||n.visualId}),!0):!1}function Ae(){const r=s.useEditorStore(n=>{var d;return((d=n.card.customCardPreferences)==null?void 0:d.url)||""}),a=Ve(r);return{getUpdatedFrame:v.useCallback(()=>{var T;f.flushPendingEditorDrafts();const{frame:n,card:d,isDevMode:u,isShowingVisual:m,selectedSchemaName:x,selectedDatamodelId:p,selectedDatabaseName:C,selectedTableName:y,selectedConnectionId:g}=s.useEditorStore.getState(),S=d.sql,D=(T=a==null?void 0:a.getState())==null?void 0:T.settings,k=s.buildSavedEditorCard(d,{isDevMode:u,cardSql:S,isShowingVisual:m,selectedSchemaName:x,selectedDatamodelId:p,selectedDatabaseName:C,selectedTableName:y,selectedConnectionId:g,remoteChartSettings:D,stripConfig:Te}),E=n.cards.map(O=>O.id===d.id?k:O);return{...n,cards:E,activeCardId:Ie(E,n.activeCardId)}},[a])}}function ae(){const{authToken:r,tokenProps:a}=f.useSemaphorContext(),l=f.useQueryClient(),n=f.useAddFrameWithFreshSemanticExecutionPayload(),d=f.useSelectedVisual(),{selectVisual:u}=f.useManagementActions(),{setFrame:m,setCard:x,setIsDevMode:p,initializeModeDrafts:C,setActiveTabCardId:y,updateDataSource:g,setQueryResultColumns:S,setSelectedConnectionId:D,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:T,setSelectedDatamodelId:O,setFilterValues:$,setInlineFilterValuesMap:U,setApplyFilters:R,clearEditorContext:W}=s.useEditorActions(),{setIsDashboardEditing:F,setIsVisualEditing:o,setSelectedFrameId:w,clearSelectedFrameId:Q}=s.useDashboardActions(),q=s.useDashboardStore(A=>A.selectedSheetId),Y=s.useDashboardStore(A=>A.selectedFrameId),H=s.useDashboardStore(A=>A.dashboard),X=s.useDashboardStore(A=>A.filterValues),B=s.useDashboardStore(A=>A.inlineFilterValuesMap),K=f.useVisualById((d==null?void 0:d.id)||"",{enabled:!!(d!=null&&d.id)&&!!(r!=null&&r.accessToken)}),Z=v.useCallback(async A=>{try{u(A),Q(),W();const{data:V,fromCache:P}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,l,"Opening library visual...");if(!Le(V,{setFrame:m,setCard:x,setIsDevMode:p,initializeModeDrafts:C,setActiveTabCardId:y,updateDataSource:g,setQueryResultColumns:S,setSelectedConnectionId:D,setSelectedDatabaseName:k,setSelectedSchemaName:E,setSelectedTableName:T,setSelectedDatamodelId:O,setFilterValues:$,setInlineFilterValuesMap:U,setApplyFilters:R,setIsDashboardEditing:F,setIsVisualEditing:o,dashboard:H,selectedSheetId:q,selectedFrameId:Y,filterValues:X,inlineFilterValuesMap:B}))throw new Error("Failed to setup editor with visual data");return{success:!0,fromCache:P}}catch(V){return console.error("Error editing visual:",V),{success:!1,error:"Failed to load visual for editing"}}},[r==null?void 0:r.accessToken,a.apiServiceUrl,l,u,m,x,F,o,p,C,y,g,S,D,k,E,T,O,$,U,R,W,Q,H,q,Y,X,B]),ne=v.useCallback(async A=>{var P;const V=_=>(f.ue.error(_),{success:!1,error:_});try{if(u(A),!q)return V("No sheet selected. Please select a sheet first.");const{data:_,fromCache:oe}=await be(a.apiServiceUrl,(r==null?void 0:r.accessToken)||"",A.id,l,"Adding visual to dashboard..."),re=(_==null?void 0:_.frameObject)??((P=_==null?void 0:_.visual)==null?void 0:P.frameObject);if(!re)return V("Visual has no frame data");const z=Ne(re);if(!(z!=null&&z.cards)||z.cards.length===0)return V("Visual frame is malformed");const te={...f.cloneLinkedFrameWithSourceMapping(z),visualId:A.id};return await n(q,te,"end"),F(!0),w(te.id),{success:!0,fromCache:oe}}catch(_){return console.error("Error adding visual:",_),V(_ instanceof Error?_.message:"Failed to add visual to dashboard")}},[r==null?void 0:r.accessToken,a.apiServiceUrl,l,u,q,F,w,n]);return{visual:K.data,isLoading:K.isLoading,isError:K.isError,error:K.error,handleEditLibraryVisual:Z,handleAddLibraryVisual:ne,getUpdatedFrame:Ae().getUpdatedFrame,refetch:K.refetch}}function _e(){const r=s.useEditorStore(m=>m.card.dataSource),{setSelectedConnectionId:a,setSelectedDatabaseName:l,setSelectedSchemaName:n,setSelectedTableName:d,setSelectedDatamodelId:u}=s.useEditorActions();v.useEffect(()=>{var D;if(!r)return;const{tableName:m,schemaName:x,databaseName:p,connectionId:C}=f.extractTableMetadata(r),y=(D=r.selectedEntities)==null?void 0:D[0],S=(y==null?void 0:y.type)==="model"&&"id"in y?y.id:"";a(C||""),l(p||""),n(x||""),d(m||""),u(S)},[r,a,l,n,d,u])}function Be(r,a){return{...r,sql:"",python:"",config:void 0,customCfg:"",preferences:{},interactionConfig:void 0,linkedInteractionTargetOverrides:void 0,dynamicCardPreferences:void 0,customCardPreferences:a?r.customCardPreferences:void 0,visualizationMode:"builtin",type:a?r.type:"bar"}}function Ee(){const{setTempQueryData:r}=s.useEditorActions(),a=f.useQueryClient(),l=s.useEditorStore(U=>U.tempQueryData),n=s.useEditorStore(U=>U.card),d=f.useEffectiveEditorCardType(),u=v.useMemo(()=>d!==n.type?{...n,type:d}:n,[n,d]),{queryKey:m}=f.useEditorCardQuery(u),{setCardSql:x,setSqlGen:p,setCardPython:C,setCardCustomCfg:y,setCardPreferences:g,clearQueryConfig:S,setCardConfig:D,setCardType:k,setFrame:E,setCard:T,setActiveTabCardId:O}=s.useEditorActions();function $(){var Q,q,Y,H;const U=a.getQueryData(m);l!=null&&l.queryData||r({queryKey:m,queryData:U}),a.setQueryData(m,null),a.removeQueries({queryKey:m,exact:!0}),x(""),p({}),S(),D(void 0),C(""),y(""),g({});const R=s.useEditorStore.getState().frame,W=s.useEditorStore.getState().card,F=f.findCustomVisualConfigCard(R,W),o=((Q=F==null?void 0:F.customCardPreferences)==null?void 0:Q.visualType)==="multiple"||!!((q=F==null?void 0:F.customCardPreferences)!=null&&q.dataInputCardIds)||(((Y=F==null?void 0:F.customCardPreferences)==null?void 0:Y.minInputs)||0)>1||(((H=F==null?void 0:F.customCardPreferences)==null?void 0:H.maxInputs)||0)>1,w=Be(W,o);E({...R,cards:R.cards.map(X=>X.id===w.id?w:X)}),O(w.id),T(w),o||k("bar")}return $}function qe({type:r,isLinked:a,className:l,showLabel:n=!1,showLocal:d=!1}){const u=s.useDashboardStore(E=>E.selectedFrameId),m=f.useManagementStore(E=>E.selectedVisual),x=s.useEditorStore(E=>E.frame);let p;if(r)p=r;else if(a!==void 0)p=a?"linked":"library";else if(!!!(x!=null&&x.visualId||m!=null&&m.id)&&u)p="local";else if(m&&!u)p="library";else if(x!=null&&x.visualId&&u)p="linked";else if(m!=null&&m.id&&u)p="library";else return null;if(p==="local"&&!d)return null;const C={local:"border-slate-200/70 bg-slate-50/80 text-slate-700 shadow-sm hover:bg-slate-100/80 dark:border-slate-700 dark:bg-slate-900/70 dark:text-slate-200 dark:hover:bg-slate-800/80",linked:"border-purple-200/70 bg-gradient-to-r from-purple-50/50 to-purple-100/30 text-purple-900 shadow-sm hover:from-purple-100/60 hover:to-purple-100/50 hover:shadow-md dark:border-purple-800/50 dark:from-purple-950/40 dark:to-purple-900/30 dark:text-purple-100 dark:hover:from-purple-950/60 dark:hover:to-purple-900/50",library:"border-blue-200/70 bg-gradient-to-r from-blue-50/50 to-blue-100/30 text-blue-900 shadow-sm hover:from-blue-100/60 hover:to-blue-100/50 hover:shadow-md dark:border-blue-800/50 dark:from-blue-950/40 dark:to-blue-900/30 dark:text-blue-100 dark:hover:from-blue-950/60 dark:hover:to-blue-900/50"},y={local:"Local to this dashboard: Changes made here only affect this dashboard copy.",linked:"Linked to library: Changes made here update the library visual and all linked instances.",library:"Library visual: Share and reuse this visual across multiple dashboards."},g={local:"border-slate-200 bg-slate-50 text-slate-900 dark:border-slate-700 dark:bg-slate-900 dark:text-slate-100",linked:"border-purple-200 bg-purple-50 text-purple-900 dark:border-purple-800 dark:bg-purple-950 dark:text-purple-100",library:"border-blue-200 bg-blue-50 text-blue-900 dark:border-blue-800 dark:bg-blue-950 dark:text-blue-100"},S={local:"fill-slate-50 dark:fill-slate-900",linked:"fill-purple-50 dark:fill-purple-950",library:"fill-blue-50 dark:fill-blue-950"},D={local:e.jsx("span",{className:"h-2 w-2 rounded-full bg-current/70"}),linked:e.jsx(ke,{className:"h-3.5 w-3.5"}),library:e.jsx(je,{className:"h-3.5 w-3.5"})},k={local:"Local",linked:"Linked",library:"Library"};return e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{delayDuration:300,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsxs(f.Badge,{variant:"outline",className:s.cn("cursor-help select-none transition-all",C[p],l),children:[D[p],n&&e.jsx("span",{className:"ml-1 text-xs font-medium leading-none",children:k[p]})]})}),e.jsxs(s.TooltipContent,{side:"bottom",className:s.cn("max-w-xs",g[p]),children:[e.jsx(s.TooltipArrow,{className:S[p]}),e.jsx("p",{children:y[p]})]})]})})}function we(r){const{control:a,onChange:l}=r;return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:a.label,placeholder:"Control label",onChange:n=>l(n.target.value)})]})}function Me(r){const{currentStep:a,labels:l}=r;return e.jsx("div",{className:"sticky top-0 z-10 -mx-1 border-b border-border/60 bg-background/95 px-1 pb-2.5 pt-1 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:e.jsx("div",{className:"flex flex-wrap items-center gap-2 sm:gap-2.5",children:l.map((n,d)=>{const u=d+1,m=u===a,x=u<a;return e.jsxs(v.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:s.cn("flex h-5 w-5 items-center justify-center rounded-full border text-[10px] font-medium tabular-nums",m?"border-foreground bg-foreground text-background":x?"border-foreground/30 bg-foreground/10 text-foreground":"border-border/60 bg-background text-muted-foreground"),children:u}),e.jsx("span",{className:s.cn("text-[12px]",m?"font-medium text-foreground":"text-muted-foreground"),children:n})]}),d<l.length-1?e.jsx("span",{className:"h-px w-4 bg-border/60 sm:w-6","aria-hidden":"true"}):null]},n)})})})}function se(r){const{secondary:a,tertiary:l,primary:n}=r;return e.jsxs("div",{className:"sticky bottom-0 z-10 -mx-1 flex justify-end gap-2 border-t bg-background/95 px-1 pb-1 pt-3 backdrop-blur supports-[backdrop-filter]:bg-background/85",children:[a,l,n]})}function Oe(r){const{control:a,scope:l,detail:n}=r;return e.jsxs("div",{className:"flex items-start gap-2.5 rounded-control border border-border/60 bg-muted/30 px-3 py-2.5",children:[e.jsx(f.CircleCheck,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-foreground"}),e.jsxs("div",{className:"min-w-0 space-y-0.5",children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:a.label}),e.jsxs("div",{className:"text-[12px] text-muted-foreground",children:[s.getFriendlyTypeOption(a.type).label," ·"," ",s.getControlOptionPreview(a)," ·"," ",s.getPlacementLabel(l,a.placement)]}),n?e.jsx("div",{className:"text-[12px] text-muted-foreground",children:n}):null]})]})}function ye(r){const{control:a,defaultValue:l,availableFieldChoices:n,availableMetricChoices:d,previewControlDefinitions:u,previewControlValues:m,onControlChange:x,onLabelChange:p,onDefaultValueChange:C,onBack:y,onNext:g,nextDisabled:S}=r;return e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:a,onChange:p}),e.jsx(f.ControlDefinitionOptionsEditor,{control:a,availableFieldChoices:n,availableMetricChoices:d,previewControlDefinitions:u,previewControlValues:m,controlLifecycle:"create",onChange:x}),e.jsx(f.ControlDefaultValueEditor,{control:a,value:l,onChange:C,allowNoDefault:!0,allowCardDefault:!0,hint:"This is the value viewers will see first.",previewControlDefinitions:u,previewControlValues:m}),e.jsx(se,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:y,children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:g,disabled:S,children:"Next"})})]})}const Ue=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]);function ve(r){const{text:a,ariaLabel:l}=r,[n,d]=v.useState(!1);return e.jsxs("button",{type:"button","aria-label":l,onClick:async()=>{try{await navigator.clipboard.writeText(a),d(!0),setTimeout(()=>d(!1),1200)}catch(u){console.error("Failed to copy",u)}},className:"group flex w-full items-center justify-between gap-2 rounded-control bg-muted/40 px-2 py-1 text-left transition-colors hover:bg-muted/60 focus-visible:bg-muted/60 focus-visible:outline-none",children:[e.jsx("code",{className:"min-w-0 truncate font-mono text-[12px] text-foreground",children:a}),e.jsx("span",{className:"shrink-0 text-[11px] text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100",children:n?"Copied":"Click to copy"})]})}function Ce(r){const{control:a,scope:l,createdReference:n,explorerContent:d,sqlDescription:u,summaryDetail:m,onBack:x,onCancel:p,onDone:C}=r,y=Ue.has(a.type),g=n.match(/\[\[param\.(.+?)\]\]/),S=g?`{{ param('${g[1]}') }}`:"";return e.jsxs("div",{className:"space-y-4",children:[e.jsx(Oe,{control:a,scope:l,detail:m}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[13px] font-medium text-foreground",children:"How cards use this control"}),e.jsxs("div",{className:"divide-y divide-border/60 overflow-hidden rounded-control border border-border/60",children:[y?e.jsxs("div",{className:"space-y-1 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Explorer cards"}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:d})]}):null,e.jsxs("div",{className:"space-y-1.5 px-3 py-2.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"SQL cards"}),e.jsx(ve,{text:n,ariaLabel:"Copy SQL control reference"}),S?e.jsx(ve,{text:S,ariaLabel:"Copy Jinja control reference"}):null,e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[u," ",e.jsx("a",{href:"https://docs.semaphor.cloud/docs/concepts/template-expressions",target:"_blank",rel:"noreferrer",className:"underline underline-offset-2 hover:text-foreground",children:"Template expressions docs"}),"."]})]})]})]}),e.jsx(se,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:x,children:"Back"}),tertiary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:p,children:"Cancel"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:C,children:"Done"})})]})}function ze(r){const a=s.createBlankControl(r.scope,r.existingControls,r.reservedIds),l=r.type===a.type?{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}:{...s.applyControlTypeChange({controls:[{...a,label:s.DEFAULT_LABEL_BY_TYPE[r.type]}],controlId:a.id,nextType:r.type}).controls[0],label:s.DEFAULT_LABEL_BY_TYPE[r.type]};return{step:2,control:l,defaultValue:s.getDefaultValueForType(l,void 0)}}function Re({scope:r,controls:a,reservedControlIds:l,defaultValues:n,onChange:d,emptyMessage:u,initialCreateFlow:m=!1,usageByControlId:x,availableFieldChoices:p,availableMetricChoices:C,structuralParticipants:y,structuralParticipantIdsByControlId:g,card:S,allowedControlTypes:D,onCreateFlowActiveChange:k,onCreateFlowComplete:E}){const T=v.useMemo(()=>new Set(l||[]),[l]),O=s.getPlacementOptionsForScope(r),$=s.getDefaultPlacement(r),[U,R]=v.useState(null),[W,F]=v.useState(null),[o,w]=v.useState(()=>m?{step:1,control:s.createBlankControl(r,a,Array.from(T))}:null),Q=v.useRef({}),q=v.useRef(void 0),Y=v.useRef(m),H=v.useMemo(()=>{const t=s.getFriendlyControlTypeOptions({scope:r,card:S});if(!D)return t;const c=new Set(D);return t.filter(i=>c.has(i.value))},[D,S,r]),X=v.useCallback(t=>{const c=s.getFriendlyControlTypeOptions({scope:r,card:S,includeType:D?void 0:t});if(!D)return c;const i=new Set(D);return c.filter(h=>i.has(h.value))},[D,S,r]),B=v.useCallback(t=>r==="dashboard"&&(t==="field_selector"||t==="metric_selector"),[r]),K=v.useMemo(()=>o?s.getEligibleParticipantsForStructuralControl(y||[],o.control.type):[],[o,y]),Z=v.useMemo(()=>{if(!o)return{fields:p||[],metrics:C||[]};if(!B(o.control.type))return{fields:p||[],metrics:C||[]};const t=o.selectedCardIds||[],c=s.getCompatibleStructuralChoiceCatalog({controlType:o.control.type,participants:y||[],selectedCardIds:t});return{fields:o.control.type==="field_selector"?c.choices.map(i=>({option:i,target:c.fieldTargetMap[i.value]})):[],metrics:o.control.type==="metric_selector"?c.choices.map(i=>({option:i,target:c.metricTargetMap[i.value]})):[]}},[p,C,o,B,y]);v.useEffect(()=>{k==null||k(!!o)},[o,k]),v.useEffect(()=>{const t=m&&!Y.current;Y.current=m,t&&(w({step:1,control:s.createBlankControl(r,a,Array.from(T))}),F(null),R(null))},[a,m,T,r]);const ne=t=>{if(!B(t.type))return{fields:p||[],metrics:C||[]};const c=(g==null?void 0:g[t.id])||[];if(c.length===0)return{fields:p||[],metrics:C||[]};const i=s.getCompatibleStructuralChoiceCatalog({controlType:t.type,participants:y||[],selectedCardIds:c});return{fields:t.type==="field_selector"?i.choices.map(h=>({option:h,target:i.fieldTargetMap[h.value]})):[],metrics:t.type==="metric_selector"?i.choices.map(h=>({option:h,target:i.metricTargetMap[h.value]})):[]}},A=t=>{if(!B(t.control.type))return{nextControl:t.control,cardBindingsById:void 0};const c=(g==null?void 0:g[t.control.id])||[],i=s.getCompatibleStructuralChoiceCatalog({controlType:t.control.type,participants:y||[],selectedCardIds:t.nextSelectedCardIds}),h=s.reconcileStructuralControlChoices({control:t.control,choices:i.choices}),j=Object.fromEntries(c.filter(N=>!t.nextSelectedCardIds.includes(N)).map(N=>[N,void 0]));return t.nextSelectedCardIds.length>0&&h.source.kind==="manual"&&h.source.options.length>0&&Object.assign(j,s.buildStructuralControlBindingsForParticipants({control:h,participants:y||[],selectedCardIds:t.nextSelectedCardIds})),{nextControl:h,cardBindingsById:j}},V=v.useCallback((t,c=n,i={type:"update"})=>{const h=t.map(j=>(s.resolveAuthoringControlDefaultValue({control:j,defaultValues:c}),s.syncSqlQueryControlExecutionRequirement(j)));d(h,c,i)},[n,d]),P=(t,c)=>{const i=a.find(L=>L.id===t);let h=a.map(L=>L.id!==t?L:c(L));const j=h.find(L=>L.id===t);let N,b;if(j&&r==="dashboard"&&(j.type==="field_selector"||j.type==="metric_selector")){const L=(g==null?void 0:g[j.id])||[],ee=A({control:j,nextSelectedCardIds:L});h=h.map(G=>G.id===t?ee.nextControl:G),N=ee.cardBindingsById,b=[j.id]}else if(i&&r==="dashboard"&&(i.type==="field_selector"||i.type==="metric_selector")){const L=(g==null?void 0:g[i.id])||[];N=Object.fromEntries(L.map(ee=>[ee,void 0])),b=[i.id]}const I=h.find(L=>L.id===t);let M=n;if(i&&I){const L=s.resolveAuthoringControlDefaultValue({control:i,defaultValues:n});i.source.kind==="manual"&&I.source.kind==="sql_query"&&(Q.current[t]=L);const ee=L===void 0&&i.source.kind==="sql_query"&&I.source.kind==="manual"?Q.current[t]:L,G=s.getNextEditedControlDefaultValue({previousControl:i,nextControl:I,currentDefaultValue:ee});I.source.kind==="manual"&&(Q.current[t]=G),n&&(M={...n},G===void 0?delete M[t]:M[t]=G),h=h.map(xe=>xe.id===t?{...I,defaultValue:G}:xe)}V(h,M,{type:"update",cardBindingsById:N,affectedBindingControlIds:b})},_=(t,c)=>{if(!c.trim())return;const i=f.normalizeDashboardInputVariableName(c);if(i===t||T.has(i)||a.some(N=>N.id===i&&N.id!==t))return;const h=a.map(N=>N.id===t?{...N,id:i}:N);if(!n){V(h,void 0,{type:"rename",oldId:t,newId:i});return}const j={...n};Object.prototype.hasOwnProperty.call(j,t)&&(j[i]=j[t],delete j[t]),V(h,j,{type:"rename",oldId:t,newId:i})},oe=t=>{const c=a.filter(h=>h.id!==t);if(!n){V(c,void 0,{type:"remove",controlId:t});return}const i={...n};delete i[t],V(c,i,{type:"remove",controlId:t})},re=v.useCallback(()=>{q.current=void 0,w({step:1,control:s.createBlankControl(r,a,Array.from(T))}),F(null),R(null)},[a,T,r]),z=t=>{w(c=>c&&(()=>{const i=t(c.control);c.control.source.kind==="manual"&&i.source.kind==="sql_query"&&(q.current=c.defaultValue);const h=c.defaultValue===void 0&&c.control.source.kind==="sql_query"&&i.source.kind==="manual"?q.current:c.defaultValue,j=s.getNextEditedControlDefaultValue({previousControl:c.control,nextControl:i,currentDefaultValue:h});return i.source.kind==="manual"&&(q.current=j),{...c,control:i,defaultValue:j}})())},te=t=>{w(c=>c&&(c.control.source.kind==="manual"&&(q.current=t),{...c,defaultValue:t}))},le=(()=>{if(!o)return!1;if(o.step===2&&B(o.control.type))return(o.selectedCardIds||[]).length>0;if(o.step!==2&&o.step!==3||!o.control.label.trim())return!1;const c=o.control.source.kind==="sql_query"?o.control:s.ensureManualSource(o.control);if(c.source.kind==="manual"&&(s.needsManualOptions(c)&&c.source.options.length===0||c.source.options.some(h=>h.label.trim().length===0||h.value.trim().length===0)))return!1;if(c.source.kind==="sql_query"){const{connectionId:i,sql:h,valueColumn:j}=c.source;return i.trim().length>0&&h.trim().length>0&&j.trim().length>0}return s.hasConcreteDefaultValue(s.getDefaultValueForType(c,o.defaultValue))})(),pe=()=>{var N;if(!o)return;const t=s.ensureManualSource(o.control),c=s.deriveUniqueControlId({label:t.label,fallbackId:t.id,existingControls:a,reservedIds:Array.from(T)}),i={...t,id:c},h=r==="dashboard"&&(i.type==="field_selector"||i.type==="metric_selector")&&((N=o.selectedCardIds)!=null&&N.length)?s.buildStructuralControlBindingsForParticipants({control:i,participants:y||[],selectedCardIds:o.selectedCardIds}):void 0,j=s.getDefaultValueForType(i,o.defaultValue);w({step:r==="dashboard"&&(i.type==="field_selector"||i.type==="metric_selector")?4:3,control:i,defaultValue:j,createdControlId:c,selectedCardIds:o.selectedCardIds,cardBindingsById:h})},ie=v.useCallback(()=>{w(null)},[]),me=v.useCallback(()=>{if(!(o!=null&&o.createdControlId)){w(null);return}const t=o.control,c=o.createdControlId,i=s.getDefaultValueForType(t,o.defaultValue);if(n){const h={...n};i===void 0?delete h[c]:h[c]=i,V([...a,{...t,defaultValue:i}],h,{type:"add",cardBindingsById:o.cardBindingsById})}else V([...a,{...t,defaultValue:i}],void 0,{type:"add",cardBindingsById:o.cardBindingsById});F(c),w(null),E==null||E()},[a,o,n,V,E]),De=o?B(o.control.type)?["Choose type","Select cards","Configure","Finish"]:["Choose type","Configure","Finish"]:[],fe=o!=null&&o.createdControlId?`[[param.${o.createdControlId}]]`:o?`[[param.${s.slugifyControlValue(o.control.label)||o.control.id}]]`:"",de=s.buildAuthoringPreviewControlValues({controls:a,defaultValues:n}),ce=o?[...a,o.control]:a,he=o?s.buildAuthoringPreviewControlValues({controls:ce,defaultValues:n,overrides:[{controlId:o.control.id,value:o.defaultValue}]}):de;return e.jsxs("div",{className:"space-y-4",children:[o?e.jsxs("div",{className:"space-y-4 pb-1",children:[e.jsx(Me,{currentStep:o.step,labels:De}),o.step===1&&(()=>{const t=new Set(["grain_selector","aggregation_selector","field_selector","metric_selector"]),c=new Set(["date","text"]),i=H.filter(N=>!t.has(N.value)&&!c.has(N.value)),h=H.filter(N=>t.has(N.value)),j=N=>e.jsxs("button",{type:"button",className:"rounded-control border border-border/60 bg-background px-3 py-2.5 text-left transition-colors hover:bg-muted/40 focus-visible:bg-muted/40 focus-visible:outline-none",onClick:()=>w(ze({scope:r,existingControls:a,reservedIds:Array.from(T),type:N.value})),children:[e.jsx("div",{className:"text-[13px] font-medium text-foreground",children:N.label}),e.jsx("p",{className:"mt-0.5 text-[12px] text-muted-foreground",children:N.description})]},N.value);return e.jsxs("div",{className:"space-y-4",children:[r==="card"&&(S==null?void 0:S.sql)==null?e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Explorer cards support displayed metric, group by field, aggregation, and time grain controls here."}):null,i.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Input controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:i.map(j)})]}),h.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Data-driven controls"}),e.jsx("div",{className:"grid gap-1.5 sm:grid-cols-2",children:h.map(j)})]}),e.jsx(se,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:ie,children:"Back to controls"})})]})})(),o.step===2&&B(o.control.type)&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(we,{control:o.control,onChange:t=>z(c=>({...c,label:t}))}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Choose which cards should respond to this shared control."})]}),K.length===0?e.jsx("div",{className:"rounded-control border border-border/60 bg-muted/30 px-3 py-2.5 text-[12px] text-muted-foreground",children:"No eligible cards are available yet. Add compatible metrics or group-by fields to cards first."}):e.jsx("div",{className:"space-y-1 rounded-control border border-border/60 bg-background p-2",children:K.map(t=>{const c=(o.selectedCardIds||[]).includes(t.cardId);return e.jsxs("label",{className:"flex items-start gap-2 rounded-control px-1.5 py-1 text-[13px] hover:bg-muted/40",children:[e.jsx(f.Checkbox,{checked:c,onCheckedChange:i=>w(h=>h&&{...h,selectedCardIds:i===!0?[...h.selectedCardIds||[],t.cardId]:(h.selectedCardIds||[]).filter(j=>j!==t.cardId)})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:t.title}),e.jsx("div",{className:"text-[12px] text-muted-foreground",children:o.control.type==="field_selector"?`${t.fieldChoices.length} compatible group-by fields`:`${t.metricChoices.length} compatible metrics`})]})]},t.cardId)})}),e.jsx(se,{secondary:e.jsx(s.Button,{type:"button",variant:"outline",size:"xs",onClick:()=>w(t=>t&&{...t,step:1,selectedCardIds:[]}),children:"Back"}),primary:e.jsx(s.Button,{type:"button",size:"xs",onClick:()=>w(t=>t&&{...t,step:3}),disabled:!le,children:"Next"})})]}),o.step===2&&!B(o.control.type)&&e.jsx(ye,{control:o.control,defaultValue:o.defaultValue,availableFieldChoices:Z.fields,availableMetricChoices:Z.metrics,previewControlDefinitions:ce,previewControlValues:he,onControlChange:t=>z(()=>t),onLabelChange:t=>z(c=>({...c,label:t})),onDefaultValueChange:te,onBack:()=>w(t=>t&&{...t,step:1}),onNext:pe,nextDisabled:!le}),o.step===3&&B(o.control.type)&&e.jsx(ye,{control:o.control,defaultValue:o.defaultValue,availableFieldChoices:Z.fields,availableMetricChoices:Z.metrics,previewControlDefinitions:ce,previewControlValues:he,onControlChange:t=>z(()=>t),onLabelChange:t=>z(c=>({...c,label:t})),onDefaultValueChange:te,onBack:()=>w(t=>t&&{...t,step:2}),onNext:pe,nextDisabled:!le}),o.step===3&&!B(o.control.type)&&e.jsx(Ce,{control:o.control,scope:r,createdReference:fe,explorerContent:e.jsxs(e.Fragment,{children:["Open the card and use"," ",e.jsx("span",{className:"font-medium text-foreground",children:"Settings → Controls"})," ","to choose what this control changes."]}),sqlDescription:"Reference this control directly in the SQL editor.",onBack:()=>w(t=>t&&{...t,step:2}),onCancel:ie,onDone:me}),o.step===4&&B(o.control.type)&&e.jsx(Ce,{control:o.control,scope:r,createdReference:fe,summaryDetail:e.jsxs(e.Fragment,{children:["Used by ",(o.selectedCardIds||[]).length," selected card",(o.selectedCardIds||[]).length===1?"":"s"]}),explorerContent:e.jsx(e.Fragment,{children:"Selected cards have been set up to respond to this control automatically."}),sqlDescription:"SQL cards can still reference this control directly in the SQL editor.",onBack:()=>w(t=>t&&{...t,step:3}),onCancel:ie,onDone:me})]}):null,!o&&a.length===0?e.jsx("div",{className:"rounded-md border border-dashed p-3 text-sm text-muted-foreground",children:u}):null,!o&&a.map(t=>{const c=ne(t),i=x==null?void 0:x[t.id],h=s.resolveAuthoringControlDefaultValue({control:t,defaultValues:n}),j=W===t.id,N="inline-flex shrink-0 items-center rounded-[4px] border border-border/60 bg-muted/40 px-1.5 py-0.5 text-[11px] font-medium text-muted-foreground";return e.jsxs("div",{className:"rounded-control 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",className:"flex min-w-0 flex-1 items-start gap-2 rounded-control text-left focus:outline-none focus-visible:bg-muted/40",onClick:()=>F(b=>b===t.id?null:t.id),children:[j?e.jsx(J.ChevronDown,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}):e.jsx(ge.ChevronRight,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-muted-foreground"}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx("span",{className:"truncate text-[13px] font-medium text-foreground",children:t.label||"Untitled control"}),e.jsx("span",{className:N,children:s.getFriendlyTypeOption(t.type).label}),e.jsx("span",{className:N,children:s.getPlacementLabel(r,t.placement)})]}),e.jsxs("div",{className:"mt-0.5 text-[12px] text-muted-foreground",children:[s.getControlOptionPreview(t),i!=null&&i.status?` · ${i.status}`:""]})]})]}),e.jsx(s.Button,{type:"button",size:"xs",variant:"ghost",className:"h-7 w-7 shrink-0 p-0 text-muted-foreground",onClick:()=>oe(t.id),"aria-label":`Remove ${t.label}`,children:e.jsx(f.Trash2,{className:"h-3.5 w-3.5"})})]}),j&&e.jsxs("div",{className:"space-y-4 border-t border-border/60 px-3 py-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Label"}),e.jsx(s.Input,{size:"xs",value:t.label,placeholder:"Control label",onChange:b=>P(t.id,I=>({...I,label:b.target.value}))})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Type"}),e.jsxs(s.Select,{value:t.type,onValueChange:b=>{const I=s.applyControlTypeChange({controls:a,controlId:t.id,nextType:b,defaultValues:n});V(I.controls,I.defaultValues)},children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:X(t.type).map(b=>e.jsx(s.SelectItem,{value:b.value,children:b.label},b.value))})]})]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Show in"}),e.jsxs(s.Select,{value:t.placement||$,onValueChange:b=>P(t.id,I=>({...I,placement:b})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:O.map(b=>e.jsx(s.SelectItem,{value:b.value,children:b.label},b.value))})]})]})]}),B(t.type)?e.jsx(f.StructuralParticipantSelector,{type:t.type,participants:s.getEligibleParticipantsForStructuralControl(y||[],t.type).map(b=>({cardId:b.cardId,title:b.title,choiceCount:t.type==="field_selector"?b.fieldChoices.length:b.metricChoices.length})),selectedCardIds:(g==null?void 0:g[t.id])||[],onChange:b=>{const I=A({control:t,nextSelectedCardIds:b}),M=a.map(L=>L.id===t.id?I.nextControl:L);V(M,n,{type:"update",cardBindingsById:I.cardBindingsById})}}):null,e.jsx(f.ControlDefinitionOptionsEditor,{control:t,availableFieldChoices:c.fields,availableMetricChoices:c.metrics,previewControlDefinitions:a,previewControlValues:de,controlLifecycle:"edit",onChange:b=>P(t.id,()=>b)}),t.initialValueStrategy==="saved_default"&&e.jsx(f.ControlDefaultValueEditor,{control:t,value:h,allowNoDefault:!0,allowCardDefault:!0,previewControlDefinitions:a,previewControlValues:de,onChange:b=>{const I=a.map(M=>M.id===t.id?{...M,defaultValue:b}:M);if(t.source.kind==="manual"&&(Q.current[t.id]=b),n){const M={...n};b===void 0?delete M[t.id]:M[t.id]=b,V(I,M);return}V(I,void 0)}}),e.jsxs(f.Collapsible,{open:U===t.id,onOpenChange:b=>R(b?t.id:null),children:[e.jsx(f.CollapsibleTrigger,{asChild:!0,children:e.jsxs(s.Button,{type:"button",variant:"ghost",size:"xs",className:"-ml-2 gap-1 text-muted-foreground hover:text-foreground",children:[U===t.id?e.jsx(J.ChevronDown,{className:"h-3.5 w-3.5"}):e.jsx(ge.ChevronRight,{className:"h-3.5 w-3.5"}),"Advanced"]})}),e.jsxs(f.CollapsibleContent,{className:"space-y-3 pt-2",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Variable name"}),e.jsx(f.ControlIdInput,{controlId:t.id,onCommit:b=>_(t.id,b)},t.id)]}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(s.Label,{className:"text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground",children:"Initial value"}),e.jsxs(s.Select,{value:t.initialValueStrategy,onValueChange:b=>P(t.id,I=>({...I,initialValueStrategy:b})),children:[e.jsx(s.SelectTrigger,{size:"xs",children:e.jsx(s.SelectValue,{})}),e.jsx(s.SelectContent,{children:s.INITIAL_VALUE_STRATEGY_OPTIONS.map(b=>e.jsx(s.SelectItem,{value:b.value,children:b.label},b.value))})]})]})]}),e.jsx(f.ControlVisibilitySettings,{control:t,onChange:b=>P(t.id,()=>b)})]})]})]})]},t.id)}),!o&&e.jsxs(s.Button,{type:"button",variant:"outline",size:"xs",onClick:re,children:[e.jsx(f.Plus,{className:"h-3.5 w-3.5"}),"Add control"]})]})}function Qe(r){const{open:a,onOpenChange:l,initialCreateFlowActive:n=!1,dismissMode:d="passive"}=r,u=a!==void 0,[m,x]=v.useState(!1),[p,C]=v.useState(n),y=u?a:m,g=v.useCallback(k=>{!k&&p&&d==="passive"||(u||x(k),k||C(!1),l==null||l(k))},[u,p,d,l]),S=v.useCallback(()=>{u||x(!1),C(!1),l==null||l(!1)},[u,l]);v.useEffect(()=>{y||C(!1)},[y]);const D=v.useCallback(k=>{p&&k.preventDefault()},[p]);return{forceClose:S,handleOpenChange:g,isCreateFlowActive:p,preventPassiveDismissDuringCreate:D,resolvedOpen:y,setIsCreateFlowActive:C}}function ue(r){const a=s.getDynamicFrameSaveIssue(r);return a?(f.ue.error(a),!1):!0}function Pe({className:r,variant:a="outline"}){const l=s.useEditorStore(u=>u.onSave),{getUpdatedFrame:n}=ae();function d(){const u=n();ue(u)&&(l==null||l(u))}return e.jsxs(s.Button,{onClick:d,className:r,size:"xs",variant:a,children:[e.jsx(s.Check,{className:"h-3.5 w-3.5"}),"Accept"]})}function $e({className:r,variant:a="default"}){const l=f.useQueryClient(),[n,d]=v.useState(!1),{setIsVisualEditing:u}=s.useDashboardActions(),{getUpdatedFrame:m}=ae(),x=f.useSelectedVisual(),p=s.useEditorStore(g=>g.frame),C=f.useUpdateVisualMutation(),y=()=>{const g=m();if(!ue(g))return;const S=(p==null?void 0:p.visualId)||(x==null?void 0:x.id);if(!S){f.ue.error("No visual to save");return}d(!0),C.mutate({visualId:S,data:{frameObject:g}},{onSuccess:()=>{d(!1),f.ue.success("Visual updated successfully"),l.invalidateQueries({queryKey:["resource-by-id","visual",S],exact:!0})},onError:()=>{d(!1),f.ue.error("Failed to update visual")}})};return e.jsx(s.Button,{onClick:y,className:r,size:"xs",variant:a,children:n?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving"]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save to Library"]})})}function Ye({className:r}){const a=f.useQueryClient(),[l,n]=v.useState(!1),d=f.useSelectedVisual(),u=s.useEditorStore(k=>k.frame),m=s.useDashboardStore(k=>k.selectedSheetId),x=s.useDashboardStore(k=>k.dashboard),{updateFrame:p,setIsVisualEditing:C}=s.useDashboardActions(),{getUpdatedFrame:y}=ae(),g=f.useUpdateVisualMutation(),S=f.useResolveExistingFrameSemanticExecutionPayload(),D=async()=>{if(!m){f.ue.error("No sheet selected");return}const k=(u==null?void 0:u.visualId)||(d==null?void 0:d.id);if(!k){f.ue.error("No visual to update");return}n(!0);try{const E=y();if(!ue(E)){n(!1);return}const T={...E,visualId:k},O=s.findDashboardFrameById(x,T.id),$=await S(T,{previousFrame:O});await g.mutateAsync({visualId:k,data:{frameObject:E}}),p(m,T,{semanticExecutionPayload:$}),a.invalidateQueries({queryKey:["visuals"]}),a.invalidateQueries({queryKey:["visual",k]}),f.ue.success("Saved to library and applied locally"),setTimeout(()=>{C(!1)},300)}catch(E){console.error("Failed to save and apply:",E),f.ue.error(E instanceof Error?E.message:"Failed to save and apply changes")}finally{n(!1)}};return e.jsx(s.Button,{onClick:D,className:r,size:"xs",variant:"default",disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Se.Save,{className:"h-3.5 w-3.5"}),"Save & Apply"]})})}function He({className:r}){const{setTempQueryData:a,setSqlGen:l}=s.useEditorActions(),n=f.useQueryClient(),d=s.useEditorStore(g=>g.tempQueryData),u=s.useEditorStore(g=>g.onClose),m=s.useEditorStore(g=>g.card),x=f.useEffectiveEditorCardType(),p=v.useMemo(()=>x!==m.type?{...m,type:x}:m,[m,x]),{queryKey:C}=f.useEditorCardQuery(p);function y(){if(d){const{queryKey:g,queryData:S}=d;g&&S&&n.setQueryData(g,S)}l({}),u==null||u()}return e.jsxs(s.Button,{onClick:y,className:r,size:"xs",variant:"outline",children:[e.jsx(J.X,{className:"h-3.5 w-3.5"}),"Close"]})}function Ke({label:r="Clear",variant:a="secondary",className:l}={}){const n=Ee();return e.jsxs(s.Button,{onClick:n,className:l,size:"xs",variant:a,children:[e.jsx(J.X,{className:"h-3.5 w-3.5"}),r]})}exports.ControlDefinitionListEditor=Re;exports.EditorAcceptButton=Pe;exports.EditorCancelButton=He;exports.EditorClearButton=Ke;exports.FilterX=Fe;exports.Library=je;exports.Link2=ke;exports.VisualBadge=qe;exports.VisualSaveAndApplyButton=Ye;exports.VisualSaveButton=$e;exports.useCreateFlowOverlayState=Qe;exports.useEditorClearAction=Ee;exports.useSyncLegacyEditorState=_e;exports.useVisualUtils=ae;
|
package/dist/chunks/{report-preferences-dialog-Ju8DjgyW.js → report-preferences-dialog-CCvFqH4Q.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),l=require("react"),n=require("./dashboard-C-eTAAKs.js"),o=require("./code-editor-M7HTUhdF.js"),V=require("../report-runtime-context/index.cjs");require("./index-jSrCwPQz.js");require("./analyze-result-contract-BswhsmWT.js");const D=require("../value-format-preferences/index.cjs");function M(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(C=>C.actions.applyResolvedCalendarPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,[v,b]=l.useState(!1),[g,j]=l.useState(!1),[y,k]=l.useState(!1),[T,f]=l.useState(null),[N,P]=l.useState(null),h=l.useRef(c);h.current=c,l.useEffect(()=>{P(null),f(null),b(!1),j(!1),k(!1)},[c]);const w=l.useCallback(async C=>{const r=V.parseCalendarPreferencesResponse(await C.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),S=l.useCallback(async()=>{if(!d||!c||!m)return;const C=c;b(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const t=await w(r);h.current===C&&P(t)}catch(r){h.current===C&&f(r instanceof Error?r.message:"Unknown error")}finally{h.current===C&&b(!1)}},[c,m,d,w]);l.useEffect(()=>{d&&S()},[d,S]);const E=l.useCallback(async C=>{if(!c||!m)return f("Not authenticated"),!1;const r=c;j(!0),f(null);try{const t=await fetch(`${m}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(C)});if(!t.ok){const z=await t.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}const x=await w(t);return h.current!==r?!1:(P(x),p(x.resolved,x.sources),!0)}catch(t){return h.current===r&&f(t instanceof Error?t.message:"Unknown error"),!1}finally{h.current===r&&j(!1)}},[c,m,p,w]),A=l.useCallback(async()=>{if(!c||!m)return f("Not authenticated"),!1;const C=c;k(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const t=await w(r);return h.current!==C?!1:(P(t),p(t.resolved,t.sources),!0)}catch(r){return h.current===C&&f(r instanceof Error?r.message:"Unknown error"),!1}finally{h.current===C&&k(!1)}},[c,m,p,w]);return{preferences:N,isLoading:v,isSaving:g,isClearing:y,error:T,updatePreferences:E,clearPreferences:A,refetch:S}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],I=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function _(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return F.map(s=>s.value)}function G(s){if(!s)return"default";if(s.tz!==s.weekStart)return"inherited";switch(s.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(s){const i=F.find(a=>a.value===s);return i?i.label:s}function W(s){const i=I.find(a=>a.value===s);return i?i.label:String(s)}function H({active:s,onClose:i}){const{preferences:a,isLoading:p,isSaving:d,isClearing:c,updatePreferences:m,clearPreferences:v}=M({enabled:s}),b=n.useCalendarContext(),g=(a==null?void 0:a.resolved.tz)||(b==null?void 0:b.tz)||"UTC",j=(a==null?void 0:a.resolved.weekStart)??(b==null?void 0:b.weekStart)??1,[y,k]=l.useState((a==null?void 0:a.stored)===null),[T,f]=l.useState(!1),[N,P]=l.useState(g),[h,w]=l.useState(j),[S,E]=l.useState(!1),A=l.useMemo(()=>_(),[]),C=l.useMemo(()=>A.filter(u=>!F.some($=>$.value===u)),[A]),r=l.useMemo(()=>U(N),[N]),t=a!=null&&a.inherited?U(a.inherited.tz):"UTC",x=a!=null&&a.inherited?W(a.inherited.weekStart):"Monday",z=G(a==null?void 0:a.inheritedSources);l.useEffect(()=>{if(!s){f(!1);return}T||(a&&k(a.stored===null),P(g),w(j))},[s,T,a,g,j]);const B=async()=>{if(p){n.ue.error("Preferences are still loading. Please try again.");return}y?await v()?(n.ue.success("Now using default settings."),i()):n.ue.error("Failed to save preferences. Please try again."):await m({tz:N,weekStart:h})?(n.ue.success("Preferences saved."),i()):n.ue.error("Failed to save preferences. Please try again.")},q=()=>{i()},L=d||c,O=L||p;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(n.RadioGroup,{value:y?"defaults":"custom",onValueChange:u=>{f(!0),k(u==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",y&&"bg-muted/50"),onClick:()=>{f(!0),k(!0)},children:[e.jsx(n.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",z," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[t,", week starts ",x]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!y&&"bg-muted/50"),onClick:()=>{f(!0),k(!1)},children:[e.jsx(n.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:o.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",y&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Timezone"}),e.jsxs(o.Popover,{open:S,onOpenChange:E,modal:!0,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":S,className:"w-full justify-between text-[12px] font-normal",disabled:y,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(n.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(o.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(n.Command,{className:"overflow-visible",children:[e.jsx(n.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(n.CommandList,{children:[e.jsx(n.CommandEmpty,{children:"No timezone found."}),e.jsx(n.CommandGroup,{heading:"Common",children:F.map(u=>e.jsxs(n.CommandItem,{value:`${u.value} ${u.label}`,onSelect:()=>{f(!0),P(u.value),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:u.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:u.value})]},u.value))}),e.jsx(n.CommandSeparator,{}),e.jsx(n.CommandGroup,{heading:"All timezones",children:C.map(u=>e.jsxs(n.CommandItem,{value:u,onSelect:()=>{f(!0),P(u),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u?"opacity-100":"opacity-0")}),u]},u))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Week starts on"}),e.jsx(n.RadioGroup,{value:String(h),onValueChange:u=>{f(!0),w(Number(u))},className:"flex gap-4",disabled:y,children:I.map(u=>e.jsxs("label",{htmlFor:`week-start-${u.value}`,className:o.cn("flex cursor-pointer items-center gap-2 text-[13px]",y&&"cursor-not-allowed"),children:[e.jsx(n.RadioGroupItem,{value:String(u.value),id:`week-start-${u.value}`,disabled:y}),u.label]},u.value))})]})]})]}),e.jsxs(n.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:q,disabled:L,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:B,disabled:O,children:L?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function K(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,v=l.useRef(c);v.current=c;const[b,g]=l.useState(null),[j,y]=l.useState(!1),[k,T]=l.useState(!1),[f,N]=l.useState(!1),[P,h]=l.useState(null);l.useEffect(()=>{g(null),h(null),y(!1),T(!1),N(!1)},[c]);const w=l.useCallback(async r=>{const t=D.parseValueFormatPreferencesResponse(await r.json());if(!t.ok)throw new Error("Value format preferences response is invalid");return t.value},[]),S=l.useCallback(async(r,t)=>{if(!c||!m)throw new Error("Not authenticated");const x=await fetch(`${m}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${c}`,...t?{"Content-Type":"application/json"}:{}},body:t?JSON.stringify(t):void 0});if(!x.ok){const z=await x.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}return w(x)},[c,m,w]),E=l.useCallback(async()=>{if(!d||!c||!m)return;const r=c;y(!0),h(null);try{const t=await S("GET");v.current===r&&g(t)}catch(t){v.current===r&&h(t instanceof Error?t.message:"Unknown error")}finally{v.current===r&&y(!1)}},[c,m,d,S]);l.useEffect(()=>{d&&E()},[d,E]);const A=l.useCallback(async r=>{const t=c;T(!0),h(null);try{const x=await S("PATCH",r);return v.current!==t?!1:(g(x),p(x.resolved,x.sources),!0)}catch(x){return v.current===t&&h(x instanceof Error?x.message:"Unknown error"),!1}finally{v.current===t&&T(!1)}},[c,p,S]),C=l.useCallback(async()=>{const r=c;N(!0),h(null);try{const t=await S("DELETE");return v.current!==r?!1:(g(t),p(t.resolved,t.sources),!0)}catch(t){return v.current===r&&h(t instanceof Error?t.message:"Unknown error"),!1}finally{v.current===r&&N(!1)}},[c,p,S]);return{preferences:b,isLoading:j,isSaving:k,isClearing:f,error:P,updatePreferences:A,clearPreferences:C,refetch:E}}function J({active:s,onClose:i}){var v,b;const{preferences:a,isLoading:p,isSaving:d,updatePreferences:c}=K({enabled:s});if(!s)return null;if(!a)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:p?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const m=[((v=a.stored)==null?void 0:v.locale)??"",((b=a.stored)==null?void 0:b.defaultCurrency)??""].join(":");return e.jsx(Z,{preferences:a,isSaving:d,updatePreferences:c,onClose:i},m)}function Z({preferences:s,isSaving:i,updatePreferences:a,onClose:p}){const[d,c]=l.useState(()=>{var g,j;return{locale:(g=s.stored)==null?void 0:g.locale,defaultCurrency:(j=s.stored)==null?void 0:j.defaultCurrency}}),m=(d.locale===void 0||D.canonicalizeSupportedLocale(d.locale)!==void 0)&&(d.defaultCurrency===void 0||D.canonicalizeSupportedCurrencyCode(d.defaultCurrency)!==void 0),v=async()=>{var T,f;const g={},j=[];d.locale!==void 0?g.locale=d.locale:((T=s.stored)==null?void 0:T.locale)!==void 0&&j.push("locale"),d.defaultCurrency!==void 0?g.defaultCurrency=d.defaultCurrency:((f=s.stored)==null?void 0:f.defaultCurrency)!==void 0&&j.push("defaultCurrency");const y={...Object.keys(g).length>0?{set:g}:{},...j.length>0?{clear:j}:{}};(Object.keys(y).length===0?!0:await a(y))?(n.ue.success("Display format preferences saved."),p()):n.ue.error("Failed to save preferences. Please try again.")},b=async()=>{await a({clear:["locale","defaultCurrency"]})?(n.ue.success("Locale and currency preferences reset."),p()):n.ue.error("Failed to reset locale and currency preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(n.DisplayFormatPreferencesFields,{value:d,inherited:s.inherited,inheritedSources:s.inheritedSources,onChange:c,disabled:i})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:b,disabled:i||s.stored===null,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:p,disabled:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:v,disabled:i||!m,children:i?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function Y({open:s,onOpenChange:i}){const[a,p]=l.useState("display"),d=()=>i(!1);return e.jsx(n.Dialog,{open:s,onOpenChange:i,children:e.jsxs(n.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(n.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(o.Tabs,{value:a,onValueChange:p,children:[e.jsxs(o.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(o.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(o.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(o.TabsContent,{value:"display",children:e.jsx(J,{active:s&&a==="display",onClose:d})}),e.jsx(o.TabsContent,{value:"calendar",children:e.jsx(H,{active:s&&a==="calendar",onClose:d})})]})]})})}exports.ReportPreferencesDialog=Y;
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),l=require("react"),n=require("./dashboard-cB3xmTNn.js"),o=require("./code-editor-M7HTUhdF.js"),V=require("../report-runtime-context/index.cjs");require("./index-jSrCwPQz.js");require("./analyze-result-contract-BswhsmWT.js");const D=require("../value-format-preferences/index.cjs");function M(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(C=>C.actions.applyResolvedCalendarPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,[v,b]=l.useState(!1),[g,j]=l.useState(!1),[y,k]=l.useState(!1),[T,f]=l.useState(null),[N,P]=l.useState(null),h=l.useRef(c);h.current=c,l.useEffect(()=>{P(null),f(null),b(!1),j(!1),k(!1)},[c]);const w=l.useCallback(async C=>{const r=V.parseCalendarPreferencesResponse(await C.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),S=l.useCallback(async()=>{if(!d||!c||!m)return;const C=c;b(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to fetch preferences")}const t=await w(r);h.current===C&&P(t)}catch(r){h.current===C&&f(r instanceof Error?r.message:"Unknown error")}finally{h.current===C&&b(!1)}},[c,m,d,w]);l.useEffect(()=>{d&&S()},[d,S]);const E=l.useCallback(async C=>{if(!c||!m)return f("Not authenticated"),!1;const r=c;j(!0),f(null);try{const t=await fetch(`${m}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify(C)});if(!t.ok){const z=await t.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}const x=await w(t);return h.current!==r?!1:(P(x),p(x.resolved,x.sources),!0)}catch(t){return h.current===r&&f(t instanceof Error?t.message:"Unknown error"),!1}finally{h.current===r&&j(!1)}},[c,m,p,w]),A=l.useCallback(async()=>{if(!c||!m)return f("Not authenticated"),!1;const C=c;k(!0),f(null);try{const r=await fetch(`${m}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${c}`}});if(!r.ok){const x=await r.json().catch(()=>({}));throw new Error(x.error||"Failed to clear preferences")}const t=await w(r);return h.current!==C?!1:(P(t),p(t.resolved,t.sources),!0)}catch(r){return h.current===C&&f(r instanceof Error?r.message:"Unknown error"),!1}finally{h.current===C&&k(!1)}},[c,m,p,w]);return{preferences:N,isLoading:v,isSaving:g,isClearing:y,error:T,updatePreferences:E,clearPreferences:A,refetch:S}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],I=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function _(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return F.map(s=>s.value)}function G(s){if(!s)return"default";if(s.tz!==s.weekStart)return"inherited";switch(s.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(s){const i=F.find(a=>a.value===s);return i?i.label:s}function W(s){const i=I.find(a=>a.value===s);return i?i.label:String(s)}function H({active:s,onClose:i}){const{preferences:a,isLoading:p,isSaving:d,isClearing:c,updatePreferences:m,clearPreferences:v}=M({enabled:s}),b=n.useCalendarContext(),g=(a==null?void 0:a.resolved.tz)||(b==null?void 0:b.tz)||"UTC",j=(a==null?void 0:a.resolved.weekStart)??(b==null?void 0:b.weekStart)??1,[y,k]=l.useState((a==null?void 0:a.stored)===null),[T,f]=l.useState(!1),[N,P]=l.useState(g),[h,w]=l.useState(j),[S,E]=l.useState(!1),A=l.useMemo(()=>_(),[]),C=l.useMemo(()=>A.filter(u=>!F.some($=>$.value===u)),[A]),r=l.useMemo(()=>U(N),[N]),t=a!=null&&a.inherited?U(a.inherited.tz):"UTC",x=a!=null&&a.inherited?W(a.inherited.weekStart):"Monday",z=G(a==null?void 0:a.inheritedSources);l.useEffect(()=>{if(!s){f(!1);return}T||(a&&k(a.stored===null),P(g),w(j))},[s,T,a,g,j]);const B=async()=>{if(p){n.ue.error("Preferences are still loading. Please try again.");return}y?await v()?(n.ue.success("Now using default settings."),i()):n.ue.error("Failed to save preferences. Please try again."):await m({tz:N,weekStart:h})?(n.ue.success("Preferences saved."),i()):n.ue.error("Failed to save preferences. Please try again.")},q=()=>{i()},L=d||c,O=L||p;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(n.RadioGroup,{value:y?"defaults":"custom",onValueChange:u=>{f(!0),k(u==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",y&&"bg-muted/50"),onClick:()=>{f(!0),k(!0)},children:[e.jsx(n.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",z," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[t,", week starts ",x]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:o.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!y&&"bg-muted/50"),onClick:()=>{f(!0),k(!1)},children:[e.jsx(n.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:o.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",y&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Timezone"}),e.jsxs(o.Popover,{open:S,onOpenChange:E,modal:!0,children:[e.jsx(o.PopoverTrigger,{asChild:!0,children:e.jsxs(o.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":S,className:"w-full justify-between text-[12px] font-normal",disabled:y,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(n.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(o.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(n.Command,{className:"overflow-visible",children:[e.jsx(n.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(n.CommandList,{children:[e.jsx(n.CommandEmpty,{children:"No timezone found."}),e.jsx(n.CommandGroup,{heading:"Common",children:F.map(u=>e.jsxs(n.CommandItem,{value:`${u.value} ${u.label}`,onSelect:()=>{f(!0),P(u.value),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:u.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:u.value})]},u.value))}),e.jsx(n.CommandSeparator,{}),e.jsx(n.CommandGroup,{heading:"All timezones",children:C.map(u=>e.jsxs(n.CommandItem,{value:u,onSelect:()=>{f(!0),P(u),E(!1)},children:[e.jsx(o.Check,{className:o.cn("h-3.5 w-3.5",N===u?"opacity-100":"opacity-0")}),u]},u))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(o.Label,{className:R,children:"Week starts on"}),e.jsx(n.RadioGroup,{value:String(h),onValueChange:u=>{f(!0),w(Number(u))},className:"flex gap-4",disabled:y,children:I.map(u=>e.jsxs("label",{htmlFor:`week-start-${u.value}`,className:o.cn("flex cursor-pointer items-center gap-2 text-[13px]",y&&"cursor-not-allowed"),children:[e.jsx(n.RadioGroupItem,{value:String(u.value),id:`week-start-${u.value}`,disabled:y}),u.label]},u.value))})]})]})]}),e.jsxs(n.DialogFooter,{children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:q,disabled:L,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:B,disabled:O,children:L?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function K(s={}){const{authToken:i,tokenProps:a}=n.useSemaphorContext(),p=o.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),d=s.enabled??!0,c=(i==null?void 0:i.accessToken)??null,m=(a==null?void 0:a.apiServiceUrl)??null,v=l.useRef(c);v.current=c;const[b,g]=l.useState(null),[j,y]=l.useState(!1),[k,T]=l.useState(!1),[f,N]=l.useState(!1),[P,h]=l.useState(null);l.useEffect(()=>{g(null),h(null),y(!1),T(!1),N(!1)},[c]);const w=l.useCallback(async r=>{const t=D.parseValueFormatPreferencesResponse(await r.json());if(!t.ok)throw new Error("Value format preferences response is invalid");return t.value},[]),S=l.useCallback(async(r,t)=>{if(!c||!m)throw new Error("Not authenticated");const x=await fetch(`${m}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${c}`,...t?{"Content-Type":"application/json"}:{}},body:t?JSON.stringify(t):void 0});if(!x.ok){const z=await x.json().catch(()=>({}));throw new Error(z.error||"Failed to update preferences")}return w(x)},[c,m,w]),E=l.useCallback(async()=>{if(!d||!c||!m)return;const r=c;y(!0),h(null);try{const t=await S("GET");v.current===r&&g(t)}catch(t){v.current===r&&h(t instanceof Error?t.message:"Unknown error")}finally{v.current===r&&y(!1)}},[c,m,d,S]);l.useEffect(()=>{d&&E()},[d,E]);const A=l.useCallback(async r=>{const t=c;T(!0),h(null);try{const x=await S("PATCH",r);return v.current!==t?!1:(g(x),p(x.resolved,x.sources),!0)}catch(x){return v.current===t&&h(x instanceof Error?x.message:"Unknown error"),!1}finally{v.current===t&&T(!1)}},[c,p,S]),C=l.useCallback(async()=>{const r=c;N(!0),h(null);try{const t=await S("DELETE");return v.current!==r?!1:(g(t),p(t.resolved,t.sources),!0)}catch(t){return v.current===r&&h(t instanceof Error?t.message:"Unknown error"),!1}finally{v.current===r&&N(!1)}},[c,p,S]);return{preferences:b,isLoading:j,isSaving:k,isClearing:f,error:P,updatePreferences:A,clearPreferences:C,refetch:E}}function J({active:s,onClose:i}){var v,b;const{preferences:a,isLoading:p,isSaving:d,updatePreferences:c}=K({enabled:s});if(!s)return null;if(!a)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:p?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const m=[((v=a.stored)==null?void 0:v.locale)??"",((b=a.stored)==null?void 0:b.defaultCurrency)??""].join(":");return e.jsx(Z,{preferences:a,isSaving:d,updatePreferences:c,onClose:i},m)}function Z({preferences:s,isSaving:i,updatePreferences:a,onClose:p}){const[d,c]=l.useState(()=>{var g,j;return{locale:(g=s.stored)==null?void 0:g.locale,defaultCurrency:(j=s.stored)==null?void 0:j.defaultCurrency}}),m=(d.locale===void 0||D.canonicalizeSupportedLocale(d.locale)!==void 0)&&(d.defaultCurrency===void 0||D.canonicalizeSupportedCurrencyCode(d.defaultCurrency)!==void 0),v=async()=>{var T,f;const g={},j=[];d.locale!==void 0?g.locale=d.locale:((T=s.stored)==null?void 0:T.locale)!==void 0&&j.push("locale"),d.defaultCurrency!==void 0?g.defaultCurrency=d.defaultCurrency:((f=s.stored)==null?void 0:f.defaultCurrency)!==void 0&&j.push("defaultCurrency");const y={...Object.keys(g).length>0?{set:g}:{},...j.length>0?{clear:j}:{}};(Object.keys(y).length===0?!0:await a(y))?(n.ue.success("Display format preferences saved."),p()):n.ue.error("Failed to save preferences. Please try again.")},b=async()=>{await a({clear:["locale","defaultCurrency"]})?(n.ue.success("Locale and currency preferences reset."),p()):n.ue.error("Failed to reset locale and currency preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(n.DisplayFormatPreferencesFields,{value:d,inherited:s.inherited,inheritedSources:s.inheritedSources,onChange:c,disabled:i})}),e.jsxs(n.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(o.Button,{variant:"ghost",size:"xs",onClick:b,disabled:i||s.stored===null,children:"Reset locale and currency"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(o.Button,{variant:"outline",size:"xs",onClick:p,disabled:i,children:"Cancel"}),e.jsx(o.Button,{size:"xs",onClick:v,disabled:i||!m,children:i?e.jsxs(e.Fragment,{children:[e.jsx(o.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function Y({open:s,onOpenChange:i}){const[a,p]=l.useState("display"),d=()=>i(!1);return e.jsx(n.Dialog,{open:s,onOpenChange:i,children:e.jsxs(n.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(n.DialogHeader,{children:[e.jsx(n.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(n.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(o.Tabs,{value:a,onValueChange:p,children:[e.jsxs(o.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(o.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(o.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(o.TabsContent,{value:"display",children:e.jsx(J,{active:s&&a==="display",onClose:d})}),e.jsx(o.TabsContent,{value:"calendar",children:e.jsx(H,{active:s&&a==="calendar",onClose:d})})]})]})})}exports.ReportPreferencesDialog=Y;
|
package/dist/chunks/{report-preferences-dialog-Bjj_tIgL.js → report-preferences-dialog-TtwdAuNn.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as l, Fragment as R, jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import le, { useState as C, useRef as Y, useEffect as U, useCallback as A, useMemo as _ } from "react";
|
|
3
|
-
import { az as Q, aA as ce, aB as B, aC as $, aD as oe, h as ie, i as ue, j as de, k as fe, l as M, m as W, aE as me, aF as V, aG as z, a as he, aH as pe, aI as ve, aJ as ye, aK as ge, aL as be } from "./dashboard
|
|
4
|
-
import { u as X, c as F, O as q, P as we, a as Ce, B as L, b as Se, d as G, L as ee, T as ke, F as Te, G as H, I as K } from "./code-editor-
|
|
3
|
+
import { az as Q, aA as ce, aB as B, aC as $, aD as oe, h as ie, i as ue, j as de, k as fe, l as M, m as W, aE as me, aF as V, aG as z, a as he, aH as pe, aI as ve, aJ as ye, aK as ge, aL as be } from "./dashboard-Bd1Quco-.js";
|
|
4
|
+
import { u as X, c as F, O as q, P as we, a as Ce, B as L, b as Se, d as G, L as ee, T as ke, F as Te, G as H, I as K } from "./code-editor-BpADiIlq.js";
|
|
5
5
|
import { parseCalendarPreferencesResponse as xe } from "../report-runtime-context/index.js";
|
|
6
6
|
import "./index-xHCrHprY.js";
|
|
7
7
|
import "./analyze-result-contract-CfOBEwaC.js";
|
package/dist/dashboard/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/dashboard-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../chunks/dashboard-cB3xmTNn.js"),e=require("../chunks/common-types-C73-Ud1-.js");exports.Dashboard=o.Dashboard;exports.CONTROL_CARD_DEFAULT_VALUE=e.CONTROL_CARD_DEFAULT_VALUE;exports.EMPTY_SELECTION=e.EMPTY_SELECTION;
|
package/dist/dashboard/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),An=require("react-dom/client"),k=require("../chunks/dashboard-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("react"),An=require("react-dom/client"),k=require("../chunks/dashboard-cB3xmTNn.js"),w=require("../chunks/code-editor-M7HTUhdF.js"),Ze=require("../data-app-builder-browser-runtime/index.cjs"),Q=require("../chunks/index-jSrCwPQz.js"),Cn=require("../chunks/save-Xdc4pnys.js"),tt=require("../chunks/search-Dcud9ajy.js");function Tr(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const d=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,d.get?d:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const Rn=Tr(p),Bn=Tr(An);/**
|
|
2
2
|
* @license lucide-react v0.453.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|