@adcops/autocore-react 3.3.85 → 3.3.87

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 (83) hide show
  1. package/dist/components/ValueInput.css +9 -12
  2. package/dist/components/ValueInput.d.ts +45 -154
  3. package/dist/components/ValueInput.d.ts.map +1 -1
  4. package/dist/components/ValueInput.js +1 -1
  5. package/dist/components/forms/FormRow.d.ts +20 -0
  6. package/dist/components/forms/FormRow.d.ts.map +1 -0
  7. package/dist/components/forms/FormRow.js +1 -0
  8. package/dist/components/forms/FormSection.d.ts +19 -0
  9. package/dist/components/forms/FormSection.d.ts.map +1 -0
  10. package/dist/components/forms/FormSection.js +1 -0
  11. package/dist/components/forms/forms.css +89 -0
  12. package/dist/components/forms/index.d.ts +3 -0
  13. package/dist/components/forms/index.d.ts.map +1 -0
  14. package/dist/components/forms/index.js +1 -0
  15. package/dist/components/tis-editor/TisConfigEditor.css +121 -0
  16. package/dist/components/tis-editor/TisConfigEditor.d.ts +28 -0
  17. package/dist/components/tis-editor/TisConfigEditor.d.ts.map +1 -0
  18. package/dist/components/tis-editor/TisConfigEditor.js +1 -0
  19. package/dist/components/tis-editor/editor/AnalysisEditor.d.ts +7 -0
  20. package/dist/components/tis-editor/editor/AnalysisEditor.d.ts.map +1 -0
  21. package/dist/components/tis-editor/editor/AnalysisEditor.js +1 -0
  22. package/dist/components/tis-editor/editor/AssetRefsEditor.d.ts +10 -0
  23. package/dist/components/tis-editor/editor/AssetRefsEditor.d.ts.map +1 -0
  24. package/dist/components/tis-editor/editor/AssetRefsEditor.js +1 -0
  25. package/dist/components/tis-editor/editor/ChartViewDialog.d.ts +16 -0
  26. package/dist/components/tis-editor/editor/ChartViewDialog.d.ts.map +1 -0
  27. package/dist/components/tis-editor/editor/ChartViewDialog.js +1 -0
  28. package/dist/components/tis-editor/editor/FieldArrayEditor.d.ts +8 -0
  29. package/dist/components/tis-editor/editor/FieldArrayEditor.d.ts.map +1 -0
  30. package/dist/components/tis-editor/editor/FieldArrayEditor.js +1 -0
  31. package/dist/components/tis-editor/editor/IdentitySection.d.ts +7 -0
  32. package/dist/components/tis-editor/editor/IdentitySection.d.ts.map +1 -0
  33. package/dist/components/tis-editor/editor/IdentitySection.js +1 -0
  34. package/dist/components/tis-editor/editor/MethodFormEditor.d.ts +20 -0
  35. package/dist/components/tis-editor/editor/MethodFormEditor.d.ts.map +1 -0
  36. package/dist/components/tis-editor/editor/MethodFormEditor.js +1 -0
  37. package/dist/components/tis-editor/editor/RawDataEditor.d.ts +7 -0
  38. package/dist/components/tis-editor/editor/RawDataEditor.d.ts.map +1 -0
  39. package/dist/components/tis-editor/editor/RawDataEditor.js +1 -0
  40. package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts +22 -0
  41. package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts.map +1 -0
  42. package/dist/components/tis-editor/editor/SaveDiffDialog.js +1 -0
  43. package/dist/components/tis-editor/editor/TestFieldDialog.d.ts +11 -0
  44. package/dist/components/tis-editor/editor/TestFieldDialog.d.ts.map +1 -0
  45. package/dist/components/tis-editor/editor/TestFieldDialog.js +1 -0
  46. package/dist/components/tis-editor/editor/ViewsEditor.d.ts +7 -0
  47. package/dist/components/tis-editor/editor/ViewsEditor.d.ts.map +1 -0
  48. package/dist/components/tis-editor/editor/ViewsEditor.js +1 -0
  49. package/dist/components/tis-editor/types.d.ts +78 -0
  50. package/dist/components/tis-editor/types.d.ts.map +1 -0
  51. package/dist/components/tis-editor/types.js +1 -0
  52. package/dist/components/tis-editor/validation.d.ts +20 -0
  53. package/dist/components/tis-editor/validation.d.ts.map +1 -0
  54. package/dist/components/tis-editor/validation.js +1 -0
  55. package/dist/hooks/useAmsAssetTypes.d.ts +23 -0
  56. package/dist/hooks/useAmsAssetTypes.d.ts.map +1 -0
  57. package/dist/hooks/useAmsAssetTypes.js +1 -0
  58. package/dist/hooks/useTisConfig.d.ts +51 -0
  59. package/dist/hooks/useTisConfig.d.ts.map +1 -0
  60. package/dist/hooks/useTisConfig.js +1 -0
  61. package/package.json +9 -3
  62. package/src/components/ValueInput.css +9 -12
  63. package/src/components/ValueInput.tsx +132 -317
  64. package/src/components/forms/FormRow.tsx +37 -0
  65. package/src/components/forms/FormSection.tsx +39 -0
  66. package/src/components/forms/forms.css +89 -0
  67. package/src/components/forms/index.ts +2 -0
  68. package/src/components/tis-editor/TisConfigEditor.css +121 -0
  69. package/src/components/tis-editor/TisConfigEditor.tsx +321 -0
  70. package/src/components/tis-editor/editor/AnalysisEditor.tsx +54 -0
  71. package/src/components/tis-editor/editor/AssetRefsEditor.tsx +187 -0
  72. package/src/components/tis-editor/editor/ChartViewDialog.tsx +170 -0
  73. package/src/components/tis-editor/editor/FieldArrayEditor.tsx +131 -0
  74. package/src/components/tis-editor/editor/IdentitySection.tsx +36 -0
  75. package/src/components/tis-editor/editor/MethodFormEditor.tsx +176 -0
  76. package/src/components/tis-editor/editor/RawDataEditor.tsx +117 -0
  77. package/src/components/tis-editor/editor/SaveDiffDialog.tsx +160 -0
  78. package/src/components/tis-editor/editor/TestFieldDialog.tsx +134 -0
  79. package/src/components/tis-editor/editor/ViewsEditor.tsx +101 -0
  80. package/src/components/tis-editor/types.ts +95 -0
  81. package/src/components/tis-editor/validation.ts +104 -0
  82. package/src/hooks/useAmsAssetTypes.ts +70 -0
  83. package/src/hooks/useTisConfig.ts +164 -0
