react-semaphor 0.1.159 → 0.1.162

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.
Files changed (27) hide show
  1. package/dist/chunks/{dashboard-controls-DIo_VMBS.js → dashboard-controls-4GSRkLCI.js} +6 -6
  2. package/dist/chunks/{dashboard-controls-DnlJRUpY.js → dashboard-controls-CeSBs5Hq.js} +191 -190
  3. package/dist/chunks/{dashboard-export-dialog-CZhtshog.js → dashboard-export-dialog-D514_qGz.js} +1 -1
  4. package/dist/chunks/{dashboard-export-dialog-D6bmvl-v.js → dashboard-export-dialog-MpHrSiyY.js} +22 -22
  5. package/dist/chunks/{dashboard-json-Bagczd1F.js → dashboard-json-O63iXsoj.js} +1 -1
  6. package/dist/chunks/{dashboard-json-D1jy0qDk.js → dashboard-json-UCoG-_cW.js} +1 -1
  7. package/dist/chunks/{edit-dashboard-visual-ANoND-SH.js → edit-dashboard-visual-DsBEfgxL.js} +1 -1
  8. package/dist/chunks/{edit-dashboard-visual-B6Q0AUbn.js → edit-dashboard-visual-E6Kq46ex.js} +656 -656
  9. package/dist/chunks/{editor-action-buttons-CMNOhq91.js → editor-action-buttons-CMCgCcUE.js} +2 -2
  10. package/dist/chunks/{editor-action-buttons-B1yfEUpI.js → editor-action-buttons-Cm7pHxM_.js} +1 -1
  11. package/dist/chunks/{index-CMymongy.js → index-B9l7fpA-.js} +18375 -18463
  12. package/dist/chunks/{index-Dy-VUjSy.js → index-oMb4lVSV.js} +222 -222
  13. package/dist/chunks/{resource-management-panel-BPl4Mk9m.js → resource-management-panel-BxvT3mn3.js} +343 -335
  14. package/dist/chunks/resource-management-panel-yBYy59zu.js +6 -0
  15. package/dist/chunks/use-role-aware-display-preferences-97_9jIzt.js +29 -0
  16. package/dist/chunks/use-role-aware-display-preferences-jONtUniC.js +1 -0
  17. package/dist/chunks/{use-visual-utils-BH4FZWUV.js → use-visual-utils-D6xUgbea.js} +1 -1
  18. package/dist/chunks/{use-visual-utils-H7arppWh.js → use-visual-utils-lD1p2yII.js} +24 -24
  19. package/dist/dashboard/index.cjs +1 -1
  20. package/dist/dashboard/index.js +1 -1
  21. package/dist/index.cjs +2 -2
  22. package/dist/index.js +67 -65
  23. package/dist/surfboard/index.cjs +1 -1
  24. package/dist/surfboard/index.js +1 -1
  25. package/dist/types/main.d.ts +68 -1
  26. package/package.json +1 -1
  27. package/dist/chunks/resource-management-panel--vwXhI58.js +0 -6
@@ -11,6 +11,8 @@ import * as React_2 from 'react';
11
11
  import { RefetchOptions } from '@tanstack/query-core';
12
12
  import { StoreApi } from 'zustand';
13
13
  import { UseBoundStore } from 'zustand';
14
+ import { UseMutateFunction } from '@tanstack/react-query';
15
+ import { UseQueryResult } from '@tanstack/react-query';
14
16
  import { WritableDraft } from 'immer';
15
17
 
