react-semaphor 0.1.258 → 0.1.259
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-51P6aUVB.js +1847 -0
- package/dist/chunks/dashboard-controls-BC3hDGwD.js +47 -0
- package/dist/chunks/{dashboard-json-BbWGnNc9.js → dashboard-json-B43n1l6C.js} +1 -1
- package/dist/chunks/{dashboard-json-DQ0vVX6u.js → dashboard-json-D0oSxmLa.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-BHDFPFcb.js → dashboard-summary-settings-dialog-CxZAMb8B.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-DnO9F32_.js → dashboard-summary-settings-dialog-DMWYgbwB.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-C7AmHaBY.js → edit-dashboard-visual-CCoz1oGX.js} +5410 -5397
- package/dist/chunks/edit-dashboard-visual-D1mwhPGF.js +193 -0
- package/dist/chunks/{editor-action-buttons-cYw_xuDg.js → editor-action-buttons-B6ElCCo2.js} +2 -2
- package/dist/chunks/{editor-action-buttons-BMx1hBQx.js → editor-action-buttons-Dbs6eczj.js} +1 -1
- package/dist/chunks/{index-VHKvmdqy.js → index-DAhkssOV.js} +235 -235
- package/dist/chunks/{index-BYHlElCS.js → index-DpSxZvI0.js} +25297 -24971
- package/dist/chunks/{notification-bell-lsGohR1o.js → notification-bell-DoIAAZqX.js} +1 -1
- package/dist/chunks/{notification-bell-BUdmlEsb.js → notification-bell-cYCkxEbp.js} +3 -3
- package/dist/chunks/{resource-management-panel-B44u1bn9.js → resource-management-panel-B_bDGuq_.js} +2 -2
- package/dist/chunks/{resource-management-panel-CwFqah6P.js → resource-management-panel-L51m1i4h.js} +1 -1
- package/dist/chunks/{use-visual-utils-C5IqT21V.js → use-visual-utils-Cp5KVbr6.js} +1 -1
- package/dist/chunks/{use-visual-utils-CrpWH7gW.js → use-visual-utils-V6paZich.js} +1 -1
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +5 -5
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/dashboard.d.ts +7 -1
- package/dist/types/main.d.ts +9 -2
- package/dist/types/shared.d.ts +7 -1
- package/dist/types/surfboard.d.ts +7 -1
- package/dist/types/types.d.ts +7 -1
- package/package.json +1 -1
- package/dist/chunks/dashboard-controls-B2vul1xX.js +0 -1837
- package/dist/chunks/dashboard-controls-CzPVz6hs.js +0 -47
- package/dist/chunks/edit-dashboard-visual-_u9hxm-2.js +0 -193
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-DAhkssOV.js"),b=require("react");require("react-dom");const R=require("./notification-bell-DoIAAZqX.js"),As=require("./date-formatter-CqXdM6JO.js"),Ve=require("./dashboard-summary-settings-dialog-DMWYgbwB.js"),Es=require("./use-debounced-dirty-check-XHSwAefL.js"),be=require("./normalize-dashboard-for-dirty-check-B7NQDI1H.js"),$e=require("./editor-action-buttons-Dbs6eczj.js");function Is(t){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(o,a,r.get?r:{enumerable:!0,get:()=>t[a]})}}return o.default=t,Object.freeze(o)}const w=Is(b);/**
|
|
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 ks=s.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 Ts=s.createLucideIcon("Glasses",[["circle",{cx:"6",cy:"15",r:"4",key:"vux9w4"}],["circle",{cx:"18",cy:"15",r:"4",key:"18o8ve"}],["path",{d:"M14 15a2 2 0 0 0-2-2 2 2 0 0 0-2 2",key:"1ag4bs"}],["path",{d:"M2.5 13 5 7c.7-1.3 1.4-2 3-2",key:"1hm1gs"}],["path",{d:"M21.5 13 19 7c-.7-1.3-1.5-2-3-2",key:"1r31ai"}]]);/**
|
|
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 Os=s.createLucideIcon("Menu",[["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}],["line",{x1:"4",x2:"20",y1:"6",y2:"6",key:"1owob3"}],["line",{x1:"4",x2:"20",y1:"18",y2:"18",key:"yk5zj1"}]]);/**
|
|
17
|
+
* @license lucide-react v0.453.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const Ps=s.createLucideIcon("Moon",[["path",{d:"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z",key:"a7tn18"}]]);/**
|
|
22
|
+
* @license lucide-react v0.453.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const _s=s.createLucideIcon("ShieldX",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m14.5 9.5-5 5",key:"17q4r4"}],["path",{d:"m9.5 9.5 5 5",key:"18nt4w"}]]);/**
|
|
27
|
+
* @license lucide-react v0.453.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const Us=s.createLucideIcon("Sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]);var ye={exports:{}},je={};/**
|
|
32
|
+
* @license React
|
|
33
|
+
* use-sync-external-store-shim.production.js
|
|
34
|
+
*
|
|
35
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
36
|
+
*
|
|
37
|
+
* This source code is licensed under the MIT license found in the
|
|
38
|
+
* LICENSE file in the root directory of this source tree.
|
|
39
|
+
*/var Ke;function Fs(){if(Ke)return je;Ke=1;var t=b;function o(n,u){return n===u&&(n!==0||1/n===1/u)||n!==n&&u!==u}var a=typeof Object.is=="function"?Object.is:o,r=t.useState,l=t.useEffect,c=t.useLayoutEffect,d=t.useDebugValue;function m(n,u){var p=u(),f=r({inst:{value:p,getSnapshot:u}}),v=f[0].inst,S=f[1];return c(function(){v.value=p,v.getSnapshot=u,h(v)&&S({inst:v})},[n,p,u]),l(function(){return h(v)&&S({inst:v}),n(function(){h(v)&&S({inst:v})})},[n]),d(p),p}function h(n){var u=n.getSnapshot;n=n.value;try{var p=u();return!a(n,p)}catch{return!0}}function j(n,u){return u()}var x=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?j:m;return je.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:x,je}var Se={};/**
|
|
40
|
+
* @license React
|
|
41
|
+
* use-sync-external-store-shim.development.js
|
|
42
|
+
*
|
|
43
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
44
|
+
*
|
|
45
|
+
* This source code is licensed under the MIT license found in the
|
|
46
|
+
* LICENSE file in the root directory of this source tree.
|
|
47
|
+
*/var Qe;function Rs(){return Qe||(Qe=1,process.env.NODE_ENV!=="production"&&function(){function t(p,f){return p===f&&(p!==0||1/p===1/f)||p!==p&&f!==f}function o(p,f){x||l.startTransition===void 0||(x=!0,console.error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));var v=f();if(!n){var S=f();c(v,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),n=!0)}S=d({inst:{value:v,getSnapshot:f}});var D=S[0].inst,I=S[1];return h(function(){D.value=v,D.getSnapshot=f,a(D)&&I({inst:D})},[p,v,f]),m(function(){return a(D)&&I({inst:D}),p(function(){a(D)&&I({inst:D})})},[p]),j(v),v}function a(p){var f=p.getSnapshot;p=p.value;try{var v=f();return!c(p,v)}catch{return!0}}function r(p,f){return f()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=b,c=typeof Object.is=="function"?Object.is:t,d=l.useState,m=l.useEffect,h=l.useLayoutEffect,j=l.useDebugValue,x=!1,n=!1,u=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?r:o;Se.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:u,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Se}process.env.NODE_ENV==="production"?ye.exports=Fs():ye.exports=Rs();var Gs=ye.exports;function Bs(){const{setTheme:t}=s.useTheme(),o=s.useDashboardStore(a=>a.actions.setDashboardTheme);return e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(s.Button,{className:"h-7 p-2",variant:"ghost",size:"sm",children:[e.jsx(Us,{strokeWidth:1.5,className:"h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"}),e.jsx(Ps,{strokeWidth:1.5,className:"absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"}),e.jsx("span",{className:"sr-only",children:"Toggle theme"})]})}),e.jsxs(s.DropdownMenuContent,{align:"end",children:[e.jsx(s.DropdownMenuItem,{onClick:()=>{t("light"),o("light")},children:"Light"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("dark"),o("dark")},children:"Dark"}),e.jsx(s.DropdownMenuItem,{onClick:()=>{t("system"),o("system")},children:"System"})]})]})}async function qs(t,o,a,r,l){if(!l)return null;const c=JSON.stringify(a),d=`${t}/v1/lens`;return await s.postRequest(d,l,{name:o,template:c,filterValues:r,operation:"create"})}async function De(t,o,a){if(!a)return null;const{id:r,template:l,filterValues:c,isDefault:d,shared:m}=o,h=`${t}/v1/lens`;return await s.postRequest(h,a,{lensId:r,template:l,filterValues:c,isDefault:d,shared:m,operation:"update"})}async function Hs(t,o,a){if(!a)return null;const r=`${t}/v1/lens`;return await s.postRequest(r,a,{operation:"delete",lensId:o})}function zs(){const[t,o]=b.useState(""),[a,r]=b.useState(!1),l=s.useDashboardStore(S=>S.lenses),{setLenses:c,setSelectedLensId:d}=s.useDashboardActions(),[m,h]=b.useState(!1),[j,x]=b.useState(!1),n=s.useDashboardStore(S=>S.dashboard),u=s.useDashboardStore(S=>S.filterValues),{authToken:p,tokenProps:f}=s.useSemaphorContext();async function v(){h(!0);const S=await qs(f.apiServiceUrl,t,n,u,p==null?void 0:p.accessToken);S&&(c([...l||[],S]),d(S.id),x(!1)),h(!1)}return e.jsxs(s.Dialog,{open:j,onOpenChange:x,children:[e.jsx(s.DialogTrigger,{asChild:!0,children:e.jsxs(s.Button,{variant:"secondary",className:"h-7 p-2",size:"sm",children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Lens"]})}),e.jsxs(s.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:"Create Lens"}),e.jsx(s.DialogDescription,{children:"Lenses are private by default and are only visible to you."})]}),e.jsx("div",{className:"grid gap-4 py-4",children:e.jsxs("div",{className:"grid grid-cols-8 items-center gap-4",children:[e.jsx(s.Label,{className:"text-right",children:"Name"}),e.jsx(s.Input,{value:t,onChange:S=>{o(S.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),a&&e.jsx("p",{className:"text-sm",children:"The lens name already exists. Use a differnet name."}),e.jsx(s.DialogFooter,{children:e.jsx(s.Button,{size:"sm",variant:"outline",type:"submit",onClick:v,disabled:m,children:m?"Creating...":"Add"})})]})]})}function Vs(){const[t,o]=b.useState(!1),a=s.useDashboardStore(n=>n.lenses),r=s.useDashboardStore(n=>n.selectedLensId),{setLenses:l,setSelectedLensId:c}=s.useDashboardActions(),{authToken:d,tokenProps:m}=s.useSemaphorContext();async function h(n){c(n)}async function j(n){if(await Hs(m.apiServiceUrl,n,d==null?void 0:d.accessToken)){const p=a==null?void 0:a.filter(f=>f.id!==n);l(p||[]),c("original")}}async function x(n){const u=a==null?void 0:a.map(v=>v.id===n.id?{...v,isDefault:!n.isDefault}:{...v,isDefault:!1});l(u||[]);const p={...n,isDefault:!n.isDefault};await De(m.apiServiceUrl,p,d==null?void 0:d.accessToken);const f=a==null?void 0:a.find(v=>v.isDefault);if(f&&f.id!==n.id){const v={...f,isDefault:!1};await De(m.apiServiceUrl,v,d==null?void 0:d.accessToken)}}return e.jsxs(s.DropdownMenu,{open:t,onOpenChange:o,children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"Lenses",className:"h-7 p-2",children:e.jsx(Ts,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-60",children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{}),e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:h,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),a==null?void 0:a.map(n=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:n.id,children:[e.jsx("p",{children:n.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:u=>{u.preventDefault(),x(n)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!n.isDefault,"text-green-500":n.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:u=>{u.preventDefault(),j(n.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},n.id))]})]})]})}function $s(){const{displayPreferences:t,shouldShowElement:o}=s.useDisplayPreferences(),{currentUser:a,userContext:r}=s.useCurrentUserInfo(),l=b.useMemo(()=>s.getRoleBasedDisplayOverrides(a),[a]),c=b.useMemo(()=>m=>l&&l[m]!==void 0&&l[m]===!1?!1:o(m),[l,o,t]),d=b.useMemo(()=>{var m,h,j,x,n;return{canEdit:((m=r==null?void 0:r.permissions)==null?void 0:m.canEdit)??s.canUserEdit(a),canUseFilters:((h=r==null?void 0:r.permissions)==null?void 0:h.canEdit)??s.canUserUseFilters(a),canManageDashboards:((j=r==null?void 0:r.permissions)==null?void 0:j.canCreateDashboard)??s.canUserManageDashboards(a),canCreateDashboards:((x=r==null?void 0:r.permissions)==null?void 0:x.canCreateDashboard)??s.canUserCreateDashboards(a),canAccessVisuals:((n=r==null?void 0:r.permissions)==null?void 0:n.canEdit)??s.canUserAccessVisuals(a)}},[a,r]);return{displayPreferences:t,shouldShowElement:c,permissions:d,currentUser:a}}const Ks=async(t,o,a)=>{const r=`${t}/management/v1/groups`;return await s.postRequestRegular(r,o,a)},Qs=async(t,o,a)=>{const r=`${t}/management/v1/groups/${a}`,l=await fetch(r,{method:"DELETE",headers:{Authorization:`Bearer ${o}`}});if(!l.ok){const c=await l.text();throw new Error(c||"Failed to delete group")}},Ws=async(t,o,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`;return await s.postRequestRegular(l,o,r)},Js=async(t,o,a,r)=>{const l=`${t}/management/v1/groups/${a}/members`,c=await fetch(l,{method:"DELETE",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o}`},body:JSON.stringify(r)});if(!c.ok){const d=await c.text();throw new Error(d||"Failed to remove group members")}};function Xs(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Ks(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:()=>{a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:r=>{console.error("Failed to create group:",r),s.ue.error("Failed to create group",{description:r.message})}})}function Ys(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:r=>Qs(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["groups"]}),a.removeQueries({queryKey:["group",l]}),s.ue.success("Group deleted successfully")},onError:r=>{console.error("Failed to delete group:",r),s.ue.error("Failed to delete group",{description:r.message})}})}function Zs(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>Ws(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:r=>{console.error("Failed to add group members:",r),s.ue.error("Failed to add members",{description:r.message})}})}function et(){const{authToken:t,tokenProps:o}=s.useSemaphorContext(),a=s.useQueryClient();return s.useMutation({mutationFn:({groupId:r,data:l})=>Js(o.apiServiceUrl,(t==null?void 0:t.accessToken)||"",r,l),onSuccess:(r,l)=>{a.invalidateQueries({queryKey:["group",l.groupId]}),a.invalidateQueries({queryKey:["group-members",l.groupId]}),a.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:r=>{console.error("Failed to remove group members:",r),s.ue.error("Failed to remove members",{description:r.message})}})}function st({onSuccess:t,tenantId:o,isTenantUser:a}){const[r,l]=b.useState(""),[c,d]=b.useState(""),[m,h]=b.useState({}),j=Xs(),x=()=>{const u={};return r.trim()?r.length<3?u.name="Group name must be at least 3 characters":r.length>50&&(u.name="Group name must be less than 50 characters"):u.name="Group name is required",c&&c.length>200&&(u.description="Description must be less than 200 characters"),h(u),Object.keys(u).length===0},n=async u=>{if(u.preventDefault(),!x())return;const p={name:r.trim(),description:c.trim()||void 0,type:a?"TENANT_GROUP":"ORG_GROUP",...a&&o?{tenantId:o}:{}};try{await j.mutateAsync(p),l(""),d(""),h({}),t()}catch(f){console.error("Failed to create group:",f)}};return e.jsxs("form",{onSubmit:n,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-name",children:["Group Name ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(s.Input,{id:"group-name",placeholder:"e.g., Marketing Team, Engineering Squad",value:r,onChange:u=>{l(u.target.value),m.name&&h(p=>({...p,name:""}))},className:m.name?"border-destructive":"",disabled:j.isPending}),m.name&&e.jsx("p",{className:"text-sm text-destructive",children:m.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(s.Label,{htmlFor:"group-description",children:["Description",e.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:"(optional)"})]}),e.jsx(s.Textarea,{id:"group-description",placeholder:"Describe the purpose of this group...",value:c,onChange:u=>{d(u.target.value),m.description&&h(p=>({...p,description:""}))},className:m.description?"border-destructive":"",disabled:j.isPending,rows:3}),m.description&&e.jsx("p",{className:"text-sm text-destructive",children:m.description}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[c.length,"/200 characters"]})]}),e.jsx("div",{className:"rounded-lg border bg-muted/50 p-4",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx(s.CircleAlert,{className:"h-4 w-4 mt-0.5 text-muted-foreground"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"This group will be accessible to users in your workspace. You can add members after creating the group."})]})})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx(s.Button,{type:"button",variant:"outline",onClick:()=>{l(""),d(""),h({})},disabled:j.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:j.isPending||!r.trim(),children:j.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Create Group"]})})]})]})}function tt(t,o=[]){let a=[];function r(c,d){const m=w.createContext(d);m.displayName=c+"Context";const h=a.length;a=[...a,d];const j=n=>{var D;const{scope:u,children:p,...f}=n,v=((D=u==null?void 0:u[t])==null?void 0:D[h])||m,S=w.useMemo(()=>f,Object.values(f));return e.jsx(v.Provider,{value:S,children:p})};j.displayName=c+"Provider";function x(n,u){var v;const p=((v=u==null?void 0:u[t])==null?void 0:v[h])||m,f=w.useContext(p);if(f)return f;if(d!==void 0)return d;throw new Error(`\`${n}\` must be used within \`${c}\``)}return[j,x]}const l=()=>{const c=a.map(d=>w.createContext(d));return function(m){const h=(m==null?void 0:m[t])||c;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:h}}),[m,h])}};return l.scopeName=t,[r,at(l,...o)]}function at(...t){const o=t[0];if(t.length===1)return o;const a=()=>{const r=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const d=r.reduce((m,{useScope:h,scopeName:j})=>{const n=h(c)[`__scope${j}`];return{...m,...n}},{});return w.useMemo(()=>({[`__scope${o.scopeName}`]:d}),[d])}};return a.scopeName=o.scopeName,a}var rt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Ne=rt.reduce((t,o)=>{const a=s.createSlot(`Primitive.${o}`),r=w.forwardRef((l,c)=>{const{asChild:d,...m}=l,h=d?a:o;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(h,{...m,ref:c})});return r.displayName=`Primitive.${o}`,{...t,[o]:r}},{});function nt(){return Gs.useSyncExternalStore(ot,()=>!0,()=>!1)}function ot(){return()=>{}}var we="Avatar",[it]=tt(we),[lt,Je]=it(we),Xe=w.forwardRef((t,o)=>{const{__scopeAvatar:a,...r}=t,[l,c]=w.useState("idle");return e.jsx(lt,{scope:a,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(Ne.span,{...r,ref:o})})});Xe.displayName=we;var Ye="AvatarImage",Ze=w.forwardRef((t,o)=>{const{__scopeAvatar:a,src:r,onLoadingStatusChange:l=()=>{},...c}=t,d=Je(Ye,a),m=ct(r,c),h=s.useCallbackRef(j=>{l(j),d.onImageLoadingStatusChange(j)});return s.useLayoutEffect2(()=>{m!=="idle"&&h(m)},[m,h]),m==="loaded"?e.jsx(Ne.img,{...c,ref:o,src:r}):null});Ze.displayName=Ye;var es="AvatarFallback",ss=w.forwardRef((t,o)=>{const{__scopeAvatar:a,delayMs:r,...l}=t,c=Je(es,a),[d,m]=w.useState(r===void 0);return w.useEffect(()=>{if(r!==void 0){const h=window.setTimeout(()=>m(!0),r);return()=>window.clearTimeout(h)}},[r]),d&&c.imageLoadingStatus!=="loaded"?e.jsx(Ne.span,{...l,ref:o}):null});ss.displayName=es;function We(t,o){return t?o?(t.src!==o&&(t.src=o),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function ct(t,{referrerPolicy:o,crossOrigin:a}){const r=nt(),l=w.useRef(null),c=r?(l.current||(l.current=new window.Image),l.current):null,[d,m]=w.useState(()=>We(c,t));return s.useLayoutEffect2(()=>{m(We(c,t))},[c,t]),s.useLayoutEffect2(()=>{const h=n=>()=>{m(n)};if(!c)return;const j=h("loaded"),x=h("error");return c.addEventListener("load",j),c.addEventListener("error",x),o&&(c.referrerPolicy=o),typeof a=="string"&&(c.crossOrigin=a),()=>{c.removeEventListener("load",j),c.removeEventListener("error",x)}},[c,a,o]),d}var ts=Xe,as=Ze,rs=ss;const Ce=w.forwardRef(({className:t,...o},a)=>e.jsx(ts,{ref:a,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...o}));Ce.displayName=ts.displayName;const dt=w.forwardRef(({className:t,...o},a)=>e.jsx(as,{ref:a,className:s.cn("aspect-square h-full w-full",t),...o}));dt.displayName=as.displayName;const Me=w.forwardRef(({className:t,...o},a)=>e.jsx(rs,{ref:a,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...o}));Me.displayName=rs.displayName;function ut({open:t,onOpenChange:o,group:a,onUpdate:r}){const[l,c]=b.useState("members"),[d,m]=b.useState(""),[h,j]=b.useState([]),[x,n]=b.useState([]),{data:u,isLoading:p,refetch:f}=s.useGroupMembers(a.id),v=a.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:D}=s.useUnifiedUsers({type:v,tenantId:a.tenantId||void 0,active:!0,limit:100}),I=Zs(),k=et(),A=(u==null?void 0:u.members)||[],O=b.useMemo(()=>new Set(A.map(g=>g.userId)),[A]),P=b.useMemo(()=>S.filter(g=>!O.has(g.id)),[S,O]),_=b.useMemo(()=>{if(!d)return P;const g=d.toLowerCase();return P.filter(C=>{var M,F;return((M=C.name)==null?void 0:M.toLowerCase().includes(g))||((F=C.email)==null?void 0:F.toLowerCase().includes(g))})},[P,d]),y=b.useMemo(()=>{if(!d)return A;const g=d.toLowerCase();return A.filter(C=>{var M,F,W,J;return((F=(M=C.user)==null?void 0:M.name)==null?void 0:F.toLowerCase().includes(g))||((J=(W=C.user)==null?void 0:W.email)==null?void 0:J.toLowerCase().includes(g))})},[A,d]),U=async()=>{if(h.length!==0)try{await I.mutateAsync({groupId:a.id,data:{userIds:h,userType:v==="tenant"?"tenant":"org"}}),j([]),c("members"),f(),r==null||r()}catch(g){console.error("Failed to add members:",g)}},re=async()=>{if(x.length!==0)try{await k.mutateAsync({groupId:a.id,data:{userIds:x}}),n([]),f(),r==null||r()}catch(g){console.error("Failed to remove members:",g)}},G=g=>{j(C=>C.includes(g)?C.filter(M=>M!==g):[...C,g])},B=g=>{n(C=>C.includes(g)?C.filter(M=>M!==g):[...C,g])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:o,children:e.jsxs(s.DialogContent,{className:"max-w-3xl max-h-[80vh]","aria-describedby":"group-members-description",children:[e.jsxs(s.DialogHeader,{children:[e.jsx(s.DialogTitle,{children:a.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[A.length," ",A.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",a.name," group"]})]}),e.jsxs(s.Tabs,{value:l,onValueChange:g=>{c(g),m(""),n([])},className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsx(s.TabsTrigger,{value:"members",children:"Current Members"}),e.jsx(s.TabsTrigger,{value:"add",children:"Add Members"})]}),e.jsxs(s.TabsContent,{value:"members",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{placeholder:"Search members...",value:d,onChange:g=>m(g.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:x.length>0?"h-[300px]":"h-[350px]",children:p?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):y.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:d?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:y.map(g=>e.jsx(mt,{member:g,selected:x.includes(g.userId),onToggle:()=>B(g.userId)},g.id))})}),x.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[x.length," member",x.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:re,disabled:k.isPending,children:k.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Removing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.Trash2,{className:"mr-2 h-4 w-4"}),"Remove Selected"]})})]})]}),e.jsxs(s.TabsContent,{value:"add",className:"mt-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{placeholder:"Search users to add...",value:d,onChange:g=>m(g.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:D?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(g=>e.jsx(s.Skeleton,{className:"h-16 w-full"},g))}):_.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.UserPlus,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No available users"}),e.jsx("p",{className:"text-xs mt-1",children:d?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:_.map(g=>e.jsx(ht,{user:g,selected:h.includes(g.id),onToggle:()=>G(g.id)},g.id))})}),h.length>0&&e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h.length," user",h.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:U,disabled:I.isPending,children:I.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Adding..."]}):e.jsxs(e.Fragment,{children:[e.jsx(s.UserPlus,{className:"mr-2 h-4 w-4"}),"Add Members"]})})]})]})]})]})})})}function mt({member:t,selected:o,onToggle:a}){var l,c,d,m;const r=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(h=>h[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(Ce,{className:"h-8 w-8",children:e.jsx(Me,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((d=t.user)==null?void 0:d.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function ht({user:t,selected:o,onToggle:a}){var l;const r=((l=t.name)==null?void 0:l.split(" ").map(c=>c[0]).join("").toUpperCase())||"?";return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border bg-card hover:bg-muted/50 cursor-pointer",onClick:a,children:[e.jsx(s.Checkbox,{checked:o}),e.jsx(Ce,{className:"h-8 w-8",children:e.jsx(Me,{className:"text-xs",children:r})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:t.name}),e.jsx("p",{className:"text-xs text-muted-foreground",children:t.email})]})]})}function pt({open:t,onOpenChange:o}){const[a,r]=b.useState("groups"),[l,c]=b.useState(""),[d,m]=b.useState(null),[h,j]=b.useState(!1),[x,n]=b.useState(null),{tokenProps:u}=s.useSemaphorContext(),{currentUser:p}=s.useCurrentUserInfo(),f=Ys(),v=(p==null?void 0:p.type)==="tenant",S=u==null?void 0:u.tenantId,{groups:D,isLoading:I,refetch:k}=s.useGroups({type:v?"TENANT_GROUP":"all",tenantId:v?S:void 0,includeMembers:!1}),A=D.filter(y=>{var U;return y.name.toLowerCase().includes(l.toLowerCase())||((U=y.description)==null?void 0:U.toLowerCase().includes(l.toLowerCase()))}),O=async()=>{if(x)try{await f.mutateAsync(x.id),n(null),k()}catch(y){console.error("Failed to delete group:",y)}},P=y=>{m(y),j(!0)},_=()=>{r("groups"),k()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:o,children:e.jsxs(s.DialogContent,{className:"max-w-4xl max-h-[80vh]",children:[e.jsxs(s.DialogHeader,{children:[e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-5 w-5"}),"Group Management"]}),e.jsx(s.DialogDescription,{children:"Manage your groups, create new groups, and control group membership"})]}),e.jsxs(s.Tabs,{value:a,onValueChange:r,className:"mt-4",children:[e.jsxs(s.TabsList,{className:"grid w-full grid-cols-2",children:[e.jsxs(s.TabsTrigger,{value:"groups",className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"h-4 w-4"}),"Groups"]}),e.jsxs(s.TabsTrigger,{value:"create",className:"flex items-center gap-2",children:[e.jsx(s.Plus,{className:"h-4 w-4"}),"Create Group"]})]}),e.jsx(s.TabsContent,{value:"groups",className:"mt-4",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(s.Search,{className:"absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx(s.Input,{placeholder:"Search groups...",value:l,onChange:y=>c(y.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:I?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(y=>e.jsx(s.Skeleton,{className:"h-24 w-full"},y))}):A.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(s.Users,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{className:"text-sm font-medium",children:"No groups found"}),e.jsx("p",{className:"text-xs mt-1",children:l?"Try a different search":"Create your first group to get started"})]}):e.jsx("div",{className:"space-y-3",children:A.map(y=>e.jsx(xt,{group:y,onManageMembers:()=>P(y),onDelete:()=>n(y),currentUserId:p==null?void 0:p.id},y.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(st,{onSuccess:_,tenantId:S,isTenantUser:v})})]})]})}),d&&e.jsx(ut,{open:h,onOpenChange:j,group:d,onUpdate:()=>k()}),e.jsx(s.AlertDialog,{open:!!x,onOpenChange:()=>n(null),children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Group"}),e.jsxs(s.AlertDialogDescription,{children:['Are you sure you want to delete "',x==null?void 0:x.name,'"? This action cannot be undone and will remove all members from the group.']})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:O,disabled:f.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:f.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function xt({group:t,onManageMembers:o,onDelete:a,currentUserId:r}){const l=t.createdBy===r;return e.jsx("div",{className:"rounded-lg border bg-card p-4 transition-colors hover:bg-muted/50",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("h4",{className:"font-medium",children:t.name}),t.description&&e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:t.description})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(s.Users,{className:"h-3 w-3"}),t.memberCount," ",t.memberCount===1?"member":"members"]}),e.jsxs("span",{children:["Created ",As.format(new Date(t.createdAt),"MMM d, yyyy")]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:o,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),l&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:a,title:"Delete group",className:"text-destructive hover:text-destructive",children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]})})}function gt(){var Ue,Fe,Re,Ge;R.useExportRecovery(),R.useExportPolling();const{authToken:t,tokenProps:o,id:a}=s.useSemaphorContext(),{isLocalDev:r}=s.useDashboardPreferences(),{permissions:l}=$s(),c=s.useHasDashboardId(),{isLoading:d}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const m=s.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),h=s.useDashboardStore(i=>i.lenses),j=s.useDashboardStore(i=>i.selectedLensId),x=h==null?void 0:h.find(i=>i.id===j),n=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const u=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:p}=s.useDashboardStore(i=>i.actions),[f,v]=b.useState(!1),[S,D]=b.useState(!1),[I,k]=b.useState(!1),[A,O]=b.useState(!1),[P,_]=b.useState(!1),[y,U]=b.useState(!1),[re,G]=b.useState(!1),[B,g]=b.useState(null),[C,M]=b.useState(!1),F=s.useDashboardStore(i=>i.isDashboardPanelOpen),W=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),J=s.useDashboardStore(i=>i.filterValues),N=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const H=s.useManagementStore(i=>i.selectedDashboard),X=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const Y=H?(Fe=H==null?void 0:H.permissions)==null?void 0:Fe.canEdit:(Ue=X==null?void 0:X.permissions)==null?void 0:Ue.canEdit,ne=s.useDashboardStore(i=>i.showFilters),ns=s.useAssistantLayoutStore(i=>i.setPanelOpen),os=s.useDashboardStore(i=>i.showDashboardJSON),oe=s.useDashboardStore(i=>i.onSaveFunction),is=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:Le,setShowDashboardJSON:Ae}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:Ee,clearSelectedDashboard:ie}=s.useManagementStore(i=>i.actions),{resources:Z}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:le}=s.useUserPreferences(),ls=((Re=le==null?void 0:le.preference)==null?void 0:Re.defaultDashboardId)||null,{mutate:cs,isPending:ds}=s.useDefaultDashboardMutation(),{currentUser:us}=s.useCurrentUserInfo(),ms=s.canUserManageGroups(us),q=H||X,Ie=q?{id:q.id,title:(n==null?void 0:n.title)||q.title||"Dashboard"}:null,{handleAddNewFrame:hs}=s.useAddNewFrame(),[ce,de]=b.useState(!1),[ps,z]=b.useState(!1),[ue,ee]=b.useState("close"),V=s.useUpdateResource(s.ResourceType.DASHBOARD),[T,me]=b.useState(null),xs=async(i,L)=>{if(!(n!=null&&n.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:n.id,newTitle:i,previousTitle:L}),V.mutate({resourceId:n.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:Q=>{console.error("Failed to update dashboard title:",Q),s.ue.error("Failed to update dashboard title"),p(L)}})};b.useEffect(()=>{if(Z&&Z.length>0){const i=n==null?void 0:n.id;if(i){const L=Z.find(Q=>Q.id===i);L&&Ee(L)}}},[Z,n==null?void 0:n.id,Ee]);const se=o.orgUserId||o.tenantId,ke=u&&!N&&se&&Y,{setDashboard:he}=s.useDashboardStore(i=>i.actions),gs=()=>{Le(!0)},pe=()=>{Le(!1),Ae(!1),me(null)};R.usePristineSnapshotInitializer(u,n,T,i=>me(i));const{isDirty:Te,isDirtyPending:fs,resetDirty:te}=Es.useDebouncedDirtyCheck(n,T,300,1e3,be.serializeDashboardForDirtyCheck),Oe=b.useCallback(()=>T?be.serializeDashboardForDirtyCheck(n)!==be.serializeDashboardForDirtyCheck(T):!1,[n,T]),xe=Te||fs,$=ce||V.isPending,vs=()=>{Oe()?(ee("close"),z(!0)):(pe(),te())},bs=async()=>{await ge({closeAfterSave:!0,navigateHomeAfterSave:ue==="home"})},js=()=>{T&&he(T),pe(),ue==="home"&&ie(),ee("close"),z(!1),te()},Ss=()=>{T&&(he(T),te())},ys=()=>{if(u&&Oe()){ee("home"),z(!0);return}ie()};async function ge(i){const L=(i==null?void 0:i.closeAfterSave)??C,Q=(i==null?void 0:i.navigateHomeAfterSave)??!1;M(L),L&&z(!1);const Ms=s.cloneDeep(n);G(!0),g(null),de(!0);const Ls={template:n};V.mutate({resourceId:n.id,data:Ls},{onSuccess:E=>{var qe,He,ze;const Be=(E==null?void 0:E.id)||((qe=E==null?void 0:E.dashboard)==null?void 0:qe.id)||((He=E==null?void 0:E.resource)==null?void 0:He.id)||((ze=E==null?void 0:E.template)==null?void 0:ze.id)||null;if(!n.id&&Be){const ve=s.useAIInteractionStore.getState(),ae=ve.pendingDashboardDraftMigration;(ae==null?void 0:ae.scopeKey)===m?ve.actions.setPendingDashboardDraftMigrationExpectedDashboardId(Be):ae&&ve.actions.clearPendingDashboardDraftMigration()}de(!1),s.ue.success("Dashboard saved!"),me(Ms),G(!1),M(!1),L&&(pe(),te(),Q&&ie()),ee("close")},onError:()=>{de(!1),g("Failed to save dashboard. Please try again."),s.ue.error("Failed to save dashboard")}})}async function Ds(){if(v(!0),!j||!x)return;const i=JSON.stringify(n),L={...x,template:i,filterValues:J};await De(o.apiServiceUrl,L,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),oe==null||oe(n),v(!1)}const Pe=(x==null?void 0:x.name)||n.title;V.isPending&&console.log("Title during update:",{title:Pe,dashboardStateTitle:n.title,dashboardId:n==null?void 0:n.id,currentLensName:x==null?void 0:x.name});const _e=o.orgUserId||o.tenantId&&o.endUserId&&o.endUserEmail,Ns=!!_e&&!!(t!=null&&t.accessToken)&&!!(o!=null&&o.apiServiceUrl),ws=c,K=(n==null?void 0:n.id)||null,fe=!!K&&ls===K,Cs=()=>{K&&cs({dashboardId:fe?null:K})};return e.jsxs("div",{className:"flex h-11 shrink-0 items-center justify-between gap-2 overflow-x-auto border-b px-4 py-2",role:"dashboard-controls",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[_e&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{W(!F)},className:"h-7 p-2",children:e.jsx(Os,{className:"h-4 w-4"})}),ws&&!N&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:ys,className:"h-7 p-2",children:e.jsx(s.House,{className:"h-4 w-4"})})]}),!N&&c&&(d?e.jsx("div",{className:"h-4 w-28 rounded-md bg-muted/70 animate-pulse","aria-label":"Loading dashboard title",role:"status",children:e.jsx("span",{className:"sr-only",children:"Loading dashboard title"})}):e.jsxs(e.Fragment,{children:[e.jsx(s.EditableText,{value:Pe||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:Y,dashboardId:n==null?void 0:n.id});const L=(n==null?void 0:n.title)||"";p(i),xs(i,L)},isEditable:Y&&!x,displayClassName:"text-sm font-medium",inputClassName:"text-sm font-medium",placeholder:"Dashboard Title",isPending:V.isPending}),Ns&&K&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"icon",onClick:Cs,disabled:ds||!(t!=null&&t.accessToken)||!(o!=null&&o.apiServiceUrl),className:"h-7 w-7",children:e.jsx(s.Star,{className:s.cn("h-4 w-4 transition-colors",fe?"fill-yellow-400 text-yellow-400":"text-muted-foreground hover:text-yellow-400")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:fe?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[N&&e.jsxs(e.Fragment,{children:[e.jsx(R.AdvancedModeToggle,{className:"mr-2"}),e.jsx(R.VisualEditingControls,{className:"h-7"})]}),r&&!N&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{tooltip:"Copy Token",onClick:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},className:"h-7 p-2",children:e.jsx(s.Copy,{className:"h-4 w-4"})}),e.jsx(s.IconButton,{tooltip:"Invalidate Token",onClick:()=>s.invalidateToken(o.apiServiceUrl),className:"h-7 p-2",children:e.jsx(_s,{className:"h-4 w-4"})})]}),!N&&c&&e.jsx(s.DownloadPdf,{}),!N&&c&&e.jsx(R.NotificationBell,{}),!N&&c&&((Ge=q==null?void 0:q.permissions)==null?void 0:Ge.canShare)&&e.jsx(s.IconButton,{tooltip:"Share Dashboard",onClick:()=>D(!0),className:"h-7 p-2",children:e.jsx(s.Share2,{className:"h-4 w-4"})}),!N&&u&&l.canUseFilters&&c&&e.jsxs(s.Button,{className:"h-7 px-2",variant:"outline",onClick:()=>{ne||ns("dashboard",!1),is(!ne)},size:"sm",children:[ne?e.jsx(ks,{className:"mr-2 h-4 w-4"}):e.jsx(s.Filter,{className:"mr-2 h-4 w-4"}),"Filter"]}),u&&!N&&se&&r&&c&&e.jsx(zs,{}),!N&&se&&r&&c&&e.jsx(Vs,{}),u&&!N&&se&&x&&r&&c&&e.jsxs(s.Button,{className:"h-7 p-2",variant:"secondary",disabled:f,onClick:Ds,size:"sm",children:[e.jsx($e.Save,{className:"mr-2 h-4 w-4"}),"Save Lens"]}),u&&!N&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",size:"sm",disabled:!u,onClick:()=>hs(),children:[e.jsx(s.Plus,{className:"mr-2 h-4 w-4"}),"Visual"]}),!N&&!u&&Y&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:gs,size:"sm",children:[e.jsx(s.Pencil,{className:"mr-2 h-4 w-4"}),"Edit"]}),ke&&c&&Te&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:Ss,size:"sm",disabled:$,children:[e.jsx(s.Undo2,{className:"mr-2 h-4 w-4"}),"Undo"]}),ke&&c&&e.jsxs("div",{className:"relative inline-flex",children:[e.jsxs(s.Button,{className:s.cn("h-7 p-2",!xe&&"opacity-60"),disabled:$||!xe,onClick:()=>ge(),size:"sm",children:[$?e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx($e.Save,{className:"mr-2 h-4 w-4"}),$?"Saving...":"Save"]}),xe&&!$&&e.jsx("span",{"aria-hidden":"true",className:"pointer-events-none absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full bg-orange-500 ring-2 ring-background"})]}),!N&&u&&r&&c&&e.jsx("div",{className:"flex items-center space-x-2",children:e.jsx(s.Button,{className:"h-7 p-2",onClick:()=>Ae(!os),size:"sm",variant:"ghost",children:e.jsx(s.Code,{className:"h-4 w-4"})})}),!N&&r&&e.jsx(Bs,{}),u&&!N&&c&&e.jsxs(s.Button,{variant:"outline",className:"h-7 p-2",onClick:vs,children:[e.jsx(s.Cross2Icon,{className:"mr-2 h-4 w-4"}),"Close"]}),!N&&c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"h-8 w-8 rounded-md border border-transparent p-0 text-muted-foreground hover:bg-muted/50 hover:text-foreground",buttonProps:{"aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-4 w-4"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-xl border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Automation"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>O(!0),className:"flex items-center gap-2",children:[e.jsx(s.Clock,{className:"mr-2 h-4 w-4"}),"Schedule Dashboard"]}),e.jsx(s.DropdownMenuSeparator,{}),ms&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>k(!0),className:"flex items-center gap-2",children:[e.jsx(s.Users,{className:"mr-2 h-4 w-4"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{className:"px-2.5 text-xs font-medium text-muted-foreground",children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>_(!0),className:"flex items-center gap-2",children:[e.jsx(s.Calendar,{className:"mr-2 h-4 w-4"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>U(!0),className:"flex items-center gap-2",children:[e.jsx(s.FileText,{className:"mr-2 h-4 w-4"}),"Summary Settings"]})]})]}),S&&Ie&&e.jsx(s.ShareDialog,{resource:Ie,resourceType:s.ResourceType.DASHBOARD,onClose:()=>D(!1)}),e.jsx(pt,{open:I,onOpenChange:k}),(n==null?void 0:n.id)&&e.jsx(s.EmailScheduleDialog,{open:A,onOpenChange:O,dashboardId:n.id,dashboardName:n==null?void 0:n.title}),e.jsx(Ve.CalendarPreferencesDialog,{open:P,onOpenChange:_}),e.jsx(Ve.DashboardSummarySettingsDialog,{open:y,onOpenChange:U,dashboard:n,disabled:!u,onApply:i=>he({...n,summary:i})}),e.jsx(s.AlertDialog,{open:re,onOpenChange:i=>{!i&&ce&&!B||(G(i),i||(g(null),M(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:B?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:B?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:B?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{G(!1),g(null),M(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>ge({closeAfterSave:C,navigateHomeAfterSave:ue==="home"}),className:"m-0",children:"Retry"})]}):e.jsxs(s.AlertDialogAction,{disabled:!0,className:"m-0 cursor-default",children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]})})]})}),e.jsx(R.UnsavedChangesAlert,{open:ps,onOpenChange:i=>{z(i)},onSave:bs,onDiscard:js,isSaving:ce,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=gt;
|
|
@@ -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-DAhkssOV.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-DpSxZvI0.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-DpSxZvI0.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-VHKvmdqy.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-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;
|