@object-ui/console 4.0.1 → 4.0.4
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/assets/{AppManagementPage-Da4DphqI.js → AppManagementPage-ynJLzxVY.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-C2rFxE3n.js +1 -0
- package/dist/assets/DashboardView-x75VLMQW.js +1 -0
- package/dist/assets/MetadataDetailPage-B9EzoQgu.js +1 -0
- package/dist/assets/{MetadataFormDialog-CSuCo9Qt.js → MetadataFormDialog-BebGlAr3.js} +1 -1
- package/dist/assets/{MetadataManagerPage-DJ2ZjoVP.js → MetadataManagerPage-B0xfI-4w.js} +1 -1
- package/dist/assets/{PageView-CJFNRux1.js → PageView-C2GS-SQP.js} +1 -1
- package/dist/assets/{ProfilePage-CK0mmAvw.js → ProfilePage-BO3TRbTV.js} +1 -1
- package/dist/assets/RecordDetailView-Clze41HE.js +1 -0
- package/dist/assets/RecordFormPage-B6mEBKMB.js +1 -0
- package/dist/assets/{ReportView-B6tHCvDV.js → ReportView-B16PsGer.js} +1 -1
- package/dist/assets/{SearchResultsPage-CDUPn8G4.js → SearchResultsPage-932jfRUX.js} +1 -1
- package/dist/assets/{SystemHubPage-CVOYNpyU.js → SystemHubPage-CqrYgpYf.js} +1 -1
- package/dist/assets/{data-adapter-DBWF2sV-.js → data-adapter-BwfAq_h0.js} +1 -1
- package/dist/assets/{getIcon-CWhoWdFA.js → getIcon-DF6zJOtU.js} +1 -1
- package/dist/assets/index-CPatxDwz.js +2 -0
- package/dist/assets/index-vbGrAsEJ.css +2 -0
- package/dist/assets/{plugin-calendar-DBrkXKZq.js → plugin-calendar-D1bCBBwe.js} +1 -1
- package/dist/assets/{plugin-charts-BHH2XtQC.js → plugin-charts-x_9Q2-i_.js} +1 -1
- package/dist/assets/{plugin-chatbot-Cdf-WJAv.js → plugin-chatbot-CgNZnFch.js} +6 -6
- package/dist/assets/{plugin-form-CKcMp4d_.js → plugin-form-DOfn-uRa.js} +1 -1
- package/dist/assets/{plugin-gantt-DwFZiNye.js → plugin-gantt-CHZ4HLjh.js} +1 -1
- package/dist/assets/{plugin-grid-CQS8zk9l.js → plugin-grid-Cn_T_wpz.js} +1 -1
- package/dist/assets/{plugin-kanban-CaM_pxR_.js → plugin-kanban-BsgjJQam.js} +1 -1
- package/dist/assets/{plugin-map-BFlwDcr7.js → plugin-map-DZdVR1tc.js} +1 -1
- package/dist/assets/{plugin-markdown-PR8tBwTD.js → plugin-markdown-BlHuacDq.js} +1 -1
- package/dist/assets/{plugin-timeline-B-vzj0Pe.js → plugin-timeline-OEB0nyvd.js} +1 -1
- package/dist/assets/{plugin-view-djqft75T.js → plugin-view-CJFsgQ9v.js} +1 -1
- package/dist/assets/{plugins-views-BDVYhbx4.js → plugins-views-DqZMtAOw.js} +1 -1
- package/dist/assets/{src-D1MGEpQM.js → src-D5NTzWsi.js} +1 -1
- package/dist/assets/{ui-components-3HVEceOY.js → ui-components-B7mlp0en.js} +1 -1
- package/dist/assets/{ui-layout-_xO4eFwD.js → ui-layout-jqAD528v.js} +1 -1
- package/dist/assets/utils-DMMB8Xfh.js +1 -0
- package/dist/assets/{vendor-charts-DHZsyaJw.js → vendor-charts-D0g2ZI3F.js} +1 -1
- package/dist/index.html +3 -3
- package/package.json +30 -30
- package/dist/assets/ConsoleFloatingChatbot-BWbRwcSc.js +0 -1
- package/dist/assets/DashboardView-l8ACItY-.js +0 -1
- package/dist/assets/MetadataDetailPage-D7yDeoSe.js +0 -1
- package/dist/assets/RecordDetailView-BfzfI4-e.js +0 -1
- package/dist/assets/index-BimUnPgZ.js +0 -2
- package/dist/assets/index-DoG5QbE6.css +0 -2
- /package/dist/assets/{maplibre-gl-ChgVR8ni.js → maplibre-gl-CKvz_wTN.js} +0 -0
- /package/dist/assets/{vendor-dndkit-BGB4qgc3.js → vendor-dndkit-BfOuYFuz.js} +0 -0
- /package/dist/assets/{vendor-icons-core-s9WPLoP3.js → vendor-icons-core-BA-_NHij.js} +0 -0
- /package/dist/assets/{vendor-markdown-D-LpQJes.js → vendor-markdown-Cdqza44B.js} +0 -0
- /package/dist/assets/{vendor-ui-utils-AywTz3cM.js → vendor-ui-utils-Dyl9EYZi.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{o}from"./vendor-ui-utils-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{o}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as s,Fo as c,Jm as l,No as u,Qn as d,Rd as f,ar as p,dn as m,er as h,hc as g,mo as _,pE as v,um as y,yb as b,yr as x}from"./ui-components-B7mlp0en.js";import"./index-CPatxDwz.js";var S=e(t(),1);function C(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}var w=r();function T(){let e=i(),{appName:t}=n(),r=t?`/apps/${t}`:``,{apps:T,refresh:E}=a(),[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(new Set),[j,M]=(0,S.useState)(null),[N,P]=(0,S.useState)(!1),F=(T||[]).filter(e=>{if(!D)return!0;let t=D.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),I=(0,S.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),L=(0,S.useCallback)(()=>{k.size===F.length?A(new Set):A(new Set(F.map(e=>e.name)))},[k.size,F]),R=(0,S.useCallback)(async e=>{P(!0);try{let t=e.active===!1;o.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await E()}catch{o.error(`Failed to toggle app status`)}finally{P(!1)}},[E]),z=(0,S.useCallback)(async e=>{P(!0);try{o.success(`${e.label||e.name} set as default`),await E()}catch{o.error(`Failed to set default app`)}finally{P(!1)}},[E]),B=(0,S.useCallback)(async e=>{if(j!==e.name){M(e.name);return}P(!0);try{o.success(`${e.label||e.name} deleted`),M(null),await E()}catch{o.error(`Failed to delete app`)}finally{P(!1)}},[j,E]),V=(0,S.useCallback)(async e=>{P(!0);try{o.success(`${k.size} apps ${e?`enabled`:`disabled`}`),A(new Set),await E()}catch{o.error(`Bulk operation failed`)}finally{P(!1)}},[k,E]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,w.jsxs)(x,{onClick:()=>e(`${r}/create-app`),"data-testid":`create-app-btn`,children:[(0,w.jsx)(y,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,w.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,w.jsx)(f,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,w.jsx)(m,{id:`app-search`,placeholder:`Search apps...`,value:D,onChange:e=>O(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),k.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(p,{variant:`secondary`,children:[k.size,` selected`]}),(0,w.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>V(!0),disabled:N,children:`Enable`}),(0,w.jsx)(x,{variant:`outline`,size:`sm`,onClick:()=>V(!1),disabled:N,children:`Disable`})]})]}),F.length>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,w.jsx)(d,{id:`select-all-apps`,checked:k.size===F.length&&F.length>0,onCheckedChange:()=>L()}),(0,w.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,F.length,`)`]})]}),F.length===0?(0,w.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,w.jsx)(b,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,w.jsx)(`p`,{children:`No apps found.`})]}):(0,w.jsx)(`div`,{className:`grid gap-3`,children:F.map(t=>{let n=t.active!==!1,i=t.isDefault===!0,a=j===t.name;return(0,w.jsx)(s,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,w.jsxs)(h,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,w.jsx)(d,{id:`select-app-${t.name}`,checked:k.has(t.name),onCheckedChange:()=>I(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,w.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,w.jsx)(b,{className:`h-4 w-4`})}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`span`,{className:`font-medium truncate`,children:C(t.label)||t.name}),i&&(0,w.jsx)(p,{variant:`default`,className:`text-xs`,children:`Default`}),(0,w.jsx)(p,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:C(t.description)})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t.name}`),children:(0,w.jsx)(v,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${r}/edit-app/${t.name}`),children:(0,w.jsx)(l,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>R(t),disabled:N,children:n?(0,w.jsx)(u,{className:`h-4 w-4`}):(0,w.jsx)(c,{className:`h-4 w-4`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>z(t),disabled:N||i,children:(0,w.jsx)(g,{className:`h-4 w-4 ${i?`fill-current text-yellow-500`:``}`})}),(0,w.jsx)(x,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>B(t),disabled:N,className:a?`text-destructive`:``,children:(0,w.jsx)(_,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{T as AppManagementPage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{$t as r,Qt as i,en as a,nn as o,tn as s}from"./ui-components-B7mlp0en.js";import{n as c,r as l,t as u}from"./plugin-chatbot-CgNZnFch.js";var d=e(t(),1),f=n(),p=`/api/v1/ai`;function m(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`/console/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:`https://demo.objectstack.ai`,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${p}`}function h({appLabel:e,objects:t,agents:n,agentsLoading:c,agentsError:p,activeAgent:m,onAgentChange:h,chatApi:g}){let _=t.map(e=>e.label||e.name).join(`, `),v=d.useMemo(()=>n.find(e=>e.name===m)?.label??m??e,[n,m,e]),y=m?`Hello! I'm **${v}**, your ${e} assistant. How can I help you today?`:`Hello! I'm your **${e}** assistant. ${p?`(Backend unreachable — running in offline demo mode.)`:``}`,{messages:b,isLoading:x,error:S,sendMessage:C,stop:w,reload:T,clear:E}=l({api:g,conversationId:m?`${e}:${m}`:void 0,body:{context:{activeApp:e,objects:t.map(e=>({name:e.name,label:e.label})),agentName:m}},initialMessages:[{id:`welcome`,role:`assistant`,content:y}],autoResponse:!g,autoResponseText:_?`I can help you work with ${_}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600}),D=n.length>0?(0,f.jsxs)(i,{value:m,onValueChange:h,disabled:c,children:[(0,f.jsx)(s,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,f.jsx)(o,{placeholder:`Choose agent...`})}),(0,f.jsx)(r,{align:`end`,children:n.map(e=>(0,f.jsxs)(a,{value:e.name,className:`text-xs`,children:[(0,f.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,f.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null;return(0,f.jsx)(u,{floatingConfig:{position:`bottom-right`,defaultOpen:!1,panelWidth:420,panelHeight:560,title:`${e} Assistant`,triggerSize:56},headerExtra:D,messages:b,placeholder:m?`Ask ${v}...`:c?`Loading agents...`:`Ask anything...`,onSendMessage:e=>C(e),onClear:E,onStop:x?w:void 0,onReload:T,isLoading:x,error:S,enableMarkdown:!0})}function g({appLabel:e,objects:t,apiBase:n,defaultAgent:r}){let i=d.useMemo(()=>m(n),[n]),a={BASE_URL:`/console/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:`https://demo.objectstack.ai`,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:o,isLoading:s,error:l}=c({apiBase:i}),[u,p]=d.useState(void 0);d.useEffect(()=>{if(!u&&o.length>0){let e=r??a;p(((e?o.find(t=>t.name===e):void 0)??o[0]).name)}},[o,u,r,a]);let g=u?`${i}/agents/${encodeURIComponent(u)}/chat`:void 0;return(0,f.jsx)(h,{appLabel:e,objects:t,agents:o,agentsLoading:s,agentsError:l,activeAgent:u,onAgentChange:p,chatApi:g},g??`local`)}export{g as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,t as i}from"./vendor-react-B1k2FF9f.js";import{a,f as o,p as ee}from"./framework-CoXA0nY6.js";import{d as s}from"./infrastructure-Djv3I7gr.js";import{o as c}from"./vendor-ui-utils-Dyl9EYZi.js";import{Gn as te,Jm as ne,Jn as l,Kn as u,Oj as d,Un as f,Vs as p,Wn as m,ao as h,at as re,it as ie,jj as g,mo as ae,ot as oe,qn as se,um as _,vj as v,xb as y,yb as b,yr as x}from"./ui-components-B7mlp0en.js";import{r as S}from"./utils-DMMB8Xfh.js";import{i as C,n as w,r as T}from"./plugins-views-DqZMtAOw.js";import{n as E}from"./plugin-form-DOfn-uRa.js";import{a as D,o as ce,s as le}from"./index-CPatxDwz.js";var O=e({DashboardView:()=>z}),k=t(n(),1),A=i(),j=[{type:`metric`,label:`KPI Metric`,Icon:h},{type:`bar`,label:`Bar Chart`,Icon:g},{type:`line`,label:`Line Chart`,Icon:d},{type:`pie`,label:`Pie Chart`,Icon:v},{type:`table`,label:`Table`,Icon:p},{type:`grid`,label:`Grid`,Icon:b}],M=0;function N(){return M+=1,`widget_${Date.now()}_${M}`}function P(e){return!e.widgets?.length||!e.widgets.some(e=>!e.id)?e:{...e,widgets:e.widgets.map(e=>e.id?e:{...e,id:N()})}}function F(e){let t=j.find(t=>t.type===e);return t?`New ${t.label}`:`New Widget`}function I(e){return{title:e.title??``,description:e.description??``,type:e.type??`metric`,object:e.object??``,categoryField:e.categoryField??``,valueField:e.valueField??``,aggregate:e.aggregate??`count`,layoutW:e.layout?.w??1,layoutH:e.layout?.h??1,colorVariant:e.colorVariant??`default`,actionUrl:e.actionUrl??``}}function L(e,t){return{title:e.title,description:e.description,type:e.type,object:e.object,categoryField:e.categoryField,valueField:e.valueField,aggregate:e.aggregate,layout:{...t.layout||{},w:e.layoutW,h:e.layoutH},colorVariant:e.colorVariant,actionUrl:e.actionUrl}}function R(e){return{columns:e.columns??3,gap:e.gap??4,rowHeight:String(e.rowHeight??`120`),refreshInterval:String(e.refreshInterval??`0`),title:e.title??``,showDescription:e.showDescription??!0,theme:e.theme??`auto`}}function z({dataSource:e}){let{dashboardName:t}=r(),{showDebug:n}=le(),i=o(),{t:d}=a(),{dashboardLabel:p,dashboardDescription:h}=s(),[g,v]=(0,k.useState)(!0),[b,O]=(0,k.useState)(!1),[M,z]=(0,k.useState)(null),[B,V]=(0,k.useState)(0),[H,U]=(0,k.useState)(null),W=(0,k.useCallback)(e=>{U(t=>(t&&t.resolve(e),null))},[]),ue=(0,k.useCallback)(e=>new Promise(t=>{let n;if(typeof e==`string`){let t=e.match(/^(create|new|add|edit|update)_(.+)$/);if(t){let e=t[1];n={objectName:t[2],mode:e===`edit`||e===`update`?`edit`:`create`}}else n={objectName:e,mode:`create`}}else n=e;U({schema:n,resolve:t})}),[]),de=(0,k.useMemo)(()=>({export_dashboard_pdf:async()=>{c.info(`Preparing PDF export…`);try{return window.print(),{success:!0}}catch(e){return c.error(`Export failed: ${e?.message||String(e)}`),{success:!1,error:e?.message||String(e)}}},forecast_dashboard:async()=>(c.info(`Forecast view coming soon`),{success:!0})}),[]);(0,k.useEffect)(()=>{v(!0),Y(null),O(!1),z(null),queueMicrotask(()=>v(!1))},[t]);let{dashboards:fe,objects:G,refresh:K}=ee(),q=fe?.find(e=>e.name===t),[J,Y]=(0,k.useState)(null);(0,k.useEffect)(()=>{b||Y(null)},[q]);let X=(0,k.useCallback)(async e=>{try{i&&(await i.update(`sys_dashboard`,t,e),K().catch(()=>{}))}catch(e){console.warn(`[DashboardView] Auto-save failed:`,e)}},[i,t,K]),pe=(0,k.useCallback)(()=>{Y(P(q)),O(!0),V(e=>e+1)},[q]),Z=(0,k.useCallback)(()=>{O(!1),z(null)},[]),me=(0,k.useCallback)(e=>{if(!J)return;let t=N(),n={id:t,title:F(e),type:e,layout:{x:0,y:J.widgets?.length??0,w:J.columns??2,h:1}},r={...J,widgets:[...J.widgets||[],n]};Y(r),X(r),z(t),V(e=>e+1)},[J,X]),he=(0,k.useCallback)(e=>{if(!J)return;let t={...J,widgets:J.widgets.filter(t=>t.id!==e)};Y(t),X(t),M===e&&z(null)},[J,M,X]),ge=(0,k.useMemo)(()=>R(J||q),[B]),_e=(0,k.useCallback)(e=>{if(!J)return;let t={...J,columns:e.columns,gap:e.gap,rowHeight:e.rowHeight,refreshInterval:Number(e.refreshInterval)||0,title:e.title,showDescription:e.showDescription,theme:e.theme};Y(t),X(t),V(e=>e+1)},[J,X]),ve=(0,k.useCallback)((e,t)=>{J&&Y(n=>n&&(e===`refreshInterval`?{...n,refreshInterval:Number(t)||0}:{...n,[e]:t}))},[J]),Q=J?.widgets?.find(e=>e.id===M),ye=(0,k.useMemo)(()=>Q?I(Q):{},[M,B]),be=(0,k.useCallback)(e=>{if(!J||!M||!Q)return;let t=L(e,Q),n={...J,widgets:J.widgets.map(e=>e.id===M?{...e,...t}:e)};Y(n),X(n),V(e=>e+1)},[J,M,Q,X]),xe=(0,k.useCallback)((e,t)=>{M&&Y(n=>{if(!n)return n;let r=n.widgets?.find(e=>e.id===M);if(!r)return n;let i=I(r);i[e]=t;let a=L(i,r);return{...n,widgets:n.widgets.map(e=>e.id===M?{...e,...a}:e)}})},[M]),Se=(0,k.useMemo)(()=>{if(G?.length)return G.map(e=>({value:e.name,label:e.label||e.name}))},[G]),Ce=(0,k.useMemo)(()=>{let e=Q?.object;if(!e||!G?.length)return;let t=G.find(t=>t.name===e);if(!t?.fields)return;let n=t.fields;return Array.isArray(n)?n.filter(e=>e.name).map(e=>({value:e.name,label:e.label||e.name})):Object.entries(n).map(([e,t])=>({value:e,label:t.label||e}))},[Q?.object,G]);if(g)return(0,A.jsx)(D,{});if(!q)return(0,A.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,A.jsxs)(ie,{children:[(0,A.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,A.jsx)(y,{className:`h-6 w-6 text-muted-foreground`})}),(0,A.jsx)(oe,{children:`Dashboard Not Found`}),(0,A.jsxs)(re,{children:[`The dashboard "`,t,`" could not be found. It may have been removed or renamed.`]})]})});let $=J||q;return(0,A.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,A.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,A.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,A.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:p({name:q.name,label:S(q.label,d)})||q.name}),(()=>{let e=h({name:q.name,description:S(q.description,d)});return e?(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:e}):null})()]}),(0,A.jsxs)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:[b&&(0,A.jsx)(`div`,{className:`flex items-center gap-1 mr-2`,role:`toolbar`,"aria-label":`Add widgets`,"data-testid":`dashboard-widget-toolbar`,children:j.map(({type:e,label:t,Icon:n})=>(0,A.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>me(e),className:`inline-flex items-center gap-1 rounded-md border border-input bg-background px-2 py-1.5 text-[11px] font-medium text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,title:`Add ${t}`,"aria-label":`Add ${t} widget`,children:[(0,A.jsx)(_,{className:`h-3 w-3`}),(0,A.jsx)(n,{className:`h-3 w-3`})]},e))}),(0,A.jsxs)(`button`,{type:`button`,onClick:pe,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`dashboard-edit-button`,children:[(0,A.jsx)(ne,{className:`h-3.5 w-3.5`}),d(`common.edit`,{defaultValue:`Edit`})]})]})]}),(0,A.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,A.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-2 sm:p-4 md:p-6`,children:(0,A.jsx)(C,{schema:$,dataSource:e,designMode:b,selectedWidgetId:M,onWidgetClick:z,modalHandler:ue,scriptHandlers:de})}),Q?(0,A.jsx)(w,{open:b,onClose:Z,config:ye,onSave:be,onFieldChange:xe,availableObjects:Se,availableFields:Ce,headerExtra:(0,A.jsx)(x,{size:`sm`,variant:`ghost`,onClick:()=>he(M),className:`h-7 w-7 p-0 text-destructive hover:text-destructive`,"data-testid":`widget-delete-button`,title:`Delete widget`,children:(0,A.jsx)(ae,{className:`h-3.5 w-3.5`})})},M):(0,A.jsx)(T,{open:b,onClose:Z,config:ge,onSave:_e,onFieldChange:ve}),(0,A.jsx)(ce,{open:n,sections:[{title:`Dashboard Configuration`,data:$}]})]}),H&&H.schema?.objectName?(0,A.jsx)(E,{schema:{type:`object-form`,formType:`modal`,objectName:H.schema.objectName,mode:H.schema.mode||`create`,recordId:H.schema.recordId,title:H.schema.title,description:H.schema.description,fields:H.schema.fields,open:!0,onOpenChange:e=>{e||W({success:!1})},onSuccess:e=>{W({success:!0,reload:!0,data:e})},onCancel:()=>{W({success:!1})},showSubmit:!0,showCancel:!0},dataSource:i}):H?(0,A.jsx)(f,{open:!0,onOpenChange:e=>{e||W({success:!1})},children:(0,A.jsxs)(m,{children:[(0,A.jsxs)(se,{children:[(0,A.jsx)(l,{children:H.schema?.title||`Action`}),H.schema?.description&&(0,A.jsx)(te,{children:H.schema.description})]}),(0,A.jsxs)(u,{children:[(0,A.jsx)(x,{variant:`outline`,onClick:()=>W({success:!1}),children:`Cancel`}),(0,A.jsx)(x,{onClick:()=>W({success:!0}),children:`OK`})]})]})}):null]})}export{O as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{D as a,p as o}from"./framework-CoXA0nY6.js";import{c as s}from"./infrastructure-Djv3I7gr.js";import{o as c}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as l,Cy as u,Jm as d,ar as f,cI as p,er as m,no as h,nr as g,rr as _,yr as v}from"./ui-components-B7mlp0en.js";import{r as y}from"./index-CPatxDwz.js";import{i as b,n as x,t as S}from"./getIcon-DF6zJOtU.js";import{t as C}from"./MetadataFormDialog-BebGlAr3.js";var w=e(t(),1),T=r(),E=class extends w.Component{constructor(e){super(e),this.state={hasError:!1}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[MetadataDetailPage] Schema rendering error:`,e,t.componentStack)}render(){return this.state.hasError?(0,T.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/5 p-6 text-center`,"data-testid":`schema-render-error`,children:[(0,T.jsx)(h,{className:`h-8 w-8 mx-auto mb-3 text-destructive`}),(0,T.jsxs)(`p`,{className:`text-sm font-medium text-destructive`,children:[`Failed to render `,this.props.fallbackLabel||`detail`,` page`]}),(0,T.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:this.state.error?.message||`An unexpected error occurred.`})]}):this.props.children}};function D({schema:e}){let t=e.body||[];return t.length===0?null:(0,T.jsx)(`div`,{className:`flex flex-col gap-6`,"data-testid":`schema-detail-content`,children:t.map((e,t)=>(0,T.jsx)(a,{schema:e},e?.id||t))})}function O(){let e=i(),{appName:t,metadataType:r,itemName:a}=n(),h=t?`/apps/${t}`:``,O=y(),{refresh:k}=o(),{user:A}=s(),j=A?.role===`admin`,M=r?b(r):void 0,[N,P]=(0,w.useState)(null),[F,I]=(0,w.useState)(!0),[L,R]=(0,w.useState)(!1),[z,B]=(0,w.useState)(!1),V=(0,w.useRef)(O);V.current=O;let H=(0,w.useRef)(M?.label);H.current=M?.label;let U=(0,w.useCallback)(async()=>{let e=V.current;if(!(!e||!r||!a)){I(!0);try{P((await e.getItems(r)).find(e=>String(e.name)===a&&!e._deleted)??null)}catch{c.error(`Failed to load ${H.current??r}`)}finally{I(!1)}}},[r,a]);(0,w.useEffect)(()=>{U()},[U]);let W=(0,w.useCallback)(async e=>{let t=V.current;if(!(!t||!r||!a)){B(!0);try{let n={...N,...e};await t.saveMetadataItem(r,a,n),await k(),await U(),c.success(`${H.current??`Item`} "${a}" updated`)}catch{throw c.error(`Failed to update "${a}"`),Error(`Failed to save ${H.current??`item`} "${a}"`)}finally{B(!1)}}},[r,a,N,k,U]),G=M?.customRoute?`${h}${M.customRoute}`:`${h}/system/metadata/${r??``}`;if(!M)return(0,T.jsx)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:(0,T.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,children:[(0,T.jsxs)(`p`,{className:`text-lg font-medium`,children:[`Unknown metadata type: `,r]}),(0,T.jsx)(v,{variant:`outline`,className:`mt-4`,onClick:()=>e(`${h}/system`),children:`Back to System Settings`})]})});if(M.pageSchemaFactory){let t=M.pageSchemaFactory(a,N),n=S(M.icon);return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:[(0,T.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(v,{variant:`ghost`,size:`icon`,onClick:()=>e(G),"data-testid":`back-to-list-btn`,children:(0,T.jsx)(p,{className:`h-4 w-4`})}),(0,T.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,T.jsx)(n,{className:`h-5 w-5 text-primary`})}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:t.title||a}),(0,T.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[M.label,` · `,(0,T.jsx)(`span`,{className:`font-mono text-xs`,children:a})]})]})]})}),(0,T.jsx)(E,{fallbackLabel:M.label,children:(0,T.jsx)(D,{schema:t})})]})}let K=S(M.icon),q=M.editable!==!1&&j,J=M.formFields??x,Y=M.detailComponent;return(0,T.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-detail-page`,children:[(0,T.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,T.jsx)(v,{variant:`ghost`,size:`icon`,onClick:()=>e(G),"data-testid":`back-to-list-btn`,children:(0,T.jsx)(p,{className:`h-4 w-4`})}),(0,T.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,T.jsx)(K,{className:`h-5 w-5 text-primary`})}),(0,T.jsxs)(`div`,{className:`min-w-0`,children:[(0,T.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:F?`Loading...`:String(N?.label??N?.name??a)}),(0,T.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:[M.label,` Details`]})]})]}),q&&!F&&N&&(0,T.jsxs)(v,{variant:`outline`,onClick:()=>R(!0),disabled:z,"data-testid":`detail-edit-btn`,children:[(0,T.jsx)(d,{className:`mr-2 h-4 w-4`}),`Edit`]})]}),F&&(0,T.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`detail-loading`,children:[(0,T.jsx)(u,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading...`]}),!F&&!N&&(0,T.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,"data-testid":`detail-not-found`,children:[(0,T.jsxs)(`p`,{className:`text-lg font-medium`,children:[M.label,` "`,a,`" not found.`]}),(0,T.jsxs)(v,{variant:`outline`,className:`mt-4`,onClick:()=>e(G),children:[`Back to `,M.pluralLabel]})]}),!F&&N&&(0,T.jsx)(T.Fragment,{children:Y?(0,T.jsx)(Y,{item:N}):(0,T.jsxs)(l,{"data-testid":`detail-card`,children:[(0,T.jsx)(g,{children:(0,T.jsxs)(_,{className:`flex items-center gap-2`,children:[(0,T.jsx)(f,{variant:`secondary`,children:M.label}),String(N.name??``)]})}),(0,T.jsx)(m,{children:(0,T.jsx)(`dl`,{className:`grid gap-3 sm:grid-cols-2`,children:J.map(e=>(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`dt`,{className:`text-sm font-medium text-muted-foreground`,children:e.label}),(0,T.jsx)(`dd`,{className:`mt-1 text-sm`,children:String(N[e.key]??`—`)})]},e.key))})})]})}),q&&N&&(0,T.jsx)(C,{open:L,onOpenChange:R,mode:`edit`,typeLabel:M.label,formFields:M.formFields,initialValues:N,onSubmit:W})]})}export{O as MetadataDetailPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{Cy as r,Gn as i,Jn as a,Kn as o,Un as s,Wn as c,dn as l,fn as u,pt as d,qn as f,wt as p,yr as m}from"./ui-components-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{Cy as r,Gn as i,Jn as a,Kn as o,Un as s,Wn as c,dn as l,fn as u,pt as d,qn as f,wt as p,yr as m}from"./ui-components-B7mlp0en.js";import{n as h}from"./getIcon-DF6zJOtU.js";var g=e(t(),1),_=n();function v({open:e,onOpenChange:t,mode:n,typeLabel:v,formFields:y,initialValues:b,onSubmit:x}){let S=y??h,C=n===`edit`,[w,T]=(0,g.useState)({}),[E,D]=(0,g.useState)(!1);(0,g.useEffect)(()=>{if(e){let e={};for(let t of S)e[t.key]=String(b?.[t.key]??``);T(e)}},[e,b,S]);let O=(0,g.useCallback)((e,t)=>{T(n=>({...n,[e]:t}))},[]),k=(0,g.useCallback)(async()=>{D(!0);try{await x(w),t(!1)}catch{}finally{D(!1)}},[w,x,t]),A=S.filter(e=>e.required).every(e=>(w[e.key]??``).trim().length>0);return(0,_.jsx)(s,{open:e,onOpenChange:t,children:(0,_.jsxs)(c,{className:`sm:max-w-[480px]`,"data-testid":`metadata-form-dialog`,children:[(0,_.jsxs)(f,{children:[(0,_.jsx)(a,{children:C?`Edit ${v}`:`New ${v}`}),(0,_.jsx)(i,{children:C?`Update the ${v.toLowerCase()} details below.`:`Fill in the details to create a new ${v.toLowerCase()}.`})]}),(0,_.jsx)(`div`,{className:`space-y-4 py-4`,children:S.map(e=>{let t=E||C&&e.disabledOnEdit===!0,n=w[e.key]??``,r=`metadata-field-${e.key}`;return(0,_.jsxs)(`div`,{className:`space-y-2`,children:[(0,_.jsxs)(u,{htmlFor:r,children:[e.label,e.required&&(0,_.jsx)(`span`,{className:`text-destructive ml-1`,"aria-hidden":`true`,children:`*`})]}),e.type===`textarea`?(0,_.jsx)(d,{id:r,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`}):e.type===`select`&&e.options?(0,_.jsxs)(`select`,{id:r,value:n,onChange:t=>O(e.key,t.target.value),disabled:t,"aria-required":e.required?!0:void 0,className:`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,"data-testid":`metadata-field-${e.key}`,children:[(0,_.jsx)(`option`,{value:``,children:`Select...`}),e.options.map(e=>(0,_.jsx)(`option`,{value:e.value,children:e.label},e.value))]}):e.type===`number`?(0,_.jsx)(l,{id:r,type:`number`,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`}):e.type===`boolean`?(0,_.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,_.jsx)(p,{id:r,checked:n===`true`,onCheckedChange:t=>O(e.key,String(t)),disabled:t,"data-testid":`metadata-field-${e.key}`}),(0,_.jsx)(u,{htmlFor:r,className:`text-sm text-muted-foreground cursor-pointer`,children:n===`true`?`Yes`:`No`})]}):(0,_.jsx)(l,{id:r,value:n,onChange:t=>O(e.key,t.target.value),placeholder:e.placeholder,disabled:t,"data-testid":`metadata-field-${e.key}`})]},e.key)})}),(0,_.jsxs)(o,{children:[(0,_.jsx)(m,{variant:`outline`,onClick:()=>t(!1),disabled:E,"data-testid":`metadata-form-cancel-btn`,children:`Cancel`}),(0,_.jsxs)(m,{onClick:k,disabled:E||!A,"data-testid":`metadata-form-submit-btn`,children:[E&&(0,_.jsx)(r,{className:`mr-2 h-4 w-4 animate-spin`}),C?`Save`:`Create`]})]})]})})}export{v as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{c as o}from"./infrastructure-Djv3I7gr.js";import{o as s}from"./vendor-ui-utils-AywTz3cM.js";import{$n as c,Cy as l,Jm as u,Rd as d,ar as ee,cI as f,dn as p,er as te,mo as m,um as h,yr as g}from"./ui-components-3HVEceOY.js";import{r as _}from"./index-BimUnPgZ.js";import{i as ne,t as v}from"./getIcon-CWhoWdFA.js";import{t as y}from"./MetadataFormDialog-CSuCo9Qt.js";var b=e(t(),1),x=r();function re({items:e,columns:t,editable:n=!1,saving:r=!1,deletingName:i=null,typeLabel:a=`item`,rowActions:o=[],onItemClick:s,onEdit:c,onDelete:l}){return(0,x.jsx)(`div`,{className:`rounded-lg border bg-card`,"data-testid":`metadata-grid`,children:(0,x.jsx)(`div`,{className:`overflow-x-auto`,children:(0,x.jsxs)(`table`,{className:`w-full text-sm`,"aria-label":`${a} list`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b bg-muted/50`,children:[t.map(e=>(0,x.jsx)(`th`,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,style:e.width?{width:e.width}:void 0,children:e.label},e.key)),n&&(0,x.jsx)(`th`,{className:`px-4 py-3 text-right font-medium text-muted-foreground w-24`,children:`Actions`})]})}),(0,x.jsx)(`tbody`,{children:e.map(e=>{let d=String(e.name??``);return(0,x.jsxs)(`tr`,{className:`border-b last:border-0 hover:bg-accent/50 cursor-pointer transition-colors`,"data-testid":`metadata-item-${d}`,onClick:()=>s?.(d),children:[t.map(t=>{let n=String(e[t.key]??`—`);return(0,x.jsx)(`td`,{className:`px-4 py-3 truncate max-w-[200px]`,title:n,children:n},t.key)}),n&&(0,x.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[o.map(t=>(0,x.jsx)(g,{variant:t.variant??`ghost`,size:`icon`,title:t.label,"aria-label":t.label,onClick:n=>{n.stopPropagation(),t.handler?.(e)},"data-testid":`row-action-${t.key}-${d}`,children:(0,x.jsx)(`span`,{className:`text-xs`,children:t.label.charAt(0)})},t.key)),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:`Edit ${a}`,onClick:t=>{t.stopPropagation(),c?.(e)},disabled:r,"data-testid":`edit-${d}-btn`,children:(0,x.jsx)(u,{className:`h-4 w-4`})}),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:i===d?`Click again to confirm`:`Delete ${a}`,onClick:e=>{e.stopPropagation(),l?.(d)},disabled:r,"data-testid":`delete-${d}-btn`,children:(0,x.jsx)(m,{className:`h-4 w-4 ${i===d?`text-destructive`:``}`})})]})})]},d)})})]})})})}function S(){let e=i(),{appName:t,metadataType:r}=n(),S=t?`/apps/${t}`:``,C=_(),{refresh:w}=a(),{user:ie}=o(),T=ie?.role===`admin`,E=r?ne(r):void 0,[D,O]=(0,b.useState)([]),[k,A]=(0,b.useState)(!0),[j,ae]=(0,b.useState)(``),[M,N]=(0,b.useState)(!1),[P,F]=(0,b.useState)(null),[oe,I]=(0,b.useState)(!1),[L,R]=(0,b.useState)(`create`),[z,B]=(0,b.useState)(null),V=(0,b.useCallback)(async()=>{if(!(!C||!r)){A(!0);try{O((await C.getItems(r)).filter(e=>!e._deleted))}catch{s.error(`Failed to load ${E?.pluralLabel??r}`)}finally{A(!1)}}},[C,r,E?.pluralLabel]);(0,b.useEffect)(()=>{V()},[V]);let H=(0,b.useMemo)(()=>{if(!j.trim())return D;let e=j.toLowerCase();return D.filter(t=>{let n=String(t.name??``).toLowerCase(),r=String(t.label??``).toLowerCase();return n.includes(e)||r.includes(e)})},[D,j]),U=(0,b.useCallback)(async e=>{if(!(!C||!r))if(P===e){N(!0);try{await C.deleteMetadataItem(r,e),O(t=>t.filter(t=>t.name!==e)),await w(),s.success(`${E?.label??`Item`} "${e}" deleted`)}catch{s.error(`Failed to delete "${e}"`)}finally{N(!1),F(null)}}else F(e)},[C,r,P,E?.label,w]),W=(0,b.useCallback)(()=>{B(null),R(`create`),I(!0)},[]),G=(0,b.useCallback)(e=>{B(e),R(`edit`),I(!0)},[]),K=(0,b.useCallback)(async e=>{if(!C||!r)return;let t=e.name??String(z?.name??``);if(t){N(!0);try{let n=L===`edit`?{...z,...e}:{...e};await C.saveMetadataItem(r,t,n),await w(),await V(),s.success(L===`edit`?`${E?.label??`Item`} "${t}" updated`:`${E?.label??`Item`} "${t}" created`)}catch{throw s.error(L===`edit`?`Failed to update "${t}"`:`Failed to create "${t}"`),Error(`Failed to save ${E?.label??`item`} "${t}"`)}finally{N(!1)}}},[C,r,z,L,E?.label,w,V]);if(!E)return(0,x.jsx)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:(0,x.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,children:[(0,x.jsxs)(`p`,{className:`text-lg font-medium`,children:[`Unknown metadata type: `,r]}),(0,x.jsx)(g,{variant:`outline`,className:`mt-4`,onClick:()=>e(`${S}/system`),children:`Back to System Settings`})]})});let q=v(E.icon),J=E.editable!==!1&&T,Y=E.listComponent;if(Y)return(0,x.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:[(0,x.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`icon`,onClick:()=>e(`${S}/system`),"data-testid":`back-to-hub-btn`,children:(0,x.jsx)(f,{className:`h-4 w-4`})}),(0,x.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,x.jsx)(q,{className:`h-5 w-5 text-primary`})}),(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:E.pluralLabel}),(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:E.description})]})]})}),(0,x.jsx)(Y,{config:E,basePath:S,metadataType:r,isAdmin:T})]});let X=(E.actions??[]).filter(e=>e.scope===`page`),Z=(E.actions??[]).filter(e=>e.scope===`row`),Q=E.listMode??`card`,$=Q===`grid`||Q===`table`,se=E.columns??[{key:`name`,label:`Name`},{key:`label`,label:`Label`}];return(0,x.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:[(0,x.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`icon`,onClick:()=>e(`${S}/system`),"data-testid":`back-to-hub-btn`,children:(0,x.jsx)(f,{className:`h-4 w-4`})}),(0,x.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,x.jsx)(q,{className:`h-5 w-5 text-primary`})}),(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:E.pluralLabel}),(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:E.description})]})]}),J&&(0,x.jsxs)(g,{onClick:W,"data-testid":`create-metadata-btn`,children:[(0,x.jsx)(h,{className:`mr-2 h-4 w-4`}),`New `,E.label]}),X.length>0&&(0,x.jsx)(`div`,{className:`flex items-center gap-2`,children:X.map(e=>(0,x.jsx)(g,{variant:e.variant??`outline`,onClick:()=>e.handler?.(),"data-testid":`page-action-${e.key}`,children:e.label},e.key))})]}),(0,x.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,x.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,x.jsxs)(`label`,{htmlFor:`metadata-search`,className:`sr-only`,children:[`Search `,E.pluralLabel.toLowerCase()]}),(0,x.jsx)(d,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,x.jsx)(p,{id:`metadata-search`,placeholder:`Search ${E.pluralLabel.toLowerCase()}...`,value:j,onChange:e=>ae(e.target.value),className:`pl-8`,"data-testid":`metadata-search-input`})]}),(0,x.jsxs)(ee,{variant:`secondary`,"data-testid":`metadata-count-badge`,children:[H.length,` `,E.pluralLabel.toLowerCase()]})]}),k&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`metadata-loading`,children:[(0,x.jsx)(l,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading `,E.pluralLabel.toLowerCase(),`...`]}),M&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`metadata-saving`,children:[(0,x.jsx)(l,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Saving...`]}),!k&&H.length===0&&(0,x.jsx)(`div`,{className:`text-center text-muted-foreground py-12`,"data-testid":`metadata-empty`,children:(0,x.jsxs)(`p`,{children:[`No `,E.pluralLabel.toLowerCase(),` found.`]})}),!k&&H.length>0&&!$&&(0,x.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:H.map(t=>{let n=String(t.name??``),i=String(t.label??t.name??``),a=String(t.description??``);return(0,x.jsx)(c,{className:`transition-colors hover:bg-accent/50 cursor-pointer`,"data-testid":`metadata-item-${n}`,onClick:()=>e(`${S}/system/metadata/${r}/${n}`),children:(0,x.jsxs)(te,{className:`flex items-center justify-between p-4`,children:[(0,x.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,x.jsx)(`p`,{className:`font-medium truncate`,children:i}),(0,x.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:n}),a&&(0,x.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 truncate`,children:a})]}),J&&(0,x.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0 ml-2`,children:[Z.map(e=>(0,x.jsx)(g,{variant:e.variant??`ghost`,size:`icon`,title:e.label,onClick:n=>{n.stopPropagation(),e.handler?.(t)},"data-testid":`row-action-${e.key}-${n}`,children:(0,x.jsx)(`span`,{className:`text-xs`,children:e.label.charAt(0)})},e.key)),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:`Edit ${E.label.toLowerCase()}`,onClick:e=>{e.stopPropagation(),G(t)},disabled:M,"data-testid":`edit-${n}-btn`,children:(0,x.jsx)(u,{className:`h-4 w-4`})}),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:P===n?`Click again to confirm`:`Delete ${E.label.toLowerCase()}`,onClick:e=>{e.stopPropagation(),U(n)},disabled:M,"data-testid":`delete-${n}-btn`,children:(0,x.jsx)(m,{className:`h-4 w-4 ${P===n?`text-destructive`:``}`})})]})]})},n)})}),!k&&H.length>0&&$&&(0,x.jsx)(re,{items:H,columns:se,editable:J,saving:M,deletingName:P,typeLabel:E.label.toLowerCase(),rowActions:Z,onItemClick:t=>e(`${S}/system/metadata/${r}/${t}`),onEdit:G,onDelete:U}),J&&(0,x.jsx)(y,{open:oe,onOpenChange:I,mode:L,typeLabel:E.label,formFields:E.formFields,initialValues:z??void 0,onSubmit:K})]})}export{S as MetadataManagerPage};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{p as a}from"./framework-CoXA0nY6.js";import{c as o}from"./infrastructure-Djv3I7gr.js";import{o as s}from"./vendor-ui-utils-Dyl9EYZi.js";import{$n as c,Cy as l,Jm as u,Rd as d,ar as ee,cI as f,dn as p,er as te,mo as m,um as h,yr as g}from"./ui-components-B7mlp0en.js";import{r as _}from"./index-CPatxDwz.js";import{i as ne,t as v}from"./getIcon-DF6zJOtU.js";import{t as y}from"./MetadataFormDialog-BebGlAr3.js";var b=e(t(),1),x=r();function re({items:e,columns:t,editable:n=!1,saving:r=!1,deletingName:i=null,typeLabel:a=`item`,rowActions:o=[],onItemClick:s,onEdit:c,onDelete:l}){return(0,x.jsx)(`div`,{className:`rounded-lg border bg-card`,"data-testid":`metadata-grid`,children:(0,x.jsx)(`div`,{className:`overflow-x-auto`,children:(0,x.jsxs)(`table`,{className:`w-full text-sm`,"aria-label":`${a} list`,children:[(0,x.jsx)(`thead`,{children:(0,x.jsxs)(`tr`,{className:`border-b bg-muted/50`,children:[t.map(e=>(0,x.jsx)(`th`,{className:`px-4 py-3 text-left font-medium text-muted-foreground`,style:e.width?{width:e.width}:void 0,children:e.label},e.key)),n&&(0,x.jsx)(`th`,{className:`px-4 py-3 text-right font-medium text-muted-foreground w-24`,children:`Actions`})]})}),(0,x.jsx)(`tbody`,{children:e.map(e=>{let d=String(e.name??``);return(0,x.jsxs)(`tr`,{className:`border-b last:border-0 hover:bg-accent/50 cursor-pointer transition-colors`,"data-testid":`metadata-item-${d}`,onClick:()=>s?.(d),children:[t.map(t=>{let n=String(e[t.key]??`—`);return(0,x.jsx)(`td`,{className:`px-4 py-3 truncate max-w-[200px]`,title:n,children:n},t.key)}),n&&(0,x.jsx)(`td`,{className:`px-4 py-3 text-right`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[o.map(t=>(0,x.jsx)(g,{variant:t.variant??`ghost`,size:`icon`,title:t.label,"aria-label":t.label,onClick:n=>{n.stopPropagation(),t.handler?.(e)},"data-testid":`row-action-${t.key}-${d}`,children:(0,x.jsx)(`span`,{className:`text-xs`,children:t.label.charAt(0)})},t.key)),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:`Edit ${a}`,onClick:t=>{t.stopPropagation(),c?.(e)},disabled:r,"data-testid":`edit-${d}-btn`,children:(0,x.jsx)(u,{className:`h-4 w-4`})}),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:i===d?`Click again to confirm`:`Delete ${a}`,onClick:e=>{e.stopPropagation(),l?.(d)},disabled:r,"data-testid":`delete-${d}-btn`,children:(0,x.jsx)(m,{className:`h-4 w-4 ${i===d?`text-destructive`:``}`})})]})})]},d)})})]})})})}function S(){let e=i(),{appName:t,metadataType:r}=n(),S=t?`/apps/${t}`:``,C=_(),{refresh:w}=a(),{user:ie}=o(),T=ie?.role===`admin`,E=r?ne(r):void 0,[D,O]=(0,b.useState)([]),[k,A]=(0,b.useState)(!0),[j,ae]=(0,b.useState)(``),[M,N]=(0,b.useState)(!1),[P,F]=(0,b.useState)(null),[oe,I]=(0,b.useState)(!1),[L,R]=(0,b.useState)(`create`),[z,B]=(0,b.useState)(null),V=(0,b.useCallback)(async()=>{if(!(!C||!r)){A(!0);try{O((await C.getItems(r)).filter(e=>!e._deleted))}catch{s.error(`Failed to load ${E?.pluralLabel??r}`)}finally{A(!1)}}},[C,r,E?.pluralLabel]);(0,b.useEffect)(()=>{V()},[V]);let H=(0,b.useMemo)(()=>{if(!j.trim())return D;let e=j.toLowerCase();return D.filter(t=>{let n=String(t.name??``).toLowerCase(),r=String(t.label??``).toLowerCase();return n.includes(e)||r.includes(e)})},[D,j]),U=(0,b.useCallback)(async e=>{if(!(!C||!r))if(P===e){N(!0);try{await C.deleteMetadataItem(r,e),O(t=>t.filter(t=>t.name!==e)),await w(),s.success(`${E?.label??`Item`} "${e}" deleted`)}catch{s.error(`Failed to delete "${e}"`)}finally{N(!1),F(null)}}else F(e)},[C,r,P,E?.label,w]),W=(0,b.useCallback)(()=>{B(null),R(`create`),I(!0)},[]),G=(0,b.useCallback)(e=>{B(e),R(`edit`),I(!0)},[]),K=(0,b.useCallback)(async e=>{if(!C||!r)return;let t=e.name??String(z?.name??``);if(t){N(!0);try{let n=L===`edit`?{...z,...e}:{...e};await C.saveMetadataItem(r,t,n),await w(),await V(),s.success(L===`edit`?`${E?.label??`Item`} "${t}" updated`:`${E?.label??`Item`} "${t}" created`)}catch{throw s.error(L===`edit`?`Failed to update "${t}"`:`Failed to create "${t}"`),Error(`Failed to save ${E?.label??`item`} "${t}"`)}finally{N(!1)}}},[C,r,z,L,E?.label,w,V]);if(!E)return(0,x.jsx)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:(0,x.jsxs)(`div`,{className:`text-center text-muted-foreground py-12`,children:[(0,x.jsxs)(`p`,{className:`text-lg font-medium`,children:[`Unknown metadata type: `,r]}),(0,x.jsx)(g,{variant:`outline`,className:`mt-4`,onClick:()=>e(`${S}/system`),children:`Back to System Settings`})]})});let q=v(E.icon),J=E.editable!==!1&&T,Y=E.listComponent;if(Y)return(0,x.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:[(0,x.jsx)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`icon`,onClick:()=>e(`${S}/system`),"data-testid":`back-to-hub-btn`,children:(0,x.jsx)(f,{className:`h-4 w-4`})}),(0,x.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,x.jsx)(q,{className:`h-5 w-5 text-primary`})}),(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:E.pluralLabel}),(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:E.description})]})]})}),(0,x.jsx)(Y,{config:E,basePath:S,metadataType:r,isAdmin:T})]});let X=(E.actions??[]).filter(e=>e.scope===`page`),Z=(E.actions??[]).filter(e=>e.scope===`row`),Q=E.listMode??`card`,$=Q===`grid`||Q===`table`,se=E.columns??[{key:`name`,label:`Name`},{key:`label`,label:`Label`}];return(0,x.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,"data-testid":`metadata-manager-page`,children:[(0,x.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`icon`,onClick:()=>e(`${S}/system`),"data-testid":`back-to-hub-btn`,children:(0,x.jsx)(f,{className:`h-4 w-4`})}),(0,x.jsx)(`div`,{className:`bg-primary/10 p-2 rounded-md shrink-0`,children:(0,x.jsx)(q,{className:`h-5 w-5 text-primary`})}),(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:E.pluralLabel}),(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:E.description})]})]}),J&&(0,x.jsxs)(g,{onClick:W,"data-testid":`create-metadata-btn`,children:[(0,x.jsx)(h,{className:`mr-2 h-4 w-4`}),`New `,E.label]}),X.length>0&&(0,x.jsx)(`div`,{className:`flex items-center gap-2`,children:X.map(e=>(0,x.jsx)(g,{variant:e.variant??`outline`,onClick:()=>e.handler?.(),"data-testid":`page-action-${e.key}`,children:e.label},e.key))})]}),(0,x.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,x.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,x.jsxs)(`label`,{htmlFor:`metadata-search`,className:`sr-only`,children:[`Search `,E.pluralLabel.toLowerCase()]}),(0,x.jsx)(d,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,x.jsx)(p,{id:`metadata-search`,placeholder:`Search ${E.pluralLabel.toLowerCase()}...`,value:j,onChange:e=>ae(e.target.value),className:`pl-8`,"data-testid":`metadata-search-input`})]}),(0,x.jsxs)(ee,{variant:`secondary`,"data-testid":`metadata-count-badge`,children:[H.length,` `,E.pluralLabel.toLowerCase()]})]}),k&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`metadata-loading`,children:[(0,x.jsx)(l,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading `,E.pluralLabel.toLowerCase(),`...`]}),M&&(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,"data-testid":`metadata-saving`,children:[(0,x.jsx)(l,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Saving...`]}),!k&&H.length===0&&(0,x.jsx)(`div`,{className:`text-center text-muted-foreground py-12`,"data-testid":`metadata-empty`,children:(0,x.jsxs)(`p`,{children:[`No `,E.pluralLabel.toLowerCase(),` found.`]})}),!k&&H.length>0&&!$&&(0,x.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:H.map(t=>{let n=String(t.name??``),i=String(t.label??t.name??``),a=String(t.description??``);return(0,x.jsx)(c,{className:`transition-colors hover:bg-accent/50 cursor-pointer`,"data-testid":`metadata-item-${n}`,onClick:()=>e(`${S}/system/metadata/${r}/${n}`),children:(0,x.jsxs)(te,{className:`flex items-center justify-between p-4`,children:[(0,x.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,x.jsx)(`p`,{className:`font-medium truncate`,children:i}),(0,x.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:n}),a&&(0,x.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1 truncate`,children:a})]}),J&&(0,x.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0 ml-2`,children:[Z.map(e=>(0,x.jsx)(g,{variant:e.variant??`ghost`,size:`icon`,title:e.label,onClick:n=>{n.stopPropagation(),e.handler?.(t)},"data-testid":`row-action-${e.key}-${n}`,children:(0,x.jsx)(`span`,{className:`text-xs`,children:e.label.charAt(0)})},e.key)),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:`Edit ${E.label.toLowerCase()}`,onClick:e=>{e.stopPropagation(),G(t)},disabled:M,"data-testid":`edit-${n}-btn`,children:(0,x.jsx)(u,{className:`h-4 w-4`})}),(0,x.jsx)(g,{variant:`ghost`,size:`icon`,title:P===n?`Click again to confirm`:`Delete ${E.label.toLowerCase()}`,onClick:e=>{e.stopPropagation(),U(n)},disabled:M,"data-testid":`delete-${n}-btn`,children:(0,x.jsx)(m,{className:`h-4 w-4 ${P===n?`text-destructive`:``}`})})]})]})},n)})}),!k&&H.length>0&&$&&(0,x.jsx)(re,{items:H,columns:se,editable:J,saving:M,deletingName:P,typeLabel:E.label.toLowerCase(),rowActions:Z,onItemClick:t=>e(`${S}/system/metadata/${r}/${t}`),onEdit:G,onDelete:U}),J&&(0,x.jsx)(y,{open:oe,onOpenChange:I,mode:L,typeLabel:E.label,formFields:E.formFields,initialValues:z??void 0,onSubmit:K})]})}export{S as MetadataManagerPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-B5ROGaJH.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,p as a,t as o}from"./vendor-react-B1k2FF9f.js";import{D as s,f as c,p as l}from"./framework-CoXA0nY6.js";import{o as u}from"./vendor-ui-utils-
|
|
2
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,p as a,t as o}from"./vendor-react-B1k2FF9f.js";import{D as s,f as c,p as l}from"./framework-CoXA0nY6.js";import{o as u}from"./vendor-ui-utils-Dyl9EYZi.js";import{Gt as d,Jm as f,Jt as p,Kt as m,Yt as h,at as g,cT as _,it as v,ot as y,qt as b}from"./ui-components-B7mlp0en.js";import{o as x,s as S}from"./index-CPatxDwz.js";var C=t(n(),1),w=o();function T({open:e,onOpenChange:t,title:n,description:r,schema:i,onSchemaChange:a,collection:o,recordName:s,children:l}){let f=c(),g=(0,C.useRef)(i);g.current=i;let _=(0,C.useCallback)(async e=>{try{if(f)return await f.update(o,s,e),!0}catch(e){console.warn(`[DesignDrawer] Auto-save failed:`,e)}return!1},[f,o,s]),v=(0,C.useCallback)(async e=>{a(e),await _(e)},[a,_]);return(0,C.useEffect)(()=>{if(!e)return;let t=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),_(g.current).then(e=>{e&&u.success(`${n} saved`)}))};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[e,_,n]),(0,w.jsx)(d,{open:e,onOpenChange:t,modal:!1,children:(0,w.jsxs)(m,{side:`right`,hideOverlay:!0,className:`w-full sm:w-[540px] sm:max-w-[540px] lg:w-[640px] lg:max-w-[640px] p-0 flex flex-col`,"data-testid":`design-drawer`,children:[(0,w.jsxs)(p,{className:`px-4 py-3 border-b shrink-0`,children:[(0,w.jsx)(h,{children:n}),(0,w.jsx)(b,{className:r?``:`sr-only`,children:r||`Visual editor — configure and preview ${n}`})]}),(0,w.jsx)(`div`,{className:`flex-1 overflow-auto p-4`,children:l(i,v)})]})})}var E=e({PageView:()=>O}),D=(0,C.lazy)(()=>i(()=>import(`./src-D5NTzWsi.js`).then(e=>e.t).then(e=>({default:e.PageCanvasEditor})),__vite__mapDeps([0])));function O(){let{pageName:e}=r(),[t]=a(),{showDebug:n}=S(),[i,o]=(0,C.useState)(!1),{pages:c}=l(),u=c?.find(t=>t.name===e),[d,p]=(0,C.useState)(null),m=(0,C.useCallback)(()=>{p(u),o(!0)},[u]),h=(0,C.useCallback)(e=>{o(e)},[]);if(!u)return(0,w.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,w.jsxs)(v,{children:[(0,w.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,w.jsx)(_,{className:`h-6 w-6 text-muted-foreground`})}),(0,w.jsx)(y,{children:`Page Not Found`}),(0,w.jsxs)(g,{children:[`The page "`,e,`" could not be found. It may have been removed or renamed.`]})]})});let b=Object.fromEntries(t.entries()),E=i&&d?d:u;return(0,w.jsxs)(`div`,{className:`flex flex-row h-full w-full overflow-hidden relative`,children:[(0,w.jsxs)(`div`,{className:`flex-1 overflow-auto h-full relative group`,children:[(0,w.jsx)(`div`,{className:`absolute top-1.5 sm:top-2 right-1.5 sm:right-2 z-50 flex items-center gap-1.5 transition-opacity ${n?`opacity-100`:`opacity-0 group-hover:opacity-100`}`,children:(0,w.jsxs)(`button`,{type:`button`,onClick:m,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`page-edit-button`,children:[(0,w.jsx)(f,{className:`h-3.5 w-3.5`}),`Edit`]})}),(0,w.jsx)(s,{schema:{...E,type:E.type||`page`,context:{...E.context,params:b}}})]}),(0,w.jsx)(x,{open:n,sections:[{title:`Page Configuration`,data:E}]}),(0,w.jsx)(T,{open:i,onOpenChange:h,title:`Edit Page: ${u.label||u.title||e}`,schema:d||u,onSchemaChange:p,collection:`sys_page`,recordName:e,children:(e,t)=>(0,w.jsx)(C.Suspense,{fallback:(0,w.jsx)(`div`,{className:`p-4 text-muted-foreground`,children:`Loading editor…`}),children:(0,w.jsx)(D,{schema:e,onChange:t})})})]})}export{E as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{c as r,r as i}from"./infrastructure-Djv3I7gr.js";import{$n as a,IA as o,TA as s,ar as c,cr as l,dn as u,er as d,fn as f,lr as p,nr as m,or as h,py as g,ra as _,rr as v,sr as y,tr as b,ur as x,yr as S}from"./ui-components-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n}from"./vendor-react-B1k2FF9f.js";import{c as r,r as i}from"./infrastructure-Djv3I7gr.js";import{$n as a,IA as o,TA as s,ar as c,cr as l,dn as u,er as d,fn as f,lr as p,nr as m,or as h,py as g,ra as _,rr as v,sr as y,tr as b,ur as x,yr as S}from"./ui-components-B7mlp0en.js";var C=e(t(),1),w=n();function T(){let{user:e,updateUser:t,isLoading:n}=r(),[T,E]=(0,C.useState)(e?.name??``),[D,O]=(0,C.useState)(!1),[k,A]=(0,C.useState)(null);return e?(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-2xl`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Profile`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage your account settings`})]}),(0,w.jsx)(a,{children:(0,w.jsx)(d,{className:`pt-6`,children:(0,w.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,w.jsxs)(h,{className:`h-16 w-16`,children:[(0,w.jsx)(l,{src:e.image??void 0,alt:e.name??`User`}),(0,w.jsx)(y,{className:`text-lg bg-primary text-primary-foreground`,children:i(e)})]}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsx)(`p`,{className:`text-lg font-semibold truncate`,children:e.name??`User`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground truncate`,children:e.email}),(0,w.jsx)(c,{variant:`secondary`,className:`mt-1`,children:e.role??`member`})]})]})})}),(0,w.jsxs)(a,{children:[(0,w.jsxs)(m,{children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(_,{className:`h-4 w-4 text-muted-foreground`}),(0,w.jsx)(v,{className:`text-base sm:text-lg`,children:`Personal Information`})]}),(0,w.jsx)(b,{children:`Update your name and view account details`})]}),(0,w.jsx)(d,{children:(0,w.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),A(null),O(!1);try{await t({name:T}),O(!0)}catch(e){A(e instanceof Error?e.message:String(e))}},className:`space-y-4`,children:[k&&(0,w.jsxs)(p,{variant:`destructive`,children:[(0,w.jsx)(o,{className:`h-4 w-4`}),(0,w.jsx)(x,{children:k})]}),D&&(0,w.jsxs)(p,{children:[(0,w.jsx)(s,{className:`h-4 w-4 text-green-600`}),(0,w.jsx)(x,{className:`text-green-800 dark:text-green-400`,children:`Profile updated successfully.`})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(f,{htmlFor:`profile-name`,children:`Name`}),(0,w.jsx)(u,{id:`profile-name`,type:`text`,value:T,onChange:e=>E(e.target.value),required:!0,"aria-required":`true`,disabled:n})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(f,{htmlFor:`profile-email`,children:`Email`}),(0,w.jsx)(u,{id:`profile-email`,type:`email`,value:e.email,disabled:!0,className:`bg-muted text-muted-foreground`}),(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Email cannot be changed.`})]}),(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(f,{children:`Role`}),(0,w.jsx)(u,{type:`text`,value:e.role??`member`,disabled:!0,className:`bg-muted text-muted-foreground`})]}),(0,w.jsx)(S,{type:`submit`,disabled:n,className:`w-full sm:w-auto`,children:n?`Saving...`:`Save Changes`})]})})]}),(0,w.jsx)(a,{children:(0,w.jsxs)(m,{children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(g,{className:`h-4 w-4 text-muted-foreground`}),(0,w.jsx)(v,{className:`text-base sm:text-lg`,children:`Change Password`})]}),(0,w.jsx)(b,{children:`To change your password, use the password reset flow from the login page.`})]})})]}):null}export{T as ProfilePage};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,t as i,u as a}from"./vendor-react-B1k2FF9f.js";import{a as o,g as s}from"./framework-CoXA0nY6.js";import{c,u as l}from"./infrastructure-Djv3I7gr.js";import{o as u}from"./vendor-ui-utils-Dyl9EYZi.js";import{$t as d,Gn as f,Jn as p,Kn as m,OD as h,Qt as g,Un as _,Wn as v,_r as y,at as b,dn as x,dr as S,ea as C,en as w,fn as T,fr as E,gr as D,hr as O,it as ee,mr as k,nn as te,ot as ne,pr as A,pt as j,qn as M,tn as N,vr as P,yr as F}from"./ui-components-B7mlp0en.js";import{n as re}from"./utils-DMMB8Xfh.js";import{a as ie,o as ae}from"./plugins-views-DqZMtAOw.js";import{i as oe,o as se,s as ce}from"./index-CPatxDwz.js";var I=t(n(),1),L=i(),R=(0,I.createContext)(void 0);function z({children:e}){let[t,n]=(0,I.useState)(`home`),[r,i]=(0,I.useState)(),[a,o]=(0,I.useState)(),s=(0,I.useMemo)(()=>({context:t,setContext:n,currentAppName:r,setCurrentAppName:i,recordTitle:a,setRecordTitle:o}),[t,r,a]);return(0,L.jsx)(R.Provider,{value:s,children:e})}function B(){return(0,I.useContext)(R)||{context:`app`,setContext:()=>{},currentAppName:void 0,setCurrentAppName:()=>{},recordTitle:void 0,setRecordTitle:()=>{}}}function le(e){let{setRecordTitle:t}=B();(0,I.useEffect)(()=>(t(e),()=>t(void 0)),[e,t])}function V(e){let{url:t,channel:n,autoReconnect:r=!0,reconnectInterval:i=1e3,maxReconnectAttempts:a=10,authToken:o}=e,[s,c]=(0,I.useState)(`disconnected`),[l,u]=(0,I.useState)(null),[d,f]=(0,I.useState)([]),[p,m]=(0,I.useState)(null),h=(0,I.useRef)(null),g=(0,I.useRef)(0),_=(0,I.useRef)(null),v=(0,I.useRef)(new Map),y=(0,I.useRef)([]),b=(0,I.useRef)(!0),x=(0,I.useRef)(!1),S=(0,I.useCallback)(()=>{_.current!==null&&(clearTimeout(_.current),_.current=null)},[]),C=(0,I.useCallback)(e=>{for(;y.current.length>0;){let t=y.current.shift(),r={type:t.type,channel:n,data:t.data,timestamp:new Date().toISOString()};e.send(JSON.stringify(r))}},[n]),w=(0,I.useCallback)(()=>{if(typeof WebSocket>`u`){m(Error(`WebSocket is not available in this environment`)),c(`error`);return}if(!t){m(Error(`WebSocket URL is required`)),c(`error`);return}try{let e=new URL(t);if(e.protocol!==`ws:`&&e.protocol!==`wss:`){m(Error(`WebSocket URL must use ws: or wss: protocol`)),c(`error`);return}}catch{m(Error(`Invalid WebSocket URL`)),c(`error`);return}h.current&&=(x.current=!0,h.current.close(),null),x.current=!1,c(`connecting`),m(null);let e=o?`${t}?token=${encodeURIComponent(o)}&channel=${encodeURIComponent(n)}`:`${t}?channel=${encodeURIComponent(n)}`,s;try{s=new WebSocket(e)}catch(e){if(!b.current)return;m(e instanceof Error?e:Error(`Failed to create WebSocket connection`)),c(`error`);return}h.current=s,s.onopen=()=>{b.current&&(c(`connected`),m(null),g.current=0,C(s))},s.onmessage=e=>{if(b.current)try{let t=JSON.parse(String(e.data));if(t.channel!==n)return;u(t),f(e=>[...e,t]);let r=v.current.get(t.type);r&&r.forEach(e=>e(t.data))}catch{}},s.onerror=()=>{b.current&&(m(Error(`WebSocket connection error`)),c(`error`))},s.onclose=()=>{if(b.current){if(h.current=null,x.current){c(`disconnected`);return}if(r&&g.current<a){c(`reconnecting`);let e=Math.min(i*2**g.current,3e4);g.current+=1,_.current=setTimeout(()=>{b.current&&w()},e)}else c(`disconnected`)}}},[t,n,o,r,i,a,C]),T=(0,I.useCallback)(()=>{S(),x.current=!0,g.current=0,h.current&&=(h.current.close(),null),c(`disconnected`)},[S]),E=(0,I.useCallback)(()=>{S(),g.current=0,w()},[w,S]),D=(0,I.useCallback)((e,t)=>{let r=h.current;if(r&&r.readyState===WebSocket.OPEN){let i={type:e,channel:n,data:t,timestamp:new Date().toISOString()};r.send(JSON.stringify(i))}else y.current.push({type:e,data:t})},[n]),O=(0,I.useCallback)((e,t)=>(v.current.has(e)||v.current.set(e,new Set),v.current.get(e).add(t),()=>{let n=v.current.get(e);n&&(n.delete(t),n.size===0&&v.current.delete(e))}),[]);return(0,I.useEffect)(()=>(b.current=!0,t&&w(),()=>{b.current=!1,S(),x.current=!0,h.current&&=(h.current.close(),null)}),[t,n,o]),{connectionState:s,isConnected:s===`connected`,lastMessage:l,messages:d,send:D,subscribe:O,disconnect:T,reconnect:E,error:p}}var H=0;function U(){return H+=1,`conflict-${Date.now()}-${H}`}var W=0;function G(){return W+=1,`ver-${Date.now()}-${W}`}function K(e,t,n){let[r,i]=(0,I.useState)([]),[a,o]=(0,I.useState)([]);return{versions:r,currentVersion:(0,I.useMemo)(()=>r.length===0?0:r[r.length-1].version,[r]),conflicts:a,hasConflicts:a.length>0,recordVersion:(0,I.useCallback)((n,r)=>{i(i=>{let a=i.length===0?1:i[i.length-1].version+1,o={id:G(),version:a,timestamp:new Date().toISOString(),userId:e,userName:t,changes:n,message:r};return[...i,o]})},[e,t]),resolveConflict:(0,I.useCallback)((n,r,a)=>{o(o=>{let s=o.find(e=>e.id===n);if(!s)return o;let c;switch(r){case`local`:c=s.localValue;break;case`remote`:c=s.remoteValue;break;case`merge`:c=a??s.localValue;break}return i(n=>{let i=n.length===0?1:n[n.length-1].version+1,a={id:G(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:{[s.field]:{before:s.baseValue,after:c}},message:`Resolved conflict on "${s.field}" using ${r} strategy`};return[...n,a]}),o.filter(e=>e.id!==n)})},[e,t]),resolveAllConflicts:(0,I.useCallback)(n=>{o(r=>{if(r.length===0)return r;let a={};for(let e of r)a[e.field]={before:e.baseValue,after:n===`local`?e.localValue:e.remoteValue};return i(r=>{let i=r.length===0?1:r[r.length-1].version+1,o={id:G(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:a,message:`Resolved all conflicts using ${n} strategy`};return[...r,o]}),[]})},[e,t]),revertToVersion:(0,I.useCallback)(n=>{let a=r.findIndex(e=>e.id===n);if(a===-1)return null;let o={};for(let e=0;e<=a;e++){let t=r[e];for(let[e,n]of Object.entries(t.changes))o[e]=n.after}let s={},c={};for(let e of r)for(let[t,n]of Object.entries(e.changes))c[t]=n.after;for(let[e,t]of Object.entries(o))c[e]!==t&&(s[e]={before:c[e],after:t});return Object.keys(s).length>0&&i(n=>{let i=n.length===0?1:n[n.length-1].version+1,o={id:G(),version:i,timestamp:new Date().toISOString(),userId:e,userName:t,changes:s,message:`Reverted to version ${r[a].version}`};return[...n,o]}),o},[r,e,t]),compareVersions:(0,I.useCallback)((e,t)=>{let n=r.findIndex(t=>t.id===e),i=r.findIndex(e=>e.id===t);if(n===-1||i===-1)return null;let[a,o]=n<i?[n,i]:[i,n],s=e=>{let t={};for(let n=0;n<=e;n++)for(let[e,i]of Object.entries(r[n].changes))t[e]=i.after;return t},c=s(a),l=s(o),u=new Set([...Object.keys(c),...Object.keys(l)]),d={};for(let e of u){let t=c[e],n=l[e];t!==n&&(d[e]={before:t,after:n})}return d},[r]),addConflict:(0,I.useCallback)(e=>{let t={...e,id:U()};o(e=>[...e,t])},[]),clearHistory:(0,I.useCallback)(()=>{i([]),o([])},[])}}var q={sm:24,md:32,lg:40},J={active:`#22c55e`,idle:`#f59e0b`,away:`#94a3b8`};function Y(e){return e.split(` `).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function X({users:e,maxVisible:t=5,size:n=`md`,showStatus:r=!0,className:i}){let a=q[n],o=Math.round(a*.3),s=Math.round(a*.35),c=Math.max(8,Math.round(a*.28)),l=(0,I.useMemo)(()=>e.slice(0,t),[e,t]),u=Math.max(0,e.length-t),d={display:`inline-flex`,alignItems:`center`,flexDirection:`row-reverse`,fontFamily:`-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`},f={width:`${a}px`,height:`${a}px`,borderRadius:`50%`,border:`2px solid #fff`,display:`flex`,alignItems:`center`,justifyContent:`center`,fontSize:`${s}px`,fontWeight:600,color:`#fff`,position:`relative`,flexShrink:0,overflow:`hidden`,boxSizing:`border-box`},p={...f,backgroundColor:`#e2e8f0`,color:`#475569`,marginLeft:`-${o}px`},m={position:`absolute`,bottom:`-1px`,right:`-1px`,width:`${c}px`,height:`${c}px`,borderRadius:`50%`,border:`2px solid #fff`,boxSizing:`border-box`},h=(0,I.useMemo)(()=>[...l].reverse(),[l]);return I.createElement(`div`,{style:d,className:i,role:`group`,"aria-label":`${e.length} user${e.length===1?``:`s`} present`},u>0&&I.createElement(`div`,{key:`overflow`,style:p,title:`${u} more user${u===1?``:`s`}`},`+${u}`),h.map((e,t)=>I.createElement(`div`,{key:e.userId,style:{...f,backgroundColor:e.color,marginLeft:t>0||u>0?`-${o}px`:`0`},title:`${e.userName} (${e.status})`},e.avatar?I.createElement(`img`,{src:e.avatar,alt:e.userName,style:{width:`100%`,height:`100%`,objectFit:`cover`}}):Y(e.userName),r&&I.createElement(`span`,{style:{...m,backgroundColor:J[e.status]}}))))}function Z({state:e,onOpenChange:t}){let n=()=>{e.resolve?.(!0),t(!1)},r=()=>{e.resolve?.(!1),t(!1)};return(0,L.jsx)(S,{open:e.open,onOpenChange:e=>{e||r()},children:(0,L.jsxs)(k,{children:[(0,L.jsxs)(y,{children:[(0,L.jsx)(P,{children:e.options?.title||`Confirm Action`}),(0,L.jsx)(O,{children:e.message})]}),(0,L.jsxs)(D,{children:[(0,L.jsx)(A,{onClick:r,children:e.options?.cancelText||`Cancel`}),(0,L.jsx)(E,{onClick:n,children:e.options?.confirmText||`Continue`})]})]})})}function ue({state:e,onOpenChange:t}){let[n,r]=(0,I.useState)({}),[i,a]=(0,I.useState)({});(0,I.useEffect)(()=>{if(e.open){let t={};for(let n of e.params)n.defaultValue!==void 0&&(t[n.name]=n.defaultValue);r(t),a({})}},[e.open,e.params]);let o=e=>e==null?!0:typeof e==`string`?e.trim()===``:Array.isArray(e)?e.length===0:!1,s=()=>{let r={};for(let t of e.params)t.required&&o(n[t.name])&&(r[t.name]=!0);if(Object.keys(r).length>0){a(r);return}e.resolve?.(n),t(!1)},c=()=>{e.resolve?.(null),t(!1)},l=(e,t)=>{r(n=>({...n,[e]:t})),a(t=>({...t,[e]:!1}))};return(0,L.jsx)(_,{open:e.open,onOpenChange:e=>{e||c()},children:(0,L.jsxs)(v,{children:[(0,L.jsxs)(M,{children:[(0,L.jsx)(p,{children:`Action Parameters`}),(0,L.jsx)(f,{children:`Please provide the required information to continue.`})]}),(0,L.jsx)(`div`,{className:`grid gap-4 py-4`,children:e.params.map(e=>(0,L.jsxs)(`div`,{className:`grid gap-2`,children:[(0,L.jsxs)(T,{htmlFor:e.name,children:[e.label,e.required&&(0,L.jsx)(`span`,{className:`text-destructive ml-1`,children:`*`})]}),e.type===`select`&&e.options?(0,L.jsxs)(g,{value:n[e.name]??``,onValueChange:t=>l(e.name,t),children:[(0,L.jsx)(N,{id:e.name,className:i[e.name]?`border-destructive`:``,children:(0,L.jsx)(te,{placeholder:e.placeholder||`Select ${e.label}`})}),(0,L.jsx)(d,{children:e.options.map(e=>(0,L.jsx)(w,{value:e.value,children:e.label},e.value))})]}):e.type===`textarea`?(0,L.jsx)(j,{id:e.name,value:n[e.name]??``,onChange:t=>l(e.name,t.target.value),placeholder:e.placeholder,className:i[e.name]?`border-destructive`:``}):e.type===`number`?(0,L.jsx)(x,{id:e.name,type:`number`,value:n[e.name]??``,onChange:t=>l(e.name,t.target.value===``?void 0:t.target.valueAsNumber),placeholder:e.placeholder,className:i[e.name]?`border-destructive`:``}):(0,L.jsx)(x,{id:e.name,type:[`email`,`url`,`date`,`datetime-local`,`time`,`password`].includes(e.type)?e.type:`text`,value:n[e.name]??``,onChange:t=>l(e.name,t.target.value),placeholder:e.placeholder,className:i[e.name]?`border-destructive`:``}),i[e.name]&&(0,L.jsxs)(`p`,{className:`text-xs text-destructive`,children:[e.label,` is required`]}),e.helpText&&(0,L.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.helpText})]},e.name))}),(0,L.jsxs)(m,{children:[(0,L.jsx)(F,{variant:`outline`,onClick:c,children:`Cancel`}),(0,L.jsx)(F,{onClick:s,children:`Confirm`})]})]})})}var Q=e({RecordDetailView:()=>$}),de={id:`current-user`,name:`Demo User`};function $({dataSource:e,objects:t,onEdit:n}){let{objectName:i,recordId:d}=r(),{showDebug:f}=ce(),{user:p}=c(),m=a(),{t:g}=o(),[_,v]=(0,I.useState)(!0),[y,x]=(0,I.useState)([]),[S,w]=(0,I.useState)([]),[T,E]=(0,I.useState)(0),[D,O]=(0,I.useState)({}),[k,te]=(0,I.useState)(),A=t.find(e=>e.name===i);le(k);let j=d,[M,N]=(0,I.useState)({open:!1,message:``}),[P,F]=(0,I.useState)({open:!1,params:[]}),R=(0,I.useCallback)((e,t)=>new Promise(n=>{N({open:!0,message:e,options:t,resolve:n})}),[]),z=(0,I.useCallback)(e=>new Promise(t=>{F({open:!0,params:e,resolve:t})}),[]),B=(0,I.useCallback)((e,t)=>{t?.type===`error`?u.error(e):u.success(e)},[]),V=(0,I.useCallback)((e,t)=>{t?.external||t?.newTab?window.open(e,`_blank`,`noopener,noreferrer`):m(e)},[m]),H=(0,I.useCallback)(async t=>{try{let n=t.target||t.name,r=t.params||{};switch(n){case`opportunity_change_stage`:await e.update(i,j,{stage:r.new_stage});break;case`opportunity_mark_won`:await e.update(i,j,{stage:`closed_won`});break;case`opportunity_mark_lost`:await e.update(i,j,{stage:`closed_lost`,loss_reason:r.loss_reason});break;default:Object.keys(r).length>0&&await e.update(i,j,r);break}let a=t.refreshAfter===!0;return a&&E(e=>e+1),{success:!0,reload:a}}catch(e){return{success:!1,error:e.message}}},[e,i,j]),U=(0,I.useMemo)(()=>l(),[]),W=(0,I.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No flow target provided for flow action`};try{let n=await U(`https://demo.objectstack.ai/api/v1/automation/${encodeURIComponent(t)}/trigger`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:j,objectName:i,params:e.params??{}})}),r=await n.json().catch(()=>null);if(!n.ok||r&&r.success===!1)return{success:!1,error:r?.error||`Flow "${t}" failed (HTTP ${n.status})`};let a=e.refreshAfter!==!1;return a&&E(e=>e+1),{success:!0,data:r?.data,reload:a}}catch(e){return{success:!1,error:e.message}}},[U,j,i]),G=(0,I.useCallback)(async e=>{let t=e.target||e.name;if(!t)return{success:!1,error:`No action target provided`};let n=e.params&&!Array.isArray(e.params)?e.params:{};try{let r=e.objectName||i||`global`,a=await U(`https://demo.objectstack.ai/api/v1/actions/${encodeURIComponent(r)}/${encodeURIComponent(t)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({recordId:j,params:n})}),o=await a.json().catch(()=>null);if(!a.ok||o&&o.success===!1)return{success:!1,error:o?.error||`Action "${t}" failed (HTTP ${a.status})`};let s=e.refreshAfter!==!1;return s&&E(e=>e+1),{success:!0,data:o?.data,reload:s}}catch(e){return{success:!1,error:e.message}}},[U,j,i]),K=(0,I.useMemo)(()=>{if(!A||!t)return[];let e=[];for(let n of t)if(n.name!==A.name)for(let[t,r]of Object.entries(n.fields||{}))r&&(r.type===`lookup`||r.type===`master_detail`)&&(r.reference_to||r.reference)===A.name&&e.push({childObject:n.name,childLabel:n.label||n.name,referenceField:t});return e},[A,t]);(0,I.useEffect)(()=>{if(!e||!j||K.length===0)return;let t=!1;return Promise.all(K.map(({childObject:t,referenceField:n})=>e.find(t,{$filter:{[n]:j}}).then(e=>({childObject:t,items:Array.isArray(e)?e:e?.data||[]})).catch(e=>(console.warn(`[RecordDetailView] Failed to fetch related ${t}:`,e),{childObject:t,items:[]})))).then(e=>{if(t)return;let n={};for(let{childObject:t,items:r}of e)n[t]=r;O(n)}),()=>{t=!0}},[e,j,K]);let q=p?{id:p.id,name:p.name,avatar:p.image}:de;(0,I.useEffect)(()=>{if(!e||!i||!j)return;let t=`${i}:${j}`;e.find(`sys_presence`,{$filter:{recordId:j}}).then(e=>{e.data?.length&&w(e.data)}).catch(()=>{}),e.find(`sys_comment`,{$filter:{threadId:t},$orderby:{createdAt:`asc`}}).then(e=>{e.data?.length&&x(e.data.map(e=>({id:e.id,type:`comment`,actor:e.author?.name??`Unknown`,actorAvatarUrl:e.author?.avatar,body:e.content,createdAt:e.createdAt,updatedAt:e.updatedAt,parentId:e.parentId,reactions:e.reactions?Object.entries(e.reactions).map(([e,t])=>({emoji:e,count:t.length,reacted:t.includes(q.id)})):void 0})))}).catch(()=>{})},[e,i,j,q]);let J=(0,I.useCallback)(async t=>{let n={id:crypto.randomUUID(),type:`comment`,actor:q.name,actorAvatarUrl:`avatar`in q?q.avatar:void 0,body:t,createdAt:new Date().toISOString()};if(x(e=>[...e,n]),e){let r=`${i}:${j}`;e.create(`sys_comment`,{id:n.id,threadId:r,author:q,content:t,mentions:[],createdAt:n.createdAt}).catch(()=>{})}},[q,e,i,j]),Y=(0,I.useCallback)(async(t,n)=>{let r={id:crypto.randomUUID(),type:`comment`,actor:q.name,actorAvatarUrl:`avatar`in q?q.avatar:void 0,body:n,createdAt:new Date().toISOString(),parentId:t};if(x(e=>[...e,r].map(e=>e.id===t?{...e,replyCount:(e.replyCount??0)+1}:e)),e){let a=`${i}:${j}`;e.create(`sys_comment`,{id:r.id,threadId:a,author:q,content:n,mentions:[],createdAt:r.createdAt,parentId:t}).catch(()=>{})}},[q,e,i,j]),Q=(0,I.useCallback)((t,n)=>{x(r=>r.map(r=>{if(r.id!==t)return r;let i=[...r.reactions??[]],a=i.findIndex(e=>e.emoji===n);if(a>=0){let e=i[a];e.reacted?e.count<=1?i.splice(a,1):i[a]={...e,count:e.count-1,reacted:!1}:i[a]={...e,count:e.count+1,reacted:!0}}else i.push({emoji:n,count:1,reacted:!0});let o={...r,reactions:i};return e&&e.update(`sys_comment`,String(t),{$toggleReaction:{emoji:n,userId:q.id}}).catch(()=>{}),o}))},[q.id,e]);(0,I.useEffect)(()=>{v(!0),queueMicrotask(()=>v(!1))},[i,d]);let $=(0,I.useMemo)(()=>{if(!A)return{type:`detail-view`};let e=A.primaryField||Object.keys(A.fields||{}).find(e=>e===`name`||e===`title`),n=A.views?.form?.sections,r=n&&n.length>0?n.map(e=>({title:e.title,collapsible:e.collapsible,defaultCollapsed:e.defaultCollapsed,fields:(e.fields||[]).map(e=>{let t=typeof e==`string`?e:e.name,n=A.fields[t];if(!n)return console.warn(`[RecordDetailView] Field "${t}" not found in ${A.name} definition`),{name:t,label:t};let r=n.reference_to||n.reference;return{name:t,label:n.label||t,type:n.type||`text`,...n.options&&{options:n.options},...r&&{reference_to:r},...n.reference_field&&{reference_field:n.reference_field},...n.currency&&{currency:n.currency}}})})):[{showBorder:!1,fields:Object.keys(A.fields||{}).map(e=>{let t=A.fields[e],n=t.reference_to||t.reference;return{name:e,label:t.label||e,type:t.type||`text`,...t.options&&{options:t.options},...n&&{reference_to:n},...t.reference_field&&{reference_field:t.reference_field},...t.currency&&{currency:t.currency}}})}],i=(()=>{let e=new Set;return(A.actions||[]).filter(t=>t.locations?.includes(`record_header`)?t.name?e.has(t.name)?!1:(e.add(t.name),!0):!0:!1)})(),a=A.views?.detail?.highlightFields??[],o=A.views?.detail?.sectionGroups??A.views?.form?.sectionGroups,s=K.map(({childObject:e,childLabel:n,referenceField:r})=>{let i=t.find(t=>t.name===e);return{title:n,type:`table`,api:e,data:D[e]||[],referenceField:r,icon:i?.icon}});return{type:`detail-view`,objectName:A.name,resourceId:j,showBack:!0,onBack:`history`,showEdit:!0,title:A.label,primaryField:e,sections:r,autoTabs:!0,autoDiscoverRelated:!0,...s.length>0&&{related:s},...a.length>0&&{highlightFields:a},...o&&o.length>0&&{sectionGroups:o},...i.length>0&&{actions:[{type:`action:bar`,location:`record_header`,actions:i}]}}},[A?.name,j,D,T]);return _?(0,L.jsx)(oe,{}):A?(0,L.jsxs)(`div`,{className:`h-full bg-background overflow-hidden flex flex-col relative`,children:[(0,L.jsx)(`div`,{className:`absolute top-2 sm:top-4 right-2 sm:right-4 z-50 flex items-center gap-2`,children:S.length>0&&(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5`,title:`Users viewing this record`,children:[(0,L.jsx)(C,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,L.jsx)(X,{users:S,size:`sm`,maxVisible:4,showStatus:!0})]})}),(0,L.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-row`,children:[(0,L.jsx)(`div`,{className:`flex-1 overflow-auto p-3 sm:p-4 lg:p-6 scroll-pb-48`,children:(0,L.jsx)(s,{context:{record:{},objectName:i,user:q},onConfirm:R,onToast:B,onNavigate:V,onParamCollection:z,handlers:{api:H,flow:W,script:G,modal:G},children:(0,L.jsx)(ae,{schema:$,dataSource:e,objectLabel:A.label,onDataLoaded:e=>{if(!e||typeof e!=`object`)return;let t=re(A,e);t&&t!==k&&t!==`Untitled`&&te(t)},onEdit:()=>{n({id:j})},discussionSlot:(0,L.jsx)(ie,{config:{position:`bottom`,collapsible:!1,feed:{enableReactions:!0,enableThreading:!0,showCommentInput:!0}},items:y,onAddComment:J,onAddReply:Y,onToggleReaction:Q})},T)})}),(0,L.jsx)(se,{open:f,sections:[{title:`View Schema`,data:$}]})]}),(0,L.jsx)(Z,{state:M,onOpenChange:e=>{e||N(e=>({...e,open:!1}))}}),(0,L.jsx)(ue,{state:P,onOpenChange:e=>{e||F(e=>({...e,open:!1}))}})]}):(0,L.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,L.jsxs)(ee,{children:[(0,L.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,L.jsx)(h,{className:`h-6 w-6 text-muted-foreground`})}),(0,L.jsx)(ne,{children:`Object Not Found`}),(0,L.jsxs)(b,{children:[`Object "`,i,`" definition missing. Check your configuration or navigate back to select a valid object.`]})]})})}export{K as a,B as c,X as i,ue as n,V as o,Z as r,z as s,Q as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,r as i,t as a,u as o}from"./vendor-react-B1k2FF9f.js";import{F as s,a as c,f as l,p as u}from"./framework-CoXA0nY6.js";import{c as d,d as f}from"./infrastructure-Djv3I7gr.js";import{o as p}from"./vendor-ui-utils-Dyl9EYZi.js";import{OD as m,at as h,cI as g,it as _,ot as v,yr as y}from"./ui-components-B7mlp0en.js";import{t as b}from"./plugin-form-DOfn-uRa.js";import{i as x}from"./index-CPatxDwz.js";var S=t(n(),1),C=a(),w=(0,S.createContext)(null);function T({children:e,user:t={},app:n={},data:r={}}){let i=(0,S.useMemo)(()=>({user:t,app:n,data:r,evaluator:new s({user:t,app:n,data:r})}),[t,n,r]);return(0,C.jsx)(w.Provider,{value:i,children:e})}function E(){let e=(0,S.useContext)(w);if(!e){let e={user:{},app:{},data:{}};return{...e,evaluator:new s(e)}}return e}function D(e,t){if(e==null||e===!0||e===`true`)return!0;if(e===!1||e===`false`)return!1;if(typeof e==`string`&&e.includes("${"))try{return t.evaluateCondition(e)}catch{return!0}return!0}var O=e({RecordFormPage:()=>k});function k({mode:e}){let{appName:t,objectName:n,recordId:a}=r(),w=o(),E=l(),{objects:O,loading:k}=u(),{t:A}=c(),{objectLabel:j}=f(),{user:M}=d(),N=(0,S.useMemo)(()=>O.find(e=>e.name===n),[O,n]),P=`/apps/${t}`,F=`${P}/${n}`,I=e===`edit`&&a?`${P}/${n}/record/${encodeURIComponent(a)}`:F,L=(0,S.useCallback)(()=>{typeof window<`u`&&window.history.length>1?w(-1):w(I,{replace:!0})},[w,I]),R=N?j(N):n??``,z=e===`create`?A(`form.createTitle`,{object:R,defaultValue:`New ${R}`}):A(`form.editTitle`,{object:R,defaultValue:`Edit ${R}`}),B=(0,S.useCallback)(()=>{p.success(e===`create`?A(`form.createSuccess`,{object:R,defaultValue:`${R} created successfully`}):A(`form.updateSuccess`,{object:R,defaultValue:`${R} updated successfully`})),L()},[e,A,R,L]),V=(0,S.useCallback)(()=>{L()},[L]),H=(0,S.useMemo)(()=>M?{name:M.name,email:M.email,role:M.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},[M]),U=(0,S.useMemo)(()=>new s({user:H,app:{name:t},data:{}}),[H,t]),W=(0,S.useMemo)(()=>N?.fields?Array.isArray(N.fields)?N.fields.filter(e=>typeof e==`string`?!0:D(e.visible,U)).map(e=>typeof e==`string`?e:e.name):Object.entries(N.fields).filter(([,e])=>D(e.visible,U)).map(([e])=>e):[],[N,U]);return k?(0,C.jsx)(x,{}):N?(0,C.jsx)(T,{user:H,app:{name:t},data:{},children:(0,C.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,"data-testid":`record-form-page`,"data-mode":e,children:[(0,C.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-3 border-b bg-background px-4 py-3 sm:px-6`,children:[(0,C.jsx)(y,{variant:`ghost`,size:`sm`,onClick:L,"data-testid":`record-form-page-back`,"aria-label":A(`common.back`,{defaultValue:`Back`}),children:(0,C.jsx)(g,{className:`h-4 w-4`})}),(0,C.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,C.jsx)(i,{to:F,className:`hover:text-foreground transition-colors`,children:R}),(0,C.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,C.jsx)(`span`,{className:`text-foreground font-medium`,"data-testid":`record-form-page-title`,children:z})]})]}),(0,C.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,C.jsx)(`div`,{className:`mx-auto max-w-4xl`,children:(0,C.jsx)(b,{schema:{type:`object-form`,formType:`simple`,objectName:N.name,mode:e,recordId:e===`edit`?a:void 0,title:z,description:e===`create`?A(`form.createDescription`,{object:R,defaultValue:`Create a new ${R}.`}):A(`form.editDescription`,{object:R,defaultValue:`Edit this ${R}.`}),layout:`vertical`,fields:W,onSuccess:B,onCancel:V,showSubmit:!0,showCancel:!0,submitText:A(`form.saveRecord`,{defaultValue:`Save`}),cancelText:A(`common.cancel`,{defaultValue:`Cancel`})},dataSource:E??void 0},`${e}:${n}:${a??`new`}`)})})]})}):(0,C.jsx)(`div`,{className:`flex h-full items-center justify-center p-4`,children:(0,C.jsxs)(_,{children:[(0,C.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,C.jsx)(m,{className:`h-6 w-6 text-muted-foreground`})}),(0,C.jsx)(v,{children:`Object Not Found`}),(0,C.jsxs)(h,{children:[`Object "`,n,`" definition missing. Check your configuration or navigate back to select a valid object.`]}),(0,C.jsx)(`div`,{className:`mt-4`,children:(0,C.jsxs)(y,{variant:`outline`,onClick:()=>w(P),children:[(0,C.jsx)(g,{className:`mr-2 h-4 w-4`}),`Back`]})})]})})}export{E as i,T as n,D as r,O as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ui-components-B5ROGaJH.css","assets/plugins-views-DnNKJB60.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,t as a}from"./vendor-react-B1k2FF9f.js";import{f as o,p as s}from"./framework-CoXA0nY6.js";import{Cy as c,Jm as l,at as u,it as d,jj as f,ot as p}from"./ui-components-
|
|
2
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,m as i,t as a}from"./vendor-react-B1k2FF9f.js";import{f as o,p as s}from"./framework-CoXA0nY6.js";import{Cy as c,Jm as l,at as u,it as d,jj as f,ot as p}from"./ui-components-B7mlp0en.js";import{o as m,s as h}from"./index-CPatxDwz.js";var g=e({ReportView:()=>S}),_=t(n(),1),v=a(),y=(0,_.lazy)(()=>i(()=>import(`./plugins-views-DqZMtAOw.js`).then(e=>e.t).then(e=>({default:e.ReportViewer})),__vite__mapDeps([0,1]))),b=(0,_.lazy)(()=>i(()=>import(`./plugins-views-DqZMtAOw.js`).then(e=>e.t).then(e=>({default:e.ReportConfigPanel})),__vite__mapDeps([0,1]))),x=[{value:`month`,label:`Month`,type:`text`},{value:`revenue`,label:`Revenue`,type:`number`},{value:`count`,label:`Count`,type:`number`},{value:`region`,label:`Region`,type:`text`},{value:`product`,label:`Product`,type:`text`},{value:`source`,label:`Lead Source`,type:`text`},{value:`stage`,label:`Stage`,type:`text`},{value:`amount`,label:`Amount`,type:`number`}];function S({dataSource:e}){let{reportName:t}=r(),{showDebug:n}=h(),i=o(),[a,g]=(0,_.useState)(!1),[S,C]=(0,_.useState)(0),{reports:w,objects:T,loading:E,refresh:D}=s(),O=w?.find(e=>e.name===t),[k,A]=(0,_.useState)(O),[j,M]=(0,_.useState)(null),[N,P]=(0,_.useState)([]),[F,I]=(0,_.useState)(!1),L=(0,_.useMemo)(()=>{let e=j||k,t=e?.objectName||e?.dataSource?.object||e?.dataSource?.resource;if(t&&T?.length){let e=T.find(e=>e.name===t);if(e?.fields){let t=e.fields;return Array.isArray(t)?t.map(e=>typeof e==`string`?{value:e,label:e,type:`text`}:{value:e.name,label:e.label||e.name,type:e.type||`text`}):Object.entries(t).map(([e,t])=>({value:e,label:t.label||e,type:t.type||`text`}))}}return x},[j,k,T]),R=(0,_.useCallback)(async e=>{try{i&&(await i.update(`sys_report`,t,e),D().catch(()=>{}))}catch(e){console.warn(`[ReportView] Auto-save failed:`,e)}},[i,t,D]),z=(0,_.useCallback)(()=>{M(k),g(!0),C(e=>e+1)},[k]),B=(0,_.useCallback)(()=>{g(!1)},[]),V=(0,_.useMemo)(()=>j||k,[S]),H=(0,_.useCallback)(e=>{M(e),R(e),C(e=>e+1)},[R]),U=(0,_.useCallback)((e,t)=>{M(n=>({...n,[e]:t}))},[]);(0,_.useEffect)(()=>{A(O)},[O]),(0,_.useEffect)(()=>{a||M(null)},[O]);let W=j||k,G=(0,_.useMemo)(()=>JSON.stringify(W?.filters),[W?.filters]),K=(0,_.useMemo)(()=>JSON.stringify(W?.dataSource),[W?.dataSource]),q=(0,_.useMemo)(()=>JSON.stringify(W?.data),[W?.data]);if((0,_.useEffect)(()=>{if(!W||!e){P([]);return}if(W.data&&Array.isArray(W.data)){P(W.data);return}if(W.dataSource){(async()=>{I(!0);try{let t=W.dataSource.object||W.dataSource.resource;if(!t){console.warn(`ReportView: dataSource missing object/resource property`),P([]);return}P((await e.find(t,{$filter:W.dataSource.filter,$orderby:W.dataSource.sort,$top:W.dataSource.limit})).data||[])}catch(e){console.error(`ReportView: Failed to load data from dataSource`,e),P([])}finally{I(!1)}})();return}if(W.objectName){(async()=>{I(!0);try{P((await e.find(W.objectName,{$filter:W.filters,$orderby:W.sort,$top:W.limit||100})).data||[])}catch(e){console.error(`ReportView: Failed to load data from objectName`,e),P([])}finally{I(!1)}})();return}P([])},[W?.objectName,W?.limit,G,K,q,e]),E)return(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsx)(c,{className:`h-8 w-8 animate-spin text-muted-foreground`})});if(!O||!k)return!E&&!O?(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsxs)(d,{children:[(0,v.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,v.jsx)(f,{className:`h-6 w-6 text-muted-foreground`})}),(0,v.jsx)(p,{children:`Report Not Found`}),(0,v.jsxs)(u,{children:[`The report "`,t,`" could not be found. It may have been removed or renamed.`]})]})}):(0,v.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,v.jsx)(c,{className:`h-8 w-8 animate-spin text-muted-foreground`})});let J=e=>{let t={...e};if(!t.title&&t.label&&(t.title=t.label),!t.fields&&Array.isArray(t.columns)&&(t.fields=t.columns.map(e=>({name:e.field||e.name,label:e.label,type:e.type,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap,...e.aggregate?{aggregation:e.aggregate,showInSummary:!0}:{}}))),t.fields&&Array.isArray(t.fields)&&t.fields.length>0){let n=t.fields.some(e=>e.showInSummary||e.aggregation),r=t.reportType||`tabular`,i=[];if((r===`summary`||n)&&i.push({type:`summary`,title:`Key Metrics`}),i.push({type:`table`,title:`Details`,columns:t.fields.map(e=>({name:e.name,label:e.label,type:e.type,format:e.format,renderAs:e.renderAs,colorMap:e.colorMap}))}),t.chartConfig?.chartType&&i.push({type:`chart`,title:`Chart`,chart:{type:`chart`,chartType:t.chartConfig.chartType,xAxisField:t.chartConfig.xAxisField,yAxisFields:t.chartConfig.yAxisFields}}),Array.isArray(e.sections)){let n=e.sections.filter(e=>e.type===`chart`&&!t.chartConfig?.chartType);i.push(...n)}t.sections=i}else t.sections||=[];return t},Y=j||k,X={type:`report-viewer`,report:J(Y),data:N,showToolbar:!0,allowExport:!0,loading:F};return(0,v.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden bg-background`,children:[(0,v.jsxs)(`div`,{className:`flex flex-col sm:flex-row justify-between sm:items-center gap-3 sm:gap-4 p-4 sm:p-6 border-b shrink-0`,children:[(0,v.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,v.jsx)(`h1`,{className:`text-lg sm:text-xl md:text-2xl font-bold tracking-tight truncate`,children:Y.title||Y.label||`Report Viewer`}),Y.description&&(0,v.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 line-clamp-2`,children:Y.description})]}),(0,v.jsx)(`div`,{className:`shrink-0 flex items-center gap-1.5`,children:(0,v.jsxs)(`button`,{type:`button`,onClick:z,className:`inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground`,"data-testid":`report-edit-button`,children:[(0,v.jsx)(l,{className:`h-3.5 w-3.5`}),`Edit`]})})]}),(0,v.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col sm:flex-row relative`,children:[(0,v.jsx)(`div`,{className:`flex-1 min-w-0 overflow-auto p-4 sm:p-6 lg:p-8 bg-muted/5`,children:(0,v.jsx)(`div`,{className:`max-w-5xl mx-auto shadow-sm border rounded-lg sm:rounded-xl bg-background overflow-hidden min-h-150`,children:(0,v.jsx)(_.Suspense,{fallback:(0,v.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:`Loading report…`}),children:(0,v.jsx)(y,{schema:X})})})}),(0,v.jsx)(_.Suspense,{fallback:null,children:(0,v.jsx)(b,{open:a,onClose:B,config:V,onSave:H,onFieldChange:U,availableFields:L})}),(0,v.jsx)(m,{open:n,sections:[{title:`Report Configuration`,data:Y}]})]})]})}export{g as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,p as i,r as a,t as o}from"./vendor-react-B1k2FF9f.js";import{p as s}from"./framework-CoXA0nY6.js";import{$n as c,OD as l,Rd as u,ar as d,cI as f,cT as p,dn as m,er as h,jj as g,xb as _}from"./ui-components-
|
|
1
|
+
import{n as e,r as t}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as n,f as r,p as i,r as a,t as o}from"./vendor-react-B1k2FF9f.js";import{p as s}from"./framework-CoXA0nY6.js";import{$n as c,OD as l,Rd as u,ar as d,cI as f,cT as p,dn as m,er as h,jj as g,xb as _}from"./ui-components-B7mlp0en.js";import"./index-CPatxDwz.js";var v=e({SearchResultsPage:()=>w}),y=t(n(),1),b=o();function x(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...x(n.children)):t.push(n);return t}var S={object:l,dashboard:_,page:p,report:g},C={object:`bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200`,dashboard:`bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200`,page:`bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200`,report:`bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200`};function w(){let{appName:e}=r(),[t,n]=i(),[o,p]=(0,y.useState)(t.get(`q`)||``),{apps:g}=s(),_=g||[],v=_.find(t=>t.name===e)||_[0],w=`/apps/${e}`,T=(0,y.useMemo)(()=>v?x(v.navigation||[]).map(e=>{let t=`#`;return e.type===`object`?(t=`${w}/${e.objectName}`,e.viewName&&(t+=`/view/${e.viewName}`)):e.type===`dashboard`?t=`${w}/dashboard/${e.dashboardName}`:e.type===`page`?t=`${w}/page/${e.pageName}`:e.type===`report`&&(t=`${w}/report/${e.reportName}`),{id:e.id,label:e.label||e.objectName||e.dashboardName||e.pageName||e.reportName||``,href:t,type:e.type,description:e.description}}).filter(e=>e.href!==`#`):[],[v,w]),E=(0,y.useMemo)(()=>{if(!o.trim())return T;let e=o.toLowerCase();return T.filter(t=>t.label.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description&&t.description.toLowerCase().includes(e))},[T,o]),D=e=>{p(e),n(e?{q:e}:{})},O=(0,y.useMemo)(()=>{let e={};for(let t of E)(e[t.type]||=[]).push(t);return e},[E]);return(0,b.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6 max-w-4xl mx-auto`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsxs)(a,{to:w,className:`flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground transition-colors`,children:[(0,b.jsx)(f,{className:`h-4 w-4`}),`Back`]}),(0,b.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Search`})]}),(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(`label`,{htmlFor:`search-results-input`,className:`sr-only`,children:`Search objects, dashboards, pages, reports`}),(0,b.jsx)(u,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`,"aria-hidden":`true`}),(0,b.jsx)(m,{id:`search-results-input`,value:o,onChange:e=>D(e.target.value),placeholder:`Search objects, dashboards, pages, reports...`,className:`pl-10 h-11 text-base`,autoFocus:!0})]}),(0,b.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:o.trim()?`${E.length} result${E.length===1?``:`s`} for "${o}"`:`${T.length} items available`}),E.length===0?(0,b.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-12 text-center`,children:[(0,b.jsx)(u,{className:`h-12 w-12 text-muted-foreground/30 mb-4`}),(0,b.jsx)(`p`,{className:`text-lg font-medium text-muted-foreground`,children:`No results found`}),(0,b.jsx)(`p`,{className:`text-sm text-muted-foreground/80 mt-1`,children:`Try adjusting your search terms`})]}):(0,b.jsx)(`div`,{className:`space-y-6`,children:Object.entries(O).map(([e,t])=>(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(`h2`,{className:`text-sm font-medium text-muted-foreground mb-2 flex items-center gap-1.5`,children:[(0,b.jsx)(S[e]||l,{className:`h-4 w-4`}),e.charAt(0).toUpperCase()+e.slice(1),`s`,(0,b.jsx)(d,{variant:`secondary`,className:`ml-1 text-xs`,children:t.length})]}),(0,b.jsx)(`div`,{className:`grid gap-2`,children:t.map(e=>{let t=S[e.type]||l;return(0,b.jsx)(a,{to:e.href,className:`rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:(0,b.jsx)(c,{className:`hover:bg-accent/50 transition-colors cursor-pointer`,children:(0,b.jsxs)(h,{className:`flex items-center gap-3 p-3`,children:[(0,b.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded ${C[e.type]||``}`,children:(0,b.jsx)(t,{className:`h-4 w-4`})}),(0,b.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,b.jsx)(`p`,{className:`text-sm font-medium truncate`,children:e.label}),e.description&&(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]}),(0,b.jsx)(d,{variant:`outline`,className:`text-xs shrink-0`,children:e.type})]})})},e.id)})})]},e))})]})}export{v as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{f as a,p as o}from"./framework-CoXA0nY6.js";import{$n as s,Cy as c,Jb as l,KM as u,Kd as d,ar as f,ea as p,ed as m,er as h,nr as g,ra as _,rr as v,tr as y}from"./ui-components-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,f as n,t as r,u as i}from"./vendor-react-B1k2FF9f.js";import{f as a,p as o}from"./framework-CoXA0nY6.js";import{$n as s,Cy as c,Jb as l,KM as u,Kd as d,ar as f,ea as p,ed as m,er as h,nr as g,ra as _,rr as v,tr as y}from"./ui-components-B7mlp0en.js";import"./index-CPatxDwz.js";import{r as b,t as x}from"./getIcon-DF6zJOtU.js";var S=e(t(),1),C=r();function w(){let e=i(),{appName:t}=n(),r=t?`/apps/${t}`:``,w=a(),{apps:T,objects:E,dashboards:D,reports:O,pages:k}=o(),[A,j]=(0,S.useState)({apps:null,objects:null,users:null,orgs:null,roles:null,permissions:null,auditLogs:null,dashboard:null,page:null,report:null}),[M,N]=(0,S.useState)(!0),P=(0,S.useCallback)(async()=>{if(w){N(!0);try{let[e,t,n,r,i]=await Promise.all([w.find(`sys_user`).catch(()=>({data:[]})),w.find(`sys_org`).catch(()=>({data:[]})),w.find(`sys_role`).catch(()=>({data:[]})),w.find(`sys_permission`).catch(()=>({data:[]})),w.find(`sys_audit_log`).catch(()=>({data:[]}))]);j({apps:T?.length??0,objects:E?.length??0,users:e.data?.length??0,orgs:t.data?.length??0,roles:n.data?.length??0,permissions:r.data?.length??0,auditLogs:i.data?.length??0,dashboard:D?.length??0,page:k?.length??0,report:O?.length??0})}catch{}finally{N(!1)}}},[w,T,E,D,O,k]);(0,S.useEffect)(()=>{P()},[P]);let F=b().map(e=>{let t=e.customRoute?`${r}${e.customRoute}`:`${r}/system/metadata/${e.type}`,n=x(e.icon),i=null;return i=e.type===`app`?A.apps:e.type===`object`?A.objects:A[e.type]??null,{title:e.pluralLabel,description:e.description,icon:n,href:t,countLabel:e.pluralLabel.toLowerCase(),count:i}}),I=[{title:`Users`,description:`Manage system users and accounts`,icon:p,href:`${r}/system/users`,countLabel:`users`,count:A.users},{title:`Organizations`,description:`Manage organizations and teams`,icon:u,href:`${r}/system/organizations`,countLabel:`organizations`,count:A.orgs},{title:`Roles`,description:`Configure roles and access levels`,icon:m,href:`${r}/system/roles`,countLabel:`roles`,count:A.roles},{title:`Permissions`,description:`Manage permission rules and assignments`,icon:l,href:`${r}/system/permissions`,countLabel:`permissions`,count:A.permissions},{title:`Audit Log`,description:`View system activity and changes`,icon:d,href:`${r}/system/audit-log`,countLabel:`entries`,count:A.auditLogs},{title:`Profile`,description:`View and edit your account settings`,icon:_,href:`${r}/system/profile`,countLabel:``,count:null}],L=[...F,...I];return(0,C.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,C.jsxs)(`div`,{className:`min-w-0`,children:[(0,C.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`System Settings`}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage applications, users, roles, permissions, and system configuration`})]}),M&&(0,C.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,C.jsx)(c,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading statistics...`]}),(0,C.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:L.map(t=>{let n=t.icon;return(0,C.jsxs)(s,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>e(t.href),"data-testid":`hub-card-${t.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${t.title}: ${t.description}`,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(t.href))},children:[(0,C.jsxs)(g,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,C.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,C.jsx)(n,{className:`h-5 w-5`})}),(0,C.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,C.jsx)(v,{className:`text-base`,children:t.title}),(0,C.jsx)(y,{className:`text-xs`,children:t.description})]})]}),(0,C.jsx)(h,{className:`pt-0`,children:t.count!==null&&(0,C.jsxs)(f,{variant:`secondary`,children:[t.count,` `,t.countLabel]})})]},t.title)})})]})}export{w as SystemHubPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{V as e}from"./framework-CoXA0nY6.js";import{n as t}from"./vendor-objectstack-CBpPY_xk.js";var n=class{cache;inflight;maxSize;ttl;stats;constructor(e={}){this.cache=new Map,this.inflight=new Map,this.maxSize=e.maxSize||100,this.ttl=e.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0,coalesced:0}}async get(e,t){let n=Date.now(),r=this.cache.get(e);if(r){if(n-r.timestamp<this.ttl)return r.accessCount++,r.lastAccessed=n,this.stats.hits++,this.cache.delete(e),this.cache.set(e,r),r.data;this.cache.delete(e)}let i=this.inflight.get(e);if(i)return this.stats.coalesced++,i;this.stats.misses++;let a=(async()=>{try{let n=await t();return this.set(e,n),n}finally{this.inflight.delete(e)}})();return this.inflight.set(e,a),a}prime(e,t){this.set(e,t)}set(e,t){let n=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictLRU(),this.cache.set(e,{data:t,timestamp:n,accessCount:1,lastAccessed:n})}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}invalidate(e){e?this.cache.delete(e):this.cache.clear()}clear(){this.cache.clear(),this.inflight.clear(),this.stats={hits:0,misses:0,evictions:0,coalesced:0}}getStats(){let e=this.stats.hits+this.stats.misses,t=e>0?this.stats.hits/e:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,coalesced:this.stats.coalesced,hitRate:t}}getCachedSync(e){let t=this.cache.get(e);if(t){if(this.ttl>0&&Date.now()-t.timestamp>this.ttl){this.cache.delete(e);return}return this.cache.delete(e),this.cache.set(e,t),this.stats.hits++,t.data}}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>=this.ttl?(this.cache.delete(e),!1):!0:!1}},r=class extends Error{constructor(e,t,n,r){super(e),this.code=t,this.statusCode=n,this.details=r,this.name=`ObjectStackError`,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}},i=class extends r{constructor(e,t){super(`Metadata not found for object: ${e}`,`METADATA_NOT_FOUND`,404,{objectName:e,...t}),this.name=`MetadataNotFoundError`}},a=class extends r{constructor(e,t,n,r,i){super(`Bulk ${e} operation failed: ${t} succeeded, ${n} failed`,`BULK_OPERATION_ERROR`,500,{operation:e,successCount:t,failureCount:n,errors:r,...i}),this.successCount=t,this.failureCount=n,this.errors=r,this.name=`BulkOperationError`}getSummary(){let e=this.successCount+this.failureCount,t=e>0?this.failureCount/e:0;return{operation:this.details?.operation,total:e,successful:this.successCount,failed:this.failureCount,failureRate:t,errors:this.errors}}},o=class extends r{constructor(e,t,n,r){super(`Connection error: ${e}`,`CONNECTION_ERROR`,r||503,{url:t,...n}),this.url=t,this.name=`ConnectionError`}},s=class extends r{constructor(e=`Authentication failed`,t,n){super(e,`AUTHENTICATION_ERROR`,n||401,t),this.name=`AuthenticationError`}},c=class extends r{constructor(e,t,n,r){super(e,`VALIDATION_ERROR`,400,{field:t,validationErrors:n,...r}),this.field=t,this.validationErrors=n,this.name=`ValidationError`}getValidationErrors(){return this.validationErrors||[]}};function l(e,t){let n=e?.status||e?.statusCode||500,a=e?.message||e?.statusText||`Unknown error`,l={context:t,response:{status:n,data:e?.data,headers:e?.headers}};switch(n){case 401:return new s(a,l,401);case 403:return new s(a,l,403);case 404:return t?.includes(`metadata`)||t?.includes(`schema`)||t?.includes(`getObjectSchema`)?new i(u(t),l):new r(a,`NOT_FOUND`,404,l);case 400:return new c(a,void 0,e?.data?.errors,l);case 503:return new o(a,e?.config?.url,l,503);case 504:return new o(a,e?.config?.url,l,504);default:return new r(a,`UNKNOWN_ERROR`,n,l)}}function u(e){if(!e)return`unknown`;let t=e.match(/\(([^)]+)\)/);return t?t[1]:`unknown`}var d={equals:`=`,eq:`=`,"==":`=`,not_equals:`!=`,notequals:`!=`,ne:`!=`,greater_than:`>`,greaterthan:`>`,gt:`>`,greater_than_or_equal:`>=`,greater_than_or_equals:`>=`,greaterthanorequal:`>=`,gte:`>=`,less_than:`<`,lessthan:`<`,lt:`<`,less_than_or_equal:`<=`,less_than_or_equals:`<=`,lessthanorequal:`<=`,lte:`<=`,in:`in`,not_in:`nin`,notin:`nin`,nin:`nin`,contains:`contains`,not_contains:`notcontains`,notcontains:`notcontains`,starts_with:`startswith`,startswith:`startswith`,ends_with:`endswith`,endswith:`endswith`,between:`between`,is_null:`isnull`,isnull:`isnull`,is_not_null:`isnotnull`,isnotnull:`isnotnull`};function f(e){return typeof e==`string`?d[e.toLowerCase()]??d[e]??e:null}function p(e){if(!e||typeof e!=`object`)return null;let t=e.field??e.name,n=f(e.operator??e.op??`=`);return!t||!n?null:[String(t),n,e.value]}var m=new Map;async function h(e,t){let n=e||`<default>`,r=m.get(n);if(r)return r;let i=t().catch(e=>{throw m.delete(n),e});return m.set(n,i),i}function g(e){if(typeof e!=`object`||!e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(g).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${g(t[e])}`).join(`,`)}}`}var _=class{client;connected=!1;connectPromise=null;metadataCache;connectionState=`disconnected`;connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;fetchImpl;inflightFinds=new Map;constructor(e){this.client=new t(e),this.metadataCache=new n(e.cache),this.autoReconnect=e.autoReconnect??!0,this.maxReconnectAttempts=e.maxReconnectAttempts??3,this.reconnectDelay=e.reconnectDelay??1e3,this.baseUrl=e.baseUrl,this.token=e.token,this.fetchImpl=e.fetch||globalThis.fetch.bind(globalThis)}async connect(){if(!this.connected)return this.connectPromise?this.connectPromise:(this.setConnectionState(`connecting`),this.connectPromise=(async()=>{try{let e=this.baseUrl||``,t=e?`${e.replace(/\/$/,``)}/api/v1/discovery`:`/api/v1/discovery`,n=await h(e,async()=>{let e=await this.fetchImpl(t,{method:`GET`,headers:this.token?{Authorization:`Bearer ${this.token}`}:void 0});if(!e.ok)throw Error(`discovery ${e.status} ${e.statusText}`);let n=await e.json();return n&&typeof n.success==`boolean`&&`data`in n?n.data:n});this.client.discoveryInfo=n,this.connected=!0,this.reconnectAttempts=0,this.setConnectionState(`connected`)}catch(e){let t=new o(e instanceof Error?e.message:`Failed to connect to ObjectStack server`,void 0,{originalError:e});if(this.setConnectionState(`error`,t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw t}finally{this.connectPromise=null}})(),this.connectPromise)}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState(`reconnecting`);let e=this.reconnectDelay*2**(this.reconnectAttempts-1);await new Promise(t=>setTimeout(t,e)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState===`connected`}onConnectionStateChange(e){return this.connectionStateListeners.push(e),()=>{let t=this.connectionStateListeners.indexOf(e);t>-1&&this.connectionStateListeners.splice(t,1)}}onBatchProgress(e){return this.batchProgressListeners.push(e),()=>{let t=this.batchProgressListeners.indexOf(e);t>-1&&this.batchProgressListeners.splice(t,1)}}setConnectionState(e,t){this.connectionState=e;let n={state:e,timestamp:Date.now(),error:t};this.connectionStateListeners.forEach(e=>{try{e(n)}catch(e){console.error(`Error in connection state listener:`,e)}})}emitBatchProgress(e){this.batchProgressListeners.forEach(t=>{try{t(e)}catch(e){console.error(`Error in batch progress listener:`,e)}})}async find(e,t){let n=`${e}::${g(t)}`,r=this.inflightFinds.get(n);if(r)return r;let i=(async()=>{if(await this.connect(),t?.$expand&&t.$expand.length>0){let n=await this.rawFindWithPopulate(e,t);return this.normalizeQueryResult(n,t)}let n=this.convertQueryParams(t),r=await this.client.data.find(e,n);return this.normalizeQueryResult(r,t)})();return this.inflightFinds.set(n,i),i.finally(()=>{this.inflightFinds.get(n)===i&&this.inflightFinds.delete(n)}),i}async findOne(e,t,n){if(await this.connect(),n?.$expand&&n.$expand.length>0)try{let r={...n,$filter:{id:String(t)},$top:1},i=await this.rawFindWithPopulate(e,r);if(Array.isArray(i))return i[0]||null;let a=i;return(a.records||a.value||[])[0]||null}catch(e){if(e?.status===404)return null}try{return(await this.client.data.get(e,String(t))).record}catch(e){if(e?.status===404)return null;throw e}}async create(e,t){return await this.connect(),(await this.client.data.create(e,t)).record}async update(e,t,n){return await this.connect(),(await this.client.data.update(e,String(t),n)).record}async delete(e,t){return await this.connect(),(await this.client.data.delete(e,String(t))).deleted}async bulk(e,t,n){if(await this.connect(),!n||n.length===0)return[];let i=n.length,o=0,s=0,c=()=>{this.emitBatchProgress({operation:t,total:i,completed:o,failed:s,percentage:i>0?(o+s)/i*100:0})};try{switch(t){case`create`:{c();let t=await this.client.data.createMany(e,n);return o=t.length,s=i-o,c(),t}case`delete`:{let t=n.map(e=>e.id).filter(Boolean);if(t.length===0){let e=n.map((e,t)=>({index:t,error:`Missing ID for item at index ${t}`}));throw s=n.length,c(),new a(`delete`,0,n.length,e)}return c(),await this.client.data.deleteMany(e,t),o=t.length,s=i-o,c(),[]}case`update`:{if(typeof this.client.data.updateMany==`function`)try{c();let t=this.client.data.updateMany,r=await t(e,n);return o=r.length,s=i-o,c(),r}catch{}let t=[],r=[];for(let i=0;i<n.length;i++){let a=n[i],l=a.id;if(!l){r.push({index:i,error:`Missing ID`}),s++,c();continue}try{let n=await this.client.data.update(e,String(l),a);t.push(n.record),o++,c()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({index:i,error:t}),s++,c()}}if(r.length>0)throw new a(`update`,t.length,r.length,r,{resource:e,totalRecords:n.length});return t}default:throw new r(`Unsupported bulk operation: ${t}`,`UNSUPPORTED_OPERATION`,400)}}catch(i){if(c(),i instanceof a||i instanceof r)throw i;let o=i instanceof Error?i.message:String(i),s=n.map((e,t)=>({index:t,error:o}));throw new a(t,0,n.length,s,{resource:e,originalError:i})}}normalizeQueryResult(e,t){if(Array.isArray(e))return{data:e,total:e.length,page:1,pageSize:e.length,hasMore:!1};let n=e,r=n.records||n.value||[];return{data:r,total:n.total??n.count??r.length,page:t?.$skip&&t.$top?Math.floor(t.$skip/t.$top)+1:1,pageSize:t?.$top,hasMore:t?.$top?r.length===t.$top:!1}}async rawFindWithPopulate(e,t){let n=new URLSearchParams;if(t.$expand&&t.$expand.length>0&&n.set(`populate`,t.$expand.join(`,`)),t.$top!==void 0&&n.set(`top`,String(t.$top)),t.$skip!==void 0&&n.set(`skip`,String(t.$skip)),t.$select&&t.$select.length>0&&n.set(`select`,t.$select.join(`,`)),t.$orderby)if(Array.isArray(t.$orderby)){let e=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}).join(`,`);n.set(`sort`,e)}else{let e=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e).join(`,`);n.set(`sort`,e)}t.$filter!==void 0&&t.$filter!==null&&((Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0)||n.set(`filter`,JSON.stringify(t.$filter)));let r=this.baseUrl.replace(/\/$/,``),i=n.toString(),a=`${r}${/\/api\/v\d+$/i.test(r)?`/data`:`/api/v1/data`}/${e}${i?`?${i}`:``}`,o={"Content-Type":`application/json`};this.token&&(o.Authorization=`Bearer ${this.token}`);let s=await this.fetchImpl(a,{method:`GET`,headers:o});if(!s.ok){let e=await s.json().catch(()=>({message:s.statusText})),t=Error(e?.error?.message||e?.message||s.statusText);throw t.status=s.status,t}let c=await s.json();return c&&typeof c.success==`boolean`&&`data`in c?c.data:c}convertQueryParams(t){if(!t)return{};let n={};if(t.$select&&(n.select=t.$select),t.$filter!==void 0&&t.$filter!==null&&!(Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0))if(Array.isArray(t.$filter))if(t.$filter.length>0&&typeof t.$filter[0]==`object`&&!Array.isArray(t.$filter[0])&&t.$filter[0].field!==void 0){let e=t.$filter.map(e=>p(e)).filter(e=>e!==null);e.length===0||(e.length===1?n.filters=e[0]:n.filters=[`and`,...e])}else n.filters=t.$filter;else n.filters=e(t.$filter);return t.$orderby&&(Array.isArray(t.$orderby)?n.sort=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}):n.sort=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e)),t.$skip!==void 0&&(n.skip=t.$skip),t.$top!==void 0&&(n.top=t.$top),n}async getObjectSchema(e){await this.connect();try{return await this.metadataCache.get(e,async()=>{let t=await this.client.meta.getItem(`object`,e);return t&&t.item?t.item:t})}catch(t){let n=t;throw n?.status===404||n?.statusCode===404?new i(e,{originalError:t}):t instanceof r?t:l(n,`getObjectSchema(${e})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(e,t){await this.connect();try{let n=`view:${e}:${t}`;return await this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,`views/${t}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(e){await this.connect();try{let t=`app:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`apps`,e);return t&&t.item?t.item:t??null})}catch{return null}}async getPage(e){await this.connect();try{let t=`page:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`pages`,e);return t&&t.item?t.item:t??null})}catch{return null}}async aggregate(e,t){await this.connect();try{let n=t.function===`count`?`count`:`${t.field}_${t.function}`,r={cube:e,measures:[n],dimensions:t.groupBy&&t.groupBy!==`_all`?[t.groupBy]:[]};t.filter&&(r.filters=t.filter);let i=await this.client.analytics.query(r);return(Array.isArray(i)?i:i?.rows&&Array.isArray(i.rows)?i.rows:i?.data&&Array.isArray(i.data)?i.data:i?.data?.rows&&Array.isArray(i.data.rows)?i.data.rows:i?.results&&Array.isArray(i.results)?i.results:[]).map(e=>{let r={...e};return n!==t.field&&n in r&&(r[t.field]=r[n],delete r[n]),r})}catch{let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}}aggregateClientSide(e,t){let{field:n,function:r,groupBy:i}=t,a={};for(let t of e){let e=String(t[i]??`Unknown`);a[e]||(a[e]=[]),a[e].push(t)}return Object.entries(a).map(([e,t])=>{let a=t.map(e=>Number(e[n])||0),o;switch(r){case`count`:o=t.length;break;case`avg`:o=a.length>0?a.reduce((e,t)=>e+t,0)/a.length:0;break;case`min`:o=a.length>0?Math.min(...a):0;break;case`max`:o=a.length>0?Math.max(...a):0;break;default:o=a.reduce((e,t)=>e+t,0);break}return{[i]:e,[n]:o}})}async getItems(e,t){return await this.connect(),await Promise.all(t.map(async t=>{let n=`${e}:${t}`;return this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n})}))}getCached(e){return this.metadataCache.getCachedSync(e)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(e){this.metadataCache.invalidate(e)}clearCache(){this.metadataCache.clear()}async uploadFile(e,t,n){await this.connect();let i=new FormData;i.append(`file`,t),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}async uploadFiles(e,t,n){await this.connect();let i=new FormData;t.forEach((e,t)=>{i.append(`files`,e,e.name||`file-${t}`)}),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}getAuthHeaders(){let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e}};export{h as n,_ as t};
|
|
1
|
+
import{V as e}from"./framework-CoXA0nY6.js";import{n as t}from"./vendor-objectstack-CBpPY_xk.js";var n=class{cache;inflight;maxSize;ttl;stats;constructor(e={}){this.cache=new Map,this.inflight=new Map,this.maxSize=e.maxSize||100,this.ttl=e.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0,coalesced:0}}async get(e,t){let n=Date.now(),r=this.cache.get(e);if(r){if(n-r.timestamp<this.ttl)return r.accessCount++,r.lastAccessed=n,this.stats.hits++,this.cache.delete(e),this.cache.set(e,r),r.data;this.cache.delete(e)}let i=this.inflight.get(e);if(i)return this.stats.coalesced++,i;this.stats.misses++;let a=(async()=>{try{let n=await t();return this.set(e,n),n}finally{this.inflight.delete(e)}})();return this.inflight.set(e,a),a}prime(e,t){this.set(e,t)}set(e,t){let n=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictLRU(),this.cache.set(e,{data:t,timestamp:n,accessCount:1,lastAccessed:n})}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}invalidate(e){e?this.cache.delete(e):this.cache.clear()}clear(){this.cache.clear(),this.inflight.clear(),this.stats={hits:0,misses:0,evictions:0,coalesced:0}}getStats(){let e=this.stats.hits+this.stats.misses,t=e>0?this.stats.hits/e:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,coalesced:this.stats.coalesced,hitRate:t}}getCachedSync(e){let t=this.cache.get(e);if(t){if(this.ttl>0&&Date.now()-t.timestamp>this.ttl){this.cache.delete(e);return}return this.cache.delete(e),this.cache.set(e,t),this.stats.hits++,t.data}}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>=this.ttl?(this.cache.delete(e),!1):!0:!1}},r=class extends Error{constructor(e,t,n,r){super(e),this.code=t,this.statusCode=n,this.details=r,this.name=`ObjectStackError`,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}},i=class extends r{constructor(e,t){super(`Metadata not found for object: ${e}`,`METADATA_NOT_FOUND`,404,{objectName:e,...t}),this.name=`MetadataNotFoundError`}},a=class extends r{constructor(e,t,n,r,i){super(`Bulk ${e} operation failed: ${t} succeeded, ${n} failed`,`BULK_OPERATION_ERROR`,500,{operation:e,successCount:t,failureCount:n,errors:r,...i}),this.successCount=t,this.failureCount=n,this.errors=r,this.name=`BulkOperationError`}getSummary(){let e=this.successCount+this.failureCount,t=e>0?this.failureCount/e:0;return{operation:this.details?.operation,total:e,successful:this.successCount,failed:this.failureCount,failureRate:t,errors:this.errors}}},o=class extends r{constructor(e,t,n,r){super(`Connection error: ${e}`,`CONNECTION_ERROR`,r||503,{url:t,...n}),this.url=t,this.name=`ConnectionError`}},s=class extends r{constructor(e=`Authentication failed`,t,n){super(e,`AUTHENTICATION_ERROR`,n||401,t),this.name=`AuthenticationError`}},c=class extends r{constructor(e,t,n,r){super(e,`VALIDATION_ERROR`,400,{field:t,validationErrors:n,...r}),this.field=t,this.validationErrors=n,this.name=`ValidationError`}getValidationErrors(){return this.validationErrors||[]}};function l(e,t){let n=e?.status||e?.statusCode||500,a=e?.message||e?.statusText||`Unknown error`,l={context:t,response:{status:n,data:e?.data,headers:e?.headers}};switch(n){case 401:return new s(a,l,401);case 403:return new s(a,l,403);case 404:return t?.includes(`metadata`)||t?.includes(`schema`)||t?.includes(`getObjectSchema`)?new i(u(t),l):new r(a,`NOT_FOUND`,404,l);case 400:return new c(a,void 0,e?.data?.errors,l);case 503:return new o(a,e?.config?.url,l,503);case 504:return new o(a,e?.config?.url,l,504);default:return new r(a,`UNKNOWN_ERROR`,n,l)}}function u(e){if(!e)return`unknown`;let t=e.match(/\(([^)]+)\)/);return t?t[1]:`unknown`}var d={equals:`=`,eq:`=`,"==":`=`,not_equals:`!=`,notequals:`!=`,ne:`!=`,greater_than:`>`,greaterthan:`>`,gt:`>`,greater_than_or_equal:`>=`,greater_than_or_equals:`>=`,greaterthanorequal:`>=`,gte:`>=`,less_than:`<`,lessthan:`<`,lt:`<`,less_than_or_equal:`<=`,less_than_or_equals:`<=`,lessthanorequal:`<=`,lte:`<=`,in:`in`,not_in:`nin`,notin:`nin`,nin:`nin`,contains:`contains`,not_contains:`notcontains`,notcontains:`notcontains`,starts_with:`startswith`,startswith:`startswith`,ends_with:`endswith`,endswith:`endswith`,between:`between`,is_null:`isnull`,isnull:`isnull`,is_not_null:`isnotnull`,isnotnull:`isnotnull`};function f(e){return typeof e==`string`?d[e.toLowerCase()]??d[e]??e:null}function p(e){if(!e||typeof e!=`object`)return null;let t=e.field??e.name,n=f(e.operator??e.op??`=`);return!t||!n?null:[String(t),n,e.value]}var m=new Map;async function h(e,t){let n=e||`<default>`,r=m.get(n);if(r)return r;let i=t().catch(e=>{throw m.delete(n),e});return m.set(n,i),i}function g(e){if(typeof e!=`object`||!e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(g).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${g(t[e])}`).join(`,`)}}`}var _=class{client;connected=!1;connectPromise=null;metadataCache;connectionState=`disconnected`;connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;fetchImpl;inflightFinds=new Map;constructor(e){this.client=new t(e),this.metadataCache=new n(e.cache),this.autoReconnect=e.autoReconnect??!0,this.maxReconnectAttempts=e.maxReconnectAttempts??3,this.reconnectDelay=e.reconnectDelay??1e3,this.baseUrl=e.baseUrl,this.token=e.token,this.fetchImpl=e.fetch||globalThis.fetch.bind(globalThis)}async connect(){if(!this.connected)return this.connectPromise?this.connectPromise:(this.setConnectionState(`connecting`),this.connectPromise=(async()=>{try{let e=this.baseUrl||``,t=e?`${e.replace(/\/$/,``)}/api/v1/discovery`:`/api/v1/discovery`,n=await h(e,async()=>{let e=await this.fetchImpl(t,{method:`GET`,headers:this.token?{Authorization:`Bearer ${this.token}`}:void 0});if(!e.ok)throw Error(`discovery ${e.status} ${e.statusText}`);let n=await e.json();return n&&typeof n.success==`boolean`&&`data`in n?n.data:n});this.client.discoveryInfo=n,this.connected=!0,this.reconnectAttempts=0,this.setConnectionState(`connected`)}catch(e){let t=new o(e instanceof Error?e.message:`Failed to connect to ObjectStack server`,void 0,{originalError:e});if(this.setConnectionState(`error`,t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw t}finally{this.connectPromise=null}})(),this.connectPromise)}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState(`reconnecting`);let e=this.reconnectDelay*2**(this.reconnectAttempts-1);await new Promise(t=>setTimeout(t,e)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState===`connected`}onConnectionStateChange(e){return this.connectionStateListeners.push(e),()=>{let t=this.connectionStateListeners.indexOf(e);t>-1&&this.connectionStateListeners.splice(t,1)}}onBatchProgress(e){return this.batchProgressListeners.push(e),()=>{let t=this.batchProgressListeners.indexOf(e);t>-1&&this.batchProgressListeners.splice(t,1)}}setConnectionState(e,t){this.connectionState=e;let n={state:e,timestamp:Date.now(),error:t};this.connectionStateListeners.forEach(e=>{try{e(n)}catch(e){console.error(`Error in connection state listener:`,e)}})}emitBatchProgress(e){this.batchProgressListeners.forEach(t=>{try{t(e)}catch(e){console.error(`Error in batch progress listener:`,e)}})}async find(e,t){let n=`${e}::${g(t)}`,r=this.inflightFinds.get(n);if(r)return r;let i=(async()=>{if(await this.connect(),t?.$expand&&t.$expand.length>0){let n=await this.rawFindWithPopulate(e,t);return this.normalizeQueryResult(n,t)}let n=this.convertQueryParams(t),r=await this.client.data.find(e,n);return this.normalizeQueryResult(r,t)})();return this.inflightFinds.set(n,i),i.finally(()=>{this.inflightFinds.get(n)===i&&this.inflightFinds.delete(n)}),i}async findOne(e,t,n){if(await this.connect(),n?.$expand&&n.$expand.length>0)try{let r={...n,$filter:{id:String(t)},$top:1},i=await this.rawFindWithPopulate(e,r);if(Array.isArray(i))return i[0]||null;let a=i;return(a.records||a.value||[])[0]||null}catch(e){if(e?.status===404)return null}try{return(await this.client.data.get(e,String(t))).record}catch(e){if(e?.status===404)return null;throw e}}async create(e,t){return await this.connect(),(await this.client.data.create(e,t)).record}async update(e,t,n){return await this.connect(),(await this.client.data.update(e,String(t),n)).record}async delete(e,t){return await this.connect(),(await this.client.data.delete(e,String(t))).deleted}async bulk(e,t,n){if(await this.connect(),!n||n.length===0)return[];let i=n.length,o=0,s=0,c=()=>{this.emitBatchProgress({operation:t,total:i,completed:o,failed:s,percentage:i>0?(o+s)/i*100:0})};try{switch(t){case`create`:{c();let t=await this.client.data.createMany(e,n);return o=t.length,s=i-o,c(),t}case`delete`:{let t=n.map(e=>e.id).filter(Boolean);if(t.length===0){let e=n.map((e,t)=>({index:t,error:`Missing ID for item at index ${t}`}));throw s=n.length,c(),new a(`delete`,0,n.length,e)}return c(),await this.client.data.deleteMany(e,t),o=t.length,s=i-o,c(),[]}case`update`:{if(typeof this.client.data.updateMany==`function`)try{c();let t=this.client.data.updateMany,r=await t(e,n);return o=r.length,s=i-o,c(),r}catch{}let t=[],r=[];for(let i=0;i<n.length;i++){let a=n[i],l=a.id;if(!l){r.push({index:i,error:`Missing ID`}),s++,c();continue}try{let n=await this.client.data.update(e,String(l),a);t.push(n.record),o++,c()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({index:i,error:t}),s++,c()}}if(r.length>0)throw new a(`update`,t.length,r.length,r,{resource:e,totalRecords:n.length});return t}default:throw new r(`Unsupported bulk operation: ${t}`,`UNSUPPORTED_OPERATION`,400)}}catch(i){if(c(),i instanceof a||i instanceof r)throw i;let o=i instanceof Error?i.message:String(i),s=n.map((e,t)=>({index:t,error:o}));throw new a(t,0,n.length,s,{resource:e,originalError:i})}}normalizeQueryResult(e,t){if(Array.isArray(e))return{data:e,total:e.length,page:1,pageSize:e.length,hasMore:!1};let n=e,r=n.records||n.value||[];return{data:r,total:n.total??n.count??r.length,page:t?.$skip&&t.$top?Math.floor(t.$skip/t.$top)+1:1,pageSize:t?.$top,hasMore:t?.$top?r.length===t.$top:!1}}async rawFindWithPopulate(e,t){let n=new URLSearchParams;if(t.$expand&&t.$expand.length>0&&n.set(`populate`,t.$expand.join(`,`)),t.$top!==void 0&&n.set(`top`,String(t.$top)),t.$skip!==void 0&&n.set(`skip`,String(t.$skip)),t.$select&&t.$select.length>0&&n.set(`select`,t.$select.join(`,`)),t.$orderby)if(Array.isArray(t.$orderby)){let e=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}).join(`,`);n.set(`sort`,e)}else{let e=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e).join(`,`);n.set(`sort`,e)}t.$filter!==void 0&&t.$filter!==null&&((Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0)||n.set(`filter`,JSON.stringify(t.$filter)));let r=this.baseUrl.replace(/\/$/,``),i=n.toString(),a=`${r}${/\/api\/v\d+$/i.test(r)?`/data`:`/api/v1/data`}/${e}${i?`?${i}`:``}`,o={"Content-Type":`application/json`};this.token&&(o.Authorization=`Bearer ${this.token}`);let s=await this.fetchImpl(a,{method:`GET`,headers:o});if(!s.ok){let e=await s.json().catch(()=>({message:s.statusText})),t=Error(e?.error?.message||e?.message||s.statusText);throw t.status=s.status,t}let c=await s.json();return c&&typeof c.success==`boolean`&&`data`in c?c.data:c}convertQueryParams(t){if(!t)return{};let n={};if(t.$select&&(n.select=t.$select),t.$filter!==void 0&&t.$filter!==null&&!(Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0))if(Array.isArray(t.$filter))if(t.$filter.length>0&&typeof t.$filter[0]==`object`&&!Array.isArray(t.$filter[0])&&t.$filter[0].field!==void 0){let e=t.$filter.map(e=>p(e)).filter(e=>e!==null);e.length===0||(e.length===1?n.filters=e[0]:n.filters=[`and`,...e])}else n.filters=t.$filter;else n.filters=e(t.$filter);return t.$orderby&&(Array.isArray(t.$orderby)?n.sort=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}):n.sort=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e)),t.$skip!==void 0&&(n.skip=t.$skip),t.$top!==void 0&&(n.top=t.$top),n}async getObjectSchema(e){await this.connect();try{return await this.metadataCache.get(e,async()=>{let t=await this.client.meta.getItem(`object`,e);return t&&t.item?t.item:t})}catch(t){let n=t;throw n?.status===404||n?.statusCode===404?new i(e,{originalError:t}):t instanceof r?t:l(n,`getObjectSchema(${e})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async getView(e,t){await this.connect();try{let n=`view:${e}:${t}`;return await this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,`views/${t}`);return n&&n.item?n.item:n??null})}catch{return null}}async getApp(e){await this.connect();try{let t=`app:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`apps`,e);return t&&t.item?t.item:t??null})}catch{return null}}async getPage(e){await this.connect();try{let t=`page:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`pages`,e);return t&&t.item?t.item:t??null})}catch{return null}}async aggregate(e,t){await this.connect();try{let n=t.function===`count`?`count`:`${t.field}_${t.function}`,r={cube:e,measures:[n],dimensions:t.groupBy&&t.groupBy!==`_all`?[t.groupBy]:[]};t.filter&&(r.filters=t.filter);let i=await this.client.analytics.query(r),a=Array.isArray(i)?i:i?.rows&&Array.isArray(i.rows)?i.rows:i?.data&&Array.isArray(i.data)?i.data:i?.data?.rows&&Array.isArray(i.data.rows)?i.data.rows:i?.results&&Array.isArray(i.results)?i.results:[];if(a.length>0&&a.every(e=>e==null?!0:!(n in e&&e[n]!=null||t.field in e&&e[t.field]!=null))){let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}return a.map(e=>{let r={...e};return n!==t.field&&n in r&&(r[t.field]=r[n],delete r[n]),r})}catch{let n=(await this.find(e)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}}aggregateClientSide(e,t){let{field:n,function:r,groupBy:i}=t,a={};for(let t of e){let e=String(t[i]??`Unknown`);a[e]||(a[e]=[]),a[e].push(t)}return Object.entries(a).map(([e,t])=>{let a=t.map(e=>Number(e[n])||0),o;switch(r){case`count`:o=t.length;break;case`avg`:o=a.length>0?a.reduce((e,t)=>e+t,0)/a.length:0;break;case`min`:o=a.length>0?Math.min(...a):0;break;case`max`:o=a.length>0?Math.max(...a):0;break;default:o=a.reduce((e,t)=>e+t,0);break}return{[i]:e,[n]:o}})}async getItems(e,t){return await this.connect(),await Promise.all(t.map(async t=>{let n=`${e}:${t}`;return this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n})}))}getCached(e){return this.metadataCache.getCachedSync(e)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(e){this.metadataCache.invalidate(e)}clearCache(){this.metadataCache.clear()}async uploadFile(e,t,n){await this.connect();let i=new FormData;i.append(`file`,t),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}async uploadFiles(e,t,n){await this.connect();let i=new FormData;t.forEach((e,t)=>{i.append(`files`,e,e.name||`file-${t}`)}),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}getAuthHeaders(){let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e}};export{h as n,_ as t};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n,u as r}from"./vendor-react-B1k2FF9f.js";import{p as i}from"./framework-CoXA0nY6.js";import{o as a}from"./vendor-ui-utils-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{_ as t,t as n,u as r}from"./vendor-react-B1k2FF9f.js";import{p as i}from"./framework-CoXA0nY6.js";import{o as a}from"./vendor-ui-utils-Dyl9EYZi.js";import{Cy as o,OD as s,Q as c}from"./ui-components-B7mlp0en.js";import{r as l}from"./src-D5NTzWsi.js";import{n as u,r as d,t as f}from"./index-CPatxDwz.js";function p(e,t){let n=t?.label||e,r=t?.description||e,i=[{type:`object-detail-tabs`,id:`${e}-tabs`,objectName:e}];return{type:`page`,name:`object-detail-${e}`,title:n,description:r,icon:`database`,pageType:`record_detail`,object:e,body:i}}var m=e(t(),1),h=n();function g({basePath:e,metadataType:t}){let n=r(),{objects:s,refresh:c}=i(),p=d(),g=(0,m.useMemo)(()=>(s||[]).map(u),[s]),[_,v]=(0,m.useState)(null),[y,b]=(0,m.useState)(!1),x=_??g,S=(0,m.useRef)(x),C=(0,m.useCallback)(r=>{n(`${e}/system/metadata/${t}/${r.name}`)},[n,e,t]),w=(0,m.useCallback)(async e=>{let t=S.current;if(v(e),S.current=e,!p){a.error(`Service unavailable — changes saved locally only`);return}let n=f.diffObjects(t,e);b(!0);try{if(n)n.type===`delete`?await p.deleteObject(n.object.name):await p.saveObject(n.object);else for(let t of e)await p.saveObject(t);await c();let t=n?n.type===`create`?`Object "${n.object.label||n.object.name}" created`:n.type===`update`?`Object "${n.object.label||n.object.name}" updated`:`Object "${n.object.label||n.object.name}" deleted`:`Object definitions updated`;a.success(t)}catch(e){v(t),S.current=t,a.error(e?.message||`Failed to save object changes`)}finally{b(!1)}},[p,c]);return(0,h.jsxs)(h.Fragment,{children:[y&&(0,h.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`object-saving-indicator`,children:[(0,h.jsx)(o,{className:`h-4 w-4 animate-spin`}),`Saving object changes…`]}),(0,h.jsx)(l,{objects:x,onObjectsChange:w,onSelectObject:C,showSystemObjects:!0})]})}var _=[{type:`app`,label:`Application`,pluralLabel:`Applications`,description:`Manage all configured applications`,icon:`layout-grid`,customRoute:`/system/apps`,countSource:`metadata`},{type:`object`,label:`Object`,pluralLabel:`Object Manager`,description:`Manage object definitions and field configurations`,icon:`database`,countSource:`metadata`,pageSchemaFactory:(e,t)=>p(e,t),listComponent:g},{type:`dashboard`,label:`Dashboard`,pluralLabel:`Dashboards`,description:`Manage dashboard layouts and widgets`,icon:`layout-dashboard`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`dashboard_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Dashboard`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]},{type:`page`,label:`Page`,pluralLabel:`Pages`,description:`Manage custom page definitions`,icon:`file-text`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`page_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Page`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]},{type:`report`,label:`Report`,pluralLabel:`Reports`,description:`Manage report configurations and templates`,icon:`bar-chart-3`,listMode:`grid`,columns:[{key:`name`,label:`Name`},{key:`label`,label:`Label`},{key:`description`,label:`Description`}],formFields:[{key:`name`,label:`Name`,required:!0,placeholder:`report_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`My Report`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}]}];function v(e){return _.find(t=>t.type===e)}function y(){return _}var b=[{key:`name`,label:`Name`,required:!0,placeholder:`api_name`,disabledOnEdit:!0},{key:`label`,label:`Label`,required:!0,placeholder:`Display Label`},{key:`description`,label:`Description`,type:`textarea`,placeholder:`Brief description`}];function x(e){return e.includes(`-`)?e.toLowerCase():e.replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).toLowerCase()}var S=new Map;function C(e){if(!e)return s;let t=S.get(e);if(t)return t;let n=x(e),r=e=>m.createElement(c,{name:n,fallback:s,...e});return r.displayName=`LucideIcon(${e})`,S.set(e,r),r}export{v as i,b as n,y as r,C as t};
|