@shware/workflow-ui 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +180 -2
- package/dist/assets/iphone-17-pro-DzaacWSl.png +0 -0
- package/dist/assets/pixel-10-pro-back-7MDj1_lz.webp +0 -0
- package/dist/assets/pixel-10-pro-mask-Bi1deQ9Y.webp +0 -0
- package/dist/cli.d.mts +1 -0
- package/dist/cli.mjs +673 -0
- package/dist/cli.mjs.map +1 -0
- package/dist/config.d.mts +247 -0
- package/dist/config.d.mts.map +1 -0
- package/dist/config.mjs +27 -0
- package/dist/config.mjs.map +1 -0
- package/dist/index.d.mts +451 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2722 -0
- package/dist/index.mjs.map +1 -0
- package/dist/postgres.d.mts +34 -0
- package/dist/postgres.d.mts.map +1 -0
- package/dist/postgres.mjs +313 -0
- package/dist/postgres.mjs.map +1 -0
- package/package.json +93 -3
- package/src/app/assets/devices/iphone-17-pro.png +0 -0
- package/src/app/assets/devices/pixel-10-pro-back.webp +0 -0
- package/src/app/assets/devices/pixel-10-pro-mask.webp +0 -0
- package/src/app/assets/flags/AC.svg +1 -0
- package/src/app/assets/flags/AD.svg +1 -0
- package/src/app/assets/flags/AE.svg +1 -0
- package/src/app/assets/flags/AF.svg +1 -0
- package/src/app/assets/flags/AG.svg +1 -0
- package/src/app/assets/flags/AI.svg +1 -0
- package/src/app/assets/flags/AL.svg +1 -0
- package/src/app/assets/flags/AM.svg +1 -0
- package/src/app/assets/flags/AO.svg +1 -0
- package/src/app/assets/flags/AQ.svg +1 -0
- package/src/app/assets/flags/AR.svg +1 -0
- package/src/app/assets/flags/AS.svg +1 -0
- package/src/app/assets/flags/AT.svg +1 -0
- package/src/app/assets/flags/AU.svg +1 -0
- package/src/app/assets/flags/AW.svg +1 -0
- package/src/app/assets/flags/AX.svg +1 -0
- package/src/app/assets/flags/AZ.svg +1 -0
- package/src/app/assets/flags/BA.svg +1 -0
- package/src/app/assets/flags/BB.svg +1 -0
- package/src/app/assets/flags/BD.svg +1 -0
- package/src/app/assets/flags/BE.svg +1 -0
- package/src/app/assets/flags/BF.svg +1 -0
- package/src/app/assets/flags/BG.svg +1 -0
- package/src/app/assets/flags/BH.svg +1 -0
- package/src/app/assets/flags/BI.svg +1 -0
- package/src/app/assets/flags/BJ.svg +1 -0
- package/src/app/assets/flags/BL.svg +1 -0
- package/src/app/assets/flags/BM.svg +1 -0
- package/src/app/assets/flags/BN.svg +1 -0
- package/src/app/assets/flags/BO.svg +1 -0
- package/src/app/assets/flags/BQ-BO.svg +1 -0
- package/src/app/assets/flags/BQ-SA.svg +1 -0
- package/src/app/assets/flags/BQ-SE.svg +1 -0
- package/src/app/assets/flags/BQ.svg +1 -0
- package/src/app/assets/flags/BR.svg +1 -0
- package/src/app/assets/flags/BS.svg +1 -0
- package/src/app/assets/flags/BT.svg +1 -0
- package/src/app/assets/flags/BV.svg +1 -0
- package/src/app/assets/flags/BW.svg +1 -0
- package/src/app/assets/flags/BY.svg +1 -0
- package/src/app/assets/flags/BZ.svg +1 -0
- package/src/app/assets/flags/CA.svg +1 -0
- package/src/app/assets/flags/CC.svg +1 -0
- package/src/app/assets/flags/CD.svg +1 -0
- package/src/app/assets/flags/CF.svg +1 -0
- package/src/app/assets/flags/CG.svg +1 -0
- package/src/app/assets/flags/CH.svg +1 -0
- package/src/app/assets/flags/CI.svg +1 -0
- package/src/app/assets/flags/CK.svg +1 -0
- package/src/app/assets/flags/CL.svg +1 -0
- package/src/app/assets/flags/CM.svg +1 -0
- package/src/app/assets/flags/CN.svg +1 -0
- package/src/app/assets/flags/CO.svg +1 -0
- package/src/app/assets/flags/CR.svg +1 -0
- package/src/app/assets/flags/CU.svg +1 -0
- package/src/app/assets/flags/CV.svg +1 -0
- package/src/app/assets/flags/CW.svg +1 -0
- package/src/app/assets/flags/CX.svg +1 -0
- package/src/app/assets/flags/CY.svg +1 -0
- package/src/app/assets/flags/CZ.svg +1 -0
- package/src/app/assets/flags/DE.svg +1 -0
- package/src/app/assets/flags/DJ.svg +1 -0
- package/src/app/assets/flags/DK.svg +1 -0
- package/src/app/assets/flags/DM.svg +1 -0
- package/src/app/assets/flags/DO.svg +1 -0
- package/src/app/assets/flags/DZ.svg +1 -0
- package/src/app/assets/flags/EC.svg +1 -0
- package/src/app/assets/flags/EE.svg +1 -0
- package/src/app/assets/flags/EG.svg +1 -0
- package/src/app/assets/flags/EH.svg +1 -0
- package/src/app/assets/flags/ER.svg +1 -0
- package/src/app/assets/flags/ES-CT.svg +1 -0
- package/src/app/assets/flags/ES.svg +1 -0
- package/src/app/assets/flags/ET.svg +1 -0
- package/src/app/assets/flags/EU.svg +1 -0
- package/src/app/assets/flags/FI.svg +1 -0
- package/src/app/assets/flags/FJ.svg +1 -0
- package/src/app/assets/flags/FK.svg +1 -0
- package/src/app/assets/flags/FM.svg +1 -0
- package/src/app/assets/flags/FO.svg +1 -0
- package/src/app/assets/flags/FR.svg +1 -0
- package/src/app/assets/flags/GA.svg +1 -0
- package/src/app/assets/flags/GB-ENG.svg +1 -0
- package/src/app/assets/flags/GB-NIR.svg +1 -0
- package/src/app/assets/flags/GB-SCT.svg +1 -0
- package/src/app/assets/flags/GB-WLS.svg +1 -0
- package/src/app/assets/flags/GB.svg +1 -0
- package/src/app/assets/flags/GD.svg +1 -0
- package/src/app/assets/flags/GE.svg +1 -0
- package/src/app/assets/flags/GF.svg +1 -0
- package/src/app/assets/flags/GG.svg +1 -0
- package/src/app/assets/flags/GH.svg +1 -0
- package/src/app/assets/flags/GI.svg +1 -0
- package/src/app/assets/flags/GL.svg +1 -0
- package/src/app/assets/flags/GM.svg +1 -0
- package/src/app/assets/flags/GN.svg +1 -0
- package/src/app/assets/flags/GP.svg +1 -0
- package/src/app/assets/flags/GQ.svg +1 -0
- package/src/app/assets/flags/GR.svg +1 -0
- package/src/app/assets/flags/GS.svg +1 -0
- package/src/app/assets/flags/GT.svg +1 -0
- package/src/app/assets/flags/GU.svg +1 -0
- package/src/app/assets/flags/GW.svg +1 -0
- package/src/app/assets/flags/GY.svg +1 -0
- package/src/app/assets/flags/HK.svg +1 -0
- package/src/app/assets/flags/HM.svg +1 -0
- package/src/app/assets/flags/HN.svg +1 -0
- package/src/app/assets/flags/HR.svg +1 -0
- package/src/app/assets/flags/HT.svg +1 -0
- package/src/app/assets/flags/HU.svg +1 -0
- package/src/app/assets/flags/IC.svg +1 -0
- package/src/app/assets/flags/ID.svg +1 -0
- package/src/app/assets/flags/IE.svg +1 -0
- package/src/app/assets/flags/IL.svg +1 -0
- package/src/app/assets/flags/IM.svg +1 -0
- package/src/app/assets/flags/IN.svg +1 -0
- package/src/app/assets/flags/IO.svg +1 -0
- package/src/app/assets/flags/IQ.svg +1 -0
- package/src/app/assets/flags/IR.svg +1 -0
- package/src/app/assets/flags/IS.svg +1 -0
- package/src/app/assets/flags/IT.svg +1 -0
- package/src/app/assets/flags/JE.svg +1 -0
- package/src/app/assets/flags/JM.svg +1 -0
- package/src/app/assets/flags/JO.svg +1 -0
- package/src/app/assets/flags/JP.svg +1 -0
- package/src/app/assets/flags/KE.svg +1 -0
- package/src/app/assets/flags/KG.svg +1 -0
- package/src/app/assets/flags/KH.svg +1 -0
- package/src/app/assets/flags/KI.svg +1 -0
- package/src/app/assets/flags/KM.svg +1 -0
- package/src/app/assets/flags/KN.svg +1 -0
- package/src/app/assets/flags/KP.svg +1 -0
- package/src/app/assets/flags/KR.svg +1 -0
- package/src/app/assets/flags/KW.svg +1 -0
- package/src/app/assets/flags/KY.svg +1 -0
- package/src/app/assets/flags/KZ.svg +1 -0
- package/src/app/assets/flags/LA.svg +1 -0
- package/src/app/assets/flags/LB.svg +1 -0
- package/src/app/assets/flags/LC.svg +1 -0
- package/src/app/assets/flags/LI.svg +1 -0
- package/src/app/assets/flags/LK.svg +1 -0
- package/src/app/assets/flags/LR.svg +1 -0
- package/src/app/assets/flags/LS.svg +1 -0
- package/src/app/assets/flags/LT.svg +1 -0
- package/src/app/assets/flags/LU.svg +1 -0
- package/src/app/assets/flags/LV.svg +1 -0
- package/src/app/assets/flags/LY.svg +1 -0
- package/src/app/assets/flags/MA.svg +1 -0
- package/src/app/assets/flags/MC.svg +1 -0
- package/src/app/assets/flags/MD.svg +1 -0
- package/src/app/assets/flags/ME.svg +1 -0
- package/src/app/assets/flags/MF.svg +1 -0
- package/src/app/assets/flags/MG.svg +1 -0
- package/src/app/assets/flags/MH.svg +1 -0
- package/src/app/assets/flags/MK.svg +1 -0
- package/src/app/assets/flags/ML.svg +1 -0
- package/src/app/assets/flags/MM.svg +1 -0
- package/src/app/assets/flags/MN.svg +1 -0
- package/src/app/assets/flags/MO.svg +1 -0
- package/src/app/assets/flags/MP.svg +1 -0
- package/src/app/assets/flags/MQ.svg +1 -0
- package/src/app/assets/flags/MR.svg +1 -0
- package/src/app/assets/flags/MS.svg +1 -0
- package/src/app/assets/flags/MT.svg +1 -0
- package/src/app/assets/flags/MU.svg +1 -0
- package/src/app/assets/flags/MV.svg +1 -0
- package/src/app/assets/flags/MW.svg +1 -0
- package/src/app/assets/flags/MX.svg +1 -0
- package/src/app/assets/flags/MY.svg +1 -0
- package/src/app/assets/flags/MZ.svg +1 -0
- package/src/app/assets/flags/NA.svg +1 -0
- package/src/app/assets/flags/NC.svg +1 -0
- package/src/app/assets/flags/NE.svg +1 -0
- package/src/app/assets/flags/NF.svg +1 -0
- package/src/app/assets/flags/NG.svg +1 -0
- package/src/app/assets/flags/NI.svg +1 -0
- package/src/app/assets/flags/NL.svg +1 -0
- package/src/app/assets/flags/NO.svg +1 -0
- package/src/app/assets/flags/NP.svg +1 -0
- package/src/app/assets/flags/NR.svg +1 -0
- package/src/app/assets/flags/NU.svg +1 -0
- package/src/app/assets/flags/NZ.svg +1 -0
- package/src/app/assets/flags/OM.svg +1 -0
- package/src/app/assets/flags/PA.svg +1 -0
- package/src/app/assets/flags/PE.svg +1 -0
- package/src/app/assets/flags/PF.svg +1 -0
- package/src/app/assets/flags/PG.svg +1 -0
- package/src/app/assets/flags/PH.svg +1 -0
- package/src/app/assets/flags/PK.svg +1 -0
- package/src/app/assets/flags/PL.svg +1 -0
- package/src/app/assets/flags/PM.svg +1 -0
- package/src/app/assets/flags/PN.svg +1 -0
- package/src/app/assets/flags/PR.svg +1 -0
- package/src/app/assets/flags/PS.svg +1 -0
- package/src/app/assets/flags/PT.svg +1 -0
- package/src/app/assets/flags/PW.svg +1 -0
- package/src/app/assets/flags/PY.svg +1 -0
- package/src/app/assets/flags/QA.svg +1 -0
- package/src/app/assets/flags/RE.svg +1 -0
- package/src/app/assets/flags/README.md +6 -0
- package/src/app/assets/flags/RO.svg +1 -0
- package/src/app/assets/flags/RS.svg +1 -0
- package/src/app/assets/flags/RU.svg +1 -0
- package/src/app/assets/flags/RW.svg +1 -0
- package/src/app/assets/flags/SA.svg +1 -0
- package/src/app/assets/flags/SB.svg +1 -0
- package/src/app/assets/flags/SC.svg +1 -0
- package/src/app/assets/flags/SD.svg +1 -0
- package/src/app/assets/flags/SE.svg +1 -0
- package/src/app/assets/flags/SG.svg +1 -0
- package/src/app/assets/flags/SH.svg +1 -0
- package/src/app/assets/flags/SI.svg +1 -0
- package/src/app/assets/flags/SJ.svg +1 -0
- package/src/app/assets/flags/SK.svg +1 -0
- package/src/app/assets/flags/SL.svg +1 -0
- package/src/app/assets/flags/SM.svg +1 -0
- package/src/app/assets/flags/SN.svg +1 -0
- package/src/app/assets/flags/SO.svg +1 -0
- package/src/app/assets/flags/SR.svg +1 -0
- package/src/app/assets/flags/SS.svg +1 -0
- package/src/app/assets/flags/ST.svg +1 -0
- package/src/app/assets/flags/SV.svg +1 -0
- package/src/app/assets/flags/SX.svg +1 -0
- package/src/app/assets/flags/SY.svg +1 -0
- package/src/app/assets/flags/SZ.svg +1 -0
- package/src/app/assets/flags/TA.svg +1 -0
- package/src/app/assets/flags/TC.svg +1 -0
- package/src/app/assets/flags/TD.svg +1 -0
- package/src/app/assets/flags/TF.svg +1 -0
- package/src/app/assets/flags/TG.svg +1 -0
- package/src/app/assets/flags/TH.svg +1 -0
- package/src/app/assets/flags/TJ.svg +1 -0
- package/src/app/assets/flags/TK.svg +1 -0
- package/src/app/assets/flags/TL.svg +1 -0
- package/src/app/assets/flags/TM.svg +1 -0
- package/src/app/assets/flags/TN.svg +1 -0
- package/src/app/assets/flags/TO.svg +1 -0
- package/src/app/assets/flags/TR.svg +1 -0
- package/src/app/assets/flags/TT.svg +1 -0
- package/src/app/assets/flags/TV.svg +1 -0
- package/src/app/assets/flags/TW.svg +1 -0
- package/src/app/assets/flags/TZ.svg +1 -0
- package/src/app/assets/flags/UA.svg +1 -0
- package/src/app/assets/flags/UG.svg +1 -0
- package/src/app/assets/flags/UM.svg +1 -0
- package/src/app/assets/flags/US.svg +1 -0
- package/src/app/assets/flags/UY.svg +1 -0
- package/src/app/assets/flags/UZ.svg +1 -0
- package/src/app/assets/flags/VA.svg +1 -0
- package/src/app/assets/flags/VC.svg +1 -0
- package/src/app/assets/flags/VE.svg +1 -0
- package/src/app/assets/flags/VG.svg +1 -0
- package/src/app/assets/flags/VI.svg +1 -0
- package/src/app/assets/flags/VN.svg +1 -0
- package/src/app/assets/flags/VU.svg +1 -0
- package/src/app/assets/flags/WF.svg +1 -0
- package/src/app/assets/flags/WS.svg +1 -0
- package/src/app/assets/flags/XA.svg +1 -0
- package/src/app/assets/flags/XC.svg +1 -0
- package/src/app/assets/flags/XK.svg +1 -0
- package/src/app/assets/flags/XO.svg +1 -0
- package/src/app/assets/flags/YE.svg +1 -0
- package/src/app/assets/flags/YT.svg +1 -0
- package/src/app/assets/flags/ZA.svg +1 -0
- package/src/app/assets/flags/ZM.svg +1 -0
- package/src/app/assets/flags/ZW.svg +1 -0
- package/src/app/email-preview.ts +46 -0
- package/src/app/index.css +203 -0
- package/src/app/index.html +12 -0
- package/src/app/integrations/i18n/react-i18next.d.ts +11 -0
- package/src/app/integrations/i18n/root-provider.tsx +62 -0
- package/src/app/integrations/tanstack-query/devtools.tsx +6 -0
- package/src/app/integrations/tanstack-query/root-provider.tsx +37 -0
- package/src/app/integrations/theme/root-provider.tsx +75 -0
- package/src/app/integrations/toast/toast-provider.tsx +46 -0
- package/src/app/locales/en-US/common.ts +268 -0
- package/src/app/locales/zh-CN/common.ts +263 -0
- package/src/app/main.tsx +40 -0
- package/src/app/page-chrome.tsx +79 -0
- package/src/app/router.tsx +40 -0
- package/src/app/routes/__root.tsx +293 -0
- package/src/app/routes/emails.tsx +199 -0
- package/src/app/routes/home.tsx +87 -0
- package/src/app/routes/index.ts +19 -0
- package/src/app/routes/metrics.tsx +541 -0
- package/src/app/routes/segment-overview.tsx +211 -0
- package/src/app/routes/segments.tsx +236 -0
- package/src/app/routes/settings.tsx +90 -0
- package/src/app/routes/workflows.tsx +348 -0
- package/src/app/studio.ts +16 -0
- package/src/app/svg.d.ts +17 -0
- package/src/app/virtual-config.d.ts +6 -0
- package/src/cli.ts +110 -0
- package/src/components/avatar.tsx +57 -0
- package/src/components/breadcrumb.tsx +49 -0
- package/src/components/button/index.tsx +86 -0
- package/src/components/channel-icon.ts +39 -0
- package/src/components/chat-markup.tsx +109 -0
- package/src/components/corner-shape.ts +13 -0
- package/src/components/date-range.tsx +181 -0
- package/src/components/discord-preview.tsx +165 -0
- package/src/components/dropdown/index.tsx +172 -0
- package/src/components/email-defaults.tsx +40 -0
- package/src/components/email-list.tsx +149 -0
- package/src/components/email-thumbnail.tsx +123 -0
- package/src/components/flag.tsx +40 -0
- package/src/components/input/index.tsx +40 -0
- package/src/components/input/search-input.tsx +24 -0
- package/src/components/layout.ts +403 -0
- package/src/components/menu/index.tsx +118 -0
- package/src/components/metric-card.tsx +321 -0
- package/src/components/modal/index.tsx +70 -0
- package/src/components/nav-drawer.tsx +84 -0
- package/src/components/node-inspector.tsx +242 -0
- package/src/components/profile-drawer.tsx +331 -0
- package/src/components/push-preview.tsx +470 -0
- package/src/components/push-thumbnail.tsx +78 -0
- package/src/components/segment-list.tsx +184 -0
- package/src/components/select/index.tsx +70 -0
- package/src/components/series-chart.tsx +120 -0
- package/src/components/slack-preview.tsx +223 -0
- package/src/components/sparkline.tsx +58 -0
- package/src/components/tabs/index.tsx +45 -0
- package/src/components/template-refs.ts +110 -0
- package/src/components/templates-page.tsx +601 -0
- package/src/components/textarea/index.tsx +37 -0
- package/src/components/thumbnail-window.tsx +65 -0
- package/src/components/workflow-canvas.tsx +503 -0
- package/src/components/workflow-list.tsx +231 -0
- package/src/config.ts +288 -0
- package/src/generate.ts +56 -0
- package/src/index.ts +35 -0
- package/src/postgres.ts +415 -0
- package/src/server/project.ts +290 -0
- package/src/server.ts +500 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/label.ts +12 -0
- package/src/utils/lookup.ts +11 -0
- package/src/utils/template-content.ts +213 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { Link, Outlet, createRoute, useLocation, useNavigate } from '@tanstack/react-router';
|
|
3
|
+
import { clsx } from 'clsx';
|
|
4
|
+
import { type ReactNode, useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
import { Breadcrumb } from '../../components/breadcrumb';
|
|
7
|
+
import { EmailThumbnail } from '../../components/email-thumbnail';
|
|
8
|
+
import { SearchInput } from '../../components/input/search-input';
|
|
9
|
+
import { NodeInspector, type NodeSource } from '../../components/node-inspector';
|
|
10
|
+
import { PushThumbnail } from '../../components/push-thumbnail';
|
|
11
|
+
import { Tabs } from '../../components/tabs';
|
|
12
|
+
import { findNode } from '../../components/template-refs';
|
|
13
|
+
import { WorkflowCanvas } from '../../components/workflow-canvas';
|
|
14
|
+
import { WorkflowList } from '../../components/workflow-list';
|
|
15
|
+
import { displayName } from '../../utils/label';
|
|
16
|
+
import { lookup } from '../../utils/lookup';
|
|
17
|
+
import { formatIssues, resolvePush } from '../../utils/template-content';
|
|
18
|
+
import { useEmailPreview } from '../email-preview';
|
|
19
|
+
import { useTheme } from '../integrations/theme/root-provider';
|
|
20
|
+
import { PageChrome } from '../page-chrome';
|
|
21
|
+
import { studioGet } from '../studio';
|
|
22
|
+
import { Route as rootRoute } from './__root';
|
|
23
|
+
|
|
24
|
+
/* ---------------------------------- List ---------------------------------- */
|
|
25
|
+
|
|
26
|
+
function WorkflowsIndex() {
|
|
27
|
+
const { config } = workflowsIndexRoute.useRouteContext();
|
|
28
|
+
const navigate = useNavigate();
|
|
29
|
+
const { t } = useTranslation();
|
|
30
|
+
const [query, setQuery] = useState('');
|
|
31
|
+
|
|
32
|
+
const items = useMemo(
|
|
33
|
+
() => Object.entries(config.workflows).map(([key, ir]) => ({ key, ir })),
|
|
34
|
+
[config]
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
/* Substring match over everything a workflow is known by: key, name, description. */
|
|
38
|
+
const filtered = useMemo(() => {
|
|
39
|
+
const needle = query.trim().toLowerCase();
|
|
40
|
+
if (needle === '') return items;
|
|
41
|
+
return items.filter(({ key, ir }) =>
|
|
42
|
+
[key, ir.meta?.name ?? '', ir.meta?.description ?? ''].some((text) =>
|
|
43
|
+
text.toLowerCase().includes(needle)
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
}, [items, query]);
|
|
47
|
+
|
|
48
|
+
const { data: reports } = useQuery({
|
|
49
|
+
queryKey: ['reports'],
|
|
50
|
+
queryFn: async () => (await config.stats?.reports?.()) ?? [],
|
|
51
|
+
enabled: config.stats?.reports !== undefined,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
if (items.length === 0) {
|
|
55
|
+
return (
|
|
56
|
+
<div className="text-muted flex flex-1 items-center justify-center text-sm">
|
|
57
|
+
{t('workflows.empty')}
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
/* Nothing here scrolls: the shell's content column is the one scrollport. */
|
|
64
|
+
<div className="flex-1">
|
|
65
|
+
<PageChrome breadcrumb={<Breadcrumb items={[{ label: t('nav.workflows') }]} />} />
|
|
66
|
+
{/*
|
|
67
|
+
The search field belongs with what it filters, not up in the chrome.
|
|
68
|
+
It scrolls away with the list: only the app header pins, and a stack
|
|
69
|
+
of three fixed bars over a short list was more chrome than content.
|
|
70
|
+
*/}
|
|
71
|
+
<div className="px-6 pt-4 pb-3">
|
|
72
|
+
<SearchInput
|
|
73
|
+
className="w-72"
|
|
74
|
+
placeholder={t('workflows.searchPlaceholder')}
|
|
75
|
+
value={query}
|
|
76
|
+
onChange={(e) => setQuery(e.target.value)}
|
|
77
|
+
/>
|
|
78
|
+
</div>
|
|
79
|
+
<div className="px-6 pb-6">
|
|
80
|
+
{filtered.length === 0 ? (
|
|
81
|
+
<div className="text-muted flex items-center justify-center py-24 text-sm">
|
|
82
|
+
{t('workflows.noMatches', { query: query.trim() })}
|
|
83
|
+
</div>
|
|
84
|
+
) : (
|
|
85
|
+
<WorkflowList
|
|
86
|
+
items={filtered}
|
|
87
|
+
{...(reports !== undefined ? { reports } : {})}
|
|
88
|
+
onOpen={(key) => void navigate({ to: '/workflows/$id', params: { id: key } })}
|
|
89
|
+
/>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export const workflowsIndexRoute = createRoute({
|
|
97
|
+
getParentRoute: () => rootRoute,
|
|
98
|
+
path: '/workflows',
|
|
99
|
+
component: WorkflowsIndex,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
/* --------------------------- Detail (tabbed shell) -------------------------- */
|
|
103
|
+
|
|
104
|
+
const TABS = [
|
|
105
|
+
{ to: '/workflows/$id', label: 'workflows.tabs.overview', exact: true },
|
|
106
|
+
{ to: '/workflows/$name/workflow', label: 'workflows.tabs.canvas', exact: true },
|
|
107
|
+
] as const;
|
|
108
|
+
|
|
109
|
+
function WorkflowDetail() {
|
|
110
|
+
const { id } = workflowDetailRoute.useParams();
|
|
111
|
+
const { config } = workflowDetailRoute.useRouteContext();
|
|
112
|
+
const pathname = useLocation({ select: (location) => location.pathname });
|
|
113
|
+
/* Both tab paths are exact, so the active one is whichever equals the URL. */
|
|
114
|
+
const activeTab =
|
|
115
|
+
TABS.find((tab) => tab.to.replace('$id', id) === decodeURIComponent(pathname)) ?? TABS[0];
|
|
116
|
+
const { t } = useTranslation();
|
|
117
|
+
|
|
118
|
+
const ir = lookup(config.workflows, id);
|
|
119
|
+
|
|
120
|
+
/* Switcher options: every workflow in the project, labelled by its meta name. */
|
|
121
|
+
const options = useMemo(
|
|
122
|
+
() =>
|
|
123
|
+
Object.entries(config.workflows).map(([key, ir]) => ({
|
|
124
|
+
value: key,
|
|
125
|
+
label: displayName(ir.meta?.name, t('common.untitled')),
|
|
126
|
+
})),
|
|
127
|
+
[config, t]
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
if (ir === undefined) {
|
|
131
|
+
return (
|
|
132
|
+
<div className="text-muted flex flex-1 flex-col items-center justify-center gap-3 text-sm">
|
|
133
|
+
<p>{t('workflows.notFound', { id })}</p>
|
|
134
|
+
<Link to="/workflows" className="text-primary underline">
|
|
135
|
+
{t('common.back')}
|
|
136
|
+
</Link>
|
|
137
|
+
</div>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/*
|
|
142
|
+
* The header is the root's. This view contributes a breadcrumb whose leaf is
|
|
143
|
+
* the workflow switcher; the view tabs sit at the top-left of the content,
|
|
144
|
+
* where switching a view belongs.
|
|
145
|
+
*/
|
|
146
|
+
return (
|
|
147
|
+
<div className="flex flex-1 flex-col">
|
|
148
|
+
<PageChrome
|
|
149
|
+
breadcrumb={
|
|
150
|
+
<Breadcrumb
|
|
151
|
+
items={[
|
|
152
|
+
{ label: t('nav.workflows'), to: '/workflows' },
|
|
153
|
+
{
|
|
154
|
+
label: options.find((option) => option.value === id)?.label ?? id,
|
|
155
|
+
to: '/workflows/$id',
|
|
156
|
+
params: { id },
|
|
157
|
+
},
|
|
158
|
+
{ label: t(activeTab.label) },
|
|
159
|
+
]}
|
|
160
|
+
/>
|
|
161
|
+
}
|
|
162
|
+
/>
|
|
163
|
+
<div className="px-6 py-3">
|
|
164
|
+
<Tabs
|
|
165
|
+
className="w-fit"
|
|
166
|
+
items={TABS.map((tab) => ({ to: tab.to, label: t(tab.label), exact: tab.exact }))}
|
|
167
|
+
params={{ id }}
|
|
168
|
+
/>
|
|
169
|
+
</div>
|
|
170
|
+
|
|
171
|
+
{/*
|
|
172
|
+
`min-h-0` only for the canvas. Every other tab is a document that
|
|
173
|
+
grows and scrolls with the shell; the canvas must stay inside the
|
|
174
|
+
viewport because react-flow owns pan and zoom within a fixed frame and
|
|
175
|
+
the floating inspector's max-h hangs off that frame's height.
|
|
176
|
+
*/}
|
|
177
|
+
<div className={clsx('flex flex-1 flex-col', activeTab === TABS[1] && 'min-h-0')}>
|
|
178
|
+
<Outlet />
|
|
179
|
+
</div>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const workflowDetailRoute = createRoute({
|
|
185
|
+
getParentRoute: () => rootRoute,
|
|
186
|
+
path: '/workflows/$id',
|
|
187
|
+
component: WorkflowDetail,
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
/* --------------------------------- Canvas --------------------------------- */
|
|
191
|
+
|
|
192
|
+
const SELECTION_KEY = 'workflow-ui:canvas-selection';
|
|
193
|
+
|
|
194
|
+
function CanvasTab() {
|
|
195
|
+
const { id } = workflowDetailRoute.useParams();
|
|
196
|
+
const { config } = workflowDetailRoute.useRouteContext();
|
|
197
|
+
const navigate = useNavigate();
|
|
198
|
+
const { resolved } = useTheme();
|
|
199
|
+
/*
|
|
200
|
+
* Selection outlives a reload. Editing a workflow in the editor can
|
|
201
|
+
* full-reload the page; without this the panel you were reading vanishes and
|
|
202
|
+
* you lose your place.
|
|
203
|
+
*/
|
|
204
|
+
const [selectedId, setSelectedId] = useState<string | undefined>(() =>
|
|
205
|
+
typeof sessionStorage === 'undefined'
|
|
206
|
+
? undefined
|
|
207
|
+
: (sessionStorage.getItem(`${SELECTION_KEY}:${id}`) ?? undefined)
|
|
208
|
+
);
|
|
209
|
+
const select = useCallback(
|
|
210
|
+
(id: string | undefined) => {
|
|
211
|
+
setSelectedId(id);
|
|
212
|
+
const key = `${SELECTION_KEY}:${id}`;
|
|
213
|
+
if (id === undefined) sessionStorage.removeItem(key);
|
|
214
|
+
else sessionStorage.setItem(key, id);
|
|
215
|
+
},
|
|
216
|
+
[id]
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
const ir = lookup(config.workflows, id);
|
|
220
|
+
const selected =
|
|
221
|
+
ir !== undefined && selectedId !== undefined ? findNode(ir, selectedId) : undefined;
|
|
222
|
+
const loc = selected?.meta?.loc;
|
|
223
|
+
|
|
224
|
+
const { data: stats } = useQuery({
|
|
225
|
+
queryKey: ['node-stats', ir?.id],
|
|
226
|
+
queryFn: async () => (await config.stats?.nodeStats?.(ir?.id ?? '')) ?? {},
|
|
227
|
+
enabled: ir !== undefined && config.stats?.nodeStats !== undefined,
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
/*
|
|
231
|
+
* The DSL records where each node was built, but in the position of the
|
|
232
|
+
* module Vite served — the dev server owns the source map that turns that
|
|
233
|
+
* back into a line on disk, so resolving it is a round trip, not a lookup.
|
|
234
|
+
* Navigation only: a failed lookup leaves the source row out and nothing
|
|
235
|
+
* else waits on it.
|
|
236
|
+
*/
|
|
237
|
+
const { data: source } = useQuery({
|
|
238
|
+
queryKey: ['node-source', loc],
|
|
239
|
+
queryFn: () => studioGet<NodeSource>('/__studio/node', { ...loc }),
|
|
240
|
+
enabled: loc !== undefined,
|
|
241
|
+
retry: false,
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
/*
|
|
245
|
+
* A message node shows what it sends, rendered from the template's own
|
|
246
|
+
* validated `preview` — the same props, the same render and the same
|
|
247
|
+
* failure the templates page shows. Email is the one channel with a
|
|
248
|
+
* document; the query is keyed like the templates page's, so a template
|
|
249
|
+
* seen there (or here) is already rendered for the other.
|
|
250
|
+
*/
|
|
251
|
+
const message = selected?.type === 'message' ? selected : undefined;
|
|
252
|
+
const emailModule =
|
|
253
|
+
message?.channel === 'email' ? lookup(config.emails, message.template) : undefined;
|
|
254
|
+
const emailPreview = useEmailPreview(emailModule, message?.template ?? '');
|
|
255
|
+
/* A push has no document: its notification is drawn into the OS banner. */
|
|
256
|
+
const pushModule =
|
|
257
|
+
message?.channel === 'push' ? lookup(config.pushes, message.template) : undefined;
|
|
258
|
+
const push =
|
|
259
|
+
message !== undefined && pushModule !== undefined
|
|
260
|
+
? resolvePush(pushModule, message.template)
|
|
261
|
+
: undefined;
|
|
262
|
+
|
|
263
|
+
if (ir === undefined) return null;
|
|
264
|
+
|
|
265
|
+
const openTemplate = () => {
|
|
266
|
+
if (message !== undefined)
|
|
267
|
+
void navigate({
|
|
268
|
+
to: '/templates/$key',
|
|
269
|
+
params: { key: message.template },
|
|
270
|
+
search: { channel: message.channel },
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
let preview: ReactNode;
|
|
274
|
+
if (message?.channel === 'email') {
|
|
275
|
+
preview = (
|
|
276
|
+
<EmailThumbnail
|
|
277
|
+
html={emailPreview.data?.status === 'ok' ? emailPreview.data.html : undefined}
|
|
278
|
+
loading={emailModule !== undefined && emailPreview.isPending}
|
|
279
|
+
error={
|
|
280
|
+
emailPreview.data?.status === 'invalid'
|
|
281
|
+
? formatIssues(emailPreview.data.failure)
|
|
282
|
+
: emailPreview.error?.message
|
|
283
|
+
}
|
|
284
|
+
registered={emailModule !== undefined}
|
|
285
|
+
scheme={resolved}
|
|
286
|
+
onOpen={openTemplate}
|
|
287
|
+
/>
|
|
288
|
+
);
|
|
289
|
+
} else if (message?.channel === 'push') {
|
|
290
|
+
preview = (
|
|
291
|
+
<PushThumbnail
|
|
292
|
+
appName={config.title ?? 'App'}
|
|
293
|
+
title={push?.ok === true ? (push.push.title ?? message.template) : message.template}
|
|
294
|
+
body={push?.ok === true ? push.push.body : ''}
|
|
295
|
+
{...(push?.ok === false ? { error: formatIssues(push.failure) } : {})}
|
|
296
|
+
registered={pushModule !== undefined}
|
|
297
|
+
scheme={resolved}
|
|
298
|
+
onOpen={openTemplate}
|
|
299
|
+
/>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
/* The exception to the shell's one-scrollport rule: this pane is pinned to
|
|
305
|
+
the viewport rather than growing the page. */
|
|
306
|
+
<div className="border-border relative flex min-h-0 flex-1 flex-col border-t">
|
|
307
|
+
{/*
|
|
308
|
+
Absolute rather than a flex child: the shell's main column is sized by
|
|
309
|
+
min-height, so its height is `auto` and the canvas's own `height: 100%`
|
|
310
|
+
has nothing definite to resolve against — it collapses to zero. Filling
|
|
311
|
+
an already-positioned parent sidesteps percentage resolution entirely.
|
|
312
|
+
*/}
|
|
313
|
+
<div className="absolute inset-0">
|
|
314
|
+
<WorkflowCanvas
|
|
315
|
+
key={id}
|
|
316
|
+
ir={ir}
|
|
317
|
+
colorMode={resolved}
|
|
318
|
+
{...(stats !== undefined ? { stats } : {})}
|
|
319
|
+
selectedId={selectedId}
|
|
320
|
+
onSelectNode={select}
|
|
321
|
+
/>
|
|
322
|
+
</div>
|
|
323
|
+
{/*
|
|
324
|
+
Floating, not docked: a docked column resizes the canvas every time a
|
|
325
|
+
node is picked, which shifts the drawing under the cursor. Over the
|
|
326
|
+
canvas, the drawing stays put and the card is dismissable in place.
|
|
327
|
+
Capped to the pane's height so a long inspector scrolls inside itself.
|
|
328
|
+
z-10 clears react-flow's own panels (controls sit at z-5).
|
|
329
|
+
*/}
|
|
330
|
+
{selected !== undefined && (
|
|
331
|
+
<div className="absolute top-4 right-4 z-10 flex max-h-[calc(100%-2rem)]">
|
|
332
|
+
<NodeInspector
|
|
333
|
+
node={selected}
|
|
334
|
+
{...(source !== undefined ? { source } : {})}
|
|
335
|
+
{...(preview !== undefined ? { preview } : {})}
|
|
336
|
+
onClose={() => select(undefined)}
|
|
337
|
+
/>
|
|
338
|
+
</div>
|
|
339
|
+
)}
|
|
340
|
+
</div>
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export const workflowCanvasRoute = createRoute({
|
|
345
|
+
getParentRoute: () => workflowDetailRoute,
|
|
346
|
+
path: '/workflow',
|
|
347
|
+
component: CanvasTab,
|
|
348
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client for the studio's dev-server endpoints. Read-only: the studio views
|
|
3
|
+
* source, it never writes it — edits happen in the editor and reach the page
|
|
4
|
+
* through Vite.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Query params in, JSON out. Used to resolve a node's captured position to a line on disk. */
|
|
8
|
+
export async function studioGet<T>(path: string, params: Record<string, unknown>): Promise<T> {
|
|
9
|
+
const query = new URLSearchParams(
|
|
10
|
+
Object.entries(params).map(([key, value]) => [key, String(value)])
|
|
11
|
+
);
|
|
12
|
+
const response = await fetch(`${path}?${query.toString()}`);
|
|
13
|
+
const payload = (await response.json()) as T & { error?: string };
|
|
14
|
+
if (!response.ok) throw new Error(payload.error ?? `${response.status} ${response.statusText}`);
|
|
15
|
+
return payload;
|
|
16
|
+
}
|
package/src/app/svg.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** vite-plugin-svgr: `?react` imports resolve to a React component. */
|
|
2
|
+
declare module '*.svg?react' {
|
|
3
|
+
import type { FC, SVGProps } from 'react';
|
|
4
|
+
const Component: FC<SVGProps<SVGSVGElement>>;
|
|
5
|
+
export default Component;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Plain asset imports resolve to their served URL. */
|
|
9
|
+
declare module '*.png' {
|
|
10
|
+
const url: string;
|
|
11
|
+
export default url;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.webp' {
|
|
15
|
+
const url: string;
|
|
16
|
+
export default url;
|
|
17
|
+
}
|
package/src/cli.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { generateSchema } from './generate';
|
|
3
|
+
import { startStudio } from './server';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `workflow-ui` — start the studio over the project in ./workflow.config.ts.
|
|
7
|
+
*
|
|
8
|
+
* npx workflow-ui # reads ./workflow.config.ts (and ./workflow.stats.ts)
|
|
9
|
+
* npx workflow-ui --port 5000
|
|
10
|
+
* npx workflow-ui --config apps/marketing/workflow.config.ts
|
|
11
|
+
* npx workflow-ui generate --out ../../packages/db/src/schema/workflow.ts [--check]
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
interface Args {
|
|
15
|
+
port?: number;
|
|
16
|
+
config?: string;
|
|
17
|
+
stats?: string;
|
|
18
|
+
out?: string;
|
|
19
|
+
check: boolean;
|
|
20
|
+
open: boolean;
|
|
21
|
+
help: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function parseArgs(argv: string[]): Args {
|
|
25
|
+
const args: Args = { open: false, check: false, help: false };
|
|
26
|
+
for (let i = 0; i < argv.length; i++) {
|
|
27
|
+
const arg = argv[i];
|
|
28
|
+
if (arg === '--help' || arg === '-h') args.help = true;
|
|
29
|
+
else if (arg === '--open') args.open = true;
|
|
30
|
+
else if (arg === '--check') args.check = true;
|
|
31
|
+
else if (arg === '--out' || arg === '-o') args.out = argv[++i];
|
|
32
|
+
else if (arg === '--port' || arg === '-p') args.port = Number(argv[++i]);
|
|
33
|
+
else if (arg === '--config' || arg === '-c') args.config = argv[++i];
|
|
34
|
+
else if (arg === '--stats' || arg === '-s') args.stats = argv[++i];
|
|
35
|
+
}
|
|
36
|
+
return args;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const HELP = `
|
|
40
|
+
workflow-ui — review your workflows, templates and reports
|
|
41
|
+
|
|
42
|
+
Usage
|
|
43
|
+
$ workflow-ui [dev] [options]
|
|
44
|
+
$ workflow-ui generate --out <file> [--check] [--config <path>]
|
|
45
|
+
|
|
46
|
+
Options
|
|
47
|
+
-p, --port <port> Port to listen on (default 4321)
|
|
48
|
+
-c, --config <path> Project file (default ./workflow.config.ts)
|
|
49
|
+
-s, --stats <path> Stats source (default ./workflow.stats.ts, if present)
|
|
50
|
+
--open Open the browser on start
|
|
51
|
+
-o, --out <file> generate: where the drizzle schema file goes
|
|
52
|
+
--check generate: fail when the file is out of date, write nothing
|
|
53
|
+
-h, --help Show this message
|
|
54
|
+
`;
|
|
55
|
+
|
|
56
|
+
async function main(): Promise<void> {
|
|
57
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
58
|
+
if (command === 'generate') {
|
|
59
|
+
const args = parseArgs(rest);
|
|
60
|
+
if (args.help || args.out === undefined) {
|
|
61
|
+
console.log(HELP);
|
|
62
|
+
if (args.out === undefined && !args.help) process.exitCode = 1;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const result = await generateSchema({
|
|
67
|
+
out: args.out,
|
|
68
|
+
check: args.check,
|
|
69
|
+
...(args.config !== undefined ? { config: args.config } : {}),
|
|
70
|
+
});
|
|
71
|
+
if (result === 'outdated') {
|
|
72
|
+
console.error(
|
|
73
|
+
`\n ${args.out} is out of date — run workflow-ui generate, then your migration tool\n`
|
|
74
|
+
);
|
|
75
|
+
process.exitCode = 1;
|
|
76
|
+
} else {
|
|
77
|
+
console.log(`\n ${args.out} ${result === 'written' ? 'written' : 'is up to date'}\n`);
|
|
78
|
+
}
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error(`\n${error instanceof Error ? error.message : String(error)}\n`);
|
|
81
|
+
process.exitCode = 1;
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// `dev` is accepted so the command reads well; the studio is the default mode
|
|
87
|
+
const argv = process.argv.slice(2).filter((arg) => arg !== 'dev');
|
|
88
|
+
const args = parseArgs(argv);
|
|
89
|
+
|
|
90
|
+
if (args.help) {
|
|
91
|
+
console.log(HELP);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
const server = await startStudio({
|
|
97
|
+
...(args.port !== undefined ? { port: args.port } : {}),
|
|
98
|
+
...(args.config !== undefined ? { config: args.config } : {}),
|
|
99
|
+
...(args.stats !== undefined ? { stats: args.stats } : {}),
|
|
100
|
+
open: args.open,
|
|
101
|
+
});
|
|
102
|
+
const address = server.resolvedUrls?.local[0] ?? `http://localhost:${args.port ?? 4321}`;
|
|
103
|
+
console.log(`\n workflow-ui ready at ${address}\n`);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
console.error(`\n${error instanceof Error ? error.message : String(error)}\n`);
|
|
106
|
+
process.exitCode = 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void main();
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { cn } from '../utils/cn';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A person's round portrait, with an initial on a tinted circle behind it.
|
|
6
|
+
*
|
|
7
|
+
* The picture comes from a profile's `properties`, a dictionary the project
|
|
8
|
+
* fills — so it is typed `unknown` here and narrowed rather than asserted: an
|
|
9
|
+
* absent key, a null, or a number all mean the same thing to this component,
|
|
10
|
+
* which is "draw the initial". A URL that resolves to nothing means it too,
|
|
11
|
+
* once the browser says so, so a dead image degrades to the same fallback
|
|
12
|
+
* instead of leaving a broken-image glyph in the row.
|
|
13
|
+
*/
|
|
14
|
+
export interface AvatarProps {
|
|
15
|
+
/** Straight out of `Profile.properties`; anything but a non-empty string falls back. */
|
|
16
|
+
picture: unknown;
|
|
17
|
+
/** Whatever names the person — a name, an email, an id. Its first letter is the fallback. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** `md` heads the profile drawer; `sm` sits inside a table row. */
|
|
20
|
+
size?: 'sm' | 'md';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* Font scales with the circle: an `sm` initial at `text-sm` crowds the edges. */
|
|
24
|
+
const SIZES = {
|
|
25
|
+
sm: 'size-6 text-xs',
|
|
26
|
+
md: 'size-9 text-sm',
|
|
27
|
+
} as const;
|
|
28
|
+
|
|
29
|
+
export function Avatar({ picture, label, size = 'md' }: AvatarProps) {
|
|
30
|
+
const [failed, setFailed] = useState(false);
|
|
31
|
+
const src = typeof picture === 'string' && picture !== '' ? picture : undefined;
|
|
32
|
+
|
|
33
|
+
if (src !== undefined && !failed) {
|
|
34
|
+
return (
|
|
35
|
+
<img
|
|
36
|
+
src={src}
|
|
37
|
+
/* Decorative: the name or address it sits beside already says who this
|
|
38
|
+
is, and a screen reader repeating it is noise. */
|
|
39
|
+
alt=""
|
|
40
|
+
onError={() => setFailed(true)}
|
|
41
|
+
className={cn('shrink-0 rounded-full object-cover', SIZES[size])}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div
|
|
48
|
+
aria-hidden
|
|
49
|
+
className={cn(
|
|
50
|
+
'bg-selected text-secondary flex shrink-0 items-center justify-center rounded-full font-medium',
|
|
51
|
+
SIZES[size]
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
{label.trim().charAt(0).toUpperCase()}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Link, type LinkProps } from '@tanstack/react-router';
|
|
2
|
+
import { ChevronRight } from 'lucide-react';
|
|
3
|
+
import { Fragment, type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where you are, as a path: parents are links back up, the leaf is the current
|
|
7
|
+
* view. The leaf may be any node — a detail page puts its switcher dropdown
|
|
8
|
+
* there, so "which workflow" is both stated and changeable in one place.
|
|
9
|
+
*/
|
|
10
|
+
export interface Crumb {
|
|
11
|
+
label: ReactNode;
|
|
12
|
+
/** Route to link to; omit on the leaf (and on anything not navigable). */
|
|
13
|
+
to?: string;
|
|
14
|
+
params?: Record<string, string>;
|
|
15
|
+
search?: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function Breadcrumb({ items }: { items: readonly Crumb[] }) {
|
|
19
|
+
return (
|
|
20
|
+
<nav aria-label="Breadcrumb" className="flex min-w-0 items-center gap-1 text-sm">
|
|
21
|
+
{items.map((item, index) => {
|
|
22
|
+
const last = index === items.length - 1;
|
|
23
|
+
return (
|
|
24
|
+
<Fragment key={index}>
|
|
25
|
+
{index > 0 && (
|
|
26
|
+
<ChevronRight className="text-muted size-3.5 shrink-0" strokeWidth={2} aria-hidden />
|
|
27
|
+
)}
|
|
28
|
+
{item.to !== undefined && !last ? (
|
|
29
|
+
<Link
|
|
30
|
+
to={item.to as LinkProps['to']}
|
|
31
|
+
params={item.params as LinkProps['params']}
|
|
32
|
+
search={item.search as LinkProps['search']}
|
|
33
|
+
className="text-muted hover:text-primary shrink-0 truncate transition-colors"
|
|
34
|
+
>
|
|
35
|
+
{item.label}
|
|
36
|
+
</Link>
|
|
37
|
+
) : (
|
|
38
|
+
<span
|
|
39
|
+
className={last ? 'text-primary min-w-0 truncate' : 'text-muted shrink-0 truncate'}
|
|
40
|
+
>
|
|
41
|
+
{item.label}
|
|
42
|
+
</span>
|
|
43
|
+
)}
|
|
44
|
+
</Fragment>
|
|
45
|
+
);
|
|
46
|
+
})}
|
|
47
|
+
</nav>
|
|
48
|
+
);
|
|
49
|
+
}
|