@@ -0,0 +1,164 @@
1
+ /**
2
+ * useTisConfig — load and edit the TIS test_methods schema.
3
+ *
4
+ * Thin wrapper around the `tis.show_config` / `tis.put_method` /
5
+ * `tis.remove_method` / `tis.save_config` / `tis.discard_config_changes`
6
+ * IPC surface. Mirrors the server's staged-then-saved model: edits land in
7
+ * the server's in-memory copy (dirty = true) until `save()` persists them
8
+ * to project.json.
9
+ *
10
+ * Today the server hosts exactly one project (the one configured at
11
+ * startup), so `projectId` is informational; the hook still threads it
12
+ * through every call so the wire contract matches a future multi-project
13
+ * world without a rewrite.
14
+ *
15
+ * Pass an `invoker` override to mock the IPC layer (used by the playground
16
+ * demo and by tests). When omitted, the hook reads `EventEmitterContext`.
17
+ */
18
+
19
+ import { useCallback, useContext, useEffect, useState } from 'react';
20
+ import { EventEmitterContext } from '../core/EventEmitterContext';
21
+ import { MessageType } from '../hub/CommandMessage';
22
+
23
+ /** Minimal subset of a TestMethod we model client-side. Treat as opaque —
24
+ * the structural integrity of each method is the server's responsibility. */
25
+ export type TestMethod = Record<string, unknown>;
26
+
27
+ export interface TisConfig {
28
+ projectId: string;
29
+ methods: Record<string, TestMethod>;
30
+ dirty: boolean;
31
+ defaultMethodId: string;
32
+ }
33
+
34
+ /** IPC invoker contract: `topic` is e.g. "tis.show_config", payload is the
35
+ * request data. Returns an object with at least { success, data?, error_message? }. */
36
+ export interface TisIpcInvoker {
37
+ (topic: string, payload: object): Promise<{
38
+ success: boolean;
39
+ data?: any;
40
+ error_message?: string;
41
+ }>;
42
+ }
43
+
44
+ export interface UseTisConfigResult {
45
+ config: TisConfig | null;
46
+ loading: boolean;
47
+ /** Last server-reported error from a mutation. Cleared on next successful call. */
48
+ error: string | null;
49
+ refresh: () => Promise<void>;
50
+ putMethod: (methodId: string, method: TestMethod) => Promise<void>;
51
+ removeMethod: (methodId: string) => Promise<void>;
52
+ save: () => Promise<void>;
53
+ revert: () => Promise<void>;
54
+ }
55
+
56
+ export interface UseTisConfigOptions {
57
+ invoker?: TisIpcInvoker;
58
+ }
59
+
60
+ export function useTisConfig(
61
+ projectId: string,
62
+ options?: UseTisConfigOptions,
63
+ ): UseTisConfigResult {
64
+ const ctx = useContext(EventEmitterContext);
65
+
66
+ // Default invoker dispatches via the live EventEmitterContext. Tests and
67
+ // the playground pass a mock instead.
68
+ const invoker: TisIpcInvoker = options?.invoker
69
+ ?? (async (topic, payload) => {
70
+ return await ctx.invoke(topic as any, MessageType.Request, payload as any);
71
+ });
72
+
73
+ const [config, setConfig] = useState<TisConfig | null>(null);
74
+ const [loading, setLoading] = useState<boolean>(true);
75
+ const [error, setError] = useState<string | null>(null);
76
+
77
+ // Stable identity so consumers can put `refresh` in dep arrays without
78
+ // re-triggering loops. Reconstructed only when projectId or invoker
79
+ // identity changes.
80
+ const refresh = useCallback(async () => {
81
+ setLoading(true);
82
+ try {
83
+ const resp = await invoker('tis.show_config', { project_id: projectId });
84
+ if (!resp.success) {
85
+ setError(resp.error_message ?? 'tis.show_config failed');
86
+ setConfig(null);
87
+ return;
88
+ }
89
+ const d = resp.data ?? {};
90
+ setConfig({
91
+ projectId,
92
+ methods: (d.test_methods ?? {}) as Record<string, TestMethod>,
93
+ dirty: !!d.dirty,
94
+ defaultMethodId: typeof d.default_method_id === 'string'
95
+ ? d.default_method_id
96
+ : '',
97
+ });
98
+ setError(null);
99
+ } catch (e: any) {
100
+ setError(String(e?.message ?? e));
101
+ setConfig(null);
102
+ } finally {
103
+ setLoading(false);
104
+ }
105
+ // eslint-disable-next-line react-hooks/exhaustive-deps
106
+ }, [projectId, invoker]);
107
+
108
+ useEffect(() => {
109
+ void refresh();
110
+ }, [refresh]);
111
+
112
+ const putMethod = useCallback(async (methodId: string, method: TestMethod) => {
113
+ const resp = await invoker('tis.put_method', {
114
+ project_id: projectId,
115
+ method_id: methodId,
116
+ method,
117
+ });
118
+ if (!resp.success) {
119
+ const m = resp.error_message ?? 'tis.put_method failed';
120
+ setError(m);
121
+ throw new Error(m);
122
+ }
123
+ setError(null);
124
+ await refresh();
125
+ }, [invoker, projectId, refresh]);
126
+
127
+ const removeMethod = useCallback(async (methodId: string) => {
128
+ const resp = await invoker('tis.remove_method', {
129
+ project_id: projectId,
130
+ method_id: methodId,
131
+ });
132
+ if (!resp.success) {
133
+ const m = resp.error_message ?? 'tis.remove_method failed';
134
+ setError(m);
135
+ throw new Error(m);
136
+ }
137
+ setError(null);
138
+ await refresh();
139
+ }, [invoker, projectId, refresh]);
140
+
141
+ const save = useCallback(async () => {
142
+ const resp = await invoker('tis.save_config', { project_id: projectId });
143
+ if (!resp.success) {
144
+ const m = resp.error_message ?? 'tis.save_config failed';
145
+ setError(m);
146
+ throw new Error(m);
147
+ }
148
+ setError(null);
149
+ await refresh();
150
+ }, [invoker, projectId, refresh]);
151
+
152
+ const revert = useCallback(async () => {
153
+ const resp = await invoker('tis.discard_config_changes', { project_id: projectId });
154
+ if (!resp.success) {
155
+ const m = resp.error_message ?? 'tis.discard_config_changes failed';
156
+ setError(m);
157
+ throw new Error(m);
158
+ }
159
+ setError(null);
160
+ await refresh();
161
+ }, [invoker, projectId, refresh]);
162
+
163
+ return { config, loading, error, refresh, putMethod, removeMethod, save, revert };
164
+ }