react-semaphor 0.1.290 → 0.1.292
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/braces-0bzwctGp.js +23 -0
- package/dist/chunks/braces-hczcJsV8.js +6 -0
- package/dist/chunks/dashboard-controls-Db0F38eK.js +47 -0
- package/dist/chunks/dashboard-controls-DeUHM4uL.js +1970 -0
- package/dist/chunks/{dashboard-filter-controls-button-C4AMu723.js → dashboard-filter-controls-button-DDqEus_E.js} +54 -52
- package/dist/chunks/dashboard-filter-controls-button-DSQHVjjX.js +11 -0
- package/dist/chunks/{dashboard-json-C13EJaTK.js → dashboard-json-BDyKcoGT.js} +1 -1
- package/dist/chunks/{dashboard-json-BKs1UTLL.js → dashboard-json-COXiPm3N.js} +6 -6
- package/dist/chunks/{dashboard-summary-settings-dialog-fL9l0wUO.js → dashboard-summary-settings-dialog-CryMC_4x.js} +1 -1
- package/dist/chunks/{dashboard-summary-settings-dialog-T6aUgPAf.js → dashboard-summary-settings-dialog-DbcWMZsr.js} +1 -1
- package/dist/chunks/{edit-dashboard-visual-CKB34ird.js → edit-dashboard-visual-BqfzqW4i.js} +4 -9
- package/dist/chunks/{edit-dashboard-visual-CnVx0Xi7.js → edit-dashboard-visual-DLyimx6x.js} +11 -29
- package/dist/chunks/{index-Cr9Smn6Q.js → index-72yod5pb.js} +523 -516
- package/dist/chunks/{index-Cwg2SRSi.js → index-BQ6qu8FI.js} +93 -93
- package/dist/chunks/resource-management-panel-CSLGSJjC.js +6 -0
- package/dist/chunks/{resource-management-panel-DJgYduN9.js → resource-management-panel-DwPION_M.js} +22 -22
- package/dist/chunks/{use-create-flow-overlay-state-NGb4c5Ye.js → use-create-flow-overlay-state-UruHbtfS.js} +53 -53
- package/dist/chunks/{use-create-flow-overlay-state-DnI1SSKD.js → use-create-flow-overlay-state-zz9TYhdC.js} +1 -1
- package/dist/chunks/{use-visual-utils-ivCDI1cO.js → use-visual-utils-Bm-ZnkON.js} +1 -1
- package/dist/chunks/{use-visual-utils-BbxYtbzK.js → use-visual-utils-DPBqTRUC.js} +11 -11
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +21 -21
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/package.json +1 -1
- package/dist/chunks/dashboard-controls-BSbG43wo.js +0 -42
- package/dist/chunks/dashboard-controls-LtQ98rvL.js +0 -1938
- package/dist/chunks/dashboard-filter-controls-button-CgoIPOZZ.js +0 -11
- package/dist/chunks/resource-management-panel-Dv18tosO.js +0 -6
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { c as a } from "./index-72yod5pb.js";
|
|
2
|
+
/**
|
|
3
|
+
* @license lucide-react v0.453.0 - ISC
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the ISC license.
|
|
6
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
const c = a("Braces", [
|
|
9
|
+
[
|
|
10
|
+
"path",
|
|
11
|
+
{ d: "M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1", key: "ezmyqa" }
|
|
12
|
+
],
|
|
13
|
+
[
|
|
14
|
+
"path",
|
|
15
|
+
{
|
|
16
|
+
d: "M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",
|
|
17
|
+
key: "e1hn23"
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
]);
|
|
21
|
+
export {
|
|
22
|
+
c as B
|
|
23
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";const e=require("./index-BQ6qu8FI.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 a=e.createLucideIcon("Braces",[["path",{d:"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1",key:"ezmyqa"}],["path",{d:"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 1-2-2V5a2 2 0 0 0-2-2h-1",key:"e1hn23"}]]);exports.Braces=a;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BQ6qu8FI.js"),g=require("react");require("react-dom");const U=require("./dashboard-filter-controls-button-DSQHVjjX.js"),Hs=require("./date-formatter-CqXdM6JO.js"),ns=require("./dashboard-summary-settings-dialog-CryMC_4x.js"),zs=require("./use-debounced-dirty-check-XHSwAefL.js"),Ee=require("./normalize-dashboard-for-dirty-check-BXRUMVb2.js"),os=require("./use-create-flow-overlay-state-zz9TYhdC.js"),Vs=require("./braces-hczcJsV8.js");function Ks(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const r in t)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,a.get?a:{enumerable:!0,get:()=>t[r]})}}return n.default=t,Object.freeze(n)}const w=Ks(g);/**
|
|
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 Qs=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"}]]);/**
|
|
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 Js=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"}]]);/**
|
|
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 Ws=s.createLucideIcon("Monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]);/**
|
|
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 Ys=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 Xs=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 Zs=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 ke={exports:{}},Ae={};/**
|
|
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 is;function et(){if(is)return Ae;is=1;var t=g;function n(u,o){return u===o&&(u!==0||1/u===1/o)||u!==u&&o!==o}var r=typeof Object.is=="function"?Object.is:n,a=t.useState,l=t.useEffect,c=t.useLayoutEffect,h=t.useDebugValue;function m(u,o){var p=o(),x=a({inst:{value:p,getSnapshot:o}}),j=x[0].inst,S=x[1];return c(function(){j.value=p,j.getSnapshot=o,f(j)&&S({inst:j})},[u,p,o]),l(function(){return f(j)&&S({inst:j}),u(function(){f(j)&&S({inst:j})})},[u]),h(p),p}function f(u){var o=u.getSnapshot;u=u.value;try{var p=o();return!r(u,p)}catch{return!0}}function b(u,o){return o()}var d=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?b:m;return Ae.useSyncExternalStore=t.useSyncExternalStore!==void 0?t.useSyncExternalStore:d,Ae}var Ie={};/**
|
|
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 ls;function st(){return ls||(ls=1,process.env.NODE_ENV!=="production"&&function(){function t(p,x){return p===x&&(p!==0||1/p===1/x)||p!==p&&x!==x}function n(p,x){d||l.startTransition===void 0||(d=!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 j=x();if(!u){var S=x();c(j,S)||(console.error("The result of getSnapshot should be cached to avoid an infinite loop"),u=!0)}S=h({inst:{value:j,getSnapshot:x}});var N=S[0].inst,C=S[1];return f(function(){N.value=j,N.getSnapshot=x,r(N)&&C({inst:N})},[p,j,x]),m(function(){return r(N)&&C({inst:N}),p(function(){r(N)&&C({inst:N})})},[p]),b(j),j}function r(p){var x=p.getSnapshot;p=p.value;try{var j=x();return!c(p,j)}catch{return!0}}function a(p,x){return x()}typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());var l=g,c=typeof Object.is=="function"?Object.is:t,h=l.useState,m=l.useEffect,f=l.useLayoutEffect,b=l.useDebugValue,d=!1,u=!1,o=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?a:n;Ie.useSyncExternalStore=l.useSyncExternalStore!==void 0?l.useSyncExternalStore:o,typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"&&typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop=="function"&&__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error())}()),Ie}process.env.NODE_ENV==="production"?ke.exports=et():ke.exports=st();var tt=ke.exports;const ge=["light","dark","system"];function at(){const{theme:t,setTheme:n}=s.useTheme(),r=s.useDashboardStore(h=>h.actions.setDashboardTheme);function a(){const h=ge.includes(t)?t:"system",m=ge[(ge.indexOf(h)+1)%ge.length];n(m),r(m)}const l=t==="light"?Zs:t==="dark"?Ys:Ws,c=t==="light"?"Theme: light (click for dark)":t==="dark"?"Theme: dark (click for system)":"Theme: system (click for light)";return e.jsx(s.Button,{type:"button",variant:"ghost",size:"xs",className:"h-7 w-7 p-0 text-muted-foreground hover:text-foreground",onClick:a,"aria-label":c,title:c,children:e.jsx(l,{className:"h-3.5 w-3.5",strokeWidth:1.5})})}async function rt(t,n,r,a,l){if(!l)return null;const c=JSON.stringify(r),h=`${t}/v1/lens`;return await s.postRequest(h,l,{name:n,template:c,filterValues:a,operation:"create"})}async function Oe(t,n,r){if(!r)return null;const{id:a,template:l,filterValues:c,isDefault:h,shared:m}=n,f=`${t}/v1/lens`;return await s.postRequest(f,r,{lensId:a,template:l,filterValues:c,isDefault:h,shared:m,operation:"update"})}async function nt(t,n,r){if(!r)return null;const a=`${t}/v1/lens`;return await s.postRequest(a,r,{operation:"delete",lensId:n})}function ot({open:t,onOpenChange:n}={}){const[r,a]=g.useState(""),[l,c]=g.useState(!1),h=s.useDashboardStore(y=>y.lenses),{setLenses:m,setSelectedLensId:f}=s.useDashboardActions(),[b,d]=g.useState(!1),[u,o]=g.useState(!1),p=t!==void 0,x=p?t:u,j=y=>{p||o(y),n==null||n(y)},S=s.useDashboardStore(y=>y.dashboard),N=s.useDashboardStore(y=>y.filterValues),{authToken:C,tokenProps:O}=s.useSemaphorContext();async function E(){d(!0);const y=await rt(O.apiServiceUrl,r,S,N,C==null?void 0:C.accessToken);y&&(m([...h||[],y]),f(y.id),j(!1)),d(!1)}return e.jsxs(s.Dialog,{open:x,onOpenChange:j,children:[p?null: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:r,onChange:y=>{a(y.target.value)},id:"name",className:"col-span-7 focus-visible:ring-0 focus-visible:ring-ring focus-visible:ring-offset-0"})]})}),l&&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:E,disabled:b,children:b?"Creating...":"Add"})})]})]})}function it({includeLabel:t=!1}={}){const n=s.useDashboardStore(d=>d.lenses),r=s.useDashboardStore(d=>d.selectedLensId),{setLenses:a,setSelectedLensId:l}=s.useDashboardActions(),{authToken:c,tokenProps:h}=s.useSemaphorContext();async function m(d){l(d)}async function f(d){if(await nt(h.apiServiceUrl,d,c==null?void 0:c.accessToken)){const o=n==null?void 0:n.filter(p=>p.id!==d);a(o||[]),l("original")}}async function b(d){const u=n==null?void 0:n.map(x=>x.id===d.id?{...x,isDefault:!d.isDefault}:{...x,isDefault:!1});a(u||[]);const o={...d,isDefault:!d.isDefault};await Oe(h.apiServiceUrl,o,c==null?void 0:c.accessToken);const p=n==null?void 0:n.find(x=>x.isDefault);if(p&&p.id!==d.id){const x={...p,isDefault:!1};await Oe(h.apiServiceUrl,x,c==null?void 0:c.accessToken)}}return e.jsxs(e.Fragment,{children:[t?e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{className:"px-3",children:"Lenses"}),e.jsx(s.DropdownMenuSeparator,{})]}):null,e.jsxs(s.DropdownMenuRadioGroup,{value:r,onValueChange:m,children:[e.jsx(s.DropdownMenuRadioItem,{value:"original",children:"Original"}),n==null?void 0:n.map(d=>e.jsxs(s.DropdownMenuRadioItem,{className:"group flex justify-between gap-2",value:d.id,children:[e.jsx("p",{children:d.name}),e.jsxs("span",{className:"flex items-center gap-3",children:[e.jsx(s.House,{onClick:u=>{u.preventDefault(),b(d)},className:s.cn("size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",{invisible:!d.isDefault,"text-green-500":d.isDefault}),strokeWidth:1.5}),e.jsx(s.Cross2Icon,{onClick:u=>{u.preventDefault(),f(d.id)},className:"invisible size-3.5 text-muted-foreground hover:cursor-pointer hover:text-foreground group-hover:visible",strokeWidth:1.5})]})]},d.id))]})]})}function lt(){const{displayPreferences:t,shouldShowElement:n}=s.useDisplayPreferences(),{currentUser:r,userContext:a}=s.useCurrentUserInfo(),l=g.useMemo(()=>s.getRoleBasedDisplayOverrides(r),[r]),c=g.useMemo(()=>m=>l&&l[m]!==void 0&&l[m]===!1?!1:n(m),[l,n,t]),h=g.useMemo(()=>{var m,f,b,d,u;return{canEdit:((m=a==null?void 0:a.permissions)==null?void 0:m.canEdit)??s.canUserEdit(r),canUseFilters:((f=a==null?void 0:a.permissions)==null?void 0:f.canEdit)??s.canUserUseFilters(r),canManageDashboards:((b=a==null?void 0:a.permissions)==null?void 0:b.canCreateDashboard)??s.canUserManageDashboards(r),canCreateDashboards:((d=a==null?void 0:a.permissions)==null?void 0:d.canCreateDashboard)??s.canUserCreateDashboards(r),canAccessVisuals:((u=a==null?void 0:a.permissions)==null?void 0:u.canEdit)??s.canUserAccessVisuals(r)}},[r,a]);return{displayPreferences:t,shouldShowElement:c,permissions:h,currentUser:r}}const ct=async(t,n,r)=>{const a=`${t}/management/v1/groups`;return await s.postRequestRegular(a,n,r)},dt=async(t,n,r)=>{const a=`${t}/management/v1/groups/${r}`;await s.requestJsonRegular(a,n,"DELETE")},ut=async(t,n,r,a)=>{const l=`${t}/management/v1/groups/${r}/members`;return await s.postRequestRegular(l,n,a)},mt=async(t,n,r,a)=>{const l=`${t}/management/v1/groups/${r}/members`;await s.requestJsonRegular(l,n,"DELETE",a)};function ht(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>ct(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:()=>{r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Group created successfully")},onError:a=>{console.error("Failed to create group:",a),s.ue.error("Failed to create group",{description:s.getRequestErrorMessage(a,"Failed to create group")})}})}function pt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:a=>dt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["groups"]}),r.removeQueries({queryKey:["group",l]}),s.ue.success("Group deleted successfully")},onError:a=>{console.error("Failed to delete group:",a),s.ue.error("Failed to delete group",{description:s.getRequestErrorMessage(a,"Failed to delete group")})}})}function ft(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:l})=>ut(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,l),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["group",l.groupId]}),r.invalidateQueries({queryKey:["group-members",l.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members added successfully")},onError:a=>{console.error("Failed to add group members:",a),s.ue.error("Failed to add members",{description:s.getRequestErrorMessage(a,"Failed to add members")})}})}function gt(){const{authToken:t,tokenProps:n}=s.useSemaphorContext(),r=s.useQueryClient();return s.useMutation({mutationFn:({groupId:a,data:l})=>mt(n.apiServiceUrl,(t==null?void 0:t.accessToken)||"",a,l),onSuccess:(a,l)=>{r.invalidateQueries({queryKey:["group",l.groupId]}),r.invalidateQueries({queryKey:["group-members",l.groupId]}),r.invalidateQueries({queryKey:["groups"]}),s.ue.success("Members removed successfully")},onError:a=>{console.error("Failed to remove group members:",a),s.ue.error("Failed to remove members",{description:s.getRequestErrorMessage(a,"Failed to remove members")})}})}function xt({onSuccess:t,tenantId:n,isTenantUser:r}){const[a,l]=g.useState(""),[c,h]=g.useState(""),[m,f]=g.useState({}),b=ht(),d=()=>{const o={};return a.trim()?a.length<3?o.name="Group name must be at least 3 characters":a.length>50&&(o.name="Group name must be less than 50 characters"):o.name="Group name is required",c&&c.length>200&&(o.description="Description must be less than 200 characters"),f(o),Object.keys(o).length===0},u=async o=>{if(o.preventDefault(),!d())return;const p={name:a.trim(),description:c.trim()||void 0,type:r?"TENANT_GROUP":"ORG_GROUP",...r&&n?{tenantId:n}:{}};try{await b.mutateAsync(p),l(""),h(""),f({}),t()}catch(x){console.error("Failed to create group:",x)}};return e.jsxs("form",{onSubmit:u,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:a,onChange:o=>{l(o.target.value),m.name&&f(p=>({...p,name:""}))},className:m.name?"border-destructive":"",disabled:b.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:o=>{h(o.target.value),m.description&&f(p=>({...p,description:""}))},className:m.description?"border-destructive":"",disabled:b.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(""),h(""),f({})},disabled:b.isPending,children:"Clear"}),e.jsx(s.Button,{type:"submit",disabled:b.isPending||!a.trim(),children:b.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 bt(t,n=[]){let r=[];function a(c,h){const m=w.createContext(h);m.displayName=c+"Context";const f=r.length;r=[...r,h];const b=u=>{var N;const{scope:o,children:p,...x}=u,j=((N=o==null?void 0:o[t])==null?void 0:N[f])||m,S=w.useMemo(()=>x,Object.values(x));return e.jsx(j.Provider,{value:S,children:p})};b.displayName=c+"Provider";function d(u,o){var j;const p=((j=o==null?void 0:o[t])==null?void 0:j[f])||m,x=w.useContext(p);if(x)return x;if(h!==void 0)return h;throw new Error(`\`${u}\` must be used within \`${c}\``)}return[b,d]}const l=()=>{const c=r.map(h=>w.createContext(h));return function(m){const f=(m==null?void 0:m[t])||c;return w.useMemo(()=>({[`__scope${t}`]:{...m,[t]:f}}),[m,f])}};return l.scopeName=t,[a,vt(l,...n)]}function vt(...t){const n=t[0];if(t.length===1)return n;const r=()=>{const a=t.map(l=>({useScope:l(),scopeName:l.scopeName}));return function(c){const h=a.reduce((m,{useScope:f,scopeName:b})=>{const u=f(c)[`__scope${b}`];return{...m,...u}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:h}),[h])}};return r.scopeName=n.scopeName,r}var jt=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","select","span","svg","ul"],Te=jt.reduce((t,n)=>{const r=s.createSlot(`Primitive.${n}`),a=w.forwardRef((l,c)=>{const{asChild:h,...m}=l,f=h?r:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),e.jsx(f,{...m,ref:c})});return a.displayName=`Primitive.${n}`,{...t,[n]:a}},{});function St(){return tt.useSyncExternalStore(yt,()=>!0,()=>!1)}function yt(){return()=>{}}var Pe="Avatar",[Dt]=bt(Pe),[Nt,ds]=Dt(Pe),us=w.forwardRef((t,n)=>{const{__scopeAvatar:r,...a}=t,[l,c]=w.useState("idle");return e.jsx(Nt,{scope:r,imageLoadingStatus:l,onImageLoadingStatusChange:c,children:e.jsx(Te.span,{...a,ref:n})})});us.displayName=Pe;var ms="AvatarImage",hs=w.forwardRef((t,n)=>{const{__scopeAvatar:r,src:a,onLoadingStatusChange:l=()=>{},...c}=t,h=ds(ms,r),m=wt(a,c),f=s.useCallbackRef(b=>{l(b),h.onImageLoadingStatusChange(b)});return s.useLayoutEffect2(()=>{m!=="idle"&&f(m)},[m,f]),m==="loaded"?e.jsx(Te.img,{...c,ref:n,src:a}):null});hs.displayName=ms;var ps="AvatarFallback",fs=w.forwardRef((t,n)=>{const{__scopeAvatar:r,delayMs:a,...l}=t,c=ds(ps,r),[h,m]=w.useState(a===void 0);return w.useEffect(()=>{if(a!==void 0){const f=window.setTimeout(()=>m(!0),a);return()=>window.clearTimeout(f)}},[a]),h&&c.imageLoadingStatus!=="loaded"?e.jsx(Te.span,{...l,ref:n}):null});fs.displayName=ps;function cs(t,n){return t?n?(t.src!==n&&(t.src=n),t.complete&&t.naturalWidth>0?"loaded":"loading"):"error":"idle"}function wt(t,{referrerPolicy:n,crossOrigin:r}){const a=St(),l=w.useRef(null),c=a?(l.current||(l.current=new window.Image),l.current):null,[h,m]=w.useState(()=>cs(c,t));return s.useLayoutEffect2(()=>{m(cs(c,t))},[c,t]),s.useLayoutEffect2(()=>{const f=u=>()=>{m(u)};if(!c)return;const b=f("loaded"),d=f("error");return c.addEventListener("load",b),c.addEventListener("error",d),n&&(c.referrerPolicy=n),typeof r=="string"&&(c.crossOrigin=r),()=>{c.removeEventListener("load",b),c.removeEventListener("error",d)}},[c,r,n]),h}var gs=us,xs=hs,bs=fs;const Fe=w.forwardRef(({className:t,...n},r)=>e.jsx(gs,{ref:r,className:s.cn("relative flex h-10 w-10 shrink-0 overflow-hidden rounded-full",t),...n}));Fe.displayName=gs.displayName;const Ct=w.forwardRef(({className:t,...n},r)=>e.jsx(xs,{ref:r,className:s.cn("aspect-square h-full w-full",t),...n}));Ct.displayName=xs.displayName;const _e=w.forwardRef(({className:t,...n},r)=>e.jsx(bs,{ref:r,className:s.cn("flex h-full w-full items-center justify-center rounded-full bg-muted",t),...n}));_e.displayName=bs.displayName;function Mt({open:t,onOpenChange:n,group:r,onUpdate:a}){const[l,c]=g.useState("members"),[h,m]=g.useState(""),[f,b]=g.useState([]),[d,u]=g.useState([]),{data:o,isLoading:p,refetch:x}=s.useGroupMembers(r.id),j=r.type==="TENANT_GROUP"?"tenant":"organization",{users:S,isLoading:N}=s.useUnifiedUsers({type:j,tenantId:r.tenantId||void 0,active:!0,limit:100}),C=ft(),O=gt(),E=(o==null?void 0:o.members)||[],y=g.useMemo(()=>new Set(E.map(v=>v.userId)),[E]),T=g.useMemo(()=>S.filter(v=>!y.has(v.id)),[S,y]),$=g.useMemo(()=>{if(!h)return T;const v=h.toLowerCase();return T.filter(M=>{var k,P;return((k=M.name)==null?void 0:k.toLowerCase().includes(v))||((P=M.email)==null?void 0:P.toLowerCase().includes(v))})},[T,h]),D=g.useMemo(()=>{if(!h)return E;const v=h.toLowerCase();return E.filter(M=>{var k,P,ee,R;return((P=(k=M.user)==null?void 0:k.name)==null?void 0:P.toLowerCase().includes(v))||((R=(ee=M.user)==null?void 0:ee.email)==null?void 0:R.toLowerCase().includes(v))})},[E,h]),q=async()=>{if(f.length!==0)try{await C.mutateAsync({groupId:r.id,data:{userIds:f,userType:j==="tenant"?"tenant":"org"}}),b([]),c("members"),x(),a==null||a()}catch(v){console.error("Failed to add members:",v)}},X=async()=>{if(d.length!==0)try{await O.mutateAsync({groupId:r.id,data:{userIds:d}}),u([]),x(),a==null||a()}catch(v){console.error("Failed to remove members:",v)}},xe=v=>{b(M=>M.includes(v)?M.filter(k=>k!==v):[...M,v])},Z=v=>{u(M=>M.includes(v)?M.filter(k=>k!==v):[...M,v])};return e.jsx(e.Fragment,{children:e.jsx(s.Dialog,{open:t,onOpenChange:n,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:r.name}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[E.length," ",E.length===1?"member":"members"]})}),e.jsxs("p",{id:"group-members-description",className:"sr-only",children:["Add or remove members from the ",r.name," group"]})]}),e.jsxs(s.Tabs,{value:l,onValueChange:v=>{c(v),m(""),u([])},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:h,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:d.length>0?"h-[300px]":"h-[350px]",children:p?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):D.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:h?"No members found":"No members yet"}),e.jsx("p",{className:"text-xs mt-1",children:h?"Try a different search":'Switch to the "Add Members" tab to add people to this group'})]}):e.jsx("div",{className:"space-y-2",children:D.map(v=>e.jsx(Lt,{member:v,selected:d.includes(v.userId),onToggle:()=>Z(v.userId)},v.id))})}),d.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:[d.length," member",d.length!==1?"s":""," selected"]}),e.jsx(s.Button,{variant:"destructive",size:"sm",onClick:X,disabled:O.isPending,children:O.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:h,onChange:v=>m(v.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[300px]",children:N?e.jsx("div",{className:"space-y-2",children:[1,2,3].map(v=>e.jsx(s.Skeleton,{className:"h-16 w-full"},v))}):$.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:h?"Try a different search":"All eligible users are already members"})]}):e.jsx("div",{className:"space-y-2",children:$.map(v=>e.jsx(Et,{user:v,selected:f.includes(v.id),onToggle:()=>xe(v.id)},v.id))})}),f.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:[f.length," user",f.length!==1?"s":""," selected"]}),e.jsx(s.Button,{onClick:q,disabled:C.isPending,children:C.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 Lt({member:t,selected:n,onToggle:r}){var l,c,h,m;const a=((c=(l=t.user)==null?void 0:l.name)==null?void 0:c.split(" ").map(f=>f[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:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Fe,{className:"h-8 w-8",children:e.jsx(_e,{className:"text-xs",children:a})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium",children:((h=t.user)==null?void 0:h.name)||"Unknown User"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:(m=t.user)==null?void 0:m.email})]})]})}function Et({user:t,selected:n,onToggle:r}){var l;const a=((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:r,children:[e.jsx(s.Checkbox,{checked:n}),e.jsx(Fe,{className:"h-8 w-8",children:e.jsx(_e,{className:"text-xs",children:a})}),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 At({open:t,onOpenChange:n}){const[r,a]=g.useState("groups"),[l,c]=g.useState(""),[h,m]=g.useState(null),[f,b]=g.useState(!1),[d,u]=g.useState(null),{tokenProps:o}=s.useSemaphorContext(),{currentUser:p}=s.useCurrentUserInfo(),x=pt(),j=(p==null?void 0:p.type)==="tenant",S=o==null?void 0:o.tenantId,{groups:N,isLoading:C,refetch:O}=s.useGroups({type:j?"TENANT_GROUP":"all",tenantId:j?S:void 0,includeMembers:!1}),E=N.filter(D=>{var q;return D.name.toLowerCase().includes(l.toLowerCase())||((q=D.description)==null?void 0:q.toLowerCase().includes(l.toLowerCase()))}),y=async()=>{if(d)try{await x.mutateAsync(d.id),u(null),O()}catch(D){console.error("Failed to delete group:",D)}},T=D=>{m(D),b(!0)},$=()=>{a("groups"),O()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Dialog,{open:t,onOpenChange:n,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:r,onValueChange:a,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:D=>c(D.target.value),className:"pl-10"})]}),e.jsx(s.ScrollArea,{className:"h-[400px]",children:C?e.jsx("div",{className:"space-y-3",children:[1,2,3].map(D=>e.jsx(s.Skeleton,{className:"h-24 w-full"},D))}):E.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:E.map(D=>e.jsx(It,{group:D,onManageMembers:()=>T(D),onDelete:()=>u(D),currentUserId:p==null?void 0:p.id},D.id))})})]})}),e.jsx(s.TabsContent,{value:"create",className:"mt-4",children:e.jsx(xt,{onSuccess:$,tenantId:S,isTenantUser:j})})]})]})}),h&&e.jsx(Mt,{open:f,onOpenChange:b,group:h,onUpdate:()=>O()}),e.jsx(s.AlertDialog,{open:!!d,onOpenChange:()=>u(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 "',d==null?void 0:d.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:y,disabled:x.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:x.isPending?e.jsxs(e.Fragment,{children:[e.jsx(s.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Deleting..."]}):"Delete Group"})]})]})})]})}function It({group:t,onManageMembers:n,onDelete:r,currentUserId:a}){const l=t.createdBy===a;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 ",Hs.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:n,title:"Manage members",children:e.jsx(s.UserPlus,{className:"h-4 w-4"})}),l&&e.jsx(s.Button,{variant:"ghost",size:"sm",onClick:r,title:"Delete group",className:"text-destructive hover:text-destructive",children:e.jsx(s.Trash2,{className:"h-4 w-4"})})]})]})})}function W(t,n,r){var c,h;const a=(t.controls||[]).find(m=>m.id===r);if(a)return a.label;const l=(h=(c=s.findCardById(t,n))==null?void 0:c.controls)==null?void 0:h.find(m=>m.id===r);return(l==null?void 0:l.label)||r}function Y(t,n){var r;return((r=s.findCardById(t,n))==null?void 0:r.title)||n}function kt(t){const{errors:n,dashboard:r}=t;if(!r)return n;const a=new Map;for(const l of n){const c=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing metric '(.+)'\.$/);if(c){const[,d,u]=c,o=`${d}:${u}:missing-metric`;a.has(o)||a.set(o,`"${Y(r,d)}" has an outdated "${W(r,d,u)}" mapping. Some choices still point to metrics that are no longer available on this card. Open the card controls and choose replacements.`);continue}const h=l.match(/^Card '(.+)' binding for control '(.+)' maps to missing group-by field '(.+)'\.$/);if(h){const[,d,u]=h,o=`${d}:${u}:missing-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" has an outdated "${W(r,d,u)}" mapping. Some choices still point to fields that are no longer available on this card. Open the card controls and choose replacements.`);continue}const m=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid metric target\.$/);if(m){const[,d,u]=m,o=`${d}:${u}:invalid-metric`;a.has(o)||a.set(o,`"${Y(r,d)}" has an invalid "${W(r,d,u)}" metric mapping. Open the card controls and choose a valid metric for each option.`);continue}const f=l.match(/^Card '(.+)' binding for control '(.+)' maps to an invalid group-by target\.$/);if(f){const[,d,u]=f,o=`${d}:${u}:invalid-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" has an invalid "${W(r,d,u)}" field mapping. Open the card controls and choose a valid field for each option.`);continue}const b=l.match(/^Card '(.+)' binding for control '(.+)' requires at least one temporal group-by field\.$/);if(b){const[,d,u]=b,o=`${d}:${u}:missing-temporal-group-by`;a.has(o)||a.set(o,`"${Y(r,d)}" can no longer use "${W(r,d,u)}" for time grain because the card does not currently group by a date field.`);continue}a.set(l,l)}return Array.from(a.values())}function Ot(){var es,ss,ts,as;U.useExportRecovery(),U.useExportPolling();const{authToken:t,tokenProps:n,id:r}=s.useSemaphorContext(),{isLocalDev:a}=s.useDashboardPreferences(),{permissions:l}=lt(),c=s.useHasDashboardId(),{isLoading:h}=s.useDashboardQuery();s.useDashboardStore(i=>i.theme);const m=s.useDashboardStore(i=>i.isDownloadingPdf),f=s.useDashboardStore(i=>i.dashboardAssistantDraftScopeKey),b=s.useDashboardStore(i=>i.lenses),d=s.useDashboardStore(i=>i.selectedLensId),u=b==null?void 0:b.find(i=>i.id===d),o=s.useDashboardStore(i=>i.dashboard);s.useDashboardStore(i=>i.selectedSheetId);const p=s.useDashboardStore(i=>i.isDashboardEditing),{setDashboardTitle:x}=s.useDashboardStore(i=>i.actions),[j,S]=g.useState(!1),[N,C]=g.useState(!1),[O,E]=g.useState(!1),[y,T]=g.useState(!1),[$,D]=g.useState(!1),[q,X]=g.useState(!1),[xe,Z]=g.useState(!1),[v,M]=g.useState(!1),[k,P]=g.useState(null),[ee,R]=g.useState(!1),[se,te]=g.useState(null),[Ue,ae]=g.useState([]),[Re,re]=g.useState(!1),vs=s.useDashboardStore(i=>i.isDashboardPanelOpen),js=s.useDashboardStore(i=>i.actions.setIsDashboardPanelOpen),Ss=s.useDashboardStore(i=>i.filterValues),A=s.useDashboardStore(i=>i.isVisualEditing);s.useEditorStore(i=>i.card);const H=s.useManagementStore(i=>i.selectedDashboard),ne=s.useManagementStore(i=>i.initialDashboard);s.useManagementStore(i=>i.selectedVisual),s.useDashboardStore(i=>i.selectedFrameId),s.useEditorStore(i=>i.frame);const oe=H?(ss=H==null?void 0:H.permissions)==null?void 0:ss.canEdit:(es=ne==null?void 0:ne.permissions)==null?void 0:es.canEdit,ie=s.useDashboardStore(i=>i.showFilters),Ge=s.useAssistantLayoutStore(i=>i.setPanelOpen),$e=s.useDashboardStore(i=>i.showDashboardJSON),be=s.useDashboardStore(i=>i.onSaveFunction),qe=s.useDashboardStore(i=>i.actions.setShowFilters),{setIsDashboardEditing:Be,setShowDashboardJSON:He}=s.useDashboardStore(i=>i.actions),{setInitialDashboard:ze,clearSelectedDashboard:ve}=s.useManagementStore(i=>i.actions),{resources:le}=s.useResourceManagement(s.ResourceType.DASHBOARD),{data:je}=s.useUserPreferences(),ys=((ts=je==null?void 0:je.preference)==null?void 0:ts.defaultDashboardId)||null,{mutate:Ds,isPending:Ns}=s.useDefaultDashboardMutation(),{currentUser:ws}=s.useCurrentUserInfo(),Cs=s.canUserManageGroups(ws),B=H||ne,Ve=B?{id:B.id,title:(o==null?void 0:o.title)||B.title||"Dashboard"}:null,{handleAddNewFrame:Ms}=s.useAddNewFrame(),[Se,ye]=g.useState(!1),[Ls,z]=g.useState(!1),[De,ce]=g.useState("close"),V=s.useUpdateResource(s.ResourceType.DASHBOARD),[F,Ne]=g.useState(null),Ke=g.useCallback(i=>{window.setTimeout(()=>{P(i)},0)},[]),Es=async(i,L)=>{if(!(o!=null&&o.id)){console.log("No dashboard ID found");return}console.log("Updating dashboard title:",{dashboardId:o.id,newTitle:i,previousTitle:L}),V.mutate({resourceId:o.id,data:{title:i}},{onSuccess:()=>{console.log("Dashboard title updated successfully"),s.ue.success("Dashboard title updated")},onError:_=>{console.error("Failed to update dashboard title:",_),s.ue.error("Failed to update dashboard title"),x(L)}})};g.useEffect(()=>{if(le&&le.length>0){const i=o==null?void 0:o.id;if(i){const L=le.find(_=>_.id===i);L&&ze(L)}}},[le,o==null?void 0:o.id,ze]);const K=n.orgUserId||n.tenantId,Qe=p&&!A&&K&&oe,{setDashboard:we}=s.useDashboardStore(i=>i.actions),As=()=>{Be(!0)},Ce=()=>{Be(!1),He(!1),Ne(null),P(null)};U.usePristineSnapshotInitializer(p,o,F,i=>Ne(i));const{isDirty:Je,isDirtyPending:Is,resetDirty:de}=zs.useDebouncedDirtyCheck(o,F,300,1e3,Ee.serializeDashboardForDirtyCheck),We=g.useCallback(()=>F?Ee.serializeDashboardForDirtyCheck(o)!==Ee.serializeDashboardForDirtyCheck(F):!1,[o,F]),Ye=Je||Is,ue=Se||V.isPending,ks=()=>{We()?(ce("close"),z(!0)):(Ce(),de())},Os=async()=>{await Me({closeAfterSave:!0,navigateHomeAfterSave:De==="home"})},Ts=()=>{F&&we(F),Ce(),De==="home"&&ve(),ce("close"),z(!1),de()},Ps=()=>{F&&(we(F),de())},Fs=()=>{if(p&&We()){ce("home"),z(!0);return}ve()};async function Me(i){const L=s.useDashboardStore.getState().dashboard;if(!L)return;const _=(i==null?void 0:i.closeAfterSave)??Re,$s=(i==null?void 0:i.navigateHomeAfterSave)??!1;re(_),_&&z(!1);const qs=s.cloneDeep(L);R(!0),te(null),ae([]),ye(!0);const Bs={template:L};V.mutate({resourceId:L.id,data:Bs},{onSuccess:I=>{var he,pe,rs;const G=(I==null?void 0:I.id)||((he=I==null?void 0:I.dashboard)==null?void 0:he.id)||((pe=I==null?void 0:I.resource)==null?void 0:pe.id)||((rs=I==null?void 0:I.template)==null?void 0:rs.id)||null;if(!L.id&&G){const Le=s.useAIInteractionStore.getState(),fe=Le.pendingDashboardDraftMigration;(fe==null?void 0:fe.scopeKey)===f?Le.actions.setPendingDashboardDraftMigrationExpectedDashboardId(G):fe&&Le.actions.clearPendingDashboardDraftMigration()}ye(!1),s.ue.success("Dashboard saved!"),Ne(qs),R(!1),re(!1),_&&(Ce(),de(),$s&&ve()),ce("close")},onError:I=>{ye(!1),te("Failed to save dashboard. Please try again.");const G=I.details,he=Array.isArray(G==null?void 0:G.errors)?(G.errors||[]).filter(pe=>typeof pe=="string"):[];ae(kt({errors:he,dashboard:L||void 0})),s.ue.error("Failed to save dashboard")}})}async function _s(){if(S(!0),!d||!u)return;const i=s.useDashboardStore.getState().dashboard;if(!i){S(!1);return}const L=JSON.stringify(i),_={...u,template:L,filterValues:Ss};await Oe(n.apiServiceUrl,_,t==null?void 0:t.accessToken),s.ue.success("Lens saved"),be==null||be(i),S(!1)}const Xe=(u==null?void 0:u.name)||o.title,Q=!!(o!=null&&o.id);V.isPending&&console.log("Title during update:",{title:Xe,dashboardStateTitle:o.title,dashboardId:o==null?void 0:o.id,currentLensName:u==null?void 0:u.name});const Ze=n.orgUserId||n.tenantId&&n.endUserId&&n.endUserEmail,Us=!!Ze&&!!(t!=null&&t.accessToken)&&!!(n!=null&&n.apiServiceUrl);g.useEffect(()=>{!Q&&y&&T(!1)},[Q,y]);const Rs=c,J=(o==null?void 0:o.id)||null,me=!!J&&ys===J,Gs=()=>{J&&Ds({dashboardId:me?null:J})};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:[Ze&&e.jsxs(e.Fragment,{children:[e.jsx(s.IconButton,{"aria-label":"Manage Dashboards",tooltip:"Manage Dashboards",onClick:()=>{js(!vs)},className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(Js,{className:"h-3.5 w-3.5"})}),Rs&&!A&&e.jsx(s.IconButton,{"aria-label":"Dashboard Hub",tooltip:"Dashboard Hub",onClick:Fs,className:"h-7 w-7 px-0",buttonProps:{size:"xs"},children:e.jsx(s.House,{className:"h-3.5 w-3.5"})})]}),!A&&c&&(h?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:Xe||"Untitled Dashboard",onSave:i=>{console.log("EditableText onSave called:",{newTitle:i,canEditDashboard:oe,dashboardId:o==null?void 0:o.id});const L=(o==null?void 0:o.title)||"";x(i),Es(i,L)},isEditable:oe&&!u,displayClassName:"text-[13px] font-medium",inputClassName:"text-[13px] font-medium",placeholder:"Dashboard Title",isPending:V.isPending}),Us&&J&&e.jsx(s.TooltipProvider,{children:e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",size:"xs",onClick:Gs,disabled:Ns||!(t!=null&&t.accessToken)||!(n!=null&&n.apiServiceUrl),className:"w-7 px-0","aria-label":me?"Remove as default dashboard":"Make this a default dashboard",children:e.jsx(s.Star,{className:s.cn("h-3.5 w-3.5 transition-colors",me?"fill-foreground text-foreground":"text-muted-foreground hover:text-foreground")})})}),e.jsx(s.TooltipContent,{children:e.jsx("p",{children:me?"Remove as default dashboard":"Make this a default dashboard"})})]})})]}))]}),e.jsxs("div",{className:"flex items-center gap-2",children:[A&&e.jsxs(e.Fragment,{children:[e.jsx(U.AdvancedModeToggle,{}),e.jsx(U.VisualEditingControls,{})]}),!A&&c&&((as=B==null?void 0:B.permissions)==null?void 0:as.canShare)&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:()=>C(!0),children:[e.jsx(s.Share2,{className:"h-3.5 w-3.5"}),"Share"]}),!A&&p&&l.canUseFilters&&c&&e.jsx(U.DashboardFilterControlsButton,{showFilters:ie,onToggleFilters:()=>{ie||Ge("dashboard",!1),qe(!ie)},onAddFilter:()=>{ie||(Ge("dashboard",!1),qe(!0))},onAddControl:()=>{Ke("create")},onManageControls:()=>Ke("manage")}),p&&!A&&c&&k?e.jsx(U.DashboardControlsSettings,{open:!0,onOpenChange:i=>{i||P(null)},showTrigger:!1,initialMode:k}):null,p&&!A&&K&&u&&a&&c&&e.jsxs(s.Button,{variant:"secondary",size:"xs",disabled:j,onClick:_s,children:[e.jsx(os.Save,{className:"h-3.5 w-3.5"}),"Save Lens"]}),p&&!A&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",disabled:!p,onClick:()=>Ms(),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Visual"]}),!A&&!p&&oe&&c&&e.jsxs(s.Button,{size:"xs",onClick:As,children:[e.jsx(s.Pencil,{className:"h-3.5 w-3.5"}),"Edit"]}),Qe&&c&&Je&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:Ps,disabled:ue,children:[e.jsx(s.Undo2,{className:"h-3.5 w-3.5"}),"Undo"]}),Qe&&c&&e.jsxs(s.Button,{size:"xs",className:s.cn(!Ye&&"opacity-60"),disabled:ue||!Ye,onClick:()=>Me(),children:[ue?e.jsx(s.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(os.Save,{className:"h-3.5 w-3.5"}),ue?"Saving...":"Save"]}),p&&!A&&c&&e.jsxs(s.Button,{variant:"outline",size:"xs",onClick:ks,children:[e.jsx(s.Cross2Icon,{className:"h-3.5 w-3.5"}),"Close"]}),!A&&c&&e.jsx("div",{className:"ml-2",children:e.jsx(U.NotificationBell,{})}),!A&&a&&e.jsx(at,{}),!A&&c&&e.jsxs(s.DropdownMenu,{children:[e.jsx(s.DropdownMenuTrigger,{asChild:!0,children:e.jsx(s.IconButton,{tooltip:"More Options",className:"w-7 px-0 text-muted-foreground hover:text-foreground",buttonProps:{size:"xs",variant:"ghost","aria-label":"More dashboard options"},children:e.jsx(s.EllipsisVertical,{className:"h-3.5 w-3.5"})})}),e.jsxs(s.DropdownMenuContent,{align:"end",className:"w-56 rounded-[6px] border border-border/60 p-1 shadow-sm",children:[e.jsx(s.DropdownMenuLabel,{children:"Reports"}),e.jsxs(s.DropdownMenuItem,{disabled:m,onSelect:()=>M(!0),children:[e.jsx(s.Download,{className:"h-3.5 w-3.5"}),"Export"]}),e.jsxs(s.DropdownMenuItem,{disabled:!Q,onSelect:()=>{Q&&T(!0)},children:[e.jsx(s.Clock,{className:"h-3.5 w-3.5"}),"Schedule"]}),e.jsx(s.DropdownMenuSeparator,{}),Cs&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuLabel,{children:"Access"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>E(!0),children:[e.jsx(s.Users,{className:"h-3.5 w-3.5"}),"Manage Groups"]}),e.jsx(s.DropdownMenuSeparator,{})]}),e.jsx(s.DropdownMenuLabel,{children:"Preferences"}),e.jsxs(s.DropdownMenuItem,{onClick:()=>D(!0),children:[e.jsx(s.Calendar,{className:"h-3.5 w-3.5"}),"Calendar Preferences"]}),e.jsxs(s.DropdownMenuItem,{onClick:()=>X(!0),children:[e.jsx(s.FileText,{className:"h-3.5 w-3.5"}),"Summary Settings"]}),a&&c&&e.jsxs(e.Fragment,{children:[e.jsx(s.DropdownMenuSeparator,{}),e.jsx(s.DropdownMenuLabel,{children:"Developer"}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>{var i;t!=null&&t.accessToken&&((i=navigator==null?void 0:navigator.clipboard)!=null&&i.writeText?navigator.clipboard.writeText(t.accessToken).then(()=>s.ue.success("Token copied to clipboard")).catch(()=>s.ue.error("Unable to copy token")):s.ue.error("Clipboard not available"))},children:[e.jsx(s.Copy,{className:"h-3.5 w-3.5"}),"Copy token"]}),e.jsxs(s.DropdownMenuItem,{onSelect:()=>s.invalidateToken(n.apiServiceUrl),children:[e.jsx(Xs,{className:"h-3.5 w-3.5"}),"Invalidate token"]}),p&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>He(!$e),children:[e.jsx(Vs.Braces,{className:"h-3.5 w-3.5"}),$e?"Hide dashboard JSON":"Show dashboard JSON"]}),K&&p&&e.jsxs(s.DropdownMenuItem,{onSelect:()=>Z(!0),children:[e.jsx(s.Plus,{className:"h-3.5 w-3.5"}),"Add lens"]}),K&&e.jsxs(s.DropdownMenuSub,{children:[e.jsxs(s.DropdownMenuSubTrigger,{children:[e.jsx(Qs,{className:"h-3.5 w-3.5"}),"Lenses"]}),e.jsx(s.DropdownMenuSubContent,{className:"w-60",children:e.jsx(it,{})})]})]})]})]}),N&&Ve&&e.jsx(s.ShareDialog,{resource:Ve,resourceType:s.ResourceType.DASHBOARD,onClose:()=>C(!1)}),e.jsx(At,{open:O,onOpenChange:E}),Q&&(o==null?void 0:o.id)&&e.jsx(s.EmailScheduleDialog,{open:y,onOpenChange:T,dashboardId:o.id,dashboardName:o==null?void 0:o.title}),e.jsx(ns.CalendarPreferencesDialog,{open:$,onOpenChange:D}),e.jsx(ns.DashboardSummarySettingsDialog,{open:q,onOpenChange:X,dashboard:o,disabled:!p,onApply:i=>we({...o,summary:i})}),a&&K&&c&&e.jsx(ot,{open:xe,onOpenChange:Z}),c&&e.jsx(s.DownloadPdf,{open:v,onOpenChange:M}),e.jsx(s.AlertDialog,{open:ee,onOpenChange:i=>{!i&&Se&&!se||(R(i),i||(te(null),ae([]),re(!1)))},children:e.jsxs(s.AlertDialogContent,{className:"max-w-sm",children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:se?"Save failed":"Saving dashboard"}),e.jsx(s.AlertDialogDescription,{className:"pt-2",children:se?"We could not save the dashboard. Please try again.":"Please wait while we save your changes."}),Ue.length>0&&e.jsxs("div",{className:"space-y-1 rounded-md border border-destructive/20 bg-destructive/5 p-3 text-left",children:[e.jsx("div",{className:"text-sm font-medium text-destructive",children:"What needs attention"}),e.jsx("ul",{className:"list-disc space-y-1 pl-4 text-xs text-muted-foreground",children:Ue.slice(0,5).map(i=>e.jsx("li",{children:i},i))})]})]}),e.jsx(s.AlertDialogFooter,{className:"flex-col gap-2 sm:flex-row sm:justify-end",children:se?e.jsxs(e.Fragment,{children:[e.jsx(s.AlertDialogCancel,{onClick:()=>{R(!1),te(null),ae([]),re(!1)},className:"m-0",children:"Close"}),e.jsx(s.AlertDialogAction,{onClick:()=>Me({closeAfterSave:Re,navigateHomeAfterSave:De==="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(U.UnsavedChangesAlert,{open:Ls,onOpenChange:i=>{z(i)},onSave:Os,onDiscard:Ts,isSaving:Se,saveLabel:"Save",discardLabel:"Discard"})]})]})}exports.default=Ot;
|