@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.
Files changed (363) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +180 -2
  3. package/dist/assets/iphone-17-pro-DzaacWSl.png +0 -0
  4. package/dist/assets/pixel-10-pro-back-7MDj1_lz.webp +0 -0
  5. package/dist/assets/pixel-10-pro-mask-Bi1deQ9Y.webp +0 -0
  6. package/dist/cli.d.mts +1 -0
  7. package/dist/cli.mjs +673 -0
  8. package/dist/cli.mjs.map +1 -0
  9. package/dist/config.d.mts +247 -0
  10. package/dist/config.d.mts.map +1 -0
  11. package/dist/config.mjs +27 -0
  12. package/dist/config.mjs.map +1 -0
  13. package/dist/index.d.mts +451 -0
  14. package/dist/index.d.mts.map +1 -0
  15. package/dist/index.mjs +2722 -0
  16. package/dist/index.mjs.map +1 -0
  17. package/dist/postgres.d.mts +34 -0
  18. package/dist/postgres.d.mts.map +1 -0
  19. package/dist/postgres.mjs +313 -0
  20. package/dist/postgres.mjs.map +1 -0
  21. package/package.json +93 -3
  22. package/src/app/assets/devices/iphone-17-pro.png +0 -0
  23. package/src/app/assets/devices/pixel-10-pro-back.webp +0 -0
  24. package/src/app/assets/devices/pixel-10-pro-mask.webp +0 -0
  25. package/src/app/assets/flags/AC.svg +1 -0
  26. package/src/app/assets/flags/AD.svg +1 -0
  27. package/src/app/assets/flags/AE.svg +1 -0
  28. package/src/app/assets/flags/AF.svg +1 -0
  29. package/src/app/assets/flags/AG.svg +1 -0
  30. package/src/app/assets/flags/AI.svg +1 -0
  31. package/src/app/assets/flags/AL.svg +1 -0
  32. package/src/app/assets/flags/AM.svg +1 -0
  33. package/src/app/assets/flags/AO.svg +1 -0
  34. package/src/app/assets/flags/AQ.svg +1 -0
  35. package/src/app/assets/flags/AR.svg +1 -0
  36. package/src/app/assets/flags/AS.svg +1 -0
  37. package/src/app/assets/flags/AT.svg +1 -0
  38. package/src/app/assets/flags/AU.svg +1 -0
  39. package/src/app/assets/flags/AW.svg +1 -0
  40. package/src/app/assets/flags/AX.svg +1 -0
  41. package/src/app/assets/flags/AZ.svg +1 -0
  42. package/src/app/assets/flags/BA.svg +1 -0
  43. package/src/app/assets/flags/BB.svg +1 -0
  44. package/src/app/assets/flags/BD.svg +1 -0
  45. package/src/app/assets/flags/BE.svg +1 -0
  46. package/src/app/assets/flags/BF.svg +1 -0
  47. package/src/app/assets/flags/BG.svg +1 -0
  48. package/src/app/assets/flags/BH.svg +1 -0
  49. package/src/app/assets/flags/BI.svg +1 -0
  50. package/src/app/assets/flags/BJ.svg +1 -0
  51. package/src/app/assets/flags/BL.svg +1 -0
  52. package/src/app/assets/flags/BM.svg +1 -0
  53. package/src/app/assets/flags/BN.svg +1 -0
  54. package/src/app/assets/flags/BO.svg +1 -0
  55. package/src/app/assets/flags/BQ-BO.svg +1 -0
  56. package/src/app/assets/flags/BQ-SA.svg +1 -0
  57. package/src/app/assets/flags/BQ-SE.svg +1 -0
  58. package/src/app/assets/flags/BQ.svg +1 -0
  59. package/src/app/assets/flags/BR.svg +1 -0
  60. package/src/app/assets/flags/BS.svg +1 -0
  61. package/src/app/assets/flags/BT.svg +1 -0
  62. package/src/app/assets/flags/BV.svg +1 -0
  63. package/src/app/assets/flags/BW.svg +1 -0
  64. package/src/app/assets/flags/BY.svg +1 -0
  65. package/src/app/assets/flags/BZ.svg +1 -0
  66. package/src/app/assets/flags/CA.svg +1 -0
  67. package/src/app/assets/flags/CC.svg +1 -0
  68. package/src/app/assets/flags/CD.svg +1 -0
  69. package/src/app/assets/flags/CF.svg +1 -0
  70. package/src/app/assets/flags/CG.svg +1 -0
  71. package/src/app/assets/flags/CH.svg +1 -0
  72. package/src/app/assets/flags/CI.svg +1 -0
  73. package/src/app/assets/flags/CK.svg +1 -0
  74. package/src/app/assets/flags/CL.svg +1 -0
  75. package/src/app/assets/flags/CM.svg +1 -0
  76. package/src/app/assets/flags/CN.svg +1 -0
  77. package/src/app/assets/flags/CO.svg +1 -0
  78. package/src/app/assets/flags/CR.svg +1 -0
  79. package/src/app/assets/flags/CU.svg +1 -0
  80. package/src/app/assets/flags/CV.svg +1 -0
  81. package/src/app/assets/flags/CW.svg +1 -0
  82. package/src/app/assets/flags/CX.svg +1 -0
  83. package/src/app/assets/flags/CY.svg +1 -0
  84. package/src/app/assets/flags/CZ.svg +1 -0
  85. package/src/app/assets/flags/DE.svg +1 -0
  86. package/src/app/assets/flags/DJ.svg +1 -0
  87. package/src/app/assets/flags/DK.svg +1 -0
  88. package/src/app/assets/flags/DM.svg +1 -0
  89. package/src/app/assets/flags/DO.svg +1 -0
  90. package/src/app/assets/flags/DZ.svg +1 -0
  91. package/src/app/assets/flags/EC.svg +1 -0
  92. package/src/app/assets/flags/EE.svg +1 -0
  93. package/src/app/assets/flags/EG.svg +1 -0
  94. package/src/app/assets/flags/EH.svg +1 -0
  95. package/src/app/assets/flags/ER.svg +1 -0
  96. package/src/app/assets/flags/ES-CT.svg +1 -0
  97. package/src/app/assets/flags/ES.svg +1 -0
  98. package/src/app/assets/flags/ET.svg +1 -0
  99. package/src/app/assets/flags/EU.svg +1 -0
  100. package/src/app/assets/flags/FI.svg +1 -0
  101. package/src/app/assets/flags/FJ.svg +1 -0
  102. package/src/app/assets/flags/FK.svg +1 -0
  103. package/src/app/assets/flags/FM.svg +1 -0
  104. package/src/app/assets/flags/FO.svg +1 -0
  105. package/src/app/assets/flags/FR.svg +1 -0
  106. package/src/app/assets/flags/GA.svg +1 -0
  107. package/src/app/assets/flags/GB-ENG.svg +1 -0
  108. package/src/app/assets/flags/GB-NIR.svg +1 -0
  109. package/src/app/assets/flags/GB-SCT.svg +1 -0
  110. package/src/app/assets/flags/GB-WLS.svg +1 -0
  111. package/src/app/assets/flags/GB.svg +1 -0
  112. package/src/app/assets/flags/GD.svg +1 -0
  113. package/src/app/assets/flags/GE.svg +1 -0
  114. package/src/app/assets/flags/GF.svg +1 -0
  115. package/src/app/assets/flags/GG.svg +1 -0
  116. package/src/app/assets/flags/GH.svg +1 -0
  117. package/src/app/assets/flags/GI.svg +1 -0
  118. package/src/app/assets/flags/GL.svg +1 -0
  119. package/src/app/assets/flags/GM.svg +1 -0
  120. package/src/app/assets/flags/GN.svg +1 -0
  121. package/src/app/assets/flags/GP.svg +1 -0
  122. package/src/app/assets/flags/GQ.svg +1 -0
  123. package/src/app/assets/flags/GR.svg +1 -0
  124. package/src/app/assets/flags/GS.svg +1 -0
  125. package/src/app/assets/flags/GT.svg +1 -0
  126. package/src/app/assets/flags/GU.svg +1 -0
  127. package/src/app/assets/flags/GW.svg +1 -0
  128. package/src/app/assets/flags/GY.svg +1 -0
  129. package/src/app/assets/flags/HK.svg +1 -0
  130. package/src/app/assets/flags/HM.svg +1 -0
  131. package/src/app/assets/flags/HN.svg +1 -0
  132. package/src/app/assets/flags/HR.svg +1 -0
  133. package/src/app/assets/flags/HT.svg +1 -0
  134. package/src/app/assets/flags/HU.svg +1 -0
  135. package/src/app/assets/flags/IC.svg +1 -0
  136. package/src/app/assets/flags/ID.svg +1 -0
  137. package/src/app/assets/flags/IE.svg +1 -0
  138. package/src/app/assets/flags/IL.svg +1 -0
  139. package/src/app/assets/flags/IM.svg +1 -0
  140. package/src/app/assets/flags/IN.svg +1 -0
  141. package/src/app/assets/flags/IO.svg +1 -0
  142. package/src/app/assets/flags/IQ.svg +1 -0
  143. package/src/app/assets/flags/IR.svg +1 -0
  144. package/src/app/assets/flags/IS.svg +1 -0
  145. package/src/app/assets/flags/IT.svg +1 -0
  146. package/src/app/assets/flags/JE.svg +1 -0
  147. package/src/app/assets/flags/JM.svg +1 -0
  148. package/src/app/assets/flags/JO.svg +1 -0
  149. package/src/app/assets/flags/JP.svg +1 -0
  150. package/src/app/assets/flags/KE.svg +1 -0
  151. package/src/app/assets/flags/KG.svg +1 -0
  152. package/src/app/assets/flags/KH.svg +1 -0
  153. package/src/app/assets/flags/KI.svg +1 -0
  154. package/src/app/assets/flags/KM.svg +1 -0
  155. package/src/app/assets/flags/KN.svg +1 -0
  156. package/src/app/assets/flags/KP.svg +1 -0
  157. package/src/app/assets/flags/KR.svg +1 -0
  158. package/src/app/assets/flags/KW.svg +1 -0
  159. package/src/app/assets/flags/KY.svg +1 -0
  160. package/src/app/assets/flags/KZ.svg +1 -0
  161. package/src/app/assets/flags/LA.svg +1 -0
  162. package/src/app/assets/flags/LB.svg +1 -0
  163. package/src/app/assets/flags/LC.svg +1 -0
  164. package/src/app/assets/flags/LI.svg +1 -0
  165. package/src/app/assets/flags/LK.svg +1 -0
  166. package/src/app/assets/flags/LR.svg +1 -0
  167. package/src/app/assets/flags/LS.svg +1 -0
  168. package/src/app/assets/flags/LT.svg +1 -0
  169. package/src/app/assets/flags/LU.svg +1 -0
  170. package/src/app/assets/flags/LV.svg +1 -0
  171. package/src/app/assets/flags/LY.svg +1 -0
  172. package/src/app/assets/flags/MA.svg +1 -0
  173. package/src/app/assets/flags/MC.svg +1 -0
  174. package/src/app/assets/flags/MD.svg +1 -0
  175. package/src/app/assets/flags/ME.svg +1 -0
  176. package/src/app/assets/flags/MF.svg +1 -0
  177. package/src/app/assets/flags/MG.svg +1 -0
  178. package/src/app/assets/flags/MH.svg +1 -0
  179. package/src/app/assets/flags/MK.svg +1 -0
  180. package/src/app/assets/flags/ML.svg +1 -0
  181. package/src/app/assets/flags/MM.svg +1 -0
  182. package/src/app/assets/flags/MN.svg +1 -0
  183. package/src/app/assets/flags/MO.svg +1 -0
  184. package/src/app/assets/flags/MP.svg +1 -0
  185. package/src/app/assets/flags/MQ.svg +1 -0
  186. package/src/app/assets/flags/MR.svg +1 -0
  187. package/src/app/assets/flags/MS.svg +1 -0
  188. package/src/app/assets/flags/MT.svg +1 -0
  189. package/src/app/assets/flags/MU.svg +1 -0
  190. package/src/app/assets/flags/MV.svg +1 -0
  191. package/src/app/assets/flags/MW.svg +1 -0
  192. package/src/app/assets/flags/MX.svg +1 -0
  193. package/src/app/assets/flags/MY.svg +1 -0
  194. package/src/app/assets/flags/MZ.svg +1 -0
  195. package/src/app/assets/flags/NA.svg +1 -0
  196. package/src/app/assets/flags/NC.svg +1 -0
  197. package/src/app/assets/flags/NE.svg +1 -0
  198. package/src/app/assets/flags/NF.svg +1 -0
  199. package/src/app/assets/flags/NG.svg +1 -0
  200. package/src/app/assets/flags/NI.svg +1 -0
  201. package/src/app/assets/flags/NL.svg +1 -0
  202. package/src/app/assets/flags/NO.svg +1 -0
  203. package/src/app/assets/flags/NP.svg +1 -0
  204. package/src/app/assets/flags/NR.svg +1 -0
  205. package/src/app/assets/flags/NU.svg +1 -0
  206. package/src/app/assets/flags/NZ.svg +1 -0
  207. package/src/app/assets/flags/OM.svg +1 -0
  208. package/src/app/assets/flags/PA.svg +1 -0
  209. package/src/app/assets/flags/PE.svg +1 -0
  210. package/src/app/assets/flags/PF.svg +1 -0
  211. package/src/app/assets/flags/PG.svg +1 -0
  212. package/src/app/assets/flags/PH.svg +1 -0
  213. package/src/app/assets/flags/PK.svg +1 -0
  214. package/src/app/assets/flags/PL.svg +1 -0
  215. package/src/app/assets/flags/PM.svg +1 -0
  216. package/src/app/assets/flags/PN.svg +1 -0
  217. package/src/app/assets/flags/PR.svg +1 -0
  218. package/src/app/assets/flags/PS.svg +1 -0
  219. package/src/app/assets/flags/PT.svg +1 -0
  220. package/src/app/assets/flags/PW.svg +1 -0
  221. package/src/app/assets/flags/PY.svg +1 -0
  222. package/src/app/assets/flags/QA.svg +1 -0
  223. package/src/app/assets/flags/RE.svg +1 -0
  224. package/src/app/assets/flags/README.md +6 -0
  225. package/src/app/assets/flags/RO.svg +1 -0
  226. package/src/app/assets/flags/RS.svg +1 -0
  227. package/src/app/assets/flags/RU.svg +1 -0
  228. package/src/app/assets/flags/RW.svg +1 -0
  229. package/src/app/assets/flags/SA.svg +1 -0
  230. package/src/app/assets/flags/SB.svg +1 -0
  231. package/src/app/assets/flags/SC.svg +1 -0
  232. package/src/app/assets/flags/SD.svg +1 -0
  233. package/src/app/assets/flags/SE.svg +1 -0
  234. package/src/app/assets/flags/SG.svg +1 -0
  235. package/src/app/assets/flags/SH.svg +1 -0
  236. package/src/app/assets/flags/SI.svg +1 -0
  237. package/src/app/assets/flags/SJ.svg +1 -0
  238. package/src/app/assets/flags/SK.svg +1 -0
  239. package/src/app/assets/flags/SL.svg +1 -0
  240. package/src/app/assets/flags/SM.svg +1 -0
  241. package/src/app/assets/flags/SN.svg +1 -0
  242. package/src/app/assets/flags/SO.svg +1 -0
  243. package/src/app/assets/flags/SR.svg +1 -0
  244. package/src/app/assets/flags/SS.svg +1 -0
  245. package/src/app/assets/flags/ST.svg +1 -0
  246. package/src/app/assets/flags/SV.svg +1 -0
  247. package/src/app/assets/flags/SX.svg +1 -0
  248. package/src/app/assets/flags/SY.svg +1 -0
  249. package/src/app/assets/flags/SZ.svg +1 -0
  250. package/src/app/assets/flags/TA.svg +1 -0
  251. package/src/app/assets/flags/TC.svg +1 -0
  252. package/src/app/assets/flags/TD.svg +1 -0
  253. package/src/app/assets/flags/TF.svg +1 -0
  254. package/src/app/assets/flags/TG.svg +1 -0
  255. package/src/app/assets/flags/TH.svg +1 -0
  256. package/src/app/assets/flags/TJ.svg +1 -0
  257. package/src/app/assets/flags/TK.svg +1 -0
  258. package/src/app/assets/flags/TL.svg +1 -0
  259. package/src/app/assets/flags/TM.svg +1 -0
  260. package/src/app/assets/flags/TN.svg +1 -0
  261. package/src/app/assets/flags/TO.svg +1 -0
  262. package/src/app/assets/flags/TR.svg +1 -0
  263. package/src/app/assets/flags/TT.svg +1 -0
  264. package/src/app/assets/flags/TV.svg +1 -0
  265. package/src/app/assets/flags/TW.svg +1 -0
  266. package/src/app/assets/flags/TZ.svg +1 -0
  267. package/src/app/assets/flags/UA.svg +1 -0
  268. package/src/app/assets/flags/UG.svg +1 -0
  269. package/src/app/assets/flags/UM.svg +1 -0
  270. package/src/app/assets/flags/US.svg +1 -0
  271. package/src/app/assets/flags/UY.svg +1 -0
  272. package/src/app/assets/flags/UZ.svg +1 -0
  273. package/src/app/assets/flags/VA.svg +1 -0
  274. package/src/app/assets/flags/VC.svg +1 -0
  275. package/src/app/assets/flags/VE.svg +1 -0
  276. package/src/app/assets/flags/VG.svg +1 -0
  277. package/src/app/assets/flags/VI.svg +1 -0
  278. package/src/app/assets/flags/VN.svg +1 -0
  279. package/src/app/assets/flags/VU.svg +1 -0
  280. package/src/app/assets/flags/WF.svg +1 -0
  281. package/src/app/assets/flags/WS.svg +1 -0
  282. package/src/app/assets/flags/XA.svg +1 -0
  283. package/src/app/assets/flags/XC.svg +1 -0
  284. package/src/app/assets/flags/XK.svg +1 -0
  285. package/src/app/assets/flags/XO.svg +1 -0
  286. package/src/app/assets/flags/YE.svg +1 -0
  287. package/src/app/assets/flags/YT.svg +1 -0
  288. package/src/app/assets/flags/ZA.svg +1 -0
  289. package/src/app/assets/flags/ZM.svg +1 -0
  290. package/src/app/assets/flags/ZW.svg +1 -0
  291. package/src/app/email-preview.ts +46 -0
  292. package/src/app/index.css +203 -0
  293. package/src/app/index.html +12 -0
  294. package/src/app/integrations/i18n/react-i18next.d.ts +11 -0
  295. package/src/app/integrations/i18n/root-provider.tsx +62 -0
  296. package/src/app/integrations/tanstack-query/devtools.tsx +6 -0
  297. package/src/app/integrations/tanstack-query/root-provider.tsx +37 -0
  298. package/src/app/integrations/theme/root-provider.tsx +75 -0
  299. package/src/app/integrations/toast/toast-provider.tsx +46 -0
  300. package/src/app/locales/en-US/common.ts +268 -0
  301. package/src/app/locales/zh-CN/common.ts +263 -0
  302. package/src/app/main.tsx +40 -0
  303. package/src/app/page-chrome.tsx +79 -0
  304. package/src/app/router.tsx +40 -0
  305. package/src/app/routes/__root.tsx +293 -0
  306. package/src/app/routes/emails.tsx +199 -0
  307. package/src/app/routes/home.tsx +87 -0
  308. package/src/app/routes/index.ts +19 -0
  309. package/src/app/routes/metrics.tsx +541 -0
  310. package/src/app/routes/segment-overview.tsx +211 -0
  311. package/src/app/routes/segments.tsx +236 -0
  312. package/src/app/routes/settings.tsx +90 -0
  313. package/src/app/routes/workflows.tsx +348 -0
  314. package/src/app/studio.ts +16 -0
  315. package/src/app/svg.d.ts +17 -0
  316. package/src/app/virtual-config.d.ts +6 -0
  317. package/src/cli.ts +110 -0
  318. package/src/components/avatar.tsx +57 -0
  319. package/src/components/breadcrumb.tsx +49 -0
  320. package/src/components/button/index.tsx +86 -0
  321. package/src/components/channel-icon.ts +39 -0
  322. package/src/components/chat-markup.tsx +109 -0
  323. package/src/components/corner-shape.ts +13 -0
  324. package/src/components/date-range.tsx +181 -0
  325. package/src/components/discord-preview.tsx +165 -0
  326. package/src/components/dropdown/index.tsx +172 -0
  327. package/src/components/email-defaults.tsx +40 -0
  328. package/src/components/email-list.tsx +149 -0
  329. package/src/components/email-thumbnail.tsx +123 -0
  330. package/src/components/flag.tsx +40 -0
  331. package/src/components/input/index.tsx +40 -0
  332. package/src/components/input/search-input.tsx +24 -0
  333. package/src/components/layout.ts +403 -0
  334. package/src/components/menu/index.tsx +118 -0
  335. package/src/components/metric-card.tsx +321 -0
  336. package/src/components/modal/index.tsx +70 -0
  337. package/src/components/nav-drawer.tsx +84 -0
  338. package/src/components/node-inspector.tsx +242 -0
  339. package/src/components/profile-drawer.tsx +331 -0
  340. package/src/components/push-preview.tsx +470 -0
  341. package/src/components/push-thumbnail.tsx +78 -0
  342. package/src/components/segment-list.tsx +184 -0
  343. package/src/components/select/index.tsx +70 -0
  344. package/src/components/series-chart.tsx +120 -0
  345. package/src/components/slack-preview.tsx +223 -0
  346. package/src/components/sparkline.tsx +58 -0
  347. package/src/components/tabs/index.tsx +45 -0
  348. package/src/components/template-refs.ts +110 -0
  349. package/src/components/templates-page.tsx +601 -0
  350. package/src/components/textarea/index.tsx +37 -0
  351. package/src/components/thumbnail-window.tsx +65 -0
  352. package/src/components/workflow-canvas.tsx +503 -0
  353. package/src/components/workflow-list.tsx +231 -0
  354. package/src/config.ts +288 -0
  355. package/src/generate.ts +56 -0
  356. package/src/index.ts +35 -0
  357. package/src/postgres.ts +415 -0
  358. package/src/server/project.ts +290 -0
  359. package/src/server.ts +500 -0
  360. package/src/utils/cn.ts +6 -0
  361. package/src/utils/label.ts +12 -0
  362. package/src/utils/lookup.ts +11 -0
  363. package/src/utils/template-content.ts +213 -0
