@antelopejs/dms-automation 0.2.7 → 0.3.1

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 (312) hide show
  1. package/README.md +46 -2
  2. package/dist/data/procedures-table.d.ts +38 -4
  3. package/dist/data/procedures-table.js +264 -82
  4. package/dist/data/procedures-table.js.map +1 -1
  5. package/dist/data/runs-table.d.ts +19 -3
  6. package/dist/data/runs-table.js +254 -19
  7. package/dist/data/runs-table.js.map +1 -1
  8. package/dist/db/index.d.ts +1 -2
  9. package/dist/db/index.js +1 -2
  10. package/dist/db/index.js.map +1 -1
  11. package/dist/db/models/automation_template.model.d.ts +16 -1
  12. package/dist/db/models/automation_template.model.js +31 -11
  13. package/dist/db/models/automation_template.model.js.map +1 -1
  14. package/dist/db/models/index.d.ts +1 -1
  15. package/dist/db/models/index.js +1 -1
  16. package/dist/db/models/procedure.model.d.ts +1 -0
  17. package/dist/db/models/procedure.model.js +7 -0
  18. package/dist/db/models/procedure.model.js.map +1 -1
  19. package/dist/db/models/procedure_run.model.d.ts +16 -9
  20. package/dist/db/models/procedure_run.model.js +96 -17
  21. package/dist/db/models/procedure_run.model.js.map +1 -1
  22. package/dist/db/models/stats.model.d.ts +60 -61
  23. package/dist/db/models/stats.model.js +189 -236
  24. package/dist/db/models/stats.model.js.map +1 -1
  25. package/dist/db/models/type_switch.model.d.ts +25 -0
  26. package/dist/db/models/type_switch.model.js +25 -0
  27. package/dist/db/models/type_switch.model.js.map +1 -0
  28. package/dist/db/tables/index.d.ts +1 -2
  29. package/dist/db/tables/index.js +1 -2
  30. package/dist/db/tables/index.js.map +1 -1
  31. package/dist/db/tables/procedure.table.d.ts +6 -0
  32. package/dist/db/tables/procedure.table.js +24 -0
  33. package/dist/db/tables/procedure.table.js.map +1 -1
  34. package/dist/db/tables/procedure_run.table.d.ts +15 -1
  35. package/dist/db/tables/procedure_run.table.js +54 -0
  36. package/dist/db/tables/procedure_run.table.js.map +1 -1
  37. package/dist/db/tables/type_switch.table.d.ts +8 -0
  38. package/dist/db/tables/{trigger_type_config.table.js → type_switch.table.js} +16 -15
  39. package/dist/db/tables/type_switch.table.js.map +1 -0
  40. package/dist/displays/index.d.ts +14 -0
  41. package/dist/displays/index.js +23 -0
  42. package/dist/displays/index.js.map +1 -0
  43. package/dist/index.d.ts +7 -0
  44. package/dist/index.js +8 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/pages/builder.d.ts +1 -1
  47. package/dist/pages/builder.js +10 -3
  48. package/dist/pages/builder.js.map +1 -1
  49. package/dist/pages/index.d.ts +2 -1
  50. package/dist/pages/index.js +2 -1
  51. package/dist/pages/index.js.map +1 -1
  52. package/dist/pages/library.d.ts +2 -1
  53. package/dist/pages/library.js +54 -4
  54. package/dist/pages/library.js.map +1 -1
  55. package/dist/pages/overview.d.ts +6 -1
  56. package/dist/pages/overview.js +121 -2
  57. package/dist/pages/overview.js.map +1 -1
  58. package/dist/pages/procedures.js +111 -16
  59. package/dist/pages/procedures.js.map +1 -1
  60. package/dist/pages/runs.d.ts +4 -1
  61. package/dist/pages/runs.js +109 -13
  62. package/dist/pages/runs.js.map +1 -1
  63. package/dist/pages/shared.d.ts +18 -0
  64. package/dist/pages/shared.js +238 -0
  65. package/dist/pages/shared.js.map +1 -0
  66. package/dist/pages/trace.d.ts +10 -0
  67. package/dist/pages/trace.js +41 -0
  68. package/dist/pages/trace.js.map +1 -0
  69. package/dist/realtime.d.ts +3 -0
  70. package/dist/realtime.js +14 -0
  71. package/dist/realtime.js.map +1 -0
  72. package/dist/routes/action-types.d.ts +2 -14
  73. package/dist/routes/action-types.js +2 -32
  74. package/dist/routes/action-types.js.map +1 -1
  75. package/dist/routes/deleteConfirm.d.ts +3 -0
  76. package/dist/routes/deleteConfirm.js +64 -0
  77. package/dist/routes/deleteConfirm.js.map +1 -0
  78. package/dist/routes/graphSchema.d.ts +3 -90
  79. package/dist/routes/graphSchema.js +36 -9
  80. package/dist/routes/graphSchema.js.map +1 -1
  81. package/dist/routes/index.d.ts +1 -0
  82. package/dist/routes/index.js +1 -0
  83. package/dist/routes/index.js.map +1 -1
  84. package/dist/routes/library.d.ts +40 -0
  85. package/dist/routes/library.js +147 -0
  86. package/dist/routes/library.js.map +1 -0
  87. package/dist/routes/procedureChecks.d.ts +16 -0
  88. package/dist/routes/procedureChecks.js +72 -0
  89. package/dist/routes/procedureChecks.js.map +1 -0
  90. package/dist/routes/procedureRuns.d.ts +21 -0
  91. package/dist/routes/procedureRuns.js +45 -0
  92. package/dist/routes/procedureRuns.js.map +1 -0
  93. package/dist/routes/procedureSchemas.d.ts +107 -0
  94. package/dist/routes/procedureSchemas.js +61 -0
  95. package/dist/routes/procedureSchemas.js.map +1 -0
  96. package/dist/routes/procedures.d.ts +125 -7
  97. package/dist/routes/procedures.js +363 -67
  98. package/dist/routes/procedures.js.map +1 -1
  99. package/dist/routes/requests.d.ts +15 -0
  100. package/dist/routes/requests.js +35 -0
  101. package/dist/routes/requests.js.map +1 -0
  102. package/dist/routes/runs.d.ts +107 -2
  103. package/dist/routes/runs.js +340 -37
  104. package/dist/routes/runs.js.map +1 -1
  105. package/dist/routes/stats.d.ts +19 -1
  106. package/dist/routes/stats.js +160 -4
  107. package/dist/routes/stats.js.map +1 -1
  108. package/dist/routes/templates.d.ts +6 -2
  109. package/dist/routes/templates.js +106 -36
  110. package/dist/routes/templates.js.map +1 -1
  111. package/dist/routes/trigger-types.d.ts +2 -15
  112. package/dist/routes/trigger-types.js +2 -32
  113. package/dist/routes/trigger-types.js.map +1 -1
  114. package/dist/routes/typeConfigShared.d.ts +7 -11
  115. package/dist/routes/typeConfigShared.js +25 -15
  116. package/dist/routes/typeConfigShared.js.map +1 -1
  117. package/dist/runtime/armErrors.d.ts +16 -0
  118. package/dist/runtime/armErrors.js +69 -0
  119. package/dist/runtime/armErrors.js.map +1 -0
  120. package/dist/runtime/boundRunLog.d.ts +24 -0
  121. package/dist/runtime/boundRunLog.js +202 -10
  122. package/dist/runtime/boundRunLog.js.map +1 -1
  123. package/dist/runtime/builtins/actions/http.d.ts +10 -1
  124. package/dist/runtime/builtins/actions/http.js +306 -19
  125. package/dist/runtime/builtins/actions/http.js.map +1 -1
  126. package/dist/runtime/builtins/actions/log.js +2 -2
  127. package/dist/runtime/builtins/actions/log.js.map +1 -1
  128. package/dist/runtime/builtins/data/boolean.d.ts +1 -0
  129. package/dist/runtime/builtins/data/boolean.js +18 -10
  130. package/dist/runtime/builtins/data/boolean.js.map +1 -1
  131. package/dist/runtime/builtins/data/compare.js +60 -11
  132. package/dist/runtime/builtins/data/compare.js.map +1 -1
  133. package/dist/runtime/builtins/data/constant.js +9 -12
  134. package/dist/runtime/builtins/data/constant.js.map +1 -1
  135. package/dist/runtime/builtins/data/json.js +4 -4
  136. package/dist/runtime/builtins/data/json.js.map +1 -1
  137. package/dist/runtime/builtins/data/math.js +44 -24
  138. package/dist/runtime/builtins/data/math.js.map +1 -1
  139. package/dist/runtime/builtins/data/object.js +10 -10
  140. package/dist/runtime/builtins/data/object.js.map +1 -1
  141. package/dist/runtime/builtins/data/string.js +31 -20
  142. package/dist/runtime/builtins/data/string.js.map +1 -1
  143. package/dist/runtime/builtins/nodes/action.js +4 -0
  144. package/dist/runtime/builtins/nodes/action.js.map +1 -1
  145. package/dist/runtime/builtins/nodes/delay.js +1 -1
  146. package/dist/runtime/builtins/nodes/delay.js.map +1 -1
  147. package/dist/runtime/builtins/nodes/forRange.d.ts +1 -1
  148. package/dist/runtime/builtins/nodes/forRange.js +10 -4
  149. package/dist/runtime/builtins/nodes/forRange.js.map +1 -1
  150. package/dist/runtime/builtins/nodes/if.js +2 -1
  151. package/dist/runtime/builtins/nodes/if.js.map +1 -1
  152. package/dist/runtime/builtins/nodes/parallel.js +9 -2
  153. package/dist/runtime/builtins/nodes/parallel.js.map +1 -1
  154. package/dist/runtime/builtins/nodes/retry.js +1 -1
  155. package/dist/runtime/builtins/nodes/retry.js.map +1 -1
  156. package/dist/runtime/builtins/nodes/setVariable.js +1 -3
  157. package/dist/runtime/builtins/nodes/setVariable.js.map +1 -1
  158. package/dist/runtime/builtins/triggers/cron.d.ts +3 -0
  159. package/dist/runtime/builtins/triggers/cron.js +21 -7
  160. package/dist/runtime/builtins/triggers/cron.js.map +1 -1
  161. package/dist/runtime/builtins/triggers/manual.js +2 -2
  162. package/dist/runtime/builtins/triggers/manual.js.map +1 -1
  163. package/dist/runtime/builtins/triggers/webhook.d.ts +14 -1
  164. package/dist/runtime/builtins/triggers/webhook.js +116 -30
  165. package/dist/runtime/builtins/triggers/webhook.js.map +1 -1
  166. package/dist/runtime/describe.d.ts +23 -0
  167. package/dist/runtime/describe.js +114 -0
  168. package/dist/runtime/describe.js.map +1 -0
  169. package/dist/runtime/executionResult.d.ts +1 -0
  170. package/dist/runtime/executor.js +82 -5
  171. package/dist/runtime/executor.js.map +1 -1
  172. package/dist/runtime/graphIssues.d.ts +20 -0
  173. package/dist/runtime/graphIssues.js +290 -0
  174. package/dist/runtime/graphIssues.js.map +1 -0
  175. package/dist/runtime/graphVersion.d.ts +2 -0
  176. package/dist/runtime/graphVersion.js +43 -0
  177. package/dist/runtime/graphVersion.js.map +1 -0
  178. package/dist/runtime/nodeKinds.d.ts +4 -4
  179. package/dist/runtime/nodeKinds.js +1 -2
  180. package/dist/runtime/nodeKinds.js.map +1 -1
  181. package/dist/runtime/registry.d.ts +2 -1
  182. package/dist/runtime/registry.js +1 -2
  183. package/dist/runtime/registry.js.map +1 -1
  184. package/dist/runtime/resolveInputs.d.ts +3 -1
  185. package/dist/runtime/resolveInputs.js +12 -2
  186. package/dist/runtime/resolveInputs.js.map +1 -1
  187. package/dist/runtime/resolveSubgraph.d.ts +12 -1
  188. package/dist/runtime/resolveSubgraph.js +36 -0
  189. package/dist/runtime/resolveSubgraph.js.map +1 -1
  190. package/dist/runtime/retention.d.ts +6 -0
  191. package/dist/runtime/retention.js +54 -0
  192. package/dist/runtime/retention.js.map +1 -0
  193. package/dist/runtime/runProcedure.d.ts +12 -0
  194. package/dist/runtime/runProcedure.js +130 -0
  195. package/dist/runtime/runProcedure.js.map +1 -0
  196. package/dist/runtime/schedule.d.ts +2 -0
  197. package/dist/runtime/schedule.js +139 -0
  198. package/dist/runtime/schedule.js.map +1 -0
  199. package/dist/runtime/subscriptions.d.ts +11 -1
  200. package/dist/runtime/subscriptions.js +91 -125
  201. package/dist/runtime/subscriptions.js.map +1 -1
  202. package/dist/runtime/subwalk.js +2 -3
  203. package/dist/runtime/subwalk.js.map +1 -1
  204. package/dist/runtime/templateUsages.d.ts +4 -0
  205. package/dist/runtime/templateUsages.js +102 -0
  206. package/dist/runtime/templateUsages.js.map +1 -0
  207. package/dist/runtime/topo.d.ts +1 -0
  208. package/dist/runtime/topo.js +23 -0
  209. package/dist/runtime/topo.js.map +1 -1
  210. package/dist/runtime/trace.d.ts +44 -0
  211. package/dist/runtime/trace.js +240 -0
  212. package/dist/runtime/trace.js.map +1 -0
  213. package/dist/runtime/typeSwitches.d.ts +3 -0
  214. package/dist/runtime/typeSwitches.js +27 -0
  215. package/dist/runtime/typeSwitches.js.map +1 -0
  216. package/dist/runtime/validate.d.ts +11 -0
  217. package/dist/runtime/validate.js +118 -61
  218. package/dist/runtime/validate.js.map +1 -1
  219. package/dist/runtime/webhookRoutes.d.ts +4 -0
  220. package/dist/runtime/webhookRoutes.js +68 -0
  221. package/dist/runtime/webhookRoutes.js.map +1 -0
  222. package/dist/runtime/withTimeout.d.ts +1 -0
  223. package/dist/runtime/withTimeout.js +17 -0
  224. package/dist/runtime/withTimeout.js.map +1 -0
  225. package/dist/runtime/wording.d.ts +10 -0
  226. package/dist/runtime/wording.js +118 -0
  227. package/dist/runtime/wording.js.map +1 -0
  228. package/dist/stats/health-banner.d.ts +13 -0
  229. package/dist/stats/health-banner.js +149 -0
  230. package/dist/stats/health-banner.js.map +1 -0
  231. package/dist/stats/health.d.ts +49 -0
  232. package/dist/stats/health.js +130 -0
  233. package/dist/stats/health.js.map +1 -0
  234. package/dist/stats/kpi.d.ts +21 -0
  235. package/dist/stats/kpi.js +101 -0
  236. package/dist/stats/kpi.js.map +1 -0
  237. package/dist/stats/overview.d.ts +94 -0
  238. package/dist/stats/overview.js +244 -0
  239. package/dist/stats/overview.js.map +1 -0
  240. package/dist/types/constants.d.ts +0 -1
  241. package/dist/types/constants.js +1 -2
  242. package/dist/types/constants.js.map +1 -1
  243. package/dist/types/runLog.d.ts +2 -0
  244. package/dist/types/runLog.js +4 -0
  245. package/dist/types/runLog.js.map +1 -1
  246. package/frontend-vue/app/components/AttentionList.vue +276 -0
  247. package/frontend-vue/app/components/Catalog/SchemaTable.vue +127 -0
  248. package/frontend-vue/app/components/Catalog.vue +457 -0
  249. package/frontend-vue/app/components/Editor/BottomDock.vue +188 -0
  250. package/frontend-vue/app/components/Editor/BuilderPalette.vue +101 -45
  251. package/frontend-vue/app/components/Editor/GraphCanvas.vue +818 -206
  252. package/frontend-vue/app/components/Editor/GroupPortEditor.vue +29 -18
  253. package/frontend-vue/app/components/Editor/JsonField.vue +3 -3
  254. package/frontend-vue/app/components/Editor/NewProcedureDialog.vue +108 -0
  255. package/frontend-vue/app/components/Editor/NodeInspector.vue +373 -101
  256. package/frontend-vue/app/components/Editor/ProcedureSwitcher.vue +147 -0
  257. package/frontend-vue/app/components/Editor/RunNowDialog.vue +145 -0
  258. package/frontend-vue/app/components/Editor/WiredField.vue +3 -3
  259. package/frontend-vue/app/components/Editor/nodes/GenericNode.vue +97 -91
  260. package/frontend-vue/app/components/Editor/nodes/GroupNode.vue +5 -6
  261. package/frontend-vue/app/components/Editor/nodes/GroupSentinel.vue +3 -2
  262. package/frontend-vue/app/components/Editor/nodes/styles.ts +14 -18
  263. package/frontend-vue/app/components/Editor.vue +1894 -705
  264. package/frontend-vue/app/components/IconPicker.vue +122 -0
  265. package/frontend-vue/app/components/LiveTopics.vue +20 -0
  266. package/frontend-vue/app/components/Run/RunCompare.vue +115 -0
  267. package/frontend-vue/app/components/Run/RunFailure.vue +54 -0
  268. package/frontend-vue/app/components/Run/RunLogList.vue +167 -0
  269. package/frontend-vue/app/components/Run/RunPathTaken.vue +139 -0
  270. package/frontend-vue/app/components/Run/RunPayload.vue +85 -0
  271. package/frontend-vue/app/components/Run/RunWaterfall.vue +374 -0
  272. package/frontend-vue/app/components/RunPeek.vue +132 -0
  273. package/frontend-vue/app/components/RunTrace.vue +462 -0
  274. package/frontend-vue/app/components/Templates.vue +382 -537
  275. package/frontend-vue/app/components/WebhookEndpoint.vue +81 -0
  276. package/frontend-vue/app/composables/useAutomationNodeKinds.ts +23 -6
  277. package/frontend-vue/app/composables/useAutomationRuns.ts +160 -25
  278. package/frontend-vue/app/composables/useGraphConnect.ts +103 -51
  279. package/frontend-vue/app/composables/useRunActions.ts +60 -0
  280. package/frontend-vue/app/plugins/cell-displays.ts +169 -0
  281. package/frontend-vue/app/utils/automation.ts +4 -36
  282. package/frontend-vue/app/utils/describe.ts +252 -0
  283. package/frontend-vue/app/utils/redactedHeaders.ts +31 -0
  284. package/frontend-vue/dms.frontend.build.ts +7 -0
  285. package/frontend-vue/dms.frontend.ts +7 -4
  286. package/frontend-vue/i18n/locales/dms-automation-en-GB.json +1149 -309
  287. package/frontend-vue/i18n/locales/dms-automation-fr-FR.json +1154 -314
  288. package/frontend-vue/package.json +1 -1
  289. package/package.json +8 -6
  290. package/dist/db/models/type_config.model.d.ts +0 -47
  291. package/dist/db/models/type_config.model.js +0 -51
  292. package/dist/db/models/type_config.model.js.map +0 -1
  293. package/dist/db/tables/action_type_config.table.d.ts +0 -7
  294. package/dist/db/tables/action_type_config.table.js +0 -35
  295. package/dist/db/tables/action_type_config.table.js.map +0 -1
  296. package/dist/db/tables/trigger_type_config.table.d.ts +0 -7
  297. package/dist/db/tables/trigger_type_config.table.js.map +0 -1
  298. package/frontend-vue/app/components/Actions.vue +0 -151
  299. package/frontend-vue/app/components/Catalog/TypeConfigForm.vue +0 -170
  300. package/frontend-vue/app/components/Catalog/TypeList.vue +0 -203
  301. package/frontend-vue/app/components/DataNodes.vue +0 -275
  302. package/frontend-vue/app/components/Editor/ProcedureList.vue +0 -156
  303. package/frontend-vue/app/components/Editor/RunsDrawer.vue +0 -312
  304. package/frontend-vue/app/components/Library.vue +0 -69
  305. package/frontend-vue/app/components/Overview.vue +0 -503
  306. package/frontend-vue/app/components/RunDetailDrawer.vue +0 -165
  307. package/frontend-vue/app/components/RunFireTree.vue +0 -170
  308. package/frontend-vue/app/components/RunTraceDrawer.vue +0 -59
  309. package/frontend-vue/app/components/RunsStats.vue +0 -126
  310. package/frontend-vue/app/components/RunsTimelineDisplay.vue +0 -287
  311. package/frontend-vue/app/components/Triggers.vue +0 -147
  312. package/frontend-vue/app/plugins/runs-timeline-display.client.ts +0 -16