16
18
  declare type Actions = {
@@ -670,6 +672,12 @@ export declare type ContainerId = 'groupBy' | 'metrics' | 'pivotBy' | 'sortBy' |
670
672
  */
671
673
  export declare const createEmptyKpiConfig: () => CardConfig;
672
674
 
675
+ declare interface CreateResourceRequest {
676
+ title: string;
677
+ description?: string;
678
+ isPrivate?: boolean;
679
+ }
680
+
673
681
  export declare function createSqlGenConfig(column: TDataColumn, preSqlGen: SqlGen, calc?: AggregateCalc): SqlGen;
674
682
 
675
683
  export declare type CustomCard = CardWithContent | CardWithFooter;
@@ -1917,7 +1925,7 @@ export declare function resolveDatamodelName(datamodelName: string): string;
1917
1925
 
1918
1926
  export declare const resolveDataType: (value: any) => string;
1919
1927
 
1920
- declare interface ResourceListItem {
1928
+ export declare interface ResourceListItem {
1921
1929
  id: string;
1922
1930
  title: string;
1923
1931
  description: string;
@@ -2001,6 +2009,18 @@ declare interface ShareDialogProps {
2001
2009
  onRemoveSuccess?: () => void;
2002
2010
  }
2003
2011
 
2012
+ declare interface ShareResourceRequest {
2013
+ shares: Array<{
2014
+ scope: ShareScope;
2015
+ tenantId?: string;
2016
+ tenantUserId?: string;
2017
+ role: 'VIEWER' | 'EDITOR' | 'CONTRIBUTOR' | 'OWNER' | 'NONE';
2018
+ }>;
2019
+ message?: string;
2020
+ }
2021
+
2022
+ declare type ShareScope = 'specific_tenant_user' | 'all_tenant_users' | 'specific_org_user' | 'all_org_users' | 'org_users_only' | 'all_tenants_only';
2023
+
2004
2024
  export declare interface SortByField extends Field {
2005
2025
  role: 'sortby';
2006
2026
  direction: 'asc' | 'desc';
@@ -2976,6 +2996,16 @@ declare type UnsavedChangesAlertProps = {
2976
2996
  isSaving: boolean;
2977
2997
  };
2978
2998
 
2999
+ declare interface UpdateDashboardTemplateRequest {
3000
+ template: TDashboard;
3001
+ }
3002
+
3003
+ declare interface UpdateResourceRequest {
3004
+ title?: string;
3005
+ description?: string;
3006
+ isPrivate?: boolean;
3007
+ }
3008
+
2979
3009
  export declare interface UpdateUserPreferenceRequest {
2980
3010
  defaultDashboardId: string | null;
2981
3011
  }
@@ -3034,6 +3064,10 @@ export declare const useCurrentSheetActiveCards: () => TCard[];
3034
3064
 
3035
3065
  export declare const useDashboardActions: () => Actions_2;
3036
3066
 
3067
+ export declare function useDashboardById(dashboardId: string, options?: {
3068
+ enabled?: boolean;
3069
+ }): UseQueryResult<any, Error>;
3070
+
3037
3071
  export declare function useDashboardQuery(): {
3038
3072
  data: GetDashboardResponse | null | undefined;
3039
3073
  isLoading: boolean;
@@ -3134,6 +3168,39 @@ setState(nextStateOrUpdater: ManagementStore | Partial<ManagementStore> | ((stat
3134
3168
  */
3135
3169
  export declare function usePristineSnapshotInitializer(isDashboardEditing: boolean, dashboardState: TDashboard, pristineDashboard: TDashboard | null, setPristineDashboard: (dashboard: TDashboard) => void): void;
3136
3170
 
3171
+ export declare function useResourceManagement(resourceType: ResourceType, onDeleteSuccess?: () => void, onCreateSuccess?: (data?: any) => void): {
3172
+ resources: any;
3173
+ isLoading: boolean;
3174
+ isError: boolean;
3175
+ isFetching: boolean;
3176
+ error: Error | null;
3177
+ createResource: UseMutateFunction<any, Error, CreateResourceRequest, void>;
3178
+ updateResource: UseMutateFunction<any, Error, {
3179
+ resourceId: string;
3180
+ data: UpdateResourceRequest | UpdateDashboardTemplateRequest;
3181
+ }, void>;
3182
+ deleteResource: UseMutateFunction<any, Error, string, void>;
3183
+ duplicateResource: UseMutateFunction<any, Error, string, void>;
3184
+ shareResource: UseMutateFunction<any, Error, {
3185
+ resourceType: ResourceType;
3186
+ resourceId: string;
3187
+ data: ShareResourceRequest;
3188
+ }, void>;
3189
+ removeResourceShares: UseMutateFunction<any, Error, {
3190
+ resourceType: ResourceType;
3191
+ resourceId: string;
3192
+ data: ShareResourceRequest;
3193
+ }, void>;
3194
+ isCreating: boolean;
3195
+ isUpdating: boolean;
3196
+ isDeleting: boolean;
3197
+ isDuplicating: boolean;
3198
+ isSharing: boolean;
3199
+ isRemovingShares: boolean;
3200
+ isUpdatingShares: boolean;
3201
+ refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<any, Error>>;
3202
+ };
3203
+
3137
3204
  export declare interface UserPreference {
3138
3205
  id: string;
3139
3206
  actorType: 'ORG_USER' | 'TENANT_USER';
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "email": "support@semaphor.cloud"
6
6
  },
7
7
  "license": "MIT",
8
- "version": "0.1.159",
8
+ "version": "0.1.162",
9
9
  "description": "Fully interactive and customizable dashboards for your apps.",
10
10
  "keywords": [
11
11
  "react",
@@ -1,6 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-Dy-VUjSy.js"),c=require("react"),oe=require("./use-visual-utils-BH4FZWUV.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 ue=t.createLucideIcon("FolderOpen",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]);function he(s,f={}){const{enabled:x=!0,eventType:o="mousedown"}=f,r=c.useRef(null);return c.useEffect(()=>{const g=j=>{const a=j.target;r.current&&r.current.contains(a)||a instanceof Element&&(a.closest("[data-radix-popper-content-wrapper]")||a.closest("[data-radix-select-content]")||a.closest("[data-radix-popover-content]")||a.closest("[data-radix-dropdown-menu-content]")||a.closest("[data-radix-tooltip-content]")||a.closest('[role="listbox"]')||a.closest('[role="option"]')||a.closest('[role="combobox"]'))||a instanceof Element&&a.hasAttribute("data-radix-")||s()};return x&&document.addEventListener(o,g),()=>{document.removeEventListener(o,g)}},[s,x,o]),r}function re(){return e.jsx("div",{className:"space-y-1 px-2 py-2",children:[...Array(5)].map((s,f)=>e.jsxs("div",{className:"flex animate-pulse items-start gap-3 rounded-md px-2 py-2",children:[e.jsx("div",{className:"mt-0.5 h-4 w-4 flex-shrink-0 rounded bg-muted/60"}),e.jsxs("div",{className:"flex-1 space-y-1.5",children:[e.jsx("div",{className:"h-4 w-3/5 rounded bg-muted/60"}),e.jsx("div",{className:"h-3 w-4/5 rounded bg-muted/40"})]})]},f))})}const me=s=>{const f=t.useDashboardStore(r=>r.isVisualEditing),x=t.useDashboardStore(r=>r.selectedFrameId),o=t.useEditorStore(r=>r.frame);return!!(f&&x&&(o==null?void 0:o.visualId)===s)};function xe({visual:s,isDeleting:f,isDuplicating:x,onAddVisual:o,onOpenVisual:r,onEditDetails:g,onDeleteClick:j,onDuplicateVisual:a,onShareVisual:D,formatDate:y}){var M,S,C,T;const{selectVisual:d}=t.useManagementActions(),u=t.useIsVisualSelected(s.id),p=me(s.id),{isConsoleMode:b}=t.useDashboardPreferences(),E=c.useRef(null),[N,v]=c.useState(!1),[A,V]=c.useState(!1);c.useEffect(()=>{x?(v(!0),V(!0)):A&&(v(!1),V(!1))},[x,A]),c.useEffect(()=>{p&&E.current&&E.current.scrollIntoView({behavior:"smooth",block:"center"})},[p]);const P=()=>{d(s),r==null||r(s)};return e.jsxs("div",{ref:E,className:t.cn("group flex cursor-pointer items-start gap-3 rounded-md px-2 py-2 transition-colors hover:bg-muted",p?"bg-purple-500/10":u&&"bg-muted/80"),onClick:P,children:[e.jsx(t.ChartLine,{className:"mt-0.5 h-4 w-4 flex-shrink-0 text-muted-foreground/50"}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:s.title||"Untitled Visual",children:s.title||"Untitled Visual"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:s.description||"No description",children:(M=s.description)!=null&&M.trim()?s.description:"No description"})]}),e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-1",onClick:h=>h.stopPropagation(),children:[e.jsx("div",{className:"opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs(t.DropdownMenu,{modal:!1,open:N,onOpenChange:v,children:[e.jsx(t.DropdownMenuTrigger,{asChild:!0,children:e.jsx(t.Button,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",children:e.jsx(t.EllipsisVertical,{className:"h-3 w-3"})})}),e.jsxs(t.DropdownMenuContent,{align:"end",className:"z-[51] w-40",children:[e.jsxs(t.DropdownMenuItem,{onClick:h=>{h.stopPropagation(),o(s)},children:[e.jsx(t.Plus,{className:"mr-2 h-3 w-3"}),"Add"]}),e.jsxs(t.DropdownMenuItem,{onClick:h=>{h.stopPropagation(),r==null||r(s)},children:[e.jsx(ue,{className:"mr-2 h-3 w-3"}),"Open"]}),e.jsxs(t.DropdownMenuItem,{onClick:h=>{h.preventDefault(),h.stopPropagation(),a(s.id)},disabled:x,children:[x?e.jsx(t.LoaderCircle,{className:"mr-2 h-3 w-3 animate-spin"}):e.jsx(t.Copy,{className:"mr-2 h-3 w-3"}),x?"Duplicating...":"Duplicate"]}),s.ownership.isOwner&&e.jsxs(e.Fragment,{children:[e.jsxs(t.DropdownMenuItem,{onClick:h=>{h.stopPropagation(),g==null||g(s)},children:[e.jsx(t.PenLine,{className:"mr-2 h-3 w-3"}),"Edit details"]}),e.jsxs(t.DropdownMenuItem,{onClick:h=>{h.stopPropagation(),D(s)},children:[e.jsx(t.Users,{className:"mr-2 h-3 w-3"}),"Share"]}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs(t.DropdownMenuItem,{onClick:h=>{h.stopPropagation(),j(s)},className:"text-destructive",disabled:f,children:[e.jsx(t.Trash2,{className:"mr-2 h-3 w-3"}),f?"Deleting...":"Delete"]})]}),e.jsx(t.DropdownMenuSeparator,{}),e.jsxs("div",{className:"space-y-1 px-2 py-2 text-xs text-slate-500 dark:text-slate-400",children:[(((S=s.ownership.createdBy)==null?void 0:S.type)==="tenant"||((C=s.ownership.createdBy)==null?void 0:C.type)==="organization"&&b)&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.User,{className:"h-3 w-3"}),e.jsx("span",{children:((T=s.ownership.createdBy)==null?void 0:T.name)||"Unknown"})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(t.Calendar,{className:"h-3 w-3"}),e.jsx("span",{children:y(s.lastModified)})]})]})]})]})}),e.jsx(t.IconButton,{tooltip:"Add to dashboard",buttonProps:{variant:"ghost",size:"sm",onClick:h=>{h.stopPropagation(),o(s)}},className:"h-6 w-6 p-0",children:e.jsx(t.Plus,{className:"h-3.5 w-3.5"})})]})]})})]},s.id)}function pe({searchQuery:s}){const[f,x]=c.useState(!1),[o,r]=c.useState(null),[g,j]=c.useState(!1),[a,D]=c.useState(null),[y,d]=c.useState(null),[u,p]=c.useState(null),{selectVisual:b}=t.useManagementActions(),{handleEditLibraryVisual:E,handleAddLibraryVisual:N}=oe.useVisualUtils(),{resources:v,isLoading:A,isError:V,updateResource:P,deleteResource:M,duplicateResource:S,isDeleting:C}=t.useVisualManagement(()=>{j(!1),D(null)});t.useCurrentUserInfo();const T=v.filter(i=>{var L,l;return((L=i==null?void 0:i.title)==null?void 0:L.toLowerCase().includes(s.toLowerCase()))||((l=i==null?void 0:i.description)==null?void 0:l.toLowerCase().includes(s.toLowerCase()))}),h=i=>new Date(i).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),U=i=>{D(i),j(!0)},Y=()=>{a&&M(a.id)},{startUpdating:F,stopUpdating:K,isUpdating:R}=t.useResourceUpdateState(),B=(i,L,l)=>{var k;const W=Object.fromEntries(Object.entries(L).filter(([,O])=>O!==void 0));if(Object.keys(W).length===0){(k=l==null?void 0:l.onSuccess)==null||k.call(l);return}const $=Object.keys(W),Z=$.length===1?$[0]:void 0;F(i,Z),P({resourceId:i,data:W},{onSuccess:()=>{var O;K(i,Z),(O=l==null?void 0:l.onSuccess)==null||O.call(l)},onError:()=>{var O;K(i,Z),(O=l==null?void 0:l.onError)==null||O.call(l)}})},z=i=>{d(i),S(i,{onSettled:()=>d(null)})},J=i=>{E(i)},H=i=>{N(i)},Q=i=>{const L=v.find(l=>l.id===i);L&&P({resourceId:i,data:{isPrivate:!L.isPrivate}})},q=i=>{r(i),x(!0)},G=i=>{p(i)},w=()=>{p(null)},X=({title:i,description:L})=>{if(!u)return;const l={};i!==u.title&&(l.title=i),(u.description||"")!==L&&(l.description=L),B(u.id,l,{onSuccess:()=>{p(null)}})};return A?e.jsx(re,{}):V?e.jsx(t.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load visuals"}),e.jsx(t.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>window.location.reload(),children:"Retry"})]})}):e.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-3 overflow-y-auto",children:T.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(t.Grid3x3,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:s?"No visuals found":"No visuals yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s?"Try adjusting your search":'Click "Create" above to add your first visual'})]}):T.map(i=>e.jsx(xe,{visual:i,onAddVisual:H,onOpenVisual:J,onEditDetails:G,onDeleteClick:U,onDuplicateVisual:z,onTogglePrivacy:Q,onShareVisual:q,isDeleting:C,isDuplicating:y===i.id,formatDate:h},i.id))}),f&&o&&e.jsx(t.ShareDialog,{resource:o,resourceType:t.ResourceType.VISUAL,onClose:()=>{x(!1),r(null)}}),u&&e.jsx(t.ResourceEditDialog,{open:!!u,resourceLabel:"Visual",initialTitle:u.title||"",initialDescription:u.description||"",onClose:w,onSave:X,isSaving:R(u.id)}),e.jsx(t.AlertDialog,{open:g,onOpenChange:i=>{!i&&C||(j(i),i||D(null))},children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:"Delete Visual"}),e.jsxs(t.AlertDialogDescription,{children:['Are you sure you want to delete "',a==null?void 0:a.title,'"? This action cannot be undone.']})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(t.AlertDialogCancel,{disabled:C,children:"Cancel"}),e.jsxs(t.AlertDialogAction,{onClick:i=>{i.preventDefault(),i.stopPropagation(),Y()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:C,children:[C?e.jsx(t.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(t.Trash2,{className:"mr-2 h-3.5 w-3.5"}),C?"Deleting...":"Delete"]})]})]})})]})}function fe({dashboard:s,isDeleting:f,isDuplicating:x,isDefault:o,onLoadDashboard:r,onEditDetails:g,onDeleteClick:j,onDuplicateDashboard:a,onShareDashboard:D,formatDate:y,onDashboardItemClick:d}){var M,S;const{selectDashboard:u}=t.useManagementActions(),p=t.useIsDashboardSelected(s.id),{userContext:b,isLoading:E}=t.useCurrentUserInfo(),{mutate:N}=t.useDefaultDashboardMutation(),v=((M=b==null?void 0:b.permissions)==null?void 0:M.canEdit)??!1,A=E||!v,V=()=>{u(s),r(s.id),d==null||d(s.id)},P=C=>{C.stopPropagation(),N({dashboardId:o?null:s.id})};return e.jsx(t.TooltipProvider,{children:e.jsxs("div",{className:t.cn("group flex cursor-pointer items-start gap-3 rounded-md px-2 py-2 transition-colors hover:bg-muted",p&&"bg-muted/80"),onClick:V,children:[e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("button",{onClick:P,className:"mt-0.5 flex-shrink-0 rounded p-0.5 hover:bg-muted",children:e.jsx(t.Star,{className:t.cn("h-4 w-4 transition-colors",o?"fill-yellow-400 text-yellow-400":"text-muted-foreground/40 hover:text-yellow-400")})})}),e.jsx(t.TooltipContent,{side:"right",className:"text-xs",children:o?"Remove as default":"Set as default"})]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-sm font-medium text-foreground",title:s.title||"Untitled Dashboard",children:s.title||"Untitled Dashboard"}),e.jsx("p",{className:"truncate text-xs text-muted-foreground",title:s.description||"No description",children:(S=s.description)!=null&&S.trim()?s.description:"No description"})]}),e.jsx("div",{className:"flex-shrink-0 opacity-0 transition-opacity group-hover:opacity-100",children:e.jsx(t.DashboardActionsMenu,{dashboard:s,isDeleting:f,isDuplicating:x,shouldHideActions:A,onEditDetails:g,onDeleteClick:j,onDuplicateDashboard:a,onShareDashboard:D,formatDate:y})})]})})]},s.id)})}function ge({onRetry:s}){return e.jsx(t.ScrollArea,{className:"w-full flex-1 pr-2",children:e.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[e.jsx("p",{className:"text-sm text-destructive",children:"Failed to load dashboards"}),e.jsx(t.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:s,children:"Retry"})]})})}function je(s){var se,ne;const{searchQuery:f,onLoadDashboard:x,onEditDashboard:o,onDashboardItemClick:r}=s,[g,j]=c.useState(!1),[a,D]=c.useState(null),[y,d]=c.useState(!1),[u,p]=c.useState(null),[b,E]=c.useState(null),[N,v]=c.useState(null),A=t.useManagementStore(n=>n.lastSelectedDashboard),V=t.useManagementStore(n=>n.selectedDashboard),P=t.useManagementStore(n=>n.actions.selectDashboard),M=t.useManagementStore(n=>n.actions.clearSelectedDashboard),{tokenProps:S,id:C}=t.useSemaphorContext();t.useRoleAwareDisplayPreferences();const{resources:T,isLoading:h,isError:U,updateResource:Y,deleteResource:F,duplicateResource:K,isDeleting:R}=t.useDashboardManagement(()=>{d(!1);const n=u==null?void 0:u.id;p(null),(V==null?void 0:V.id)===n&&(!(S!=null&&S.dashboard_id)&&!C?M():A&&A.id!==n&&P(A))}),{currentUser:B,userContext:z}=t.useCurrentUserInfo(),J=((se=z==null?void 0:z.permissions)==null?void 0:se.canCreateDashboard)??!1,{data:H}=t.useUserPreferences(),Q=((ne=H==null?void 0:H.preference)==null?void 0:ne.defaultDashboardId)||null,q=T.filter(n=>{var I,m;return((I=n==null?void 0:n.title)==null?void 0:I.toLowerCase().includes(f.toLowerCase()))||((m=n==null?void 0:n.description)==null?void 0:m.toLowerCase().includes(f.toLowerCase()))}),G=n=>new Date(n).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),w=n=>{x==null||x(n)},X=n=>{p(n),d(!0)},i=()=>{u&&F(u.id)},L=n=>{E(n),K(n,{onSettled:()=>E(null)})},{startUpdating:l,stopUpdating:W,isUpdating:$}=t.useResourceUpdateState(),Z=(n,I,m)=>{var ae;const ee=Object.fromEntries(Object.entries(I).filter(([,_])=>_!==void 0));if(Object.keys(ee).length===0){(ae=m==null?void 0:m.onSuccess)==null||ae.call(m);return}const ie=Object.keys(ee),te=ie.length===1?ie[0]:void 0;l(n,te),Y({resourceId:n,data:ee},{onSuccess:()=>{var _;W(n,te),(_=m==null?void 0:m.onSuccess)==null||_.call(m)},onError:()=>{var _;W(n,te),(_=m==null?void 0:m.onError)==null||_.call(m)}})},k=n=>{const I=T.find(m=>m.id===n);I&&Y({resourceId:n,data:{isPrivate:!I.isPrivate}})},O=n=>{D(n),B==null||B.type,j(!0)},le=n=>{o==null||o(n.id),v(n)},de=()=>{v(null)},ce=({title:n,description:I})=>{if(!N)return;const m={};n!==N.title&&(m.title=n),(N.description||"")!==I&&(m.description=I),Z(N.id,m,{onSuccess:()=>{v(null)}})};return h?e.jsx(re,{}):U?e.jsx(ge,{onRetry:()=>window.location.reload()}):e.jsxs("div",{className:"flex h-full flex-1 flex-col",children:[e.jsx("div",{className:"flex flex-1 basis-0 flex-col gap-3 overflow-y-auto",children:q.length===0?e.jsxs("div",{className:"py-8 text-center",children:[e.jsx("div",{className:"mb-3",children:e.jsx(t.ChartColumn,{className:"mx-auto h-12 w-12 text-muted-foreground/50"})}),e.jsx("h3",{className:"mb-1 font-medium text-foreground",children:f?"No dashboards found":"No dashboards yet"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:f?"Try adjusting your search":J?'Click "Create" above to add your first dashboard':"No dashboards have been shared with you yet"})]}):q.map(n=>e.jsx(fe,{dashboard:n,isDeleting:R,isDuplicating:b===n.id,isDefault:n.id===Q,onLoadDashboard:w,onEditDetails:le,onDeleteClick:X,onDuplicateDashboard:L,onTogglePrivacy:k,onShareDashboard:O,formatDate:G,onDashboardItemClick:r},n.id))}),g&&a&&e.jsx(t.ShareDialog,{resource:a,resourceType:t.ResourceType.DASHBOARD,onClose:()=>{j(!1),D(null)}}),e.jsx(t.AlertDialog,{open:y,onOpenChange:n=>{!n&&R||(d(n),n||p(null))},children:e.jsxs(t.AlertDialogContent,{children:[e.jsxs(t.AlertDialogHeader,{children:[e.jsx(t.AlertDialogTitle,{children:"Delete Dashboard"}),e.jsxs(t.AlertDialogDescription,{children:['Are you sure you want to delete "',u==null?void 0:u.title,'"? This action cannot be undone.']})]}),e.jsxs(t.AlertDialogFooter,{children:[e.jsx(t.AlertDialogCancel,{disabled:R,children:"Cancel"}),e.jsxs(t.AlertDialogAction,{onClick:n=>{n.preventDefault(),n.stopPropagation(),i()},className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",disabled:R,children:[R?e.jsx(t.LoaderCircle,{className:"mr-2 h-3.5 w-3.5 animate-spin"}):e.jsx(t.Trash2,{className:"mr-2 h-3.5 w-3.5"}),R?"Deleting...":"Delete"]})]})]})}),N&&e.jsx(t.ResourceEditDialog,{open:!!N,resourceLabel:"Dashboard",initialTitle:N.title||"",initialDescription:N.description||"",onClose:de,onSave:ce,isSaving:$(N.id)})]})}function De({open:s,onOpenChange:f,onSubmit:x,isCreating:o}){const[r,g]=c.useState(""),[j,a]=c.useState("");c.useEffect(()=>{s||(g(""),a(""))},[s]);const D=()=>{r.trim()&&x({title:r,description:j})},y=d=>{f(d)};return e.jsx(t.Dialog,{open:s,onOpenChange:y,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Create New Visual"}),e.jsx(t.DialogDescription,{children:"Add a new visual to your library. You can configure it after creation."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{htmlFor:"title",children:"Visual Title"}),e.jsx(t.Input,{id:"title",placeholder:"Enter visual title...",value:r,onChange:d=>g(d.target.value),disabled:o,onKeyDown:d=>{d.key==="Enter"&&!d.shiftKey&&(d.preventDefault(),D())}})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(t.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(t.Input,{id:"description",placeholder:"Enter visual description...",value:j,onChange:d=>a(d.target.value),disabled:o})]})]}),e.jsxs(t.DialogFooter,{children:[e.jsx(t.Button,{variant:"outline",onClick:()=>y(!1),disabled:o,children:"Cancel"}),e.jsx(t.Button,{onClick:D,disabled:!r.trim()||o,children:o?e.jsxs(e.Fragment,{children:[e.jsx(t.LoaderCircle,{className:"mr-2 h-4 w-4 animate-spin"}),"Creating..."]}):"Create Visual"})]})]})})}function Ne({isOpen:s,onClose:f,className:x,onDashboardItemClick:o,variant:r="inline"}){var q,G;const g=t.useDashboardStore(w=>w.isDashboardEditing),[j,a]=c.useState(!1),[D,y]=c.useState(""),[d,u]=c.useState(!1),{currentUser:p,userContext:b}=t.useCurrentUserInfo(),E=((q=b==null?void 0:b.permissions)==null?void 0:q.canCreateDashboard)??!1,{onCreateSuccess:N}=t.useDashboardCreation({onDashboardSelect:o}),{selectVisual:v}=t.useManagementActions(),{handleEditLibraryVisual:A}=oe.useVisualUtils(),{createResource:V,isCreating:P,refetch:M}=t.useDashboardManagement(),{createResource:S,isCreating:C}=t.useVisualManagement(void 0,w=>{a(!1),w&&(v(w),A(w))}),T=r==="overlay",h=((p==null?void 0:p.name)??"").trim(),U=((p==null?void 0:p.email)??"").trim(),F=h&&h.toLowerCase()!=="undefined"?h:U||"Current user",K=((G=F.charAt(0))==null?void 0:G.toUpperCase())||"?",R=U&&U.toLowerCase()!=="undefined"?U:"",B=he(f,{enabled:s&&T}),z=t.cn("flex h-full flex-col border-r bg-background",T?t.cn("absolute inset-y-0 left-0 z-[51] w-60 shadow-lg transition-transform duration-300 ease-in-out",s?"translate-x-0":"pointer-events-none -translate-x-full"):"w-full max-w-[17rem] min-w-[11rem] overflow-hidden shadow-sm",x),J=w=>{},H=w=>{console.log("Editing dashboard:",w)},Q=w=>{V(w,{onSuccess:X=>{a(!1),N(X,M)}})};return e.jsx(e.Fragment,{children:(!T||s)&&e.jsxs("div",{ref:B,className:z,children:[e.jsxs("div",{className:"border-b border-border",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-1.5",children:[e.jsx("div",{className:"flex items-center gap-2",children:e.jsx("h2",{className:"whitespace-nowrap text-sm font-semibold",children:g?"Visuals":"Dashboards"})}),e.jsxs("div",{className:"flex items-center gap-0",children:[e.jsx(t.Button,{size:"sm",variant:"ghost",onClick:()=>u(!d),className:"h-8 w-8 p-0",children:e.jsx(t.Search,{className:"h-3.5 w-3.5"})}),(g||E)&&e.jsx(t.Button,{size:"sm",variant:"ghost",className:"h-8 w-8 whitespace-nowrap p-0",onClick:()=>a(!0),children:e.jsx(t.Plus,{className:"h-3.5 w-3.5"})})]})]}),d&&e.jsx("div",{className:"bg-muted/30 px-4 pb-3",children:e.jsx(t.Input,{placeholder:"Search...",value:D,onChange:w=>y(w.target.value),className:"h-8 border-muted-foreground/20 bg-background text-sm focus-visible:border-muted-foreground/40 focus-visible:ring-0 focus-visible:ring-offset-0",autoFocus:!0})})]}),e.jsx("div",{className:"flex flex-1 flex-col overflow-auto px-2 py-2",children:g?e.jsx(pe,{searchQuery:D}):e.jsx(je,{searchQuery:D,onLoadDashboard:J,onEditDashboard:H,onDashboardItemClick:o})}),p&&e.jsx(t.TooltipProvider,{children:e.jsx("div",{className:"border-t border-border px-4 py-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(t.Tooltip,{children:[e.jsx(t.TooltipTrigger,{asChild:!0,children:e.jsx("div",{className:"flex h-6 w-6 cursor-default items-center justify-center rounded-full bg-primary/10",children:e.jsx("span",{className:"text-xs font-medium text-primary",children:K})})}),e.jsx(t.TooltipContent,{side:"top",className:"max-w-xs",children:e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"font-medium",children:F}),R&&e.jsx("div",{className:"text-xs text-muted-foreground",children:R}),p.role&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Role: ",t.toTitleCase(p.role.replace(/_/g," "))]})]})})]}),e.jsx("span",{className:"truncate text-xs text-muted-foreground",children:F})]})})}),g?e.jsx(De,{open:j,onOpenChange:a,onSubmit:S,isCreating:C}):e.jsx(t.CreateDashboardDialog,{open:j,onOpenChange:a,onSubmit:Q,isCreating:P})]})})}exports.ResourceManagementPanel=Ne;