@shware/workflow-ui 0.0.0-stage → 0.1.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,184 @@
|
|
|
1
|
+
import type { ConditionIR } from '@shware/workflow';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { Users } from 'lucide-react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import type { SegmentReport } from '../config';
|
|
6
|
+
import { displayName } from '../utils/label';
|
|
7
|
+
import { superellipse } from './corner-shape';
|
|
8
|
+
import { Sparkline } from './sparkline';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Segments as a table, the same shape the workflows list uses: identity on the
|
|
12
|
+
* left, runtime numbers on the right.
|
|
13
|
+
*
|
|
14
|
+
* Size is the column that matters. A segment's definition is code and can be
|
|
15
|
+
* read in the editor; what the editor cannot tell you is whether the condition
|
|
16
|
+
* you wrote actually matches the population you meant, and that only shows up
|
|
17
|
+
* as a number and its trend.
|
|
18
|
+
*/
|
|
19
|
+
export interface SegmentListItem {
|
|
20
|
+
/** Wire key: how IR and the engine refer to it (`segment({ id })`). Identity, not a label. */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Human label from `segment({ id, name })`; the list shows it, else the key. */
|
|
23
|
+
label?: string;
|
|
24
|
+
/** `segment({ description })`: the second line, when there is one. */
|
|
25
|
+
description?: string;
|
|
26
|
+
/** Workflows that reference it, by id. */
|
|
27
|
+
usedBy: string[];
|
|
28
|
+
/** The condition, when the segment is declared rather than merely referenced. */
|
|
29
|
+
definition?: ConditionIR;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface SegmentListProps {
|
|
33
|
+
items: SegmentListItem[];
|
|
34
|
+
reports?: SegmentReport[];
|
|
35
|
+
/** Open a segment's detail; the row is only clickable when this is provided. */
|
|
36
|
+
onOpen?: (id: string) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const compact = (value: number) =>
|
|
40
|
+
value >= 1000
|
|
41
|
+
? `${(value / 1000).toFixed(2).replace(/0+$/, '').replace(/\.$/, '')}k`
|
|
42
|
+
: `${value}`;
|
|
43
|
+
|
|
44
|
+
/** Percentage change across the series, so the number has a direction. */
|
|
45
|
+
function trend(series: readonly number[] | undefined): { text: string; up: boolean } | undefined {
|
|
46
|
+
const first = series?.at(0);
|
|
47
|
+
const last = series?.at(-1);
|
|
48
|
+
if (first === undefined || last === undefined || first === 0) return undefined;
|
|
49
|
+
const change = ((last - first) / first) * 100;
|
|
50
|
+
return { text: `${change >= 0 ? '+' : ''}${change.toFixed(1)}%`, up: change >= 0 };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* Not pinned: the app header is the only sticky chrome, so the head scrolls
|
|
55
|
+
* away with the rows and needs no opaque fill of its own. The radii stay —
|
|
56
|
+
* the card has no `overflow` to clip with, so its top corners are cut here.
|
|
57
|
+
*/
|
|
58
|
+
const HEAD_CELL = 'border-border border-b py-3 first:rounded-tl-2xl last:rounded-tr-2xl';
|
|
59
|
+
/* The row carries the border below md, so the cells drop theirs there. */
|
|
60
|
+
const CELL = 'border-border border-b py-4 max-md:border-b-0 max-md:px-3';
|
|
61
|
+
|
|
62
|
+
export function SegmentList({ items, reports, onOpen }: SegmentListProps) {
|
|
63
|
+
const { t } = useTranslation();
|
|
64
|
+
const byId = new Map((reports ?? []).map((report) => [report.id, report]));
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
/*
|
|
68
|
+
* No `overflow` on the card, deliberately: any value at all turns it into
|
|
69
|
+
* a scrollport of its own and draws a second bar inset inside the border —
|
|
70
|
+
* the page is the one scroller (see __root). Nothing clips, so the corners
|
|
71
|
+
* are re-cut on the first and last cells below.
|
|
72
|
+
*/
|
|
73
|
+
<div className="border-border bg-card rounded-2xl border" style={superellipse}>
|
|
74
|
+
<table className="w-full table-fixed border-separate border-spacing-0 text-sm max-md:block">
|
|
75
|
+
<thead className="max-md:hidden">
|
|
76
|
+
<tr className="text-muted text-left text-xs font-medium">
|
|
77
|
+
<th className={clsx(HEAD_CELL, 'min-w-0 px-6')} style={superellipse}>
|
|
78
|
+
{t('common.name')}
|
|
79
|
+
</th>
|
|
80
|
+
<th className={clsx(HEAD_CELL, 'w-28 px-3')} style={superellipse}>
|
|
81
|
+
{t('segments.size')}
|
|
82
|
+
</th>
|
|
83
|
+
<th className={clsx(HEAD_CELL, 'w-32 px-3')} style={superellipse}>
|
|
84
|
+
{t('segments.overTime')}
|
|
85
|
+
</th>
|
|
86
|
+
</tr>
|
|
87
|
+
</thead>
|
|
88
|
+
<tbody className="max-md:block">
|
|
89
|
+
{items.map((item) => {
|
|
90
|
+
const report = byId.get(item.id);
|
|
91
|
+
/* A blank label counts as none, like everywhere else names are shown. */
|
|
92
|
+
const label = displayName(item.label, '');
|
|
93
|
+
const movement = trend(report?.series);
|
|
94
|
+
|
|
95
|
+
return (
|
|
96
|
+
<tr
|
|
97
|
+
key={item.id}
|
|
98
|
+
{...(onOpen ? { onClick: () => onOpen(item.id) } : {})}
|
|
99
|
+
/*
|
|
100
|
+
* On desktop the hover fill lives on the cells, not the row: a
|
|
101
|
+
* row box paints its background underneath them, where no cell
|
|
102
|
+
* radius reaches it, so the last row would poke square grey
|
|
103
|
+
* corners out of the unclipped card. Below md the row is an
|
|
104
|
+
* ordinary grid box and takes both itself.
|
|
105
|
+
*/
|
|
106
|
+
className={clsx(
|
|
107
|
+
'align-top [&>td]:transition-colors',
|
|
108
|
+
/* Below md the row leaves table layout and becomes the card's
|
|
109
|
+
own grid, so the fill and the radius live on it there. */
|
|
110
|
+
'max-md:grid max-md:grid-cols-2 max-md:border-b max-md:px-3',
|
|
111
|
+
'border-border max-md:first:rounded-t-2xl max-md:last:rounded-b-2xl',
|
|
112
|
+
'max-md:last:border-b-0',
|
|
113
|
+
'last:[&>td]:border-b-0 md:last:[&>td:first-child]:rounded-bl-2xl',
|
|
114
|
+
'md:last:[&>td:last-child]:rounded-br-2xl',
|
|
115
|
+
onOpen && 'max-md:hover:bg-hover md:hover:[&>td]:bg-hover cursor-pointer'
|
|
116
|
+
)}
|
|
117
|
+
style={superellipse}
|
|
118
|
+
>
|
|
119
|
+
<td
|
|
120
|
+
className={clsx(CELL, 'px-6 max-md:order-1 max-md:col-span-2 max-md:pb-2')}
|
|
121
|
+
style={superellipse}
|
|
122
|
+
>
|
|
123
|
+
<div className="flex items-start gap-3">
|
|
124
|
+
<Users className="text-muted mt-0.5 size-4 shrink-0" strokeWidth={2} />
|
|
125
|
+
<div className="min-w-0">
|
|
126
|
+
<div className="flex items-center gap-2 font-medium">
|
|
127
|
+
{label !== '' ? (
|
|
128
|
+
label
|
|
129
|
+
) : (
|
|
130
|
+
/* No label: the id, made readable — `used_api` reads "Used api". ::first-letter needs a block box, not the flex row. */
|
|
131
|
+
<span className="inline-block first-letter:uppercase">
|
|
132
|
+
{item.id.replaceAll('_', ' ')}
|
|
133
|
+
</span>
|
|
134
|
+
)}
|
|
135
|
+
{item.definition === undefined && (
|
|
136
|
+
<span className="rounded-full bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-700 dark:bg-amber-400/10 dark:text-amber-300">
|
|
137
|
+
{t('segments.notDefined')}
|
|
138
|
+
</span>
|
|
139
|
+
)}
|
|
140
|
+
</div>
|
|
141
|
+
{item.description !== undefined && (
|
|
142
|
+
<p className="text-secondary mt-1 truncate text-sm">{item.description}</p>
|
|
143
|
+
)}
|
|
144
|
+
<div className="text-muted mt-2 truncate text-xs">
|
|
145
|
+
{item.usedBy.length === 0
|
|
146
|
+
? t('segments.unused')
|
|
147
|
+
: `${t('segments.usedBy')}: ${item.usedBy.join(', ')}`}
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
</div>
|
|
151
|
+
</td>
|
|
152
|
+
|
|
153
|
+
<td
|
|
154
|
+
className={clsx(CELL, 'px-3 max-md:order-2 max-md:pt-0 max-md:pb-4')}
|
|
155
|
+
style={superellipse}
|
|
156
|
+
>
|
|
157
|
+
<div className="text-muted mb-1 truncate text-xs md:hidden">
|
|
158
|
+
{t('segments.size')}
|
|
159
|
+
</div>
|
|
160
|
+
<div className="tabular-nums">
|
|
161
|
+
{report === undefined ? '—' : compact(report.size)}
|
|
162
|
+
</div>
|
|
163
|
+
{movement !== undefined && (
|
|
164
|
+
<div className="text-muted mt-1 text-xs tabular-nums">{movement.text}</div>
|
|
165
|
+
)}
|
|
166
|
+
</td>
|
|
167
|
+
|
|
168
|
+
<td
|
|
169
|
+
className={clsx(CELL, 'px-3 max-md:order-3 max-md:pt-0 max-md:pb-4')}
|
|
170
|
+
style={superellipse}
|
|
171
|
+
>
|
|
172
|
+
<div className="text-muted mb-1 truncate text-xs md:hidden">
|
|
173
|
+
{t('segments.overTime')}
|
|
174
|
+
</div>
|
|
175
|
+
<Sparkline values={report?.series ?? []} />
|
|
176
|
+
</td>
|
|
177
|
+
</tr>
|
|
178
|
+
);
|
|
179
|
+
})}
|
|
180
|
+
</tbody>
|
|
181
|
+
</table>
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { ChevronDown } from 'lucide-react';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
import { cn } from '../../utils/cn';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Native select on the same size ramp and field colours as `Input`, adapted
|
|
7
|
+
* from the template project's design system (its floating-label variant is
|
|
8
|
+
* marketing-page specific; the studio wants a plain field).
|
|
9
|
+
*/
|
|
10
|
+
export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
11
|
+
|
|
12
|
+
interface Props extends Omit<ComponentProps<'select'>, 'size' | 'onChange'> {
|
|
13
|
+
size?: Size;
|
|
14
|
+
className?: string;
|
|
15
|
+
placeholder?: string;
|
|
16
|
+
onChange?: (value: string) => void;
|
|
17
|
+
options?: { value: string; label: string }[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const SIZE_STYLE: Record<Size, string> = {
|
|
21
|
+
xs: 'h-7 pl-2 pr-7 text-xs rounded-md focus-visible:ring-2',
|
|
22
|
+
sm: 'h-9 pl-2 pr-8 text-sm rounded-lg focus-visible:ring-3',
|
|
23
|
+
md: 'h-10 pl-3 pr-8 text-sm rounded-xl focus-visible:ring-3',
|
|
24
|
+
lg: 'h-12 pl-4 pr-9 text-md rounded-xl focus-visible:ring-4',
|
|
25
|
+
xl: 'h-14 pl-4 pr-9 text-lg rounded-2xl focus-visible:ring-4',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function Select({
|
|
29
|
+
size = 'md',
|
|
30
|
+
value,
|
|
31
|
+
options,
|
|
32
|
+
className,
|
|
33
|
+
placeholder,
|
|
34
|
+
onChange,
|
|
35
|
+
...props
|
|
36
|
+
}: Props) {
|
|
37
|
+
return (
|
|
38
|
+
<div className={cn('relative', className)}>
|
|
39
|
+
<select
|
|
40
|
+
{...props}
|
|
41
|
+
value={value}
|
|
42
|
+
className={cn(
|
|
43
|
+
'w-full cursor-pointer appearance-none truncate transition-colors duration-100',
|
|
44
|
+
'bg-textfield focus-visible:border-accent border focus:outline-none',
|
|
45
|
+
'dark:focus-visible:ring-accent/50 focus-visible:ring-accent/40',
|
|
46
|
+
value === '' || value === undefined ? 'text-placeholder' : 'text-primary',
|
|
47
|
+
SIZE_STYLE[size]
|
|
48
|
+
)}
|
|
49
|
+
onChange={(e) => onChange?.(e.target.value)}
|
|
50
|
+
>
|
|
51
|
+
{placeholder !== undefined && (
|
|
52
|
+
<option value="" hidden>
|
|
53
|
+
{placeholder}
|
|
54
|
+
</option>
|
|
55
|
+
)}
|
|
56
|
+
{options?.map((option) => (
|
|
57
|
+
<option key={option.value} value={option.value}>
|
|
58
|
+
{option.label}
|
|
59
|
+
</option>
|
|
60
|
+
))}
|
|
61
|
+
</select>
|
|
62
|
+
<ChevronDown
|
|
63
|
+
size={16}
|
|
64
|
+
strokeWidth={2}
|
|
65
|
+
aria-hidden
|
|
66
|
+
className="text-secondary pointer-events-none absolute top-1/2 right-2.5 -translate-y-1/2"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useId } from 'react';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* One series over time, filled — the shape a segment's membership takes.
|
|
5
|
+
*
|
|
6
|
+
* Hand-drawn SVG for the same reason the metrics chart is: see the note there.
|
|
7
|
+
* A filled area rather than a bare line because a segment size is a population,
|
|
8
|
+
* and an area reads as "how many are in here" where a line reads as a rate.
|
|
9
|
+
*/
|
|
10
|
+
export interface SeriesChartProps {
|
|
11
|
+
values: readonly number[];
|
|
12
|
+
/** Optional x labels, same length as `values`; at most six are drawn. */
|
|
13
|
+
labels?: readonly string[];
|
|
14
|
+
height?: number;
|
|
15
|
+
ariaLabel?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const PADDING = { top: 12, right: 16, bottom: 28, left: 56 };
|
|
19
|
+
/** viewBox units; the SVG scales to whatever width its container gives it. */
|
|
20
|
+
const VIEW_WIDTH = 900;
|
|
21
|
+
|
|
22
|
+
/** A "nice" upper bound, so the axis reads 0/50/100 rather than 0/47/94. */
|
|
23
|
+
function niceMax(value: number): number {
|
|
24
|
+
if (value <= 0) return 1;
|
|
25
|
+
const magnitude = 10 ** Math.floor(Math.log10(value));
|
|
26
|
+
return Math.ceil(value / magnitude) * magnitude;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function SeriesChart({ values, labels, height = 260, ariaLabel }: SeriesChartProps) {
|
|
30
|
+
const gradientId = useId();
|
|
31
|
+
const plotWidth = VIEW_WIDTH - PADDING.left - PADDING.right;
|
|
32
|
+
const plotHeight = height - PADDING.top - PADDING.bottom;
|
|
33
|
+
|
|
34
|
+
const max = niceMax(Math.max(...values, 0));
|
|
35
|
+
const stepX = values.length > 1 ? plotWidth / (values.length - 1) : 0;
|
|
36
|
+
|
|
37
|
+
const x = (index: number) => PADDING.left + index * stepX;
|
|
38
|
+
const y = (value: number) => PADDING.top + plotHeight - (value / max) * plotHeight;
|
|
39
|
+
|
|
40
|
+
const line = values.map((value, index) => `${x(index).toFixed(1)},${y(value).toFixed(1)}`);
|
|
41
|
+
/** The fill closes the line down to the baseline and back. */
|
|
42
|
+
const area = [
|
|
43
|
+
`${PADDING.left},${PADDING.top + plotHeight}`,
|
|
44
|
+
...line,
|
|
45
|
+
`${x(values.length - 1).toFixed(1)},${PADDING.top + plotHeight}`,
|
|
46
|
+
].join(' ');
|
|
47
|
+
|
|
48
|
+
const ticks = [0, 0.25, 0.5, 0.75, 1].map((fraction) => Math.round(max * fraction));
|
|
49
|
+
/** At most six x labels, so they never collide. */
|
|
50
|
+
const labelEvery = Math.max(1, Math.ceil(values.length / 6));
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<svg
|
|
54
|
+
viewBox={`0 0 ${VIEW_WIDTH} ${height}`}
|
|
55
|
+
className="w-full"
|
|
56
|
+
style={{ height }}
|
|
57
|
+
role="img"
|
|
58
|
+
aria-label={ariaLabel}
|
|
59
|
+
>
|
|
60
|
+
<defs>
|
|
61
|
+
<linearGradient id={gradientId} x1="0" y1="0" x2="0" y2="1">
|
|
62
|
+
<stop offset="0%" stopColor="var(--color-chart-4)" stopOpacity={0.18} />
|
|
63
|
+
<stop offset="100%" stopColor="var(--color-chart-4)" stopOpacity={0} />
|
|
64
|
+
</linearGradient>
|
|
65
|
+
</defs>
|
|
66
|
+
|
|
67
|
+
{ticks.map((tick) => (
|
|
68
|
+
<g key={tick}>
|
|
69
|
+
<line
|
|
70
|
+
x1={PADDING.left}
|
|
71
|
+
x2={VIEW_WIDTH - PADDING.right}
|
|
72
|
+
y1={y(tick)}
|
|
73
|
+
y2={y(tick)}
|
|
74
|
+
stroke="var(--color-border)"
|
|
75
|
+
strokeWidth={1}
|
|
76
|
+
/>
|
|
77
|
+
<text
|
|
78
|
+
x={PADDING.left - 8}
|
|
79
|
+
y={y(tick)}
|
|
80
|
+
textAnchor="end"
|
|
81
|
+
dominantBaseline="middle"
|
|
82
|
+
fontSize={12}
|
|
83
|
+
fill="var(--color-muted)"
|
|
84
|
+
>
|
|
85
|
+
{tick.toLocaleString()}
|
|
86
|
+
</text>
|
|
87
|
+
</g>
|
|
88
|
+
))}
|
|
89
|
+
|
|
90
|
+
{labels?.map((label, index) =>
|
|
91
|
+
index % labelEvery === 0 ? (
|
|
92
|
+
<text
|
|
93
|
+
key={label}
|
|
94
|
+
x={x(index)}
|
|
95
|
+
y={height - 8}
|
|
96
|
+
textAnchor="middle"
|
|
97
|
+
fontSize={12}
|
|
98
|
+
fill="var(--color-muted)"
|
|
99
|
+
>
|
|
100
|
+
{label.slice(5)}
|
|
101
|
+
</text>
|
|
102
|
+
) : null
|
|
103
|
+
)}
|
|
104
|
+
|
|
105
|
+
{values.length > 1 && (
|
|
106
|
+
<>
|
|
107
|
+
<polygon points={area} fill={`url(#${gradientId})`} />
|
|
108
|
+
<polyline
|
|
109
|
+
points={line.join(' ')}
|
|
110
|
+
fill="none"
|
|
111
|
+
stroke="var(--color-chart-4)"
|
|
112
|
+
strokeWidth={2}
|
|
113
|
+
strokeLinejoin="round"
|
|
114
|
+
strokeLinecap="round"
|
|
115
|
+
/>
|
|
116
|
+
</>
|
|
117
|
+
)}
|
|
118
|
+
</svg>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import type { SlackContent } from '@shware/workflow';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { ChatMarkup } from './chat-markup';
|
|
4
|
+
import { superellipse } from './corner-shape';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An incoming-webhook message as Slack draws it in a channel: the app's name and icon with the
|
|
8
|
+
* APP tag, then its Block Kit blocks (header, section with fields and accessory, divider,
|
|
9
|
+
* context, actions, image) — or the plain `text` when there are none, which is also what
|
|
10
|
+
* notifications show. Slack's palette for each theme; close enough to judge the message.
|
|
11
|
+
*/
|
|
12
|
+
export interface SlackPreviewProps {
|
|
13
|
+
message: SlackContent;
|
|
14
|
+
/** The name the app posts under when the message names none: the project title upstream. */
|
|
15
|
+
appName: string;
|
|
16
|
+
scheme: 'light' | 'dark';
|
|
17
|
+
zoom: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const PALETTE = {
|
|
21
|
+
dark: { bg: '#1a1d21', text: '#d1d2d3', muted: '#ababad', name: '#ffffff', border: '#35373b' },
|
|
22
|
+
light: { bg: '#ffffff', text: '#1d1c1d', muted: '#616061', name: '#1d1c1d', border: '#dddddd' },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** A Block Kit text object: plain text, or mrkdwn formatted. */
|
|
26
|
+
interface TextObject {
|
|
27
|
+
type: 'plain_text' | 'mrkdwn';
|
|
28
|
+
text: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Element = Record<string, unknown> & { type: string };
|
|
32
|
+
|
|
33
|
+
const textOf = (value: unknown): TextObject | undefined => {
|
|
34
|
+
if (typeof value !== 'object' || value === null) return undefined;
|
|
35
|
+
const object = value as Partial<TextObject>;
|
|
36
|
+
return typeof object.text === 'string' ? (object as TextObject) : undefined;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export function SlackPreview({ message, appName, scheme, zoom }: SlackPreviewProps) {
|
|
40
|
+
const { t } = useTranslation();
|
|
41
|
+
const colors = PALETTE[scheme];
|
|
42
|
+
const name = message.username ?? appName;
|
|
43
|
+
const linkClass = 'text-[#1d9bd1] hover:underline';
|
|
44
|
+
const Text = ({ value, className }: { value: TextObject | undefined; className?: string }) =>
|
|
45
|
+
value === undefined ? null : (
|
|
46
|
+
<div className={`break-words whitespace-pre-wrap ${className ?? ''}`}>
|
|
47
|
+
{value.type === 'mrkdwn' ? (
|
|
48
|
+
<ChatMarkup text={value.text} dialect="slack" linkClass={linkClass} />
|
|
49
|
+
) : (
|
|
50
|
+
value.text
|
|
51
|
+
)}
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
const Button = ({ element }: { element: Element }) => {
|
|
55
|
+
const style = element.style as string | undefined;
|
|
56
|
+
return (
|
|
57
|
+
<span
|
|
58
|
+
className="inline-flex h-8 items-center rounded-lg border px-3 text-[13px] font-bold"
|
|
59
|
+
style={
|
|
60
|
+
style === 'primary'
|
|
61
|
+
? { background: '#007a5a', borderColor: '#007a5a', color: '#fff' }
|
|
62
|
+
: style === 'danger'
|
|
63
|
+
? { background: '#e01e5a', borderColor: '#e01e5a', color: '#fff' }
|
|
64
|
+
: { borderColor: colors.border, color: colors.name }
|
|
65
|
+
}
|
|
66
|
+
>
|
|
67
|
+
{textOf(element.text)?.text}
|
|
68
|
+
</span>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
const blocks = (message.blocks ?? []) as Element[];
|
|
73
|
+
return (
|
|
74
|
+
<div
|
|
75
|
+
className="mx-auto w-full max-w-2xl overflow-hidden rounded-2xl border shadow-sm"
|
|
76
|
+
style={{
|
|
77
|
+
...superellipse,
|
|
78
|
+
background: colors.bg,
|
|
79
|
+
borderColor: colors.border,
|
|
80
|
+
transform: `scale(${zoom})`,
|
|
81
|
+
transformOrigin: 'top center',
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<div
|
|
85
|
+
className="flex gap-2 px-5 py-4 text-[15px] leading-[1.46668]"
|
|
86
|
+
style={{ color: colors.text }}
|
|
87
|
+
>
|
|
88
|
+
{message.icon_url ? (
|
|
89
|
+
<img src={message.icon_url} alt="" className="size-9 shrink-0 rounded-lg object-cover" />
|
|
90
|
+
) : (
|
|
91
|
+
<div className="flex size-9 shrink-0 items-center justify-center rounded-lg bg-[#4a154b] text-sm font-bold text-white">
|
|
92
|
+
{message.icon_emoji === undefined ? name.slice(0, 1).toUpperCase() : '🙂'}
|
|
93
|
+
</div>
|
|
94
|
+
)}
|
|
95
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
96
|
+
<div className="flex items-baseline gap-1.5">
|
|
97
|
+
<span className="font-black" style={{ color: colors.name }}>
|
|
98
|
+
{name}
|
|
99
|
+
</span>
|
|
100
|
+
<span
|
|
101
|
+
className="rounded-[3px] px-1 text-[10px] font-bold"
|
|
102
|
+
style={{ background: scheme === 'dark' ? '#35373b' : '#e8e8e8', color: colors.muted }}
|
|
103
|
+
>
|
|
104
|
+
APP
|
|
105
|
+
</span>
|
|
106
|
+
<span className="text-xs" style={{ color: colors.muted }}>
|
|
107
|
+
{t('emails.chatNow')}
|
|
108
|
+
</span>
|
|
109
|
+
</div>
|
|
110
|
+
{blocks.length === 0 ? (
|
|
111
|
+
<Text
|
|
112
|
+
value={{
|
|
113
|
+
type: message.mrkdwn === false ? 'plain_text' : 'mrkdwn',
|
|
114
|
+
text: message.text,
|
|
115
|
+
}}
|
|
116
|
+
/>
|
|
117
|
+
) : (
|
|
118
|
+
blocks.map((block, index) => {
|
|
119
|
+
// oxlint-disable-next-line react/no-array-index-key -- blocks are positional
|
|
120
|
+
const key = index;
|
|
121
|
+
switch (block.type) {
|
|
122
|
+
case 'header':
|
|
123
|
+
return (
|
|
124
|
+
<div
|
|
125
|
+
key={key}
|
|
126
|
+
className="mt-1 text-lg font-black"
|
|
127
|
+
style={{ color: colors.name }}
|
|
128
|
+
>
|
|
129
|
+
{textOf(block.text)?.text}
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
case 'divider':
|
|
133
|
+
return <hr key={key} className="my-2" style={{ borderColor: colors.border }} />;
|
|
134
|
+
case 'section': {
|
|
135
|
+
const fields = (block.fields as unknown[] | undefined) ?? [];
|
|
136
|
+
const accessory = block.accessory as Element | undefined;
|
|
137
|
+
return (
|
|
138
|
+
<div key={key} className="flex gap-3">
|
|
139
|
+
<div className="min-w-0 flex-1">
|
|
140
|
+
<Text value={textOf(block.text)} />
|
|
141
|
+
{fields.length > 0 && (
|
|
142
|
+
<div className="mt-2 grid grid-cols-2 gap-x-4 gap-y-2">
|
|
143
|
+
{fields.map((field, i) => (
|
|
144
|
+
// oxlint-disable-next-line react/no-array-index-key -- fields are positional
|
|
145
|
+
<Text key={i} value={textOf(field)} />
|
|
146
|
+
))}
|
|
147
|
+
</div>
|
|
148
|
+
)}
|
|
149
|
+
</div>
|
|
150
|
+
{accessory?.type === 'image' && (
|
|
151
|
+
<img
|
|
152
|
+
src={accessory.image_url as string}
|
|
153
|
+
alt={(accessory.alt_text as string | undefined) ?? ''}
|
|
154
|
+
className="size-[88px] shrink-0 rounded-lg object-cover"
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
{accessory?.type === 'button' && <Button element={accessory} />}
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
case 'context':
|
|
162
|
+
return (
|
|
163
|
+
<div
|
|
164
|
+
key={key}
|
|
165
|
+
className="flex flex-wrap items-center gap-1.5 text-xs"
|
|
166
|
+
style={{ color: colors.muted }}
|
|
167
|
+
>
|
|
168
|
+
{((block.elements as Element[] | undefined) ?? []).map((element, i) =>
|
|
169
|
+
element.type === 'image' ? (
|
|
170
|
+
// oxlint-disable-next-line react/no-array-index-key -- elements are positional
|
|
171
|
+
<img
|
|
172
|
+
key={i}
|
|
173
|
+
src={element.image_url as string}
|
|
174
|
+
alt=""
|
|
175
|
+
className="size-4 rounded"
|
|
176
|
+
/>
|
|
177
|
+
) : (
|
|
178
|
+
// oxlint-disable-next-line react/no-array-index-key -- elements are positional
|
|
179
|
+
<Text key={i} value={textOf(element)} />
|
|
180
|
+
)
|
|
181
|
+
)}
|
|
182
|
+
</div>
|
|
183
|
+
);
|
|
184
|
+
case 'actions':
|
|
185
|
+
return (
|
|
186
|
+
<div key={key} className="mt-1 flex flex-wrap gap-2">
|
|
187
|
+
{((block.elements as Element[] | undefined) ?? []).map((element, i) =>
|
|
188
|
+
element.type === 'button' ? (
|
|
189
|
+
// oxlint-disable-next-line react/no-array-index-key -- elements are positional
|
|
190
|
+
<Button key={i} element={element} />
|
|
191
|
+
) : null
|
|
192
|
+
)}
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
case 'image':
|
|
196
|
+
return (
|
|
197
|
+
<figure key={key} className="mt-1">
|
|
198
|
+
{textOf(block.title) !== undefined && (
|
|
199
|
+
<figcaption className="mb-1 text-sm" style={{ color: colors.muted }}>
|
|
200
|
+
{textOf(block.title)?.text}
|
|
201
|
+
</figcaption>
|
|
202
|
+
)}
|
|
203
|
+
<img
|
|
204
|
+
src={block.image_url as string}
|
|
205
|
+
alt={(block.alt_text as string | undefined) ?? ''}
|
|
206
|
+
className="max-h-[300px] rounded-lg object-contain"
|
|
207
|
+
/>
|
|
208
|
+
</figure>
|
|
209
|
+
);
|
|
210
|
+
default:
|
|
211
|
+
return (
|
|
212
|
+
<div key={key} className="text-xs italic" style={{ color: colors.muted }}>
|
|
213
|
+
{t('emails.slackBlockUnsupported', { type: block.type })}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
)}
|
|
219
|
+
</div>
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sparkline for the workflows list.
|
|
3
|
+
*
|
|
4
|
+
* A polyline over N points: no axes, no scales, no interaction. Same reasoning
|
|
5
|
+
* as the Metrics tab chart — at this size a charting dependency would only add
|
|
6
|
+
* weight.
|
|
7
|
+
*/
|
|
8
|
+
export interface SparklineProps {
|
|
9
|
+
values: readonly number[];
|
|
10
|
+
width?: number;
|
|
11
|
+
height?: number;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function Sparkline({ values, width = 76, height = 26, className }: SparklineProps) {
|
|
16
|
+
if (values.length < 2) {
|
|
17
|
+
return (
|
|
18
|
+
<svg width={width} height={height} className={className} aria-hidden>
|
|
19
|
+
<line
|
|
20
|
+
x1={0}
|
|
21
|
+
y1={height - 1}
|
|
22
|
+
x2={width}
|
|
23
|
+
y2={height - 1}
|
|
24
|
+
stroke="var(--color-border)"
|
|
25
|
+
strokeWidth={1.5}
|
|
26
|
+
/>
|
|
27
|
+
</svg>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const max = Math.max(...values);
|
|
32
|
+
const min = Math.min(...values);
|
|
33
|
+
const span = max - min || 1;
|
|
34
|
+
const stepX = width / (values.length - 1);
|
|
35
|
+
// 1px inset top and bottom so the stroke is never clipped
|
|
36
|
+
const points = values
|
|
37
|
+
.map((value, index) => {
|
|
38
|
+
const x = index * stepX;
|
|
39
|
+
const y = height - 1 - ((value - min) / span) * (height - 2);
|
|
40
|
+
return `${x.toFixed(1)},${y.toFixed(1)}`;
|
|
41
|
+
})
|
|
42
|
+
.join(' ');
|
|
43
|
+
|
|
44
|
+
const flat = max === min;
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<svg width={width} height={height} className={className} aria-hidden>
|
|
48
|
+
<polyline
|
|
49
|
+
points={points}
|
|
50
|
+
fill="none"
|
|
51
|
+
stroke={flat ? 'var(--color-border)' : 'var(--color-primary)'}
|
|
52
|
+
strokeWidth={1.5}
|
|
53
|
+
strokeLinejoin="round"
|
|
54
|
+
strokeLinecap="round"
|
|
55
|
+
/>
|
|
56
|
+
</svg>
|
|
57
|
+
);
|
|
58
|
+
}
|