@@ -0,0 +1,211 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { createRoute } from '@tanstack/react-router';
3
+ import { useState } from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { Avatar } from '../../components/avatar';
6
+ import { superellipse } from '../../components/corner-shape';
7
+ import { ProfileDrawer } from '../../components/profile-drawer';
8
+ import { SeriesChart } from '../../components/series-chart';
9
+ import type { Profile } from '../../config';
10
+ import { segmentDetailRoute } from './segments';
11
+
12
+ const PAGE_SIZE = 25;
13
+
14
+ const number = (value: number) => value.toLocaleString();
15
+
16
+ /** ISO timestamp → a date; the clock time is noise in a list this dense. */
17
+ const day = (iso: string | undefined) => (iso === undefined ? '—' : iso.slice(0, 10));
18
+
19
+ function Stat({ label, value }: { label: string; value: string }) {
20
+ return (
21
+ <div className="border-border bg-card rounded-2xl border px-4 py-3" style={superellipse}>
22
+ <div className="text-muted text-xs">{label}</div>
23
+ <div className="mt-1 text-xl font-semibold tabular-nums">{value}</div>
24
+ </div>
25
+ );
26
+ }
27
+
28
+ /**
29
+ * A segment's Overview: how big it is and how that has moved, then who is
30
+ * actually in it. The chart answers "is this condition matching the population
31
+ * I meant"; the table is how you check that by looking at real people.
32
+ */
33
+ function SegmentOverview() {
34
+ const { id } = segmentDetailRoute.useParams();
35
+ const { config } = segmentDetailRoute.useRouteContext();
36
+ const { t } = useTranslation();
37
+
38
+ const [page, setPage] = useState(0);
39
+ const [selected, setSelected] = useState<Profile | undefined>(undefined);
40
+
41
+ const { data: reports } = useQuery({
42
+ queryKey: ['segment-reports'],
43
+ queryFn: async () => (await config.stats?.segments?.()) ?? [],
44
+ enabled: config.stats?.segments !== undefined,
45
+ });
46
+ const report = reports?.find((row) => row.id === id);
47
+
48
+ const { data: profilePage, isPending } = useQuery({
49
+ queryKey: ['segment-profiles', id, page],
50
+ queryFn: async () =>
51
+ (await config.stats?.profiles?.(id, { limit: PAGE_SIZE, offset: page * PAGE_SIZE })) ?? {
52
+ profiles: [],
53
+ total: 0,
54
+ },
55
+ enabled: config.stats?.profiles !== undefined,
56
+ });
57
+
58
+ const series = report?.series ?? [];
59
+ const first = series.at(0);
60
+ const last = series.at(-1);
61
+ const change =
62
+ first !== undefined && last !== undefined && first !== 0
63
+ ? ((last - first) / first) * 100
64
+ : undefined;
65
+
66
+ const total = profilePage?.total ?? 0;
67
+ const lastPage = Math.max(0, Math.ceil(total / PAGE_SIZE) - 1);
68
+
69
+ if (config.stats?.segments === undefined && config.stats?.profiles === undefined) {
70
+ return (
71
+ <div className="flex flex-1 items-center justify-center p-8">
72
+ <div
73
+ className="border-border bg-card max-w-md rounded-2xl border border-dashed p-8 text-center"
74
+ style={superellipse}
75
+ >
76
+ <p className="text-sm font-medium">{t('segments.noSource')}</p>
77
+ <p className="text-muted mt-2 text-sm">{t('segments.noSourceHint')}</p>
78
+ </div>
79
+ </div>
80
+ );
81
+ }
82
+
83
+ return (
84
+ /* The drawer is fixed to the viewport, so it can sit outside the flow here
85
+ while the page itself scrolls in the shell's one scrollport. */
86
+ <>
87
+ <div className="flex-1 p-6">
88
+ <div className="grid grid-cols-2 gap-3 md:grid-cols-3">
89
+ <Stat label={t('segments.size')} value={report ? number(report.size) : '—'} />
90
+ <Stat
91
+ label={t('segments.change')}
92
+ value={change === undefined ? '—' : `${change >= 0 ? '+' : ''}${change.toFixed(1)}%`}
93
+ />
94
+ <Stat label={t('segments.profiles')} value={total > 0 ? number(total) : '—'} />
95
+ </div>
96
+
97
+ <section className="border-border bg-card mt-6 rounded-2xl border p-5" style={superellipse}>
98
+ <h2 className="text-sm font-semibold">{t('segments.overTime')}</h2>
99
+ {series.length > 1 ? (
100
+ <div className="mt-4">
101
+ <SeriesChart values={series} ariaLabel={t('segments.overTime')} />
102
+ </div>
103
+ ) : (
104
+ <p className="text-muted mt-6 text-sm">{t('segments.noData')}</p>
105
+ )}
106
+ </section>
107
+
108
+ {/* No `overflow-hidden`: it would clip the corners for free, but any
109
+ overflow value turns a card into a scrollport, which is the habit
110
+ this layout is getting rid of. The last row re-cuts its own. */}
111
+ <section className="border-border bg-card mt-6 rounded-2xl border" style={superellipse}>
112
+ <div className="border-border flex items-center justify-between border-b px-5 py-3">
113
+ <h2 className="text-sm font-semibold">{t('segments.members')}</h2>
114
+ {total > PAGE_SIZE && (
115
+ <div className="text-muted flex items-center gap-2 text-xs">
116
+ <span className="tabular-nums">
117
+ {number(page * PAGE_SIZE + 1)}–{number(Math.min((page + 1) * PAGE_SIZE, total))} /{' '}
118
+ {number(total)}
119
+ </span>
120
+ <button
121
+ type="button"
122
+ disabled={page === 0}
123
+ onClick={() => setPage((current) => current - 1)}
124
+ className="hover:bg-hover rounded px-2 py-1 transition-colors disabled:opacity-40"
125
+ >
126
+ {t('common.previous')}
127
+ </button>
128
+ <button
129
+ type="button"
130
+ disabled={page >= lastPage}
131
+ onClick={() => setPage((current) => current + 1)}
132
+ className="hover:bg-hover rounded px-2 py-1 transition-colors disabled:opacity-40"
133
+ >
134
+ {t('common.next')}
135
+ </button>
136
+ </div>
137
+ )}
138
+ </div>
139
+
140
+ {isPending ? (
141
+ <p className="text-muted p-5 text-sm">{t('common.loading')}</p>
142
+ ) : profilePage === undefined || profilePage.profiles.length === 0 ? (
143
+ <p className="text-muted p-5 text-sm">{t('segments.noProfiles')}</p>
144
+ ) : (
145
+ <table className="w-full table-fixed border-separate border-spacing-0 text-sm">
146
+ <thead>
147
+ <tr className="text-muted text-left text-xs font-medium">
148
+ <th className="border-border border-b px-5 py-2">{t('profiles.email')}</th>
149
+ <th className="border-border w-56 border-b px-5 py-2">
150
+ {t('profiles.utmSource')}
151
+ </th>
152
+ <th className="border-border w-36 border-b px-5 py-2 whitespace-nowrap">
153
+ {t('profiles.createdAt')}
154
+ </th>
155
+ </tr>
156
+ </thead>
157
+ <tbody>
158
+ {profilePage.profiles.map((profile) => (
159
+ <tr
160
+ key={profile.id}
161
+ onClick={() => setSelected(profile)}
162
+ /* The section already draws a rounded edge; a row border on
163
+ top of it reads as a doubled line. The hover fill sits on
164
+ the cells so the last row's corners can follow the card's
165
+ — a row box paints below any cell radius. */
166
+ className="hover:[&>td]:bg-hover cursor-pointer [&>td]:transition-colors last:[&>td]:border-b-0 last:[&>td:first-child]:rounded-bl-2xl last:[&>td:last-child]:rounded-br-2xl"
167
+ style={superellipse}
168
+ >
169
+ <td className="border-border border-b px-5 py-2.5" style={superellipse}>
170
+ {/* The avatar is fixed-width, so the address does the
171
+ truncating — `truncate` on the cell itself would be
172
+ undone by the flex row inside it. */}
173
+ <div className="flex items-center gap-2.5">
174
+ <Avatar
175
+ picture={profile.properties?.picture}
176
+ label={profile.email ?? profile.id}
177
+ size="sm"
178
+ />
179
+ <span className="truncate">{profile.email ?? '—'}</span>
180
+ </div>
181
+ </td>
182
+ <td className="border-border text-muted truncate border-b px-5 py-2.5 font-mono text-sm">
183
+ {/* Out of a dictionary of unknowns, so anything but a string reads as absent. */}
184
+ {typeof profile.properties?.utm_source === 'string'
185
+ ? profile.properties.utm_source
186
+ : '—'}
187
+ </td>
188
+ <td
189
+ className="border-border text-muted border-b px-5 py-2.5 whitespace-nowrap tabular-nums"
190
+ style={superellipse}
191
+ >
192
+ {day(profile.createdAt)}
193
+ </td>
194
+ </tr>
195
+ ))}
196
+ </tbody>
197
+ </table>
198
+ )}
199
+ </section>
200
+ </div>
201
+
202
+ <ProfileDrawer profile={selected} onClose={() => setSelected(undefined)} />
203
+ </>
204
+ );
205
+ }
206
+
207
+ export const segmentOverviewRoute = createRoute({
208
+ getParentRoute: () => segmentDetailRoute,
209
+ path: '/',
210
+ component: SegmentOverview,
211
+ });
@@ -0,0 +1,236 @@
1
+ import type { ConditionIR, WorkflowIR } from '@shware/workflow';
2
+ import { useQuery } from '@tanstack/react-query';
3
+ import { Outlet, createRoute, useNavigate } from '@tanstack/react-router';
4
+ import { useMemo, useState } from 'react';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { Breadcrumb } from '../../components/breadcrumb';
7
+ import { SearchInput } from '../../components/input/search-input';
8
+ import { SegmentList } from '../../components/segment-list';
9
+ import { displayName } from '../../utils/label';
10
+ import { PageChrome } from '../page-chrome';
11
+ import { Route as rootRoute } from './__root';
12
+
13
+ /**
14
+ * Segments referenced by these workflows, derived from IR the same way the
15
+ * email list is — so a segment used in a condition but never passed to the
16
+ * config is visible rather than silently missing.
17
+ */
18
+ export function collectSegmentRefs(irs: WorkflowIR[]): { id: string; usedBy: string[] }[] {
19
+ const byName = new Map<string, Set<string>>();
20
+
21
+ const walkCondition = (condition: ConditionIR | undefined, workflow: string) => {
22
+ if (condition === undefined) return;
23
+ switch (condition.type) {
24
+ case 'segment': {
25
+ const set = byName.get(condition.segment) ?? new Set();
26
+ set.add(workflow);
27
+ byName.set(condition.segment, set);
28
+ break;
29
+ }
30
+ case 'and':
31
+ case 'or':
32
+ for (const child of condition.conditions) walkCondition(child, workflow);
33
+ break;
34
+ case 'not':
35
+ walkCondition(condition.condition, workflow);
36
+ break;
37
+ default:
38
+ break;
39
+ }
40
+ };
41
+
42
+ const walkNodes = (nodes: WorkflowIR['flow'], workflow: string) => {
43
+ for (const node of nodes) {
44
+ if (node.type === 'branch') {
45
+ for (const branchCase of node.cases) {
46
+ walkCondition(branchCase.condition, workflow);
47
+ walkNodes(branchCase.flow, workflow);
48
+ }
49
+ if (node.otherwise) walkNodes(node.otherwise, workflow);
50
+ }
51
+ if (node.type === 'filter') walkCondition(node.condition, workflow);
52
+ if (node.type === 'wait_until') {
53
+ walkCondition(node.condition, workflow);
54
+ if (Array.isArray(node.onTimeout)) walkNodes(node.onTimeout, workflow);
55
+ }
56
+ if (node.type === 'cohort') for (const arm of node.arms) walkNodes(arm.flow, workflow);
57
+ }
58
+ };
59
+
60
+ for (const ir of irs) {
61
+ if (ir.trigger.type === 'segment') {
62
+ const set = byName.get(ir.trigger.segment) ?? new Set();
63
+ set.add(ir.id);
64
+ byName.set(ir.trigger.segment, set);
65
+ }
66
+ if (ir.trigger.type === 'event') walkCondition(ir.trigger.filter, ir.id);
67
+ walkCondition(ir.goal?.condition, ir.id);
68
+ walkCondition(ir.exitWhen, ir.id);
69
+ walkNodes(ir.flow, ir.id);
70
+ }
71
+
72
+ return [...byName.entries()]
73
+ .map(([id, usedBy]) => ({ id, usedBy: [...usedBy] }))
74
+ .sort((a, b) => a.id.localeCompare(b.id));
75
+ }
76
+
77
+ /**
78
+ * Every segment the studio shows: each deployed one — referenced by a workflow or not, since a
79
+ * segment is an audience worth watching on its own — plus each one a workflow references without
80
+ * it being deployed (shown as not defined). The IR only adds who uses it.
81
+ */
82
+ export function collectSegments(
83
+ irs: WorkflowIR[],
84
+ deployed: readonly { id: string }[]
85
+ ): { id: string; usedBy: string[] }[] {
86
+ const byId = new Map(collectSegmentRefs(irs).map((ref) => [ref.id, ref]));
87
+ for (const { id } of deployed) {
88
+ if (!byId.has(id)) byId.set(id, { id, usedBy: [] });
89
+ }
90
+ return [...byId.values()].sort((a, b) => a.id.localeCompare(b.id));
91
+ }
92
+
93
+ function Segments() {
94
+ const { config } = segmentsRoute.useRouteContext();
95
+ const { t } = useTranslation();
96
+ const navigate = useNavigate();
97
+ const [query, setQuery] = useState('');
98
+
99
+ const refs = useMemo(
100
+ () => collectSegments(Object.values(config.workflows), config.segments),
101
+ [config]
102
+ );
103
+
104
+ const items = useMemo(() => {
105
+ /** Definitions come from the compiled segments; a reference alone gives only a name. */
106
+ const declared = new Map(config.segments.map((segment) => [segment.id, segment]));
107
+ return refs.map((ref) => {
108
+ const found = declared.get(ref.id);
109
+ return {
110
+ ...ref,
111
+ ...(found !== undefined ? { definition: found.condition } : {}),
112
+ ...(found?.meta?.name !== undefined ? { label: found.meta.name } : {}),
113
+ ...(found?.meta?.description !== undefined ? { description: found.meta.description } : {}),
114
+ };
115
+ });
116
+ }, [refs, config]);
117
+
118
+ /* Substring match over everything a segment is known by: key, label, description. */
119
+ const filtered = useMemo(() => {
120
+ const needle = query.trim().toLowerCase();
121
+ if (needle === '') return items;
122
+ return items.filter((item) =>
123
+ [item.id, item.label ?? '', item.description ?? ''].some((text) =>
124
+ text.toLowerCase().includes(needle)
125
+ )
126
+ );
127
+ }, [items, query]);
128
+
129
+ const { data: reports } = useQuery({
130
+ queryKey: ['segment-reports'],
131
+ queryFn: async () => (await config.stats?.segments?.()) ?? [],
132
+ enabled: config.stats?.segments !== undefined,
133
+ });
134
+
135
+ if (refs.length === 0) {
136
+ return (
137
+ <div className="text-muted flex flex-1 items-center justify-center text-sm">
138
+ {t('segments.empty')}
139
+ </div>
140
+ );
141
+ }
142
+
143
+ return (
144
+ /* Nothing here scrolls: the shell's content column is the one scrollport. */
145
+ <div className="flex-1">
146
+ <PageChrome breadcrumb={<Breadcrumb items={[{ label: t('nav.segments') }]} />} />
147
+ {/*
148
+ The search field belongs with what it filters, not up in the chrome.
149
+ It scrolls away with the list: only the app header pins, and a stack
150
+ of three fixed bars over a short list was more chrome than content.
151
+ */}
152
+ <div className="px-6 pt-4 pb-3">
153
+ <SearchInput
154
+ className="w-72"
155
+ placeholder={t('segments.searchPlaceholder')}
156
+ value={query}
157
+ onChange={(e) => setQuery(e.target.value)}
158
+ />
159
+ </div>
160
+ <div className="px-6 pb-6">
161
+ {filtered.length === 0 ? (
162
+ <div className="text-muted flex items-center justify-center py-24 text-sm">
163
+ {t('segments.noMatches', { query: query.trim() })}
164
+ </div>
165
+ ) : (
166
+ <SegmentList
167
+ items={filtered}
168
+ {...(reports !== undefined ? { reports } : {})}
169
+ onOpen={(id) => void navigate({ to: '/segments/$id', params: { id } })}
170
+ />
171
+ )}
172
+ </div>
173
+ </div>
174
+ );
175
+ }
176
+
177
+ export const segmentsRoute = createRoute({
178
+ getParentRoute: () => rootRoute,
179
+ path: '/segments',
180
+ component: Segments,
181
+ });
182
+
183
+ /* ------------------------------- Detail shell ------------------------------ */
184
+
185
+ function SegmentDetail() {
186
+ const { id } = segmentDetailRoute.useParams();
187
+ const { config } = segmentDetailRoute.useRouteContext();
188
+ const { t } = useTranslation();
189
+
190
+ /* Switcher options: every segment the workflows reference, like the list page. */
191
+ const options = useMemo(() => {
192
+ const declared = new Map(config.segments.map((segment) => [segment.id, segment]));
193
+ const refs = collectSegments(Object.values(config.workflows), config.segments);
194
+ return refs.map((ref) => ({
195
+ value: ref.id,
196
+ label: displayName(declared.get(ref.id)?.meta?.name, ref.id),
197
+ }));
198
+ }, [config]);
199
+
200
+ /*
201
+ * The header is the root's: breadcrumb with the segment switcher as its
202
+ * leaf. No tab strip — there is exactly one view here, and a strip of one
203
+ * tab is a control that can never do anything. The breadcrumb still ends in
204
+ * the view's name, which is what keeps this page the same shape as the
205
+ * workflow detail page, where the tabs are real.
206
+ */
207
+ return (
208
+ <div className="flex flex-1 flex-col">
209
+ <PageChrome
210
+ breadcrumb={
211
+ <Breadcrumb
212
+ items={[
213
+ { label: t('nav.segments'), to: '/segments' },
214
+ {
215
+ label: options.find((option) => option.value === id)?.label ?? id,
216
+ to: '/segments/$id',
217
+ params: { id },
218
+ },
219
+ { label: t('segments.tabs.overview') },
220
+ ]}
221
+ />
222
+ }
223
+ />
224
+
225
+ <div className="flex flex-1 flex-col">
226
+ <Outlet />
227
+ </div>
228
+ </div>
229
+ );
230
+ }
231
+
232
+ export const segmentDetailRoute = createRoute({
233
+ getParentRoute: () => rootRoute,
234
+ path: '/segments/$id',
235
+ component: SegmentDetail,
236
+ });
@@ -0,0 +1,90 @@
1
+ import { createRoute } from '@tanstack/react-router';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { Breadcrumb } from '../../components/breadcrumb';
4
+ import { Button } from '../../components/button';
5
+ import { superellipse } from '../../components/corner-shape';
6
+ import { EmailDefaults } from '../../components/email-defaults';
7
+ import {
8
+ type SupportedLng,
9
+ languageNames,
10
+ supportedLngs,
11
+ } from '../integrations/i18n/root-provider';
12
+ import { type Theme, themes, useTheme } from '../integrations/theme/root-provider';
13
+ import { PageChrome } from '../page-chrome';
14
+ import { Route as rootRoute } from './__root';
15
+
16
+ function Settings() {
17
+ const { config } = settingsRoute.useRouteContext();
18
+ const { t, i18n } = useTranslation();
19
+ const { theme, setTheme } = useTheme();
20
+
21
+ const current = supportedLngs.find((lng) => i18n.resolvedLanguage === lng) ?? 'en-US';
22
+ const sources = (['reports', 'nodeStats', 'metrics'] as const).filter(
23
+ (key) => config.stats?.[key] !== undefined
24
+ );
25
+
26
+ return (
27
+ /* No scroll container of its own: the shell's content column is the only one. */
28
+ <div className="flex-1 p-6">
29
+ <PageChrome breadcrumb={<Breadcrumb items={[{ label: t('nav.settings') }]} />} />
30
+
31
+ <section
32
+ className="border-border bg-card mt-5 max-w-xl rounded-2xl border p-5"
33
+ style={superellipse}
34
+ >
35
+ <h2 className="text-sm font-medium">{t('settings.language')}</h2>
36
+ <p className="text-muted mt-1 text-xs">{t('settings.languageHint')}</p>
37
+ <div className="mt-3 flex gap-2">
38
+ {supportedLngs.map((lng: SupportedLng) => (
39
+ <Button
40
+ key={lng}
41
+ size="sm"
42
+ variant={current === lng ? 'default' : 'secondary'}
43
+ onClick={() => void i18n.changeLanguage(lng)}
44
+ >
45
+ {languageNames[lng]}
46
+ </Button>
47
+ ))}
48
+ </div>
49
+ </section>
50
+
51
+ <section
52
+ className="border-border bg-card mt-4 max-w-xl rounded-2xl border p-5"
53
+ style={superellipse}
54
+ >
55
+ <h2 className="text-sm font-medium">{t('settings.theme')}</h2>
56
+ <p className="text-muted mt-1 text-xs">{t('settings.themeHint')}</p>
57
+ <div className="mt-3 flex gap-2">
58
+ {themes.map((option: Theme) => (
59
+ <Button
60
+ key={option}
61
+ size="sm"
62
+ variant={theme === option ? 'default' : 'secondary'}
63
+ onClick={() => setTheme(option)}
64
+ >
65
+ {t(`settings.themes.${option}`)}
66
+ </Button>
67
+ ))}
68
+ </div>
69
+ </section>
70
+
71
+ <EmailDefaults from={config.emailDefaults.from} replyTo={config.emailDefaults.replyTo} />
72
+
73
+ <section
74
+ className="border-border bg-card mt-4 max-w-xl rounded-2xl border p-5"
75
+ style={superellipse}
76
+ >
77
+ <h2 className="text-sm font-medium">{t('settings.statsSource')}</h2>
78
+ <p className="text-secondary mt-2 font-mono text-xs">
79
+ {sources.length > 0 ? sources.join(', ') : t('common.notConfigured')}
80
+ </p>
81
+ </section>
82
+ </div>
83
+ );
84
+ }
85
+
86
+ export const settingsRoute = createRoute({
87
+ getParentRoute: () => rootRoute,
88
+ path: '/settings',
89
+ component: Settings,
90
+ });