@@ -1,11 +1,14 @@
1
1
  <script setup lang="ts">
2
- import { computed, ref, watch } from 'vue'
3
- import { unwrapList } from '../utils/automation'
2
+ import { computed, nextTick, onMounted, ref, useTemplateRef, watch } from 'vue'
3
+ import { isIconName } from './IconPicker.vue'
4
+ import { queryString } from '../utils/automation'
4
5
 
5
- // `embedded` drops the page-head when this catalog is rendered inside a Library tab.
6
- defineProps<{ embedded?: boolean }>()
6
+ // The library's templates: reusable groups other procedures place as linked
7
+ // blocks. The detail edits the name, icon and description, lists the ports
8
+ // (edited inside the graph) and where the template is used — procedures and
9
+ // other templates; deleting forks every usage into a local group so they keep
10
+ // working. The picked template is kept in the URL (`?template=`).
7
11
 
8
- // JSON Schema allows `type` to be a single name or a list (`["string", "null"]`).
9
12
  interface JsonSchema {
10
13
  type?: string | string[]
11
14
  [key: string]: unknown
@@ -26,651 +29,493 @@ interface TemplateRow {
26
29
  ports: TemplatePort[]
27
30
  subgraph: unknown
28
31
  usageCount?: number
29
- created_at?: string | Date
30
- updated_at?: string | Date
31
- }
32
-
33
- interface TemplateListResponse {
34
- results: TemplateRow[]
35
- total: number
36
- page: number
37
- limit: number
32
+ updated_at?: string
38
33
  }
39
34
 
40
35
  interface TemplateUsage {
41
36
  procedureId: string
42
37
  nodeId: string
38
+ groupPath: string[]
43
39
  }
44
40
 
45
- interface ProcedureRow {
46
- _id: string
47
- name: string
41
+ interface TemplateNesting {
42
+ templateId: string
43
+ nodeId: string
44
+ groupPath: string[]
45
+ }
46
+
47
+ interface TemplateUsages {
48
+ procedures: TemplateUsage[]
49
+ templates: TemplateNesting[]
48
50
  }
49
51
 
50
- interface ProcedureListResponse {
51
- results: ProcedureRow[]
52
+ interface ProcedureSummary {
53
+ procedureId: string
54
+ name: string
55
+ status: 'failing' | 'degraded' | 'healthy' | 'paused' | 'draft'
52
56
  }
53
57
 
58
+ const props = defineProps<{
59
+ apiUrl: string
60
+ builderUrl: string
61
+ }>()
62
+
54
63
  const DEFAULT_ICON = 'i-ph-package'
64
+ const STATE_TONES = {
65
+ failing: 'error',
66
+ degraded: 'warning',
67
+ healthy: 'success',
68
+ paused: 'neutral',
69
+ draft: 'info',
70
+ } as const
71
+ const NO_USAGES: TemplateUsages = { procedures: [], templates: [] }
55
72
 
56
73
  const { $authFetch } = useAuthFetch()
74
+ const route = useDmsRoute()
57
75
  const router = useDmsRouter()
58
76
  const toast = useToast()
77
+ const { t } = useI18n()
78
+ const { confirm } = useConfirm()
59
79
 
60
80
  const items = ref<TemplateRow[]>([])
61
- const loading = ref(false)
81
+ /** How many templates exist, when the server sent fewer than that. */
82
+ const total = ref(0)
83
+ const loading = ref(true)
62
84
  const loadError = ref<string | null>(null)
63
85
  const selectedId = ref<string | null>(null)
86
+ const search = ref('')
87
+ const detail = useTemplateRef<HTMLElement>('detail')
88
+ const list = useTemplateRef<HTMLElement>('list')
64
89
 
65
- // Form state for the currently selected template.
66
90
  const formName = ref('')
67
91
  const formDescription = ref('')
68
92
  const formIcon = ref(DEFAULT_ICON)
69
93
  const saving = ref(false)
70
- const saveError = ref<string | null>(null)
71
94
 
72
- // Usages panel state.
73
- const usages = ref<TemplateUsage[]>([])
95
+ const usages = ref<TemplateUsages>(NO_USAGES)
74
96
  const usagesLoading = ref(false)
75
- const usagesError = ref<string | null>(null)
76
- const procedureNames = ref<Map<string, string>>(new Map())
97
+ const procedures = ref<Map<string, ProcedureSummary>>(new Map())
77
98
 
78
- // Delete-confirm state.
79
- const deleteOpen = ref(false)
80
- const deleting = ref(false)
81
- const deleteError = ref<string | null>(null)
99
+ function queryTemplate(): string | null {
100
+ return queryString(route.query.template)
101
+ }
82
102
 
83
103
  async function loadList() {
84
104
  loading.value = true
85
- loadError.value = null
86
105
  try {
87
- const data = await $authFetch<TemplateListResponse | TemplateRow[]>(
88
- '/api/automation/templates',
89
- )
90
- const list = unwrapList<TemplateRow>(data)
106
+ const { results: list, total: count } = await $authFetch<{ results: TemplateRow[]; total: number }>(`${props.apiUrl}/templates`)
91
107
  items.value = list
92
- // Keep current selection if it still exists, otherwise pick the first.
93
- if (selectedId.value && !list.find((t) => t._id === selectedId.value)) {
94
- selectedId.value = list[0]?._id ?? null
95
- } else if (!selectedId.value) {
96
- selectedId.value = list[0]?._id ?? null
97
- }
108
+ total.value = count
109
+ const wanted = selectedId.value ?? queryTemplate()
110
+ selectedId.value = list.some((x) => x._id === wanted) ? wanted : (sortedItems.value[0]?._id ?? null)
111
+ loadError.value = null
98
112
  } catch (e) {
99
- loadError.value = (e as Error).message ?? 'Failed to load templates'
113
+ loadError.value = describeApiError(e)
100
114
  } finally {
101
115
  loading.value = false
102
116
  }
103
117
  }
104
118
 
105
- await loadList()
106
-
107
- // Lazily fetch the procedure list once so we can resolve procedureId -> name
108
- // in the "Used in" panel. If the fetch fails, we silently fall back to showing
109
- // the raw id (still wrapped in a link to the editor).
110
- async function ensureProcedureNames() {
111
- if (procedureNames.value.size > 0) return
119
+ async function loadProcedures() {
112
120
  try {
113
- const data = await $authFetch<ProcedureListResponse | ProcedureRow[]>(
114
- '/api/automation/procedures?limit=100000',
115
- )
116
- const list = unwrapList<ProcedureRow>(data)
117
- const map = new Map<string, string>()
118
- for (const p of list) map.set(p._id, p.name)
119
- procedureNames.value = map
121
+ const rows = await $authFetch<ProcedureSummary[]>(`${props.apiUrl}/procedures/summary`)
122
+ procedures.value = new Map(rows.map((p) => [p.procedureId, p]))
120
123
  } catch {
121
- // Non-fatal: keep the map empty so we fall back to ids.
124
+ procedures.value = new Map()
122
125
  }
123
126
  }
124
127
 
125
- const selected = computed<TemplateRow | null>(
126
- () => items.value.find((t) => t._id === selectedId.value) ?? null,
127
- )
128
+ onMounted(() => {
129
+ void loadList()
130
+ void loadProcedures()
131
+ })
128
132
 
129
- // Search filter applied to the rail.
130
- const search = ref('')
131
- const filteredItems = computed<TemplateRow[]>(() => {
133
+ const selected = computed(() => items.value.find((x) => x._id === selectedId.value) ?? null)
134
+ const templateNames = computed(() => new Map(items.value.map((x) => [x._id, x.name])))
135
+
136
+ const sortedItems = computed(() => [...items.value].sort((a, b) => a.name.localeCompare(b.name)))
137
+ const filteredItems = computed(() => {
132
138
  const q = search.value.trim().toLowerCase()
133
- if (!q) return items.value
134
- return items.value.filter(
135
- (t) =>
136
- t.name.toLowerCase().includes(q) ||
137
- (t.description ?? '').toLowerCase().includes(q),
138
- )
139
+ if (!q) return sortedItems.value
140
+ return sortedItems.value.filter((x) => x.name.toLowerCase().includes(q) || (x.description ?? '').toLowerCase().includes(q))
141
+ })
142
+
143
+ // A malformed icon is said under the picker; it can't be saved.
144
+ const iconValid = computed(() => !formIcon.value || isIconName(formIcon.value))
145
+
146
+ const dirty = computed(() => {
147
+ const s = selected.value
148
+ if (!s) return false
149
+ return formName.value !== s.name || formDescription.value !== (s.description ?? '') || formIcon.value !== (s.icon || DEFAULT_ICON)
139
150
  })
140
151
 
141
- // Sync form fields whenever the selection changes.
152
+ // Picking another template, leaving the page or the tab asks before the
153
+ // form's unsaved changes are lost.
154
+ const form = useTemplateRef<HTMLElement>('form')
155
+ const { confirmLeave } = useUnsavedChanges({ dirty, element: form })
156
+
142
157
  watch(
143
158
  selected,
144
- (t) => {
145
- formName.value = t?.name ?? ''
146
- formDescription.value = t?.description ?? ''
147
- formIcon.value = t?.icon || DEFAULT_ICON
148
- saveError.value = null
149
- // Reload usages for the new selection.
159
+ (s) => {
160
+ formName.value = s?.name ?? ''
161
+ formDescription.value = s?.description ?? ''
162
+ formIcon.value = s?.icon || DEFAULT_ICON
150
163
  void loadUsages()
151
164
  },
152
165
  { immediate: true },
153
166
  )
154
167
 
155
- async function loadUsages() {
156
- const t = selected.value
157
- if (!t) {
158
- usages.value = []
159
- usagesError.value = null
160
- return
168
+ watch(selectedId, (id) => {
169
+ if (id && id !== queryTemplate()) void router.replace({ query: { ...route.query, template: id } })
170
+ })
171
+
172
+ async function select(id: string) {
173
+ if (id === selectedId.value || !(await confirmLeave())) return
174
+ selectedId.value = id
175
+ // Below the two-column width the detail sits under the list: bring it into view.
176
+ await nextTick()
177
+ if (detail.value && list.value && detail.value.offsetTop > list.value.offsetTop) {
178
+ detail.value.scrollIntoView({ behavior: 'smooth', block: 'start' })
161
179
  }
180
+ }
181
+
182
+ function backToList() {
183
+ list.value?.scrollIntoView({ behavior: 'smooth', block: 'start' })
184
+ }
185
+
186
+ async function fetchUsages(id: string): Promise<TemplateUsages> {
187
+ return await $authFetch<TemplateUsages>(`${props.apiUrl}/templates/${id}/usages`)
188
+ }
189
+
190
+ async function loadUsages() {
191
+ const s = selected.value
192
+ usages.value = NO_USAGES
193
+ if (!s) return
162
194
  usagesLoading.value = true
163
- usagesError.value = null
164
195
  try {
165
- const data = await $authFetch<TemplateUsage[]>(
166
- `/api/automation/templates/${t._id}/usages`,
167
- )
168
- usages.value = unwrapList(data)
169
- if (usages.value.length > 0) {
170
- await ensureProcedureNames()
171
- }
172
- } catch (e) {
173
- usagesError.value = (e as Error).message ?? 'Failed to load usages'
174
- usages.value = []
196
+ usages.value = await fetchUsages(s._id)
197
+ } catch {
198
+ usages.value = NO_USAGES
175
199
  } finally {
176
200
  usagesLoading.value = false
177
201
  }
178
202
  }
179
203
 
180
- function procedureLabel(id: string): string {
181
- return procedureNames.value.get(id) ?? id
204
+ /** One line per procedure or template placing it, with how many times. */
205
+ const usageRows = computed(() => {
206
+ const rows = new Map<string, { kind: 'procedure' | 'template'; id: string; first: TemplateUsage | TemplateNesting; count: number }>()
207
+ for (const usage of usages.value.procedures) {
208
+ const row = rows.get(`p:${usage.procedureId}`)
209
+ if (row) row.count++
210
+ else rows.set(`p:${usage.procedureId}`, { kind: 'procedure', id: usage.procedureId, first: usage, count: 1 })
211
+ }
212
+ for (const nesting of usages.value.templates) {
213
+ const row = rows.get(`t:${nesting.templateId}`)
214
+ if (row) row.count++
215
+ else rows.set(`t:${nesting.templateId}`, { kind: 'template', id: nesting.templateId, first: nesting, count: 1 })
216
+ }
217
+ return [...rows.values()]
218
+ })
219
+
220
+ const NAME_ID = 'template-name'
221
+ const NAME_MAX = 200
222
+ const DESCRIPTION_MAX = 2000
223
+ // A missing or taken name shows under its field; a refused save is a toast.
224
+ const fieldErrors = useFieldErrors({ fields: { name: NAME_ID } })
225
+ watch(formName, () => fieldErrors.clear('name'))
226
+
227
+ interface RefusalBody {
228
+ code?: string
229
+ error?: string
230
+ issues?: { path?: (string | number)[]; message?: string }[]
231
+ }
232
+
233
+ /** The `code` a refused request answered with, if any. */
234
+ function errorCode(e: unknown): string | undefined {
235
+ return (e as { data?: RefusalBody }).data?.code
182
236
  }
183
237
 
184
- function procedureLink(id: string): string {
185
- return `/modules/automation/builder?selected=${encodeURIComponent(id)}`
238
+ /** What the server said was wrong, rather than the request's raw status line. */
239
+ function errorMessage(e: unknown): string {
240
+ const body = (e as { data?: RefusalBody }).data
241
+ const issues = body?.issues?.map((i) => (i.path?.length ? `${i.path.join('.')}: ${i.message}` : i.message)).filter(Boolean)
242
+ return issues?.length ? issues.join(' · ') : (body?.error ?? describeApiError(e))
186
243
  }
187
244
 
188
245
  async function onSave() {
189
- const t = selected.value
190
- if (!t) return
246
+ const s = selected.value
247
+ if (!s) return
248
+ if (!formName.value.trim()) {
249
+ await fieldErrors.setError('name', t('dms_automation.templates.form.nameRequired'))
250
+ return
251
+ }
191
252
  saving.value = true
192
- saveError.value = null
193
253
  try {
194
- // PUT is required to send the full template body (including ports +
195
- // subgraph) since the route revalidates the whole graph. We forward
196
- // the existing ports/subgraph unchanged — only the metadata changes.
197
- const body = {
198
- name: formName.value.trim() || t.name,
199
- description: formDescription.value,
200
- icon: formIcon.value || DEFAULT_ICON,
201
- ports: t.ports ?? [],
202
- subgraph: t.subgraph ?? {
203
- nodes: [],
204
- triggerEdges: [],
205
- dataEdges: [],
254
+ const updated = await $authFetch<TemplateRow>(`${props.apiUrl}/templates/${s._id}`, {
255
+ method: 'PUT',
256
+ body: {
257
+ name: formName.value.trim(),
258
+ description: formDescription.value,
259
+ icon: formIcon.value || DEFAULT_ICON,
260
+ ports: s.ports ?? [],
261
+ subgraph: s.subgraph ?? { nodes: [], triggerEdges: [], dataEdges: [] },
206
262
  },
207
- }
208
- const updated = await $authFetch<TemplateRow>(
209
- `/api/automation/templates/${t._id}`,
210
- { method: 'PUT', body },
211
- )
212
- const idx = items.value.findIndex((x) => x._id === t._id)
213
- if (idx >= 0) {
214
- items.value[idx] = {
215
- ...t,
216
- ...updated,
217
- usageCount: t.usageCount,
218
- }
219
- }
220
- toast.add({
221
- title: 'Template saved',
222
- description: updated.name,
223
- color: 'success',
224
- icon: 'i-ph-check-circle',
225
263
  })
264
+ const index = items.value.findIndex((x) => x._id === s._id)
265
+ if (index >= 0) items.value[index] = { ...s, ...updated, usageCount: s.usageCount }
266
+ toast.add({ title: t('dms_automation.templates.saved', { name: updated.name }), color: 'success', icon: 'i-ph-check-circle' })
226
267
  } catch (e) {
227
- saveError.value = (e as Error).message ?? 'Failed to save'
228
- toast.add({
229
- title: 'Failed to save template',
230
- description: (e as Error).message ?? '',
231
- color: 'error',
232
- icon: 'i-ph-warning',
233
- })
268
+ if (errorCode(e) === 'name-taken') {
269
+ await fieldErrors.setError('name', t('dms_automation.templates.nameTaken'))
270
+ return
271
+ }
272
+ toast.add({ title: t('dms_automation.templates.saveError'), description: errorMessage(e), color: 'error', icon: 'i-ph-warning' })
234
273
  } finally {
235
274
  saving.value = false
236
275
  }
237
276
  }
238
277
 
239
- function onEditSubgraph() {
240
- const t = selected.value
241
- if (!t) return
242
- router.push({
243
- path: '/modules/automation/builder',
244
- query: { template: t._id },
245
- })
278
+ function editGraph(id: string) {
279
+ void router.push(`${props.builderUrl}?template=${id}`)
246
280
  }
247
281
 
248
- function openDelete() {
249
- deleteError.value = null
250
- deleteOpen.value = true
282
+ function openUsage(usage: TemplateUsage) {
283
+ const path = usage.groupPath.length ? `&path=${usage.groupPath.map(encodeURIComponent).join(',')}` : ''
284
+ void router.push(`${props.builderUrl}?selected=${usage.procedureId}&node=${encodeURIComponent(usage.nodeId)}${path}`)
251
285
  }
252
286
 
253
- async function confirmDelete(force: boolean) {
254
- const t = selected.value
255
- if (!t) return
256
- deleting.value = true
257
- deleteError.value = null
287
+ async function onDelete() {
288
+ const s = selected.value
289
+ if (!s) return
290
+ // Counted now, not when the list loaded: a usage added since is forked too.
291
+ let fresh: TemplateUsages
258
292
  try {
259
- const url = force
260
- ? `/api/automation/templates/${t._id}?force=1`
261
- : `/api/automation/templates/${t._id}`
262
- await $authFetch(url, { method: 'DELETE' })
293
+ fresh = await fetchUsages(s._id)
294
+ usages.value = fresh
295
+ } catch (e) {
296
+ toast.add({ title: t('dms_automation.templates.deleteError'), description: errorMessage(e), color: 'error', icon: 'i-ph-warning' })
297
+ return
298
+ }
299
+ const count = fresh.procedures.length + fresh.templates.length
300
+ const ok = await confirm({
301
+ title: t('dms_automation.templates.deleteTitle', { name: s.name }),
302
+ description: count > 0 ? t('dms_automation.templates.deleteForksIn', { owners: ownersOf(fresh), count }, count) : t('dms_automation.templates.unused'),
303
+ color: 'error',
304
+ icon: 'i-ph-trash',
305
+ confirmLabel: t('dms_automation.templates.delete'),
306
+ })
307
+ if (!ok) return
308
+ try {
309
+ await $authFetch(`${props.apiUrl}/templates/${s._id}?force=1`, { method: 'DELETE' })
310
+ } catch (e) {
311
+ const kept = errorCode(e) === 'fork-incomplete'
263
312
  toast.add({
264
- title: 'Template deleted',
265
- description: t.name,
266
- color: 'success',
267
- icon: 'i-ph-check-circle',
313
+ title: kept ? t('dms_automation.templates.forkIncomplete') : t('dms_automation.templates.deleteError'),
314
+ description: kept ? t('dms_automation.templates.forkIncompleteHint') : errorMessage(e),
315
+ color: 'error',
316
+ icon: 'i-ph-warning',
268
317
  })
269
- deleteOpen.value = false
270
- // Drop from list, pick a new selection.
271
- items.value = items.value.filter((x) => x._id !== t._id)
272
- selectedId.value = items.value[0]?._id ?? null
273
- } catch (e) {
274
- deleteError.value = (e as Error).message ?? 'Failed to delete'
275
- } finally {
276
- deleting.value = false
318
+ await loadUsages()
319
+ return
277
320
  }
321
+ toast.add({ title: t('dms_automation.templates.deleted', { name: s.name }), color: 'success', icon: 'i-ph-check-circle' })
322
+ items.value = items.value.filter((x) => x._id !== s._id)
323
+ total.value = Math.max(0, total.value - 1)
324
+ selectedId.value = sortedItems.value[0]?._id ?? null
325
+ // Forking may have changed other templates' graphs and usage counts.
326
+ void loadList()
278
327
  }
279
328
 
280
- function portRowKey(p: TemplatePort, idx: number): string {
281
- return `${p.direction}-${p.kind}-${p.name}-${idx}`
329
+ /** "1 procedure", "2 procedures and 1 template": who places the template. */
330
+ function ownersOf(found: TemplateUsages): string {
331
+ const procedureCount = new Set(found.procedures.map((u) => u.procedureId)).size
332
+ const templateCount = new Set(found.templates.map((u) => u.templateId)).size
333
+ const parts = [
334
+ procedureCount ? t('dms_automation.templates.ownerProcedures', { count: procedureCount }, procedureCount) : '',
335
+ templateCount ? t('dms_automation.templates.ownerTemplates', { count: templateCount }, templateCount) : '',
336
+ ].filter(Boolean)
337
+ return parts.length === 2 ? t('dms_automation.templates.ownersAnd', { first: parts[0], second: parts[1] }) : parts[0]!
282
338
  }
283
339
 
284
340
  function schemaTypeOf(p: TemplatePort): string {
285
341
  if (p.kind !== 'data') return '—'
286
- const t = p.schema?.type
287
- if (typeof t === 'string') return t
288
- if (Array.isArray(t)) return t.join(' | ')
342
+ const type = p.schema?.type
343
+ if (typeof type === 'string') return type
344
+ if (Array.isArray(type)) return type.join(' | ')
289
345
  return 'any'
290
346
  }
291
347
  </script>
292
348
 
293
349
  <template>
294
- <!-- Embedded in the library page, which fills the panel: from `lg` up the
295
- list and the detail share the height and scroll inside; below, where
296
- they stack, the catalog scrolls as a whole. -->
297
- <div
298
- :class="
299
- embedded
300
- ? 'flex min-h-0 flex-1 flex-col gap-5 max-lg:overflow-y-auto'
301
- : 'flex flex-col gap-6 p-4 sm:p-6'
302
- "
303
- >
304
- <section v-if="!embedded" class="flex flex-wrap items-center gap-4">
305
- <div
306
- class="grid size-11 shrink-0 place-items-center rounded-xl bg-primary/10 text-primary ring ring-primary/20"
307
- >
308
- <UIcon name="i-ph-package" class="size-6" />
309
- </div>
310
- <div class="min-w-0 flex-1">
311
- <h1 class="text-2xl font-semibold tracking-tight text-highlighted">
312
- {{ $t('dms_automation.templates.title') }}
313
- </h1>
314
- <p class="text-sm text-muted">
315
- {{ $t('dms_automation.templates.description') }}
316
- </p>
317
- </div>
318
- <UButton
319
- class="ml-auto"
320
- color="neutral"
321
- variant="outline"
322
- icon="i-ph-arrows-clockwise"
323
- :loading="loading"
324
- @click="loadList"
325
- >
326
- {{ $t('dms_automation.templates.refresh') }}
327
- </UButton>
328
- </section>
329
-
330
- <UAlert
331
- v-if="loadError"
332
- color="error"
333
- variant="subtle"
334
- icon="i-ph-warning"
335
- :title="$t('dms_automation.templates.loadError')"
336
- :description="loadError"
337
- />
338
-
339
- <div
340
- class="grid grid-cols-1 gap-5 lg:min-h-0 lg:flex-1 lg:grid-cols-[minmax(280px,360px)_1fr]"
341
- >
342
- <div class="flex flex-col gap-3 lg:min-h-0">
343
- <UInput
344
- v-model="search"
345
- icon="i-ph-magnifying-glass"
346
- :placeholder="$t('dms_automation.templates.search')"
350
+ <div class="@container">
351
+ <div class="grid grid-cols-1 items-start gap-5 @5xl:grid-cols-[20rem_minmax(0,1fr)]">
352
+ <div ref="list" class="dms-card flex flex-col gap-2 p-2">
353
+ <DmsSearchInput v-model="search" size="sm" :placeholder="$t('dms_automation.templates.search')" class="w-full" />
354
+ <div v-if="loading && items.length === 0" class="flex flex-col gap-2 p-1">
355
+ <USkeleton v-for="i in 3" :key="i" class="h-12 w-full" />
356
+ </div>
357
+ <DmsEmptyState
358
+ v-else-if="loadError"
359
+ size="sm"
360
+ variant="error"
361
+ :title="$t('dms_automation.templates.loadError')"
362
+ :description="loadError"
363
+ :actions="[{ label: $t('dms_automation.common.retry'), onClick: loadList }]"
347
364
  />
348
- <DmsCard
349
- :padded="false"
350
- class="flex flex-col overflow-hidden lg:min-h-0 lg:flex-1"
351
- >
352
- <div
353
- v-if="items.length === 0"
354
- class="px-3 py-6 text-center text-sm text-dimmed"
365
+ <DmsEmptyState
366
+ v-else-if="items.length === 0"
367
+ size="sm"
368
+ icon="i-ph-stack"
369
+ :title="$t('dms_automation.templates.empty')"
370
+ :description="$t('dms_automation.templates.emptyHint')"
371
+ />
372
+ <template v-else>
373
+ <button
374
+ v-for="row in filteredItems"
375
+ :key="row._id"
376
+ type="button"
377
+ class="flex w-full items-start gap-3 rounded-md border px-3 py-2.5 text-left transition-colors"
378
+ :class="row._id === selectedId ? 'border-primary bg-primary/10' : 'border-transparent hover:bg-elevated'"
379
+ :aria-current="row._id === selectedId ? 'true' : undefined"
380
+ @click="select(row._id)"
355
381
  >
356
- {{ $t('dms_automation.templates.empty') }}
357
- </div>
358
- <ul v-else class="flex flex-col gap-1 overflow-y-auto p-2">
359
- <li v-for="t in filteredItems" :key="t._id">
360
- <button
361
- type="button"
362
- class="flex w-full items-start gap-3 rounded-lg px-3 py-2 text-left transition-colors"
363
- :class="
364
- selectedId === t._id
365
- ? 'bg-primary/10 text-primary ring-1 ring-primary/20'
366
- : 'text-toned hover:bg-elevated/60'
367
- "
368
- @click="selectedId = t._id"
369
- >
370
- <UIcon
371
- :name="t.icon || DEFAULT_ICON"
372
- class="mt-0.5 size-4 shrink-0"
373
- :class="selectedId === t._id ? 'text-primary' : 'text-dimmed'"
374
- />
375
- <div class="min-w-0 flex-1">
376
- <div
377
- class="truncate text-sm font-medium"
378
- :class="selectedId === t._id ? 'text-primary' : 'text-highlighted'"
379
- >
380
- {{ t.name }}
381
- </div>
382
- <div v-if="t.description" class="truncate text-xs text-muted">
383
- {{ t.description }}
384
- </div>
385
- </div>
386
- <UBadge
387
- color="neutral"
388
- variant="subtle"
389
- size="sm"
390
- class="shrink-0 tabular-nums"
391
- >
392
- {{ t.usageCount ?? 0 }}
393
- </UBadge>
394
- </button>
395
- </li>
396
- </ul>
397
- </DmsCard>
382
+ <UIcon :name="row.icon || DEFAULT_ICON" class="mt-0.5 size-4 shrink-0 text-muted" />
383
+ <span class="flex min-w-0 flex-1 flex-col">
384
+ <span class="truncate text-sm font-medium text-highlighted">{{ row.name }}</span>
385
+ <span v-if="row.description" class="truncate text-xs text-muted">{{ row.description }}</span>
386
+ </span>
387
+ <span class="shrink-0 font-mono text-[11px] text-dimmed">{{ $t('dms_automation.library.uses', { count: row.usageCount ?? 0 }) }}</span>
388
+ </button>
389
+ <p v-if="filteredItems.length === 0" class="p-3 text-center text-xs text-dimmed">{{ $t('dms_automation.library.noMatch') }}</p>
390
+ <p v-if="total > items.length" class="p-3 text-center text-xs text-warning">
391
+ {{ $t('dms_automation.templates.truncated', { shown: items.length, total }) }}
392
+ </p>
393
+ </template>
398
394
  </div>
399
395
 
400
- <DmsCard
401
- v-if="selected"
402
- :padded="false"
403
- class="flex flex-col lg:min-h-0 lg:overflow-y-auto"
404
- >
405
- <div class="flex items-start gap-3 border-b border-default px-5 py-4 sm:px-6">
406
- <div
407
- class="grid size-10 shrink-0 place-items-center rounded-lg bg-primary/10 text-primary ring ring-primary/20"
408
- >
409
- <UIcon :name="formIcon || DEFAULT_ICON" class="size-5" />
410
- </div>
411
- <div class="min-w-0 flex-1">
412
- <h2 class="truncate text-lg font-semibold text-highlighted">
413
- {{ selected.name }}
414
- </h2>
415
- <p class="mt-1 font-mono text-xs text-dimmed">{{ selected._id }}</p>
396
+ <div v-if="selected" ref="detail" class="flex scroll-mt-4 flex-col gap-4">
397
+ <UButton class="self-start @5xl:hidden" size="sm" variant="ghost" color="neutral" icon="i-ph-arrow-up" @click="backToList">
398
+ {{ $t('dms_automation.library.backToList') }}
399
+ </UButton>
400
+ <DmsCard>
401
+ <div class="flex flex-wrap items-start gap-4">
402
+ <DmsIconWell :icon="formIcon || DEFAULT_ICON" tone="primary" size="xl" />
403
+ <div class="flex min-w-0 flex-1 flex-col gap-1">
404
+ <h2 class="text-lg font-semibold break-words text-highlighted">{{ selected.name }}</h2>
405
+ <p class="font-mono text-xs break-all text-dimmed">{{ selected._id }}</p>
406
+ </div>
407
+ <UButton color="neutral" variant="outline" icon="i-ph-tree-structure" @click="editGraph(selected._id)">
408
+ {{ $t('dms_automation.templates.editGraph') }}
409
+ </UButton>
416
410
  </div>
417
- <UBadge color="neutral" variant="subtle" class="shrink-0">
418
- {{
419
- $t('dms_automation.templates.usedInN', {
420
- n: selected.usageCount ?? 0,
421
- })
422
- }}
423
- </UBadge>
424
- </div>
411
+ </DmsCard>
425
412
 
426
- <div class="flex flex-col gap-6 px-5 py-4 sm:px-6">
427
- <div class="flex flex-col gap-3">
428
- <UFormField
429
- :label="$t('dms_automation.templates.form.name')"
430
- required
431
- >
432
- <UInput v-model="formName" class="w-full" />
433
- </UFormField>
434
- <UFormField
435
- :label="$t('dms_automation.templates.form.description')"
436
- >
437
- <UTextarea v-model="formDescription" class="w-full" :rows="3" />
438
- </UFormField>
439
- <UFormField
440
- :label="$t('dms_automation.templates.form.icon')"
441
- :help="$t('dms_automation.templates.form.iconHelp')"
442
- >
443
- <UInput
444
- v-model="formIcon"
445
- :placeholder="DEFAULT_ICON"
446
- class="w-full"
447
- />
448
- </UFormField>
449
- <UAlert
450
- v-if="saveError"
451
- color="error"
452
- variant="subtle"
453
- icon="i-ph-warning"
454
- :title="$t('dms_automation.templates.saveError')"
455
- :description="saveError"
456
- />
457
- <div class="flex justify-end gap-2">
458
- <UButton
459
- color="primary"
460
- icon="i-ph-floppy-disk"
461
- :loading="saving"
462
- @click="onSave"
463
- >
464
- {{ $t('dms_automation.templates.save') }}
465
- </UButton>
413
+ <div ref="form">
414
+ <DmsCard :title="$t('dms_automation.templates.details')">
415
+ <div>
416
+ <DmsFieldRow layout="form" :label="$t('dms_automation.templates.form.name')" :label-for="NAME_ID" required>
417
+ <div class="grid gap-1.5">
418
+ <DmsInputText :id="NAME_ID" v-model="formName" class="w-full" :maxlength="NAME_MAX" v-bind="fieldErrors.aria('name')" />
419
+ <DmsFieldError :id="fieldErrors.errorId('name')" :message="fieldErrors.errors.name" />
420
+ </div>
421
+ </DmsFieldRow>
422
+ <DmsFieldRow layout="form" :label="$t('dms_automation.templates.form.description')" label-for="template-description">
423
+ <DmsTextarea id="template-description" v-model="formDescription" class="w-full" :rows="2" :maxlength="DESCRIPTION_MAX" />
424
+ </DmsFieldRow>
425
+ <DmsFieldRow layout="form" :label="$t('dms_automation.templates.form.icon')">
426
+ <DmsAutomationIconPicker v-model="formIcon" />
427
+ </DmsFieldRow>
428
+ <DmsFormRequiredLegend class="px-[18px] pt-3" />
466
429
  </div>
430
+ <template #footer>
431
+ <div class="flex w-full justify-end">
432
+ <UButton color="primary" icon="i-ph-floppy-disk" :disabled="!dirty || !iconValid" :loading="saving" @click="onSave">
433
+ {{ $t('dms_automation.common.save') }}
434
+ </UButton>
435
+ </div>
436
+ </template>
437
+ </DmsCard>
438
+ </div>
439
+
440
+ <DmsCard :title="$t('dms_automation.templates.ports.title')" :count="selected.ports?.length ?? 0">
441
+ <p class="mb-3 text-xs text-muted">{{ $t('dms_automation.templates.ports.editHint') }}</p>
442
+ <p v-if="(selected.ports ?? []).length === 0" class="text-xs text-dimmed">{{ $t('dms_automation.templates.ports.empty') }}</p>
443
+ <div v-else class="overflow-hidden rounded-md border border-default">
444
+ <table class="w-full text-left text-xs">
445
+ <thead class="bg-elevated/60 font-mono text-[10.5px] text-dimmed uppercase">
446
+ <tr>
447
+ <th class="px-3 py-1.5 font-normal">{{ $t('dms_automation.templates.ports.col.kind') }}</th>
448
+ <th class="px-3 py-1.5 font-normal">{{ $t('dms_automation.templates.ports.col.direction') }}</th>
449
+ <th class="px-3 py-1.5 font-normal">{{ $t('dms_automation.templates.ports.col.name') }}</th>
450
+ <th class="px-3 py-1.5 font-normal">{{ $t('dms_automation.templates.ports.col.type') }}</th>
451
+ </tr>
452
+ </thead>
453
+ <tbody class="divide-y divide-default">
454
+ <tr v-for="(port, index) in selected.ports" :key="`${port.direction}-${port.kind}-${port.name}-${index}`">
455
+ <td class="px-3 py-1.5">
456
+ <UBadge :color="port.kind === 'trigger' ? 'info' : 'success'" variant="subtle" size="sm">
457
+ {{ $t(`dms_automation.templates.ports.kind.${port.kind}`) }}
458
+ </UBadge>
459
+ </td>
460
+ <td class="px-3 py-1.5 text-muted">{{ $t(`dms_automation.templates.ports.direction.${port.direction}`) }}</td>
461
+ <td class="px-3 py-1.5 font-mono text-highlighted">{{ port.name }}</td>
462
+ <td class="px-3 py-1.5 font-mono text-muted">{{ schemaTypeOf(port) }}</td>
463
+ </tr>
464
+ </tbody>
465
+ </table>
467
466
  </div>
467
+ </DmsCard>
468
468
 
469
- <div class="flex flex-col gap-2">
470
- <div class="flex items-center justify-between">
471
- <div class="text-sm font-semibold text-highlighted">
472
- {{ $t('dms_automation.templates.ports.title') }}
473
- </div>
469
+ <DmsCard :title="$t('dms_automation.templates.usedIn')" :count="usageRows.length">
470
+ <p v-if="usageRows.length" class="mb-3 text-xs text-muted">{{ $t('dms_automation.templates.usedInHint') }}</p>
471
+ <div v-if="usagesLoading" class="flex flex-col gap-2">
472
+ <USkeleton v-for="i in 2" :key="i" class="h-8 w-full" />
473
+ </div>
474
+ <p v-else-if="usageRows.length === 0" class="text-xs text-dimmed">{{ $t('dms_automation.templates.unused') }}</p>
475
+ <ul v-else class="divide-y divide-default">
476
+ <li v-for="row in usageRows" :key="`${row.kind}-${row.id}`" class="flex items-center gap-3 py-2">
477
+ <template v-if="row.kind === 'procedure'">
478
+ <DmsStatusPill
479
+ v-if="procedures.get(row.id)"
480
+ :tone="STATE_TONES[procedures.get(row.id)!.status]"
481
+ :label="$t(`dms_automation.procedures.status.${procedures.get(row.id)!.status}`)"
482
+ size="sm"
483
+ />
484
+ <span class="min-w-0 flex-1 truncate text-sm text-highlighted">
485
+ {{ procedures.get(row.id)?.name ?? row.id }}
486
+ </span>
487
+ </template>
488
+ <template v-else>
489
+ <UBadge size="sm" color="neutral" variant="subtle" icon="i-ph-stack">{{ $t('dms_automation.templates.templateBadge') }}</UBadge>
490
+ <span class="min-w-0 flex-1 truncate text-sm text-highlighted">{{ templateNames.get(row.id) ?? row.id }}</span>
491
+ </template>
492
+ <span v-if="row.count > 1" class="shrink-0 font-mono text-[11px] text-dimmed">
493
+ {{ $t('dms_automation.templates.placements', { count: row.count }) }}
494
+ </span>
474
495
  <UButton
475
- variant="outline"
496
+ v-if="row.kind === 'procedure'"
497
+ size="xs"
498
+ variant="ghost"
476
499
  color="neutral"
477
- icon="i-ph-pencil-simple"
478
- size="sm"
479
- @click="onEditSubgraph"
500
+ trailing-icon="i-ph-arrow-up-right"
501
+ @click="openUsage(row.first as TemplateUsage)"
480
502
  >
481
- {{ $t('dms_automation.templates.editSubgraph') }}
503
+ {{ $t('dms_automation.library.open') }}
482
504
  </UButton>
483
- </div>
484
- <p class="text-xs text-muted">
485
- {{ $t('dms_automation.templates.ports.editHint') }}
486
- </p>
487
- <div
488
- v-if="(selected.ports ?? []).length === 0"
489
- class="text-sm text-dimmed"
490
- >
491
- {{ $t('dms_automation.templates.ports.empty') }}
492
- </div>
493
- <div v-else class="overflow-hidden rounded-lg border border-default">
494
- <table class="w-full text-sm">
495
- <thead>
496
- <tr class="border-b border-default bg-muted">
497
- <th class="px-4 py-2.5 text-left text-xs font-semibold text-dimmed">
498
- {{ $t('dms_automation.templates.ports.col.kind') }}
499
- </th>
500
- <th class="px-4 py-2.5 text-left text-xs font-semibold text-dimmed">
501
- {{ $t('dms_automation.templates.ports.col.direction') }}
502
- </th>
503
- <th class="px-4 py-2.5 text-left text-xs font-semibold text-dimmed">
504
- {{ $t('dms_automation.templates.ports.col.name') }}
505
- </th>
506
- <th class="px-4 py-2.5 text-left text-xs font-semibold text-dimmed">
507
- {{ $t('dms_automation.templates.ports.col.type') }}
508
- </th>
509
- </tr>
510
- </thead>
511
- <tbody>
512
- <tr
513
- v-for="(p, idx) in selected.ports"
514
- :key="portRowKey(p, idx)"
515
- class="border-b border-default/60 last:border-0"
516
- >
517
- <td class="px-4 py-2.5">
518
- <UBadge
519
- :color="p.kind === 'trigger' ? 'primary' : 'neutral'"
520
- variant="subtle"
521
- >
522
- {{ p.kind }}
523
- </UBadge>
524
- </td>
525
- <td class="whitespace-nowrap px-4 py-2.5 text-muted">
526
- {{ p.direction }}
527
- </td>
528
- <td class="px-4 py-2.5 font-mono text-highlighted">
529
- {{ p.name }}
530
- </td>
531
- <td class="whitespace-nowrap px-4 py-2.5 font-mono text-primary">
532
- {{ schemaTypeOf(p) }}
533
- </td>
534
- </tr>
535
- </tbody>
536
- </table>
537
- </div>
538
- </div>
539
-
540
- <div class="flex flex-col gap-2">
541
- <div class="text-sm font-semibold text-highlighted">
542
- {{ $t('dms_automation.templates.usages.title') }}
543
- </div>
544
- <UAlert
545
- v-if="usagesError"
546
- color="error"
547
- variant="subtle"
548
- icon="i-ph-warning"
549
- :title="$t('dms_automation.templates.usagesError')"
550
- :description="usagesError"
551
- />
552
- <div v-else-if="usagesLoading" class="text-sm text-dimmed">
553
- Loading…
554
- </div>
555
- <div v-else-if="usages.length === 0" class="text-sm text-dimmed">
556
- {{ $t('dms_automation.templates.usages.empty') }}
557
- </div>
558
- <ul v-else class="flex flex-col">
559
- <li
560
- v-for="(u, idx) in usages"
561
- :key="`${u.procedureId}-${u.nodeId}-${idx}`"
562
- class="flex items-center gap-3 border-b border-default/60 py-2 last:border-0"
563
- >
564
- <UIcon name="i-ph-puzzle-piece" class="size-4 shrink-0 text-dimmed" />
565
- <DmsLink
566
- :to="procedureLink(u.procedureId)"
567
- class="truncate text-highlighted hover:text-primary hover:underline"
568
- >
569
- {{ procedureLabel(u.procedureId) }}
570
- </DmsLink>
571
- <span class="truncate font-mono text-xs text-dimmed">
572
- {{ u.nodeId }}
573
- </span>
574
- </li>
575
- </ul>
576
- </div>
577
-
578
- <div class="flex justify-end border-t border-default pt-4">
579
- <UButton
580
- color="error"
581
- variant="subtle"
582
- icon="i-ph-trash"
583
- @click="openDelete"
584
- >
585
- {{ $t('dms_automation.templates.delete') }}
586
- </UButton>
587
- </div>
588
- </div>
589
- </DmsCard>
590
-
591
- <DmsCard
592
- v-else
593
- class="flex min-h-[16rem] items-center justify-center text-center"
594
- >
595
- <div class="flex flex-col items-center gap-3 text-dimmed">
596
- <UIcon name="i-ph-package" class="size-8" />
597
- <p class="max-w-xs text-sm">
598
- {{ $t('dms_automation.templates.empty') }}
599
- </p>
600
- </div>
601
- </DmsCard>
602
- </div>
505
+ <UButton v-else size="xs" variant="ghost" color="neutral" trailing-icon="i-ph-arrow-up-right" @click="editGraph(row.id)">
506
+ {{ $t('dms_automation.templates.editGraph') }}
507
+ </UButton>
508
+ </li>
509
+ </ul>
510
+ </DmsCard>
603
511
 
604
- <UModal
605
- v-model:open="deleteOpen"
606
- :title="$t('dms_automation.templates.deleteConfirm.title')"
607
- >
608
- <template #body>
609
- <div class="flex flex-col gap-3">
610
- <p class="text-default text-sm">
611
- {{
612
- $t(
613
- 'dms_automation.templates.deleteConfirm.message',
614
- { name: selected?.name ?? '' },
615
- )
616
- }}
617
- </p>
618
- <UAlert
619
- v-if="(selected?.usageCount ?? 0) > 0"
620
- color="warning"
621
- variant="subtle"
622
- icon="i-ph-warning"
623
- :title="
624
- $t(
625
- 'dms_automation.templates.deleteConfirm.usageWarningTitle',
626
- )
627
- "
628
- :description="
629
- $t(
630
- 'dms_automation.templates.deleteConfirm.usageWarning',
631
- { n: selected?.usageCount ?? 0 },
632
- )
633
- "
634
- />
635
- <UAlert
636
- v-if="deleteError"
637
- color="error"
638
- variant="subtle"
639
- icon="i-ph-warning"
640
- :title="$t('dms_automation.templates.deleteError')"
641
- :description="deleteError"
642
- />
643
- </div>
644
- </template>
645
- <template #footer>
646
- <div class="flex w-full justify-end gap-2">
647
- <UButton
648
- :label="$t('dms_automation.templates.deleteConfirm.cancel')"
649
- variant="outline"
650
- color="neutral"
651
- :disabled="deleting"
652
- @click="deleteOpen = false"
653
- />
654
- <UButton
655
- v-if="(selected?.usageCount ?? 0) > 0"
656
- color="error"
657
- icon="i-ph-trash"
658
- :loading="deleting"
659
- @click="confirmDelete(true)"
660
- >
661
- {{ $t('dms_automation.templates.forceDelete') }}
662
- </UButton>
663
- <UButton
664
- v-else
665
- color="error"
666
- icon="i-ph-trash"
667
- :loading="deleting"
668
- @click="confirmDelete(false)"
669
- >
512
+ <div class="flex flex-wrap items-center justify-between gap-3">
513
+ <p class="text-xs text-muted">{{ $t('dms_automation.templates.deleteHint') }}</p>
514
+ <UButton color="error" variant="soft" icon="i-ph-trash" @click="onDelete">
670
515
  {{ $t('dms_automation.templates.delete') }}
671
516
  </UButton>
672
517
  </div>
673
- </template>
674
- </UModal>
518
+ </div>
519
+ </div>
675
520
  </div>
676
521
  </template>