react-semaphor 0.1.460 → 0.1.461
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/brand-studio/index.cjs +1 -1
- package/dist/brand-studio/index.js +1 -1
- package/dist/chunks/{dashboard-briefing-launcher-B07JnyCb.js → dashboard-briefing-launcher-3owMxX5K.js} +3 -3
- package/dist/chunks/{dashboard-briefing-launcher-BCkOKkCv.cjs → dashboard-briefing-launcher-xuGrw8H3.cjs} +1 -1
- package/dist/chunks/{dashboard-controls-C8OxHQV6.js → dashboard-controls-B4GvjGr1.js} +4 -4
- package/dist/chunks/{dashboard-controls-BpxouYOZ.cjs → dashboard-controls-Bpm_xOXQ.cjs} +1 -1
- package/dist/chunks/{dashboard-json-CecgbGtq.js → dashboard-json-DzyxoBp-.js} +2 -2
- package/dist/chunks/{dashboard-json-Bc-iIwxF.cjs → dashboard-json-yLM01xK4.cjs} +1 -1
- package/dist/chunks/{edit-dashboard-visual-xacUS2i5.cjs → edit-dashboard-visual-1T278Nr_.cjs} +1 -1
- package/dist/chunks/{edit-dashboard-visual-CpJKJaER.js → edit-dashboard-visual-nwSasO_j.js} +3 -3
- package/dist/chunks/{editor-action-buttons-23Wf8EMx.cjs → editor-action-buttons-CX1Pken3.cjs} +1 -1
- package/dist/chunks/{editor-action-buttons-DEoieV2G.js → editor-action-buttons-Dqw0asfA.js} +2 -2
- package/dist/chunks/{index-B9c22LmC.cjs → index-B1qplNxl.cjs} +208 -208
- package/dist/chunks/{index-DDoyXYWM.js → index-DazD5k0F.js} +31392 -31066
- package/dist/chunks/{report-preferences-dialog-D_N6NXnq.cjs → report-preferences-dialog-DKPyjiCt.cjs} +1 -1
- package/dist/chunks/{report-preferences-dialog-CZiNX1Ri.js → report-preferences-dialog-Dv3vCCFt.js} +2 -2
- package/dist/chunks/{switch-DNFbgZz4.cjs → switch-DBZsEV0U.cjs} +37 -37
- package/dist/chunks/{switch-DSZobe8w.js → switch-kPUJEC1A.js} +2698 -2655
- package/dist/dashboard/index.cjs +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/data-app-builder/index.cjs +1 -1
- package/dist/data-app-builder/index.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -6
- package/dist/style.css +1 -1
- package/dist/surfboard/index.cjs +1 -1
- package/dist/surfboard/index.js +2 -2
- package/dist/types/briefings.d.ts +15 -4
- package/dist/types/dashboard-authoring.d.ts +15 -4
- package/dist/types/dashboard.d.ts +15 -4
- package/dist/types/main.d.ts +15 -4
- package/dist/types/shared.d.ts +15 -4
- package/dist/types/surfboard.d.ts +15 -4
- package/dist/types/types.d.ts +15 -4
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("react/jsx-runtime"),o=require("react"),l=require("./index-B9c22LmC.cjs"),u=require("./switch-DNFbgZz4.cjs"),V=require("./report-runtime-context-C0NfLPfc.cjs");require("./x-B6ghREd2.cjs");require("./saved-temporal-bucket-format-3QKveR3v.cjs");require("./validators-dJlwubP4.cjs");require("./analyze-result-contract-DSGoFuXQ.cjs");const L=require("../value-format-preferences/index.cjs");function G(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(p=>p.actions.applyResolvedCalendarPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,[g,S]=o.useState(!1),[b,C]=o.useState(!1),[f,j]=o.useState(!1),[T,x]=o.useState(null),[w,P]=o.useState(null),v=o.useRef(i);v.current=i,o.useEffect(()=>{P(null),x(null),S(!1),C(!1),j(!1)},[i]);const N=o.useCallback(async p=>{const r=V.parseCalendarPreferencesResponse(await p.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),k=o.useCallback(async()=>{if(!s||!i||!h)return;const p=i;S(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to fetch preferences")}const n=await N(r);v.current===p&&P(n)}catch(r){v.current===p&&x(r instanceof Error?r.message:"Unknown error")}finally{v.current===p&&S(!1)}},[i,h,s,N]);o.useEffect(()=>{s&&k()},[s,k]);const E=o.useCallback(async p=>{if(!i||!h)return x("Not authenticated"),!1;const r=i;C(!0),x(null);try{const n=await fetch(`${h}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify(p)});if(!n.ok){const D=await n.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}const y=await N(n);return v.current!==r?!1:(P(y),m(y.resolved,y.sources),!0)}catch(n){return v.current===r&&x(n instanceof Error?n.message:"Unknown error"),!1}finally{v.current===r&&C(!1)}},[i,h,m,N]),A=o.useCallback(async()=>{if(!i||!h)return x("Not authenticated"),!1;const p=i;j(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to clear preferences")}const n=await N(r);return v.current!==p?!1:(P(n),m(n.resolved,n.sources),!0)}catch(r){return v.current===p&&x(r instanceof Error?r.message:"Unknown error"),!1}finally{v.current===p&&j(!1)}},[i,h,m,N]);return{preferences:w,isLoading:g,isSaving:b,isClearing:f,error:T,updatePreferences:E,clearPreferences:A,refetch:k}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],B=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function W(){try{const a=Intl;if(a.supportedValuesOf)return a.supportedValuesOf("timeZone")}catch{}return F.map(a=>a.value)}function H(a){if(!a)return"default";if(a.tz!==a.weekStart)return"inherited";switch(a.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(a){const c=F.find(t=>t.value===a);return c?c.label:a}function K(a){const c=B.find(t=>t.value===a);return c?c.label:String(a)}function J({active:a,onClose:c}){const{preferences:t,isLoading:m,isSaving:s,isClearing:i,updatePreferences:h,clearPreferences:g}=G({enabled:a}),S=l.useCalendarContext(),b=(t==null?void 0:t.resolved.tz)||(S==null?void 0:S.tz)||"UTC",C=(t==null?void 0:t.resolved.weekStart)??(S==null?void 0:S.weekStart)??1,[f,j]=o.useState((t==null?void 0:t.stored)===null),[T,x]=o.useState(!1),[w,P]=o.useState(b),[v,N]=o.useState(C),[k,E]=o.useState(!1),A=o.useMemo(()=>W(),[]),p=o.useMemo(()=>A.filter(d=>!F.some(M=>M.value===d)),[A]),r=o.useMemo(()=>U(w),[w]),n=t!=null&&t.inherited?U(t.inherited.tz):"UTC",y=t!=null&&t.inherited?K(t.inherited.weekStart):"Monday",D=H(t==null?void 0:t.inheritedSources);o.useEffect(()=>{if(!a){x(!1);return}T||(t&&j(t.stored===null),P(b),N(C))},[a,T,t,b,C]);const O=async()=>{if(m){l.ue.error("Preferences are still loading. Please try again.");return}f?await g()?(l.ue.success("Now using default settings."),c()):l.ue.error("Failed to save preferences. Please try again."):await h({tz:w,weekStart:v})?(l.ue.success("Preferences saved."),c()):l.ue.error("Failed to save preferences. Please try again.")},_=()=>{c()},z=s||i,$=z||m;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(l.RadioGroup,{value:f?"defaults":"custom",onValueChange:d=>{x(!0),j(d==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",f&&"bg-muted/50"),onClick:()=>{x(!0),j(!0)},children:[e.jsx(l.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",D," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[n,", week starts ",y]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!f&&"bg-muted/50"),onClick:()=>{x(!0),j(!1)},children:[e.jsx(l.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:u.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",f&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Timezone"}),e.jsxs(u.Popover,{open:k,onOpenChange:E,modal:!0,children:[e.jsx(u.PopoverTrigger,{asChild:!0,children:e.jsxs(u.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"w-full justify-between text-[12px] font-normal",disabled:f,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(l.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(u.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(l.Command,{className:"overflow-visible",children:[e.jsx(l.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(l.CommandList,{children:[e.jsx(l.CommandEmpty,{children:"No timezone found."}),e.jsx(l.CommandGroup,{heading:"Common",children:F.map(d=>e.jsxs(l.CommandItem,{value:`${d.value} ${d.label}`,onSelect:()=>{x(!0),P(d.value),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:d.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:d.value})]},d.value))}),e.jsx(l.CommandSeparator,{}),e.jsx(l.CommandGroup,{heading:"All timezones",children:p.map(d=>e.jsxs(l.CommandItem,{value:d,onSelect:()=>{x(!0),P(d),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d?"opacity-100":"opacity-0")}),d]},d))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Week starts on"}),e.jsx(l.RadioGroup,{value:String(v),onValueChange:d=>{x(!0),N(Number(d))},className:"flex gap-4",disabled:f,children:B.map(d=>e.jsxs("label",{htmlFor:`week-start-${d.value}`,className:u.cn("flex cursor-pointer items-center gap-2 text-[13px]",f&&"cursor-not-allowed"),children:[e.jsx(l.RadioGroupItem,{value:String(d.value),id:`week-start-${d.value}`,disabled:f}),d.label]},d.value))})]})]})]}),e.jsxs(l.DialogFooter,{children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:_,disabled:z,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:O,disabled:$,children:z?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function Y(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,g=o.useRef(i);g.current=i;const[S,b]=o.useState(null),[C,f]=o.useState(!1),[j,T]=o.useState(!1),[x,w]=o.useState(!1),[P,v]=o.useState(null);o.useEffect(()=>{b(null),v(null),f(!1),T(!1),w(!1)},[i]);const N=o.useCallback(async r=>{const n=L.parseValueFormatPreferencesResponse(await r.json());if(!n.ok)throw new Error("Value format preferences response is invalid");return n.value},[]),k=o.useCallback(async(r,n)=>{if(!i||!h)throw new Error("Not authenticated");const y=await fetch(`${h}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${i}`,...n?{"Content-Type":"application/json"}:{}},body:n?JSON.stringify(n):void 0});if(!y.ok){const D=await y.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}return N(y)},[i,h,N]),E=o.useCallback(async()=>{if(!s||!i||!h)return;const r=i;f(!0),v(null);try{const n=await k("GET");g.current===r&&b(n)}catch(n){g.current===r&&v(n instanceof Error?n.message:"Unknown error")}finally{g.current===r&&f(!1)}},[i,h,s,k]);o.useEffect(()=>{s&&E()},[s,E]);const A=o.useCallback(async r=>{const n=i;T(!0),v(null);try{const y=await k("PATCH",r);return g.current!==n?!1:(b(y),m(y.resolved,y.sources),!0)}catch(y){return g.current===n&&v(y instanceof Error?y.message:"Unknown error"),!1}finally{g.current===n&&T(!1)}},[i,m,k]),p=o.useCallback(async()=>{const r=i;w(!0),v(null);try{const n=await k("DELETE");return g.current!==r?!1:(b(n),m(n.resolved,n.sources),!0)}catch(n){return g.current===r&&v(n instanceof Error?n.message:"Unknown error"),!1}finally{g.current===r&&w(!1)}},[i,m,k]);return{preferences:S,isLoading:C,isSaving:j,isClearing:x,error:P,updatePreferences:A,clearPreferences:p,refetch:E}}const I=["locale","dateStyle","dateTime.dateStyle","dateTime.timeStyle","defaultCurrency"];function q(a,c){var t,m;switch(c){case"locale":return a==null?void 0:a.locale;case"dateStyle":return a==null?void 0:a.dateStyle;case"dateTime.dateStyle":return(t=a==null?void 0:a.dateTime)==null?void 0:t.dateStyle;case"dateTime.timeStyle":return(m=a==null?void 0:a.dateTime)==null?void 0:m.timeStyle;case"defaultCurrency":return a==null?void 0:a.defaultCurrency}}function Z(a){var m,s;const c=(m=a==null?void 0:a.dateTime)==null?void 0:m.dateStyle,t=(s=a==null?void 0:a.dateTime)==null?void 0:s.timeStyle;return{locale:a==null?void 0:a.locale,dateStyle:a==null?void 0:a.dateStyle,dateTime:c===void 0&&t===void 0?void 0:{dateStyle:c,timeStyle:t},defaultCurrency:a==null?void 0:a.defaultCurrency}}function Q({active:a,onClose:c}){var g,S,b,C,f,j,T;const{preferences:t,isLoading:m,isSaving:s,updatePreferences:i}=Y({enabled:a});if(!a)return null;if(!t)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:m?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const h=[((g=t.stored)==null?void 0:g.locale)??"",((S=t.stored)==null?void 0:S.dateStyle)??"",((C=(b=t.stored)==null?void 0:b.dateTime)==null?void 0:C.dateStyle)??"",((j=(f=t.stored)==null?void 0:f.dateTime)==null?void 0:j.timeStyle)??"",((T=t.stored)==null?void 0:T.defaultCurrency)??""].join(":");return e.jsx(X,{preferences:t,isSaving:s,updatePreferences:i,onClose:c},h)}function X({preferences:a,isSaving:c,updatePreferences:t,onClose:m}){var b,C;const[s,i]=o.useState(()=>Z(a.stored)),h=(s.locale===void 0||L.canonicalizeSupportedLocale(s.locale)!==void 0)&&(s.defaultCurrency===void 0||L.canonicalizeSupportedCurrencyCode(s.defaultCurrency)!==void 0)&&(s.dateStyle===void 0||["short","medium","long"].includes(s.dateStyle))&&(((b=s.dateTime)==null?void 0:b.dateStyle)===void 0||["short","medium","long"].includes(s.dateTime.dateStyle))&&(((C=s.dateTime)==null?void 0:C.timeStyle)===void 0||["short","medium","long"].includes(s.dateTime.timeStyle)),g=async()=>{const f={...s.locale!==void 0?{locale:s.locale}:{},...s.dateStyle!==void 0?{dateStyle:s.dateStyle}:{},...s.dateTime?{dateTime:{...s.dateTime}}:{},...s.defaultCurrency!==void 0?{defaultCurrency:s.defaultCurrency}:{}},j=I.filter(w=>q(s,w)===void 0&&q(a.stored,w)!==void 0),T={...Object.keys(f).length>0?{set:f}:{},...j.length>0?{clear:j}:{}};(Object.keys(T).length===0?!0:await t(T))?(l.ue.success("Display format preferences saved."),m()):l.ue.error("Failed to save preferences. Please try again.")},S=async()=>{await t({clear:[...I]})?(l.ue.success("Display format preferences reset."),m()):l.ue.error("Failed to reset display format preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(l.DisplayFormatPreferencesFields,{value:s,inherited:a.inherited,inheritedSources:a.inheritedSources,onChange:i,disabled:c})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",onClick:S,disabled:c||a.stored===null,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:m,disabled:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:g,disabled:c||!h,children:c?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function ee({open:a,onOpenChange:c}){const[t,m]=o.useState("display"),s=()=>c(!1);return e.jsx(l.Dialog,{open:a,onOpenChange:c,children:e.jsxs(l.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(l.DialogHeader,{children:[e.jsx(l.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(l.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(u.Tabs,{value:t,onValueChange:m,children:[e.jsxs(u.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(u.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(u.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(u.TabsContent,{value:"display",children:e.jsx(Q,{active:a&&t==="display",onClose:s})}),e.jsx(u.TabsContent,{value:"calendar",children:e.jsx(J,{active:a&&t==="calendar",onClose:s})})]})]})})}exports.ReportPreferencesDialog=ee;
|
|
1
|
+
"use strict";const e=require("react/jsx-runtime"),o=require("react"),l=require("./index-B1qplNxl.cjs"),u=require("./switch-DBZsEV0U.cjs"),V=require("./report-runtime-context-C0NfLPfc.cjs");require("./x-B6ghREd2.cjs");require("./saved-temporal-bucket-format-3QKveR3v.cjs");require("./validators-dJlwubP4.cjs");require("./analyze-result-contract-DSGoFuXQ.cjs");const L=require("../value-format-preferences/index.cjs");function G(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(p=>p.actions.applyResolvedCalendarPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,[g,S]=o.useState(!1),[b,C]=o.useState(!1),[f,j]=o.useState(!1),[T,x]=o.useState(null),[w,P]=o.useState(null),v=o.useRef(i);v.current=i,o.useEffect(()=>{P(null),x(null),S(!1),C(!1),j(!1)},[i]);const N=o.useCallback(async p=>{const r=V.parseCalendarPreferencesResponse(await p.json());if(!r.ok)throw new Error("Calendar preferences response is invalid");return r.value},[]),k=o.useCallback(async()=>{if(!s||!i||!h)return;const p=i;S(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"GET",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to fetch preferences")}const n=await N(r);v.current===p&&P(n)}catch(r){v.current===p&&x(r instanceof Error?r.message:"Unknown error")}finally{v.current===p&&S(!1)}},[i,h,s,N]);o.useEffect(()=>{s&&k()},[s,k]);const E=o.useCallback(async p=>{if(!i||!h)return x("Not authenticated"),!1;const r=i;C(!0),x(null);try{const n=await fetch(`${h}/v1/user-preferences/calendar`,{method:"PATCH",headers:{"Content-Type":"application/json",Authorization:`Bearer ${i}`},body:JSON.stringify(p)});if(!n.ok){const D=await n.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}const y=await N(n);return v.current!==r?!1:(P(y),m(y.resolved,y.sources),!0)}catch(n){return v.current===r&&x(n instanceof Error?n.message:"Unknown error"),!1}finally{v.current===r&&C(!1)}},[i,h,m,N]),A=o.useCallback(async()=>{if(!i||!h)return x("Not authenticated"),!1;const p=i;j(!0),x(null);try{const r=await fetch(`${h}/v1/user-preferences/calendar`,{method:"DELETE",headers:{Authorization:`Bearer ${i}`}});if(!r.ok){const y=await r.json().catch(()=>({}));throw new Error(y.error||"Failed to clear preferences")}const n=await N(r);return v.current!==p?!1:(P(n),m(n.resolved,n.sources),!0)}catch(r){return v.current===p&&x(r instanceof Error?r.message:"Unknown error"),!1}finally{v.current===p&&j(!1)}},[i,h,m,N]);return{preferences:w,isLoading:g,isSaving:b,isClearing:f,error:T,updatePreferences:E,clearPreferences:A,refetch:k}}const F=[{value:"America/New_York",label:"Eastern Time (US & Canada)"},{value:"America/Chicago",label:"Central Time (US & Canada)"},{value:"America/Denver",label:"Mountain Time (US & Canada)"},{value:"America/Los_Angeles",label:"Pacific Time (US & Canada)"},{value:"America/Phoenix",label:"Arizona"},{value:"America/Anchorage",label:"Alaska"},{value:"Pacific/Honolulu",label:"Hawaii"},{value:"Europe/London",label:"London"},{value:"Europe/Paris",label:"Paris, Berlin, Rome"},{value:"Asia/Tokyo",label:"Tokyo"},{value:"Asia/Shanghai",label:"Beijing, Shanghai"},{value:"Asia/Kolkata",label:"Mumbai, New Delhi"},{value:"Australia/Sydney",label:"Sydney"},{value:"UTC",label:"UTC"}],B=[{value:0,label:"Sunday"},{value:1,label:"Monday"},{value:6,label:"Saturday"}],R="text-[10px] font-medium uppercase tracking-[0.08em] text-muted-foreground";function W(){try{const a=Intl;if(a.supportedValuesOf)return a.supportedValuesOf("timeZone")}catch{}return F.map(a=>a.value)}function H(a){if(!a)return"default";if(a.tz!==a.weekStart)return"inherited";switch(a.tz){case"viewer_tenant":return"tenant";case"viewer_organization":return"organization";case"system_default":return"system";case"session_initial":return"embedded";default:return"default"}}function U(a){const c=F.find(t=>t.value===a);return c?c.label:a}function K(a){const c=B.find(t=>t.value===a);return c?c.label:String(a)}function J({active:a,onClose:c}){const{preferences:t,isLoading:m,isSaving:s,isClearing:i,updatePreferences:h,clearPreferences:g}=G({enabled:a}),S=l.useCalendarContext(),b=(t==null?void 0:t.resolved.tz)||(S==null?void 0:S.tz)||"UTC",C=(t==null?void 0:t.resolved.weekStart)??(S==null?void 0:S.weekStart)??1,[f,j]=o.useState((t==null?void 0:t.stored)===null),[T,x]=o.useState(!1),[w,P]=o.useState(b),[v,N]=o.useState(C),[k,E]=o.useState(!1),A=o.useMemo(()=>W(),[]),p=o.useMemo(()=>A.filter(d=>!F.some(M=>M.value===d)),[A]),r=o.useMemo(()=>U(w),[w]),n=t!=null&&t.inherited?U(t.inherited.tz):"UTC",y=t!=null&&t.inherited?K(t.inherited.weekStart):"Monday",D=H(t==null?void 0:t.inheritedSources);o.useEffect(()=>{if(!a){x(!1);return}T||(t&&j(t.stored===null),P(b),N(C))},[a,T,t,b,C]);const O=async()=>{if(m){l.ue.error("Preferences are still loading. Please try again.");return}f?await g()?(l.ue.success("Now using default settings."),c()):l.ue.error("Failed to save preferences. Please try again."):await h({tz:w,weekStart:v})?(l.ue.success("Preferences saved."),c()):l.ue.error("Failed to save preferences. Please try again.")},_=()=>{c()},z=s||i,$=z||m;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4 py-1",children:[e.jsxs(l.RadioGroup,{value:f?"defaults":"custom",onValueChange:d=>{x(!0),j(d==="defaults")},className:"space-y-0.5",children:[e.jsxs("label",{htmlFor:"mode-defaults",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",f&&"bg-muted/50"),onClick:()=>{x(!0),j(!0)},children:[e.jsx(l.RadioGroupItem,{value:"defaults",id:"mode-defaults",className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("p",{className:"text-[13px] font-medium text-foreground",children:["Use ",D," defaults"]}),e.jsxs("p",{className:"text-[12px] text-muted-foreground",children:[n,", week starts ",y]})]})]}),e.jsxs("label",{htmlFor:"mode-custom",className:u.cn("flex cursor-pointer items-start gap-2 rounded-control px-2 py-1.5 hover:bg-muted/50",!f&&"bg-muted/50"),onClick:()=>{x(!0),j(!1)},children:[e.jsx(l.RadioGroupItem,{value:"custom",id:"mode-custom",className:"mt-0.5"}),e.jsx("p",{className:"flex-1 text-[13px] font-medium text-foreground",children:"Use custom settings"})]})]}),e.jsxs("div",{className:u.cn("space-y-4 border-t border-border/60 pt-4 transition-opacity",f&&"pointer-events-none opacity-50"),children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Timezone"}),e.jsxs(u.Popover,{open:k,onOpenChange:E,modal:!0,children:[e.jsx(u.PopoverTrigger,{asChild:!0,children:e.jsxs(u.Button,{variant:"outline",size:"xs",role:"combobox","aria-expanded":k,className:"w-full justify-between text-[12px] font-normal",disabled:f,children:[e.jsx("span",{className:"truncate",children:r}),e.jsx(l.ChevronsUpDown,{className:"ml-2 h-3.5 w-3.5 shrink-0 opacity-50"})]})}),e.jsx(u.PopoverContent,{className:"z-50 w-[--radix-popover-trigger-width] p-0",align:"start",children:e.jsxs(l.Command,{className:"overflow-visible",children:[e.jsx(l.CommandInput,{placeholder:"Search timezones…"}),e.jsxs(l.CommandList,{children:[e.jsx(l.CommandEmpty,{children:"No timezone found."}),e.jsx(l.CommandGroup,{heading:"Common",children:F.map(d=>e.jsxs(l.CommandItem,{value:`${d.value} ${d.label}`,onSelect:()=>{x(!0),P(d.value),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d.value?"opacity-100":"opacity-0")}),e.jsx("span",{className:"flex-1",children:d.label}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:d.value})]},d.value))}),e.jsx(l.CommandSeparator,{}),e.jsx(l.CommandGroup,{heading:"All timezones",children:p.map(d=>e.jsxs(l.CommandItem,{value:d,onSelect:()=>{x(!0),P(d),E(!1)},children:[e.jsx(u.Check,{className:u.cn("h-3.5 w-3.5",w===d?"opacity-100":"opacity-0")}),d]},d))})]})]})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(u.Label,{className:R,children:"Week starts on"}),e.jsx(l.RadioGroup,{value:String(v),onValueChange:d=>{x(!0),N(Number(d))},className:"flex gap-4",disabled:f,children:B.map(d=>e.jsxs("label",{htmlFor:`week-start-${d.value}`,className:u.cn("flex cursor-pointer items-center gap-2 text-[13px]",f&&"cursor-not-allowed"),children:[e.jsx(l.RadioGroupItem,{value:String(d.value),id:`week-start-${d.value}`,disabled:f}),d.label]},d.value))})]})]})]}),e.jsxs(l.DialogFooter,{children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:_,disabled:z,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:O,disabled:$,children:z?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})}function Y(a={}){const{authToken:c,tokenProps:t}=l.useSemaphorContext(),m=u.useDashboardStore(r=>r.actions.applyResolvedValueFormatPreferences),s=a.enabled??!0,i=(c==null?void 0:c.accessToken)??null,h=(t==null?void 0:t.apiServiceUrl)??null,g=o.useRef(i);g.current=i;const[S,b]=o.useState(null),[C,f]=o.useState(!1),[j,T]=o.useState(!1),[x,w]=o.useState(!1),[P,v]=o.useState(null);o.useEffect(()=>{b(null),v(null),f(!1),T(!1),w(!1)},[i]);const N=o.useCallback(async r=>{const n=L.parseValueFormatPreferencesResponse(await r.json());if(!n.ok)throw new Error("Value format preferences response is invalid");return n.value},[]),k=o.useCallback(async(r,n)=>{if(!i||!h)throw new Error("Not authenticated");const y=await fetch(`${h}/v1/user-preferences/value-format`,{method:r,headers:{Authorization:`Bearer ${i}`,...n?{"Content-Type":"application/json"}:{}},body:n?JSON.stringify(n):void 0});if(!y.ok){const D=await y.json().catch(()=>({}));throw new Error(D.error||"Failed to update preferences")}return N(y)},[i,h,N]),E=o.useCallback(async()=>{if(!s||!i||!h)return;const r=i;f(!0),v(null);try{const n=await k("GET");g.current===r&&b(n)}catch(n){g.current===r&&v(n instanceof Error?n.message:"Unknown error")}finally{g.current===r&&f(!1)}},[i,h,s,k]);o.useEffect(()=>{s&&E()},[s,E]);const A=o.useCallback(async r=>{const n=i;T(!0),v(null);try{const y=await k("PATCH",r);return g.current!==n?!1:(b(y),m(y.resolved,y.sources),!0)}catch(y){return g.current===n&&v(y instanceof Error?y.message:"Unknown error"),!1}finally{g.current===n&&T(!1)}},[i,m,k]),p=o.useCallback(async()=>{const r=i;w(!0),v(null);try{const n=await k("DELETE");return g.current!==r?!1:(b(n),m(n.resolved,n.sources),!0)}catch(n){return g.current===r&&v(n instanceof Error?n.message:"Unknown error"),!1}finally{g.current===r&&w(!1)}},[i,m,k]);return{preferences:S,isLoading:C,isSaving:j,isClearing:x,error:P,updatePreferences:A,clearPreferences:p,refetch:E}}const I=["locale","dateStyle","dateTime.dateStyle","dateTime.timeStyle","defaultCurrency"];function q(a,c){var t,m;switch(c){case"locale":return a==null?void 0:a.locale;case"dateStyle":return a==null?void 0:a.dateStyle;case"dateTime.dateStyle":return(t=a==null?void 0:a.dateTime)==null?void 0:t.dateStyle;case"dateTime.timeStyle":return(m=a==null?void 0:a.dateTime)==null?void 0:m.timeStyle;case"defaultCurrency":return a==null?void 0:a.defaultCurrency}}function Z(a){var m,s;const c=(m=a==null?void 0:a.dateTime)==null?void 0:m.dateStyle,t=(s=a==null?void 0:a.dateTime)==null?void 0:s.timeStyle;return{locale:a==null?void 0:a.locale,dateStyle:a==null?void 0:a.dateStyle,dateTime:c===void 0&&t===void 0?void 0:{dateStyle:c,timeStyle:t},defaultCurrency:a==null?void 0:a.defaultCurrency}}function Q({active:a,onClose:c}){var g,S,b,C,f,j,T;const{preferences:t,isLoading:m,isSaving:s,updatePreferences:i}=Y({enabled:a});if(!a)return null;if(!t)return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx("div",{className:"flex min-h-36 items-center justify-center text-[12px] text-muted-foreground",children:m?"Loading preferences…":"Preferences unavailable."})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",disabled:!0,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",disabled:!0,children:"Save"})]})]})]});const h=[((g=t.stored)==null?void 0:g.locale)??"",((S=t.stored)==null?void 0:S.dateStyle)??"",((C=(b=t.stored)==null?void 0:b.dateTime)==null?void 0:C.dateStyle)??"",((j=(f=t.stored)==null?void 0:f.dateTime)==null?void 0:j.timeStyle)??"",((T=t.stored)==null?void 0:T.defaultCurrency)??""].join(":");return e.jsx(X,{preferences:t,isSaving:s,updatePreferences:i,onClose:c},h)}function X({preferences:a,isSaving:c,updatePreferences:t,onClose:m}){var b,C;const[s,i]=o.useState(()=>Z(a.stored)),h=(s.locale===void 0||L.canonicalizeSupportedLocale(s.locale)!==void 0)&&(s.defaultCurrency===void 0||L.canonicalizeSupportedCurrencyCode(s.defaultCurrency)!==void 0)&&(s.dateStyle===void 0||["short","medium","long"].includes(s.dateStyle))&&(((b=s.dateTime)==null?void 0:b.dateStyle)===void 0||["short","medium","long"].includes(s.dateTime.dateStyle))&&(((C=s.dateTime)==null?void 0:C.timeStyle)===void 0||["short","medium","long"].includes(s.dateTime.timeStyle)),g=async()=>{const f={...s.locale!==void 0?{locale:s.locale}:{},...s.dateStyle!==void 0?{dateStyle:s.dateStyle}:{},...s.dateTime?{dateTime:{...s.dateTime}}:{},...s.defaultCurrency!==void 0?{defaultCurrency:s.defaultCurrency}:{}},j=I.filter(w=>q(s,w)===void 0&&q(a.stored,w)!==void 0),T={...Object.keys(f).length>0?{set:f}:{},...j.length>0?{clear:j}:{}};(Object.keys(T).length===0?!0:await t(T))?(l.ue.success("Display format preferences saved."),m()):l.ue.error("Failed to save preferences. Please try again.")},S=async()=>{await t({clear:[...I]})?(l.ue.success("Display format preferences reset."),m()):l.ue.error("Failed to reset display format preferences. Please try again.")};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"py-2",children:e.jsx(l.DisplayFormatPreferencesFields,{value:s,inherited:a.inherited,inheritedSources:a.inheritedSources,onChange:i,disabled:c})}),e.jsxs(l.DialogFooter,{className:"justify-between sm:justify-between",children:[e.jsx(u.Button,{variant:"ghost",size:"xs",onClick:S,disabled:c||a.stored===null,children:"Reset display formats"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(u.Button,{variant:"outline",size:"xs",onClick:m,disabled:c,children:"Cancel"}),e.jsx(u.Button,{size:"xs",onClick:g,disabled:c||!h,children:c?e.jsxs(e.Fragment,{children:[e.jsx(u.LoaderCircle,{className:"h-3.5 w-3.5 animate-spin"}),"Saving…"]}):"Save"})]})]})]})}function ee({open:a,onOpenChange:c}){const[t,m]=o.useState("display"),s=()=>c(!1);return e.jsx(l.Dialog,{open:a,onOpenChange:c,children:e.jsxs(l.DialogContent,{className:"rounded-control border-border/60 sm:max-w-[440px] sm:rounded-control",children:[e.jsxs(l.DialogHeader,{children:[e.jsx(l.DialogTitle,{className:"text-[15px]",children:"Report preferences"}),e.jsx(l.DialogDescription,{className:"text-[13px] leading-5",children:"Set how values and Calendar periods appear for you."})]}),e.jsxs(u.Tabs,{value:t,onValueChange:m,children:[e.jsxs(u.TabsList,{variant:"underline",className:"w-full justify-start",children:[e.jsx(u.TabsTrigger,{value:"display",children:"Display formats"}),e.jsx(u.TabsTrigger,{value:"calendar",children:"Calendar"})]}),e.jsx(u.TabsContent,{value:"display",children:e.jsx(Q,{active:a&&t==="display",onClose:s})}),e.jsx(u.TabsContent,{value:"calendar",children:e.jsx(J,{active:a&&t==="calendar",onClose:s})})]})]})})}exports.ReportPreferencesDialog=ee;
|
package/dist/chunks/{report-preferences-dialog-CZiNX1Ri.js → report-preferences-dialog-Dv3vCCFt.js}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as o, Fragment as j, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import oe, { useState as S, useRef as X, useEffect as U, useCallback as E, useMemo as _ } from "react";
|
|
3
|
-
import { az as ee, aA as ce, aB as B, aC as $, aD as de, h as ue, i as me, j as fe, k as he, l as M, m as H, aE as ve, aF as V, aG as z, b as ye, aH as pe, aI as ge, aJ as Se, aK as be, aL as Te } from "./index-
|
|
4
|
-
import { u as ae, c as F, O as W, P as we, a as Ce, B as L, b as ke, d as q, L as te, T as xe, F as Ne, G, I as K } from "./switch-
|
|
3
|
+
import { az as ee, aA as ce, aB as B, aC as $, aD as de, h as ue, i as me, j as fe, k as he, l as M, m as H, aE as ve, aF as V, aG as z, b as ye, aH as pe, aI as ge, aJ as Se, aK as be, aL as Te } from "./index-DazD5k0F.js";
|
|
4
|
+
import { u as ae, c as F, O as W, P as we, a as Ce, B as L, b as ke, d as q, L as te, T as xe, F as Ne, G, I as K } from "./switch-kPUJEC1A.js";
|
|
5
5
|
import { a as Pe } from "./report-runtime-context-CNncA3VD.js";
|
|
6
6
|
import "./x-CXDkqdur.js";
|
|
7
7
|
import "./saved-temporal-bucket-format-Dd2eixTH.js";
|