react-semaphor 0.1.259 → 0.1.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/dashboard-controls-0hbftZxY.js +42 -0
- package/dist/chunks/dashboard-controls-BYi_r2lH.js +1971 -0
- package/dist/chunks/dashboard-filter-controls-button-BPCw1GMh.js +1066 -0
- package/dist/chunks/dashboard-filter-controls-button-f4pDkDUL.js +11 -0
- package/dist/chunks/{dashboard-json-B43n1l6C.js → dashboard-json-2NJCXsDD.js} +1 -1
- package/dist/chunks/{dashboard-json-D0oSxmLa.js → dashboard-json-Dpy-zKf2.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-CxZAMb8B.js → dashboard-summary-settings-dialog-B9zRCvc-.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-DMWYgbwB.js → dashboard-summary-settings-dialog-Be3JilRI.js} +1 -1
- package/dist/chunks/edit-dashboard-visual-Bon08erH.js +188 -0
- package/dist/chunks/{edit-dashboard-visual-CCoz1oGX.js → edit-dashboard-visual-CqTlmuYL.js} +5970 -5492
- package/dist/chunks/index-BoJEr_9F.js +1114 -0
- package/dist/chunks/{index-DpSxZvI0.js → index-C2c-_lPE.js} +48682 -45193
- package/dist/chunks/{normalize-dashboard-for-dirty-check-Bn27S0PN.js → normalize-dashboard-for-dirty-check-5KpZN8xr.js} +20 -19
- package/dist/chunks/normalize-dashboard-for-dirty-check-BXRUMVb2.js +1 -0
- package/dist/chunks/{resource-management-panel-L51m1i4h.js → resource-management-panel-BtLPW2b4.js} +1 -1
- package/dist/chunks/{resource-management-panel-B_bDGuq_.js → resource-management-panel-Bva2_0OU.js} +70 -70
- package/dist/chunks/use-create-flow-overlay-state-9X7GyUzl.js +21 -0
- package/dist/chunks/use-create-flow-overlay-state-Vyd5mSnf.js +1445 -0
- package/dist/chunks/{use-visual-utils-V6paZich.js → use-visual-utils-Jv4hWSLm.js} +1 -1
- package/dist/chunks/{use-visual-utils-Cp5KVbr6.js → use-visual-utils-OPk_1t4I.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +5 -4
- package/dist/index.cjs +1 -1
- package/dist/index.js +102 -99
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.js +1 -1
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +5 -4
- package/dist/types/dashboard.d.ts +105 -0
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.js +4 -3
- package/dist/types/main.d.ts +175 -1
- package/dist/types/shared.d.ts +89 -0
- package/dist/types/surfboard.d.ts +105 -0
- package/dist/types/types.d.ts +113 -0
- package/package.json +1 -1
- package/dist/chunks/dashboard-controls-51P6aUVB.js +0 -1847
- package/dist/chunks/dashboard-controls-BC3hDGwD.js +0 -47
- package/dist/chunks/edit-dashboard-visual-D1mwhPGF.js +0 -193
- package/dist/chunks/editor-action-buttons-B6ElCCo2.js +0 -412
- package/dist/chunks/editor-action-buttons-Dbs6eczj.js +0 -21
- package/dist/chunks/index-DAhkssOV.js +0 -1109
- package/dist/chunks/normalize-dashboard-for-dirty-check-B7NQDI1H.js +0 -1
- package/dist/chunks/notification-bell-DoIAAZqX.js +0 -6
- package/dist/chunks/notification-bell-cYCkxEbp.js +0 -839
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";const g=require("react"),t=require("./index-BoJEr_9F.js"),e=require("react/jsx-runtime"),A=require("./use-create-flow-overlay-state-9X7GyUzl.js"),M=require("./use-visual-utils-Jv4hWSLm.js"),T=require("./date-formatter-CqXdM6JO.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 L=t.createLucideIcon("FileDown",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 18v-6",key:"17g6i2"}],["path",{d:"m9 15 3 3 3-3",key:"1npd3o"}]]);/**
|
|
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 P=t.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"}]]),V=1e4,O=15e3,z=3e4,R=3e4,$=12e4,k=2*60*60*1e3;function H(s){const r=Date.now()-s.getTime();return r<R?V:r<$?O:z}function q(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),p=t.useExportStore(h=>h.activeExports),[c,d]=g.useState(typeof document<"u"?!document.hidden:!0),u=g.useRef(null),n=g.useRef(!1),l=g.useRef(void 0),m=r==null?void 0:r.apiServiceUrl,o=s==null?void 0:s.accessToken,f=g.useCallback(()=>{const h=t.useExportStore.getState().activeExports;return Array.from(h.values()).filter(C=>t.isExportInProgress(C.status))},[]);g.useEffect(()=>{if(typeof document>"u")return;const h=()=>{d(!document.hidden)};return document.addEventListener("visibilitychange",h),()=>{document.removeEventListener("visibilitychange",h)}},[]);const b=g.useCallback(async()=>{if(!m||!o){n.current=!1;return}const h=f();if(h.length===0){n.current=!1;return}const C=Date.now(),N=h.filter(a=>C-a.startedAt.getTime()>k);if(N.length>0){const{updateExport:a}=t.useExportStore.getState().actions;for(const i of N)a(i.id,{status:"failed",error:"Export timed out. Please try again or contact support.",lastUpdatedAt:new Date})}const x=h.filter(a=>C-a.startedAt.getTime()<=k);if(x.length===0){n.current=!1;return}const j=await Promise.allSettled(x.map(async a=>{try{const i=await t.getExportStatus(m,o,a.id);let v;if(i.status==="completed")try{v=await t.getDownloadUrl(m,o,a.id)}catch(E){console.error(`[useExportPolling] Failed to get download URL for ${a.id}:`,E)}return{id:a.id,status:i.status,progress:i.progress,completedChunks:i.completedChunks,completedAt:i.completedAt?new Date(i.completedAt):void 0,lastUpdatedAt:new Date,fileSize:i.fileSize,error:i.error,downloadUrl:v}}catch(i){return console.error(`[useExportPolling] Failed to poll export ${a.id}:`,i),null}})),{updateExport:S}=t.useExportStore.getState().actions;for(const a of j)a.status==="fulfilled"&&a.value&&S(a.value.id,a.value);const w=f();if(w.length>0&&!document.hidden){const a=w.reduce((v,E)=>E.startedAt<v?E.startedAt:v,w[0].startedAt),i=H(a);u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{var v;(v=l.current)==null||v.call(l)},i)}else n.current=!1},[m,o,f]);return g.useEffect(()=>{l.current=b},[b]),g.useEffect(()=>{var C;f().length>0&&c&&!n.current&&(n.current=!0,(C=l.current)==null||C.call(l))},[p,c,f]),g.useEffect(()=>{var C;const h=f();c&&h.length>0&&!n.current&&(n.current=!0,(C=l.current)==null||C.call(l))},[c,f]),g.useEffect(()=>{!c&&u.current&&(clearTimeout(u.current),u.current=null,n.current=!1)},[c]),g.useEffect(()=>()=>{u.current&&(clearTimeout(u.current),u.current=null)},[]),{isPolling:n.current,isTabVisible:c,inProgressCount:f().length}}function _(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),p=t.useExportStore(l=>l.activeExports),{addExport:c}=t.useExportActions(),d=g.useRef(!1),u=r==null?void 0:r.apiServiceUrl,n=s==null?void 0:s.accessToken;g.useEffect(()=>{if(d.current||!u||!n)return;(async()=>{try{const{exports:m}=await t.getExports(u,n,{status:["pending","processing","chunking","compacting","completed","failed"],limit:20});for(const o of m){if(p.has(o.id))continue;const f=o.totalChunks?Math.round(o.completedChunks/o.totalChunks*100):0;let b;if(o.status==="completed")try{b=await t.getDownloadUrl(u,n,o.id)}catch(C){console.error(`[useExportRecovery] Failed to get download URL for ${o.id}:`,C)}const h={id:o.id,status:o.status,progress:f,title:X(o),totalRows:o.totalRows,totalChunks:o.totalChunks,completedChunks:o.completedChunks,startedAt:new Date(o.createdAt),lastUpdatedAt:new Date,completedAt:o.completedAt?new Date(o.completedAt):void 0,fileSize:o.fileSize,error:o.error,expiresAt:new Date(o.expiresAt),downloadUrl:b};c(h)}d.current=!0}catch(m){console.error("[useExportRecovery] Failed to recover exports:",m),d.current=!0}})()},[u,n,c,p])}function X(s){return s.title?s.title:t.isExportInProgress(s.status)?"Export in progress...":s.status==="completed"?"Export completed":s.status==="failed"?"Export failed":"Export"}function G({open:s,onOpenChange:r,isLibraryVisual:p,currentVisualName:c,isSaving:d=!1,destinationMode:u="both",onConfirm:n}){const[l,m]=g.useState(p&&c?`Copy of ${c}`:c||""),[o,f]=g.useState("");g.useEffect(()=>{s&&(m(p&&c?`Copy of ${c}`:c||""),f(""))},[s,p,c]);const b=!!l.trim(),h=u==="local"?{saveToLibrary:!1,saveToCurrentDashboard:!0,badgeType:"local",description:"Creates a local copy on the current dashboard.",actionLabel:"Add to Dashboard (Local)"}:u==="library"?{saveToLibrary:!0,saveToCurrentDashboard:!1,badgeType:"library",description:"Creates a reusable visual in Visual Library.",actionLabel:"Save as Library Visual"}:{saveToLibrary:!0,saveToCurrentDashboard:!0,badgeType:"linked",description:"Creates a new library visual and adds a linked copy to this dashboard.",actionLabel:"Save Copy as Linked Visual"},C=()=>{!b||d||n({name:l.trim(),description:o.trim()||void 0,saveToLibrary:h.saveToLibrary,saveToCurrentDashboard:h.saveToCurrentDashboard})};return e.jsx(t.Dialog,{open:s,onOpenChange:r,children:e.jsxs(t.DialogContent,{className:"sm:max-w-[500px]",children:[e.jsxs(t.DialogHeader,{children:[e.jsxs(t.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx("span",{children:"Save Visual As"}),h.badgeType!=="local"&&e.jsx(A.VisualBadge,{type:h.badgeType,showLabel:!0,className:"px-2 py-0.5"})]}),e.jsx(t.DialogDescription,{children:h.description})]}),e.jsxs("div",{className:"grid gap-4 py-4",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"name",children:"Name"}),e.jsx(t.Input$1,{id:"name",value:l,onChange:N=>m(N.target.value),placeholder:"Enter visual name",disabled:d})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(t.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Textarea,{id:"description",value:o,onChange:N=>f(N.target.value),placeholder:"Enter visual description",rows:3,disabled:d})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(t.Button,{variant:"outline",onClick:()=>r(!1),disabled:d,children:"Cancel"}),e.jsxs(t.Button,{onClick:C,disabled:!b||d,children:[d&&e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),h.actionLabel]})]})]})})}function K(){const[s,r]=g.useState(!1),[p,c]=g.useState(!1),[d,u]=g.useState(null),n=t.useEditorStore(i=>i.frame),l=t.useEditorStore(i=>i.card),m=t.useSelectedVisual(),o=t.useDashboardStore(i=>i.selectedSheetId),f=t.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),{getUpdatedFrame:b}=M.useVisualUtils(),{selectVisual:h}=t.useManagementActions(),{addFrame:C,setSelectedFrameId:N,setIsVisualEditing:x}=t.useDashboardActions(),j=!!(n!=null&&n.visualId),S=(()=>{var i,v;return((i=n==null?void 0:n.cards)==null?void 0:i.length)===1&&((v=n.cards[0])!=null&&v.title)?n.cards[0].title:m!=null&&m.title?m.title:(l==null?void 0:l.title)||"Untitled Visual"})(),w=t.useCreateVisualWithFrame(i=>{if(i!=null&&i.id){if(h(i),p&&d&&o){const v={...d,id:t.v4(),visualId:i.id};C(o,v,"end"),N(v.id),c(!1),u(null),x(!1)}f(!0),r(!1)}});return{saveAsDialogOpen:s,setSaveAsDialogOpen:r,handleSaveAs:async i=>{if(!o){t.ue.error("No sheet selected");return}const v=b(),y=v.cards.length===1?{...v,cards:v.cards.map(D=>({...D,title:i.name}))}:v;if(i.saveToLibrary){c(i.saveToCurrentDashboard),u(y);const D={title:i.name,description:i.description,frameObject:y,isPrivate:!1};w.mutate(D)}else if(i.saveToCurrentDashboard){const D={...y,id:t.v4(),visualId:void 0};C(o,D,"end"),N(D.id),t.ue.success("Visual saved to dashboard"),r(!1),x(!1)}},isLibraryVisual:j,currentVisualName:S,isSaving:w.isPending}}function W({className:s}){const r=t.useEditorStore(y=>y.frame),p=t.useManagementStore(y=>y.selectedVisual),c=t.useDashboardStore(y=>y.selectedFrameId),d=t.useDashboardStore(y=>y.selectedSheetId),{setIsVisualEditing:u,updateFrame:n}=t.useDashboardActions(),[l,m]=g.useState(!1),[o,f]=g.useState("both"),b=!!(r!=null&&r.visualId||p!=null&&p.id),h=!!(r!=null&&r.visualId&&c),C=b&&!h,{saveAsDialogOpen:N,setSaveAsDialogOpen:x,handleSaveAs:j,isLibraryVisual:S,currentVisualName:w,isSaving:a}=K(),{getUpdatedFrame:i}=M.useVisualUtils(),v=()=>{if(!d){t.ue.error("No sheet selected");return}if(l)return;m(!0);const D={...i(),visualId:void 0};n(d,D),setTimeout(()=>{m(!1),t.ue.success("Changes applied. Visual is now local to this dashboard"),u(!1)},300)},E=y=>{f(y),x(!0)};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"inline-flex items-center overflow-hidden rounded-md border border-input",children:[!b&&e.jsx(A.EditorAcceptButton,{className:t.cn(s,"rounded-none border-0"),variant:"default"}),b&&C&&e.jsx(A.VisualSaveButton,{className:t.cn(s,"rounded-none border-0"),variant:"default"}),b&&h&&e.jsx(A.VisualSaveAndApplyButton,{className:t.cn(s,"rounded-none border-0")}),e.jsxs(t.DropdownMenu,{modal:!1,children:[e.jsx(t.DropdownMenuTrigger,{className:"h-8",asChild:!0,children:e.jsx(t.Button,{variant:"default",size:"sm",className:t.cn(s,"w-8 rounded-none border-0 border-l border-primary-foreground/30 px-2"),"aria-label":"Open visual save options",disabled:a||l,children:e.jsx(t.ChevronDown,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",children:[h&&e.jsxs(e.Fragment,{children:[e.jsxs(t.DropdownMenuItem,{onClick:v,disabled:l,children:[e.jsx(t.Check,{className:"mr-2 h-4 w-4"}),l?"Applying...":"Apply Locally"]}),e.jsx(t.DropdownMenuSeparator,{})]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>E("local"),disabled:a,children:[e.jsx(t.Plus,{className:"mr-2 h-4 w-4"}),"Add to Dashboard (Local)"]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>E("library"),disabled:a,children:[e.jsx(A.Library,{className:"mr-2 h-4 w-4"}),"Save as Library Visual"]}),e.jsxs(t.DropdownMenuItem,{onClick:()=>E("both"),disabled:a,children:[e.jsx(A.Link2,{className:"mr-2 h-4 w-4"}),"Save Copy as Linked Visual"]})]})]})]}),e.jsx(A.EditorCancelButton,{className:s}),e.jsx(G,{open:N,onOpenChange:y=>{a||x(y)},isLibraryVisual:S,currentVisualName:w,isSaving:a,destinationMode:o,onConfirm:j})]})}function Q({className:s,switchClassName:r}){const p=t.useEditorStore(l=>l.isDevMode),c=t.useDashboardStore(l=>l.isVisualEditing),{setIsDevMode:d}=t.useEditorActions(),{config:u}=g.useContext(t.SemaphorContext).tokenProps,n=(u==null?void 0:u.showAdvancedMode)!==!1;return!c||!n?null:e.jsxs("div",{className:t.cn("flex items-center space-x-2",s),children:[e.jsx(t.DevModeSwitch,{className:t.cn("",r),checked:p,onCheckedChange:()=>d(!p),id:"advanced-mode",icon:e.jsx(t.CodeXml,{className:"h-4 w-4"}),tooltip:"Advanced Mode"}),e.jsx("label",{htmlFor:"advanced-mode",className:"sr-only",children:"Advanced Mode"})]})}function Y({open:s,onOpenChange:r,onSave:p,onDiscard:c,isSaving:d,title:u="Unsaved Changes",description:n="You have unsaved changes to this dashboard. What would you like to do?",cancelLabel:l="Cancel",discardLabel:m="Discard",saveLabel:o="Save & Close"}){const f=b=>{!b&&d||r(b)};return e.jsx(t.AlertDialog,{open:s,onOpenChange:f,children:e.jsxs(t.AlertDialogContent,{className:"max-w-[520px] border-border/70 p-6",children:[e.jsxs(t.AlertDialogHeader,{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-full bg-amber-50 ring-1 ring-amber-200/70",children:e.jsx(t.TriangleAlert,{className:"h-[18px] w-[18px] text-amber-600"})}),e.jsx(t.AlertDialogTitle,{className:"text-lg font-semibold tracking-tight",children:u})]}),e.jsx(t.AlertDialogDescription,{className:"text-sm leading-6 text-muted-foreground",children:n})]}),e.jsxs(t.AlertDialogFooter,{className:"mt-2 flex-col gap-1.5 sm:flex-row sm:justify-end",children:[e.jsx(t.AlertDialogCancel,{disabled:d,className:"order-1 m-0 h-auto min-h-9 whitespace-normal border-border/60 px-4 py-2 text-center leading-5 sm:order-1",children:l}),e.jsx("button",{onClick:c,disabled:d,className:"order-2 h-auto min-h-9 whitespace-normal rounded-md border border-destructive/30 bg-destructive/10 px-4 py-2 text-center text-sm font-medium leading-5 text-destructive transition-colors hover:bg-destructive/20 disabled:pointer-events-none disabled:opacity-50 sm:order-2",children:m}),e.jsx(t.AlertDialogAction,{onClick:p,disabled:d,className:"order-3 m-0 h-auto min-h-9 whitespace-normal px-4 py-2 text-center leading-5 sm:order-3",children:d?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):o})]})]})})}function Z(s,r,p,c){g.useEffect(()=>{s&&!p&&r&&c(t.cloneDeep(r))},[s,p,r,c])}function U({export:s,onRemove:r}){const p=()=>{s.downloadUrl&&window.open(s.downloadUrl,"_blank")},c=l=>{l.stopPropagation(),r==null||r(s.id)},d=()=>{switch(s.status){case"completed":return e.jsx(t.CircleCheck,{className:"mt-0.5 h-5 w-5 shrink-0 text-green-600"});case"failed":return e.jsx(A.CircleX,{className:"mt-0.5 h-5 w-5 shrink-0 text-destructive"});default:return e.jsx(t.LoaderCircle,{className:"text-foreground-muted mt-0.5 h-5 w-5 shrink-0 animate-spin"})}},u=t.isExportInProgress(s.status),n=(()=>{switch(s.status){case"pending":return"Queued...";case"processing":return"Processing...";case"chunking":return"Processing...";case"compacting":return"Finalizing...";default:return"Processing..."}})();return e.jsxs("div",{className:"group p-4 transition-colors hover:bg-muted/50",children:[e.jsxs("div",{className:"mb-2 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[d(),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h4",{className:"mb-1 truncate text-sm font-medium",children:s.title}),s.status==="completed"&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[s.totalRows.toLocaleString()," rows"]}),s.fileSize&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"•"}),e.jsx("span",{children:t.formatFileSize(s.fileSize)})]})]}),u&&e.jsx("div",{className:"text-xs text-muted-foreground",children:n}),s.status==="failed"&&e.jsx("div",{className:"line-clamp-2 text-xs text-destructive",children:s.error||"Export failed"})]})]}),e.jsx(t.Button,{variant:"ghost",size:"icon",className:"h-6 w-6 shrink-0 opacity-0 transition-opacity group-hover:opacity-100",onClick:c,"aria-label":"Remove notification",children:e.jsx(t.X,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"ml-8",children:[s.status==="completed"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:T.formatDistanceToNow(s.startedAt,{addSuffix:!0})}),s.downloadUrl&&e.jsxs(t.Button,{size:"sm",variant:"outline",className:"h-8 bg-transparent",onClick:p,children:[e.jsx(t.Download,{className:"mr-1.5 h-3.5 w-3.5"}),"Download"]})]}),u&&e.jsxs("div",{children:[e.jsx(t.Progress,{value:s.progress,className:"h-1.5"}),e.jsxs("span",{className:"mt-1 block text-xs text-muted-foreground",children:[s.progress,"% complete"]})]}),s.status==="failed"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:T.formatDistanceToNow(s.startedAt,{addSuffix:!0})})]})]})}function B(){const{authToken:s,tokenProps:r}=t.useSemaphorContext(),p=t.useExportStore(x=>x.activeExports),{clearCompleted:c,removeExport:d,updateExport:u}=t.useExportActions(),[n,l]=g.useState(!1),[m,o]=g.useState(!1),f=Array.from(p.values()).sort((x,j)=>j.startedAt.getTime()-x.startedAt.getTime()),b=f.some(x=>x.status==="completed"||x.status==="failed"),h=g.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!(!x||!j)){l(!0);try{const S=Array.from(p.values());await Promise.all(S.map(async w=>{try{const a=await t.getExportStatus(x,j,w.id);let i;if(a.status==="completed")try{i=await t.getDownloadUrl(x,j,w.id)}catch(v){console.error(`Failed to get download URL for ${w.id}:`,v)}u(w.id,{status:a.status,progress:a.progress,completedChunks:a.completedChunks,completedAt:a.completedAt?new Date(a.completedAt):void 0,lastUpdatedAt:new Date,fileSize:a.fileSize,error:a.error,downloadUrl:i})}catch(a){console.error(`Failed to refresh export ${w.id}:`,a)}}))}finally{l(!1)}}},[p,s==null?void 0:s.accessToken,r==null?void 0:r.apiServiceUrl,u]),C=g.useCallback(async()=>{const x=r==null?void 0:r.apiServiceUrl,j=s==null?void 0:s.accessToken;if(!x||!j){c();return}o(!0);try{const S=f.filter(a=>a.status==="completed"||a.status==="failed"),w=await Promise.allSettled(S.map(async a=>(await t.cancelExport(x,j,a.id),a.id)));for(const a of w)a.status==="fulfilled"?d(a.value):console.error("Failed to delete export:",a.reason)}finally{o(!1)}},[f,r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,c,d]),N=g.useCallback(async x=>{const j=r==null?void 0:r.apiServiceUrl,S=s==null?void 0:s.accessToken;if(j&&S)try{await t.cancelExport(j,S,x),d(x);return}catch(w){console.error(`Failed to cancel export ${x}:`,w)}d(x)},[r==null?void 0:r.apiServiceUrl,s==null?void 0:s.accessToken,d]);return f.length===0?e.jsxs("div",{className:"p-6 text-center",children:[e.jsx(L,{className:"mx-auto mb-2 h-8 w-8 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No active exports"}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"Large exports will appear here"})]}):e.jsxs("div",{className:"flex flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-4 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-5 w-5 text-muted-foreground"}),e.jsx("h4",{className:"font-semibold",children:"Exports"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 w-7 p-0",onClick:h,disabled:n,title:"Refresh status",children:e.jsx(t.RefreshCw,{className:`h-4 w-4 ${n?"animate-spin":""}`})}),b&&e.jsx(t.Button,{variant:"ghost",size:"sm",className:"h-7 px-2 text-sm",onClick:C,disabled:m,children:m?"Clearing...":"Clear all"})]})]}),e.jsx("div",{className:"max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"divide-y",children:f.map(x=>e.jsx(U,{export:x,onRemove:N},x.id))})})]})}function J({variant:s}){const r=t.useExportStore(m=>m.activeExports),p=t.useInProgressExportsCount(),c=r.size>0,d=Array.from(r.values()).some(m=>m.status==="completed"||m.status==="failed"),n=p>0?p>9?"9+":String(p):null,l=c;return e.jsxs(t.Popover,{children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:e.jsxs(t.Button,{variant:s??"ghost",size:"icon",className:"relative h-8 w-8","aria-label":"Export notifications",children:[e.jsx(t.Bell,{className:"h-4 w-4"}),l&&e.jsx("span",{className:`absolute flex items-center justify-center rounded-full bg-primary text-primary-foreground ${n?"-right-0.5 -top-0.5 h-4 min-w-4 px-0.5 text-[10px] font-semibold":"right-0.5 top-0.5 h-2 w-2"}`,children:n})]})}),e.jsx(t.PopoverContent,{className:"w-80 p-0",align:"end",sideOffset:8,children:e.jsx(B,{})})]})}function ee(s){if(s)return{renamed:s.type==="rename"?{oldId:s.oldId,newId:s.newId}:void 0,removedControlId:s.type==="remove"?s.controlId:void 0,cardBindingsById:s.type==="add"||s.type==="update"?s.cardBindingsById:void 0,affectedBindingControlIds:s.type==="add"||s.type==="update"?s.affectedBindingControlIds:void 0}}function te({open:s,onOpenChange:r,trigger:p,showTrigger:c=!0,initialMode:d="manage"}){const u=d==="create",{forceClose:n,handleOpenChange:l,isCreateFlowActive:m,preventPassiveDismissDuringCreate:o,resolvedOpen:f,setIsCreateFlowActive:b}=A.useCreateFlowOverlayState({open:s,onOpenChange:r,initialCreateFlowActive:d==="create"}),h=t.useDashboardStore(D=>D.dashboard),{setDashboardControlsModel:C}=t.useDashboardActions(),{participants:N}=t.useDashboardStructuralParticipants(t.getDashboardCards(h)),x=Array.from(new Map(N.flatMap(D=>D.fieldChoices.map(I=>{var F;return[I.value,{option:I,target:(F=D.fieldTargetMap)==null?void 0:F[I.value]}]}))).values()),j=Array.from(new Map(N.flatMap(D=>D.metricChoices.map(I=>{var F;return[I.value,{option:I,target:(F=D.metricTargetMap)==null?void 0:F[I.value]}]}))).values()),S=t.collectDashboardControlIds({...h||{},controls:[]}),w=t.buildDashboardStructuralParticipantIdsByControlId(h),a=(D,I,F)=>{C(D,I,ee(F))},i=g.useCallback(()=>{if(u){n();return}b(!1)},[u,n,b]),v=e.jsx(A.ControlDefinitionListEditor,{scope:"dashboard",controls:h.controls||[],reservedControlIds:S,defaultValues:h.defaultControlValues||{},usageByControlId:t.buildDashboardControlUsageById(h),availableFieldChoices:x,availableMetricChoices:j,structuralParticipants:N,structuralParticipantIdsByControlId:w,initialCreateFlow:d==="create",onCreateFlowActiveChange:b,onCreateFlowComplete:i,onChange:a,emptyMessage:"No dashboard controls yet."}),E=m?"Add dashboard control":"Dashboard Controls",y=e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"text-sm font-medium",children:"Dashboard Controls"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),v]});return c?e.jsxs(t.Popover,{open:f,onOpenChange:l,children:[e.jsx(t.PopoverTrigger,{asChild:!0,children:p||e.jsxs(t.Button,{variant:"outline",className:"h-7 px-2",size:"sm",children:[e.jsx(t.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Controls"]})}),e.jsx(t.PopoverContent,{className:"w-[620px] max-w-[95vw] space-y-4",align:"end",onEscapeKeyDown:o,onPointerDownOutside:o,children:y})]}):e.jsx(t.Dialog,{open:f,onOpenChange:l,children:e.jsxs(t.DialogContent,{className:"flex max-h-[88vh] max-w-[980px] flex-col overflow-hidden",showCloseButton:!m,onEscapeKeyDown:o,onPointerDownOutside:o,children:[e.jsxs(t.DialogHeader,{className:m?"space-y-0":void 0,children:[e.jsx(t.DialogTitle,{children:E}),e.jsx(t.DialogDescription,{className:m?"sr-only":void 0,children:m?"Configure and add a shared dashboard control.":"Add shared controls viewers can use across the dashboard. Each card can decide how to respond to the same control."})]}),e.jsx("div",{className:"min-h-0 overflow-y-auto pr-1",children:v})]})})}function se({showFilters:s,onToggleFilters:r,onAddFilter:p,onAddControl:c,onManageControls:d,size:u="default",className:n,primaryButtonClassName:l,secondaryButtonClassName:m,dropdownContentClassName:o}){const f=u==="toolbar";return e.jsxs("div",{className:t.cn("relative inline-flex items-stretch overflow-visible rounded-md border border-input bg-background shadow-none",n),children:[e.jsxs(t.Button,{variant:"ghost",className:t.cn(f?"h-8":"h-7","rounded-none border-0 bg-transparent pl-3 pr-2 shadow-none hover:bg-accent/50",l),onClick:r,size:"sm",children:[s?e.jsx(P,{className:"mr-2 h-4 w-4"}):e.jsx(t.Filter,{className:"mr-2 h-4 w-4"}),"Filter"]}),e.jsxs(t.DropdownMenu,{children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{className:t.cn(f?"h-8 w-8":"h-7 w-8","rounded-none border-0 bg-transparent px-1 shadow-none hover:bg-accent/50",m),variant:"ghost",size:"sm","aria-label":"Filter and control actions",children:e.jsx(t.ChevronDown,{className:"h-4 w-4"})})}),e.jsxs(t.DropdownMenuContent,{align:"start",className:t.cn("rounded-xl border border-border/60 p-1 shadow-sm",o),children:[e.jsxs(t.DropdownMenuItem,{onSelect:p,children:[e.jsx(t.Filter,{className:"mr-2 h-4 w-4"}),"Add filter"]}),e.jsxs(t.DropdownMenuItem,{onSelect:c,children:[e.jsx(t.SlidersHorizontal,{className:"mr-2 h-4 w-4"}),"Add control"]}),e.jsxs(t.DropdownMenuItem,{onSelect:d,children:[e.jsx(t.Pencil,{className:"mr-2 h-4 w-4"}),"Manage controls"]})]})]})]})}exports.AdvancedModeToggle=Q;exports.DashboardControlsSettings=te;exports.DashboardFilterControlsButton=se;exports.ExportNotificationItem=U;exports.ExportNotificationList=B;exports.NotificationBell=J;exports.UnsavedChangesAlert=Y;exports.VisualEditingControls=W;exports.useExportPolling=q;exports.useExportRecovery=_;exports.usePristineSnapshotInitializer=Z;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),a=require("./index-BoJEr_9F.js");require("react");require("react-dom");function i(){const o=a.useDashboardStore(e=>e.dashboard),r=a.useDashboardStore(e=>e.actions.setDashboard),t=a.useDashboardStore(e=>e.showDashboardJSON),n=a.useDashboardStore(e=>e.actions.setShowDashboardJSON);return s.jsxs("div",{className:a.cn("relative p-2",{hidden:!t}),children:[s.jsxs(a.Button,{variant:"secondary",size:"sm",className:"absolute right-2 top-2 z-10 h-8",onClick:()=>n(!1),children:[s.jsx(a.X,{className:"mr-2 h-4 w-4"}),"Close"]}),s.jsx(a.de,{onChange:e=>{if(e)try{JSON.parse(e),r(JSON.parse(e))}catch{}},defaultLanguage:"json",className:"h-[550px] overflow-y-auto",value:JSON.stringify(o,null,2),options:{minimap:{enabled:!1},glyphMargin:!1,wordWrap:"on",scrollbar:{verticalScrollbarSize:0,horizontalScrollbarSize:0},fontSize:12,renderLineHighlight:"none"}})]})}exports.default=i;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsxs as o, jsx as r } from "react/jsx-runtime";
|
|
2
|
-
import { u as s, c as l, B as h, X as d, d as c } from "./index-
|
|
2
|
+
import { u as s, c as l, B as h, X as d, d as c } from "./index-C2c-_lPE.js";
|
|
3
3
|
import "react";
|
|
4
4
|
import "react-dom";
|
|
5
5
|
function N() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as e, jsxs as s, Fragment as oe } from "react/jsx-runtime";
|
|
2
2
|
import de, { useState as h, useCallback as L, useEffect as G, useMemo as z } from "react";
|
|
3
|
-
import { b as ue, e as X, f as Z, g as J, h as K, i as q, R as $, c as C, j as F, L as b, P as me, k as he, B as P, C as fe, l as pe, m as ve, n as be, o as Se, p as ge, q as B, r as O, s as W, t as ye, v as Y, w as we, x as A, S as xe, y as Ne, z as Ce, A as Te, E as ke, F as R, I as Ie } from "./index-
|
|
3
|
+
import { b as ue, e as X, f as Z, g as J, h as K, i as q, R as $, c as C, j as F, L as b, P as me, k as he, B as P, C as fe, l as pe, m as ve, n as be, o as Se, p as ge, q as B, r as O, s as W, t as ye, v as Y, w as we, x as A, S as xe, y as Ne, z as Ce, A as Te, E as ke, F as R, I as Ie } from "./index-C2c-_lPE.js";
|
|
4
4
|
function Ee() {
|
|
5
5
|
var k, I, E, N;
|
|
6
6
|
const { authToken: a, tokenProps: r } = ue(), [l, S] = h(!1), [p, g] = h(!1), [x, y] = h(!1), [v, o] = h(null), [u, n] = h(null), w = u || {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-DAhkssOV.js");function W(){var N,C,T,y;const{authToken:s,tokenProps:r}=a.useSemaphorContext(),[i,S]=l.useState(!1),[x,v]=l.useState(!1),[j,b]=l.useState(!1),[p,u]=l.useState(null),[m,n]=l.useState(null),g=m||{tz:((C=(N=r==null?void 0:r.params)==null?void 0:N.calendarContext)==null?void 0:C.tz)||null,weekStart:((y=(T=r==null?void 0:r.params)==null?void 0:T.calendarContext)==null?void 0:y.weekStart)??null},d=l.useCallback(async()=>{if(!(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))){S(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to fetch preferences")}const o=await c.json();n({tz:o.tz,weekStart:o.weekStart,source:o.source,isInherited:o.isInherited,userHasPrefs:o.userHasPrefs,inherited:o.inherited})}catch(c){const o=c instanceof Error?c.message:"Unknown error";u(o)}finally{S(!1)}}},[s,r]);l.useEffect(()=>{d()},[d]);const f=l.useCallback(async c=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;v(!0),u(null);try{const o=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.accessToken}`},body:JSON.stringify(c)});if(!o.ok){const h=await o.json().catch(()=>({}));throw new Error(h.error||"Failed to update preferences")}return await d(),!0}catch(o){const h=o instanceof Error?o.message:"Unknown error";return u(h),!1}finally{v(!1)}},[s,r,d]),w=l.useCallback(async()=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;b(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to clear preferences")}const o=await c.text();if(o)try{const h=JSON.parse(o);return n({tz:h.tz,weekStart:h.weekStart,source:h.source,isInherited:h.isInherited??!0,userHasPrefs:!1,inherited:h.inherited}),!0}catch{}return await d(),!0}catch(c){const o=c instanceof Error?c.message:"Unknown error";return u(o),!1}finally{b(!1)}},[s,r,d]);return{preferences:g,isLoading:i,isSaving:x,isClearing:j,error:p,updatePreferences:f,clearPreferences:w,refetch:d}}const I=[{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"}],M=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}];function G(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return I.map(s=>s.value)}function V(s){switch(s){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function L(s){const r=I.find(i=>i.value===s);return r?r.label:s}function X(s){const r=M.find(i=>i.value===s);return r?r.label:String(s)}function q({open:s,onOpenChange:r}){var E,P,A;const{preferences:i,isLoading:S,isSaving:x,isClearing:v,updatePreferences:j,clearPreferences:b}=W(),p=i.tz||((E=i.inherited)==null?void 0:E.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,u=i.weekStart??((P=i.inherited)==null?void 0:P.weekStart)??1,[m,n]=l.useState(!i.userHasPrefs),[g,d]=l.useState(!1),[f,w]=l.useState(p),[N,C]=l.useState(u),[T,y]=l.useState(!1),c=l.useMemo(()=>G(),[]),o=l.useMemo(()=>c.filter(t=>!I.some(R=>R.value===t)),[c]),h=l.useMemo(()=>L(f),[f]),F=i.inherited?L(i.inherited.tz):"UTC",H=i.inherited?X(i.inherited.weekStart):"Monday",B=V((A=i.inherited)==null?void 0:A.source);l.useEffect(()=>{if(!s){d(!1);return}g||(i.userHasPrefs!==void 0&&n(!i.userHasPrefs),w(p),C(u))},[s,g,i.userHasPrefs,p,u]);const _=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}m?await b()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again."):await j({tz:f,weekStart:N})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again.")},$=()=>{r(!1)},D=x||v,O=D||S;return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Calendar Preferences"}),e.jsx(a.DialogDescription,{children:"Set your timezone and week start preferences for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs(a.RadioGroup,{value:m?"defaults":"custom",onValueChange:t=>{d(!0),n(t==="defaults")},className:"space-y-3",children:[e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"),onClick:()=>{d(!0),n(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs(a.Label,{htmlFor:"mode-defaults",className:"cursor-pointer font-medium",children:["Use ",B," defaults"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[F,", Week starts ",H]})]})]}),e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"),onClick:()=>{d(!0),n(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom"}),e.jsx(a.Label,{htmlFor:"mode-custom",className:"cursor-pointer font-medium",children:"Use custom settings"})]})]}),e.jsxs("div",{className:a.cn("space-y-6 transition-opacity",m&&"opacity-50 pointer-events-none"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{children:"Timezone"}),e.jsxs(a.Popover,{open:T,onOpenChange:y,modal:!0,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"outline",role:"combobox","aria-expanded":T,className:"w-full justify-between",disabled:m,children:[h,e.jsx(a.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:I.map(t=>e.jsxs(a.CommandItem,{value:`${t.value} ${t.label}`,onSelect:()=>{d(!0),w(t.value),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.value})]},t.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All Timezones",children:o.map(t=>e.jsxs(a.CommandItem,{value:t,onSelect:()=>{d(!0),w(t),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t?"opacity-100":"opacity-0")}),t]},t))})]})]})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(a.Label,{children:"Week Starts On"}),e.jsx(a.RadioGroup,{value:String(N),onValueChange:t=>{d(!0),C(Number(t))},className:"flex gap-4",disabled:m,children:M.map(t=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(a.RadioGroupItem,{value:String(t.value),id:`week-start-${t.value}`,disabled:m}),e.jsx(a.Label,{htmlFor:`week-start-${t.value}`,className:a.cn("cursor-pointer font-normal",m&&"cursor-not-allowed"),children:t.label})]},t.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:$,disabled:D,children:"Cancel"}),e.jsx(a.Button,{onClick:_,disabled:O,children:D?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})})}const k=6,z=1,U=20;function Z(s){return Number.isNaN(s)?k:Math.min(U,Math.max(z,s))}function J({open:s,onOpenChange:r,dashboard:i,onApply:S,disabled:x=!1}){const[v,j]=l.useState(!1),[b,p]=l.useState("top"),[u,m]=l.useState(String(k)),n=i.summary;l.useEffect(()=>{s&&(j((n==null?void 0:n.enabled)===!0),p((n==null?void 0:n.position)==="bottom"?"bottom":"top"),m(String((n==null?void 0:n.maxItems)??k)))},[s,n==null?void 0:n.enabled,n==null?void 0:n.position,n==null?void 0:n.maxItems]);const g=l.useMemo(()=>Z(Number.parseInt(u||`${k}`,10)),[u]),d=()=>{S({enabled:v,position:b,maxItems:g}),r(!1)};return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[420px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Summary Settings"}),e.jsx(a.DialogDescription,{children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-enabled",children:"Enable Dashboard Summary"}),e.jsx(a.SmallSwitch,{id:"dashboard-summary-enabled",checked:v,disabled:x,onCheckedChange:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-position",children:"Position"}),e.jsxs(a.Select,{value:b,disabled:x,onValueChange:f=>p(f),children:[e.jsx(a.SelectTrigger,{id:"dashboard-summary-position",children:e.jsx(a.SelectValue,{placeholder:"Select position"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"top",children:"Top"}),e.jsx(a.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-max-items",children:"Max Items"}),e.jsx(a.Input,{id:"dashboard-summary-max-items",type:"number",min:z,max:U,disabled:x,value:u,onChange:f=>m(f.target.value),onBlur:()=>m(String(g))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),x&&e.jsx("p",{className:"text-xs text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(a.Button,{onClick:d,disabled:x,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=q;exports.DashboardSummarySettingsDialog=J;
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),l=require("react"),a=require("./index-BoJEr_9F.js");function W(){var N,C,T,y;const{authToken:s,tokenProps:r}=a.useSemaphorContext(),[i,S]=l.useState(!1),[x,v]=l.useState(!1),[j,b]=l.useState(!1),[p,u]=l.useState(null),[m,n]=l.useState(null),g=m||{tz:((C=(N=r==null?void 0:r.params)==null?void 0:N.calendarContext)==null?void 0:C.tz)||null,weekStart:((y=(T=r==null?void 0:r.params)==null?void 0:T.calendarContext)==null?void 0:y.weekStart)??null},d=l.useCallback(async()=>{if(!(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))){S(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to fetch preferences")}const o=await c.json();n({tz:o.tz,weekStart:o.weekStart,source:o.source,isInherited:o.isInherited,userHasPrefs:o.userHasPrefs,inherited:o.inherited})}catch(c){const o=c instanceof Error?c.message:"Unknown error";u(o)}finally{S(!1)}}},[s,r]);l.useEffect(()=>{d()},[d]);const f=l.useCallback(async c=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;v(!0),u(null);try{const o=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s.accessToken}`},body:JSON.stringify(c)});if(!o.ok){const h=await o.json().catch(()=>({}));throw new Error(h.error||"Failed to update preferences")}return await d(),!0}catch(o){const h=o instanceof Error?o.message:"Unknown error";return u(h),!1}finally{v(!1)}},[s,r,d]),w=l.useCallback(async()=>{if(!(s!=null&&s.accessToken)||!(r!=null&&r.apiServiceUrl))return u("Not authenticated"),!1;b(!0),u(null);try{const c=await fetch(`${r.apiServiceUrl}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${s.accessToken}`}});if(!c.ok){const h=await c.json().catch(()=>({}));throw new Error(h.error||"Failed to clear preferences")}const o=await c.text();if(o)try{const h=JSON.parse(o);return n({tz:h.tz,weekStart:h.weekStart,source:h.source,isInherited:h.isInherited??!0,userHasPrefs:!1,inherited:h.inherited}),!0}catch{}return await d(),!0}catch(c){const o=c instanceof Error?c.message:"Unknown error";return u(o),!1}finally{b(!1)}},[s,r,d]);return{preferences:g,isLoading:i,isSaving:x,isClearing:j,error:p,updatePreferences:f,clearPreferences:w,refetch:d}}const I=[{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"}],M=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}];function G(){try{const s=Intl;if(s.supportedValuesOf)return s.supportedValuesOf("timeZone")}catch{}return I.map(s=>s.value)}function V(s){switch(s){case"tenant":return"tenant";case"organization":return"organization";case"system":return"system";default:return"default"}}function L(s){const r=I.find(i=>i.value===s);return r?r.label:s}function X(s){const r=M.find(i=>i.value===s);return r?r.label:String(s)}function q({open:s,onOpenChange:r}){var E,P,A;const{preferences:i,isLoading:S,isSaving:x,isClearing:v,updatePreferences:j,clearPreferences:b}=W(),p=i.tz||((E=i.inherited)==null?void 0:E.tz)||Intl.DateTimeFormat().resolvedOptions().timeZone,u=i.weekStart??((P=i.inherited)==null?void 0:P.weekStart)??1,[m,n]=l.useState(!i.userHasPrefs),[g,d]=l.useState(!1),[f,w]=l.useState(p),[N,C]=l.useState(u),[T,y]=l.useState(!1),c=l.useMemo(()=>G(),[]),o=l.useMemo(()=>c.filter(t=>!I.some(R=>R.value===t)),[c]),h=l.useMemo(()=>L(f),[f]),F=i.inherited?L(i.inherited.tz):"UTC",H=i.inherited?X(i.inherited.weekStart):"Monday",B=V((A=i.inherited)==null?void 0:A.source);l.useEffect(()=>{if(!s){d(!1);return}g||(i.userHasPrefs!==void 0&&n(!i.userHasPrefs),w(p),C(u))},[s,g,i.userHasPrefs,p,u]);const _=async()=>{if(S){a.ue.error("Preferences are still loading. Please try again.");return}m?await b()?(a.ue.success("Now using default settings. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again."):await j({tz:f,weekStart:N})?(a.ue.success("Preferences saved. Please refresh the page to apply changes.",{duration:5e3}),r(!1)):a.ue.error("Failed to save preferences. Please try again.")},$=()=>{r(!1)},D=x||v,O=D||S;return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Calendar Preferences"}),e.jsx(a.DialogDescription,{children:"Set your timezone and week start preferences for date calculations and displays."})]}),e.jsxs("div",{className:"space-y-6 py-4",children:[e.jsxs(a.RadioGroup,{value:m?"defaults":"custom",onValueChange:t=>{d(!0),n(t==="defaults")},className:"space-y-3",children:[e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-primary bg-primary/5":"border-border hover:border-muted-foreground/50"),onClick:()=>{d(!0),n(!0)},children:[e.jsx(a.RadioGroupItem,{value:"defaults",id:"mode-defaults"}),e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsxs(a.Label,{htmlFor:"mode-defaults",className:"cursor-pointer font-medium",children:["Use ",B," defaults"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[F,", Week starts ",H]})]})]}),e.jsxs("div",{className:a.cn("flex items-start space-x-3 rounded-lg border p-4 cursor-pointer transition-colors",m?"border-border hover:border-muted-foreground/50":"border-primary bg-primary/5"),onClick:()=>{d(!0),n(!1)},children:[e.jsx(a.RadioGroupItem,{value:"custom",id:"mode-custom"}),e.jsx(a.Label,{htmlFor:"mode-custom",className:"cursor-pointer font-medium",children:"Use custom settings"})]})]}),e.jsxs("div",{className:a.cn("space-y-6 transition-opacity",m&&"opacity-50 pointer-events-none"),children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{children:"Timezone"}),e.jsxs(a.Popover,{open:T,onOpenChange:y,modal:!0,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"outline",role:"combobox","aria-expanded":T,className:"w-full justify-between",disabled:m,children:[h,e.jsx(a.ChevronsUpDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(a.Command,{className:"overflow-visible",children:[e.jsx(a.CommandInput,{placeholder:"Search timezones..."}),e.jsxs(a.CommandList,{children:[e.jsx(a.CommandEmpty,{children:"No timezone found."}),e.jsx(a.CommandGroup,{heading:"Common",children:I.map(t=>e.jsxs(a.CommandItem,{value:`${t.value} ${t.label}`,onSelect:()=>{d(!0),w(t.value),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:t.label}),e.jsx("span",{className:"text-xs text-muted-foreground",children:t.value})]},t.value))}),e.jsx(a.CommandSeparator,{}),e.jsx(a.CommandGroup,{heading:"All Timezones",children:o.map(t=>e.jsxs(a.CommandItem,{value:t,onSelect:()=>{d(!0),w(t),y(!1)},children:[e.jsx(a.Check,{className:a.cn("mr-2 h-4 w-4",f===t?"opacity-100":"opacity-0")}),t]},t))})]})]})})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(a.Label,{children:"Week Starts On"}),e.jsx(a.RadioGroup,{value:String(N),onValueChange:t=>{d(!0),C(Number(t))},className:"flex gap-4",disabled:m,children:M.map(t=>e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(a.RadioGroupItem,{value:String(t.value),id:`week-start-${t.value}`,disabled:m}),e.jsx(a.Label,{htmlFor:`week-start-${t.value}`,className:a.cn("cursor-pointer font-normal",m&&"cursor-not-allowed"),children:t.label})]},t.value))})]})]})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:$,disabled:D,children:"Cancel"}),e.jsx(a.Button,{onClick:_,disabled:O,children:D?e.jsxs(e.Fragment,{children:[e.jsx(a.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):"Save"})]})]})})}const k=6,z=1,U=20;function Z(s){return Number.isNaN(s)?k:Math.min(U,Math.max(z,s))}function J({open:s,onOpenChange:r,dashboard:i,onApply:S,disabled:x=!1}){const[v,j]=l.useState(!1),[b,p]=l.useState("top"),[u,m]=l.useState(String(k)),n=i.summary;l.useEffect(()=>{s&&(j((n==null?void 0:n.enabled)===!0),p((n==null?void 0:n.position)==="bottom"?"bottom":"top"),m(String((n==null?void 0:n.maxItems)??k)))},[s,n==null?void 0:n.enabled,n==null?void 0:n.position,n==null?void 0:n.maxItems]);const g=l.useMemo(()=>Z(Number.parseInt(u||`${k}`,10)),[u]),d=()=>{S({enabled:v,position:b,maxItems:g}),r(!1)};return e.jsx(a.Dialog,{open:s,onOpenChange:r,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[420px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Summary Settings"}),e.jsx(a.DialogDescription,{children:"Configure dashboard-level summary display. Card-level summary settings still control which cards contribute."})]}),e.jsxs("div",{className:"space-y-4 py-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-enabled",children:"Enable Dashboard Summary"}),e.jsx(a.SmallSwitch,{id:"dashboard-summary-enabled",checked:v,disabled:x,onCheckedChange:j})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-position",children:"Position"}),e.jsxs(a.Select,{value:b,disabled:x,onValueChange:f=>p(f),children:[e.jsx(a.SelectTrigger,{id:"dashboard-summary-position",children:e.jsx(a.SelectValue,{placeholder:"Select position"})}),e.jsxs(a.SelectContent,{children:[e.jsx(a.SelectItem,{value:"top",children:"Top"}),e.jsx(a.SelectItem,{value:"bottom",children:"Bottom"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"dashboard-summary-max-items",children:"Max Items"}),e.jsx(a.Input,{id:"dashboard-summary-max-items",type:"number",min:z,max:U,disabled:x,value:u,onChange:f=>m(f.target.value),onBlur:()=>m(String(g))}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Display limit only. Computation is unchanged."})]}),x&&e.jsx("p",{className:"text-xs text-amber-700",children:"Enter dashboard edit mode to modify summary settings."})]}),e.jsxs(a.DialogFooter,{children:[e.jsx(a.Button,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(a.Button,{onClick:d,disabled:x,children:"Apply"})]})]})})}exports.CalendarPreferencesDialog=q;exports.DashboardSummarySettingsDialog=J;
|