@adcops/autocore-react 3.3.112 → 3.3.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ams/AmsProvider.d.ts.map +1 -1
- package/dist/components/ams/AmsProvider.js +1 -1
- package/dist/components/ams-editor/AssetFieldArray.d.ts +21 -0
- package/dist/components/ams-editor/AssetFieldArray.d.ts.map +1 -0
- package/dist/components/ams-editor/AssetFieldArray.js +1 -0
- package/dist/components/ams-editor/AssetTypeEditor.css +122 -0
- package/dist/components/ams-editor/AssetTypeEditor.d.ts +26 -0
- package/dist/components/ams-editor/AssetTypeEditor.d.ts.map +1 -0
- package/dist/components/ams-editor/AssetTypeEditor.js +1 -0
- package/dist/components/ams-editor/AssetTypeFormEditor.d.ts +21 -0
- package/dist/components/ams-editor/AssetTypeFormEditor.d.ts.map +1 -0
- package/dist/components/ams-editor/AssetTypeFormEditor.js +1 -0
- package/dist/components/ams-editor/SubLocationsEditor.d.ts +17 -0
- package/dist/components/ams-editor/SubLocationsEditor.d.ts.map +1 -0
- package/dist/components/ams-editor/SubLocationsEditor.js +1 -0
- package/dist/components/ams-editor/index.d.ts +7 -0
- package/dist/components/ams-editor/index.d.ts.map +1 -0
- package/dist/components/ams-editor/index.js +1 -0
- package/dist/components/ams-editor/types.d.ts +34 -0
- package/dist/components/ams-editor/types.d.ts.map +1 -0
- package/dist/components/ams-editor/types.js +1 -0
- package/dist/components/tis/ResultHistoryTable.d.ts.map +1 -1
- package/dist/components/tis/ResultHistoryTable.js +1 -1
- package/dist/components/tis/ScienceTable.d.ts +15 -0
- package/dist/components/tis/ScienceTable.d.ts.map +1 -1
- package/dist/components/tis/ScienceTable.js +1 -1
- package/dist/components/tis/TestDataView.d.ts +10 -4
- package/dist/components/tis/TestDataView.d.ts.map +1 -1
- package/dist/components/tis/TestDataView.js +1 -1
- package/dist/components/tis-editor/TisConfigEditor.d.ts +1 -1
- package/dist/components/tis-editor/editor/SaveDiffDialog.d.ts.map +1 -1
- package/dist/components/tis-editor/editor/SaveDiffDialog.js +1 -1
- package/dist/hooks/useAmsSchemaConfig.d.ts +39 -0
- package/dist/hooks/useAmsSchemaConfig.d.ts.map +1 -0
- package/dist/hooks/useAmsSchemaConfig.js +1 -0
- package/dist/hooks/useTisConfig.d.ts +1 -1
- package/package.json +110 -110
- package/src/components/ams/AmsProvider.tsx +20 -15
- package/src/components/ams-editor/AssetFieldArray.tsx +103 -0
- package/src/components/ams-editor/AssetTypeEditor.css +122 -0
- package/src/components/ams-editor/AssetTypeEditor.tsx +295 -0
- package/src/components/ams-editor/AssetTypeFormEditor.tsx +178 -0
- package/src/components/ams-editor/SubLocationsEditor.tsx +151 -0
- package/src/components/ams-editor/index.ts +16 -0
- package/src/components/ams-editor/types.ts +40 -0
- package/src/components/tis/ResultHistoryTable.tsx +141 -1
- package/src/components/tis/ScienceTable.tsx +71 -12
- package/src/components/tis/TestDataView.tsx +65 -6
- package/src/components/tis-editor/TisConfigEditor.tsx +1 -1
- package/src/components/tis-editor/editor/SaveDiffDialog.tsx +4 -3
- package/src/hooks/useAmsSchemaConfig.ts +142 -0
- package/src/hooks/useTisConfig.ts +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAmsSchemaConfig — load and edit the AMS custom `asset_types` catalog.
|
|
3
|
+
*
|
|
4
|
+
* Thin wrapper around the `ams.show_schema_config` / `ams.put_asset_type` /
|
|
5
|
+
* `ams.remove_asset_type` / `ams.save_schema_config` /
|
|
6
|
+
* `ams.discard_schema_changes` IPC surface. Mirrors the server's
|
|
7
|
+
* staged-then-saved model (and the TIS `useTisConfig` hook exactly): edits
|
|
8
|
+
* land in the AMS module's in-memory buffer (dirty = true) until `save()`
|
|
9
|
+
* persists them to the `asset_management.json` sidecar next to project.json.
|
|
10
|
+
*
|
|
11
|
+
* Only the project's CUSTOM asset types are editable here. The three
|
|
12
|
+
* built-in types (load_cell/linear_encoder/spring) are code-defined and
|
|
13
|
+
* surfaced read-only via `ams.list_schemas` (see `useAmsAssetTypes`).
|
|
14
|
+
*
|
|
15
|
+
* Pass an `invoker` override to mock the IPC layer (playground / tests).
|
|
16
|
+
* When omitted, the hook reads `EventEmitterContext`.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
20
|
+
import { EventEmitterContext } from '../core/EventEmitterContext';
|
|
21
|
+
import { MessageType } from '../hub/CommandMessage';
|
|
22
|
+
import type { TisIpcInvoker } from './useTisConfig';
|
|
23
|
+
import type { AssetTypeDef } from '../components/ams-editor/types';
|
|
24
|
+
|
|
25
|
+
export interface AmsSchemaConfig {
|
|
26
|
+
assetTypes: Record<string, AssetTypeDef>;
|
|
27
|
+
dirty: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface UseAmsSchemaConfigResult {
|
|
31
|
+
config: AmsSchemaConfig | null;
|
|
32
|
+
loading: boolean;
|
|
33
|
+
/** Last server-reported error from a mutation. Cleared on next success. */
|
|
34
|
+
error: string | null;
|
|
35
|
+
refresh: () => Promise<void>;
|
|
36
|
+
putType: (typeId: string, def: AssetTypeDef) => Promise<void>;
|
|
37
|
+
removeType: (typeId: string) => Promise<void>;
|
|
38
|
+
save: () => Promise<void>;
|
|
39
|
+
revert: () => Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface UseAmsSchemaConfigOptions {
|
|
43
|
+
invoker?: TisIpcInvoker;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function useAmsSchemaConfig(
|
|
47
|
+
options?: UseAmsSchemaConfigOptions,
|
|
48
|
+
): UseAmsSchemaConfigResult {
|
|
49
|
+
const ctx = useContext(EventEmitterContext);
|
|
50
|
+
|
|
51
|
+
const invoker: TisIpcInvoker = options?.invoker
|
|
52
|
+
?? (async (topic, payload) => {
|
|
53
|
+
return await ctx.invoke(topic as any, MessageType.Request, payload as any);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Hold the invoker in a ref so the memoized callbacks keep a STABLE
|
|
57
|
+
// identity even when the caller passes a freshly-built invoker each
|
|
58
|
+
// render — same refetch-loop hazard the TIS hook documents (an unstable
|
|
59
|
+
// `refresh` re-ran the mount effect, wiping in-progress edits).
|
|
60
|
+
const invokerRef = useRef(invoker);
|
|
61
|
+
invokerRef.current = invoker;
|
|
62
|
+
|
|
63
|
+
const [config, setConfig] = useState<AmsSchemaConfig | null>(null);
|
|
64
|
+
const [loading, setLoading] = useState<boolean>(true);
|
|
65
|
+
const [error, setError] = useState<string | null>(null);
|
|
66
|
+
|
|
67
|
+
const refresh = useCallback(async () => {
|
|
68
|
+
setLoading(true);
|
|
69
|
+
try {
|
|
70
|
+
const resp = await invokerRef.current('ams.show_schema_config', {});
|
|
71
|
+
if (!resp.success) {
|
|
72
|
+
setError(resp.error_message ?? 'ams.show_schema_config failed');
|
|
73
|
+
setConfig(null);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const d = resp.data ?? {};
|
|
77
|
+
setConfig({
|
|
78
|
+
assetTypes: (d.asset_types ?? {}) as Record<string, AssetTypeDef>,
|
|
79
|
+
dirty: !!d.dirty,
|
|
80
|
+
});
|
|
81
|
+
setError(null);
|
|
82
|
+
} catch (e: any) {
|
|
83
|
+
setError(String(e?.message ?? e));
|
|
84
|
+
setConfig(null);
|
|
85
|
+
} finally {
|
|
86
|
+
setLoading(false);
|
|
87
|
+
}
|
|
88
|
+
}, []);
|
|
89
|
+
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
void refresh();
|
|
92
|
+
}, [refresh]);
|
|
93
|
+
|
|
94
|
+
const putType = useCallback(async (typeId: string, def: AssetTypeDef) => {
|
|
95
|
+
const resp = await invokerRef.current('ams.put_asset_type', {
|
|
96
|
+
type_id: typeId,
|
|
97
|
+
definition: def,
|
|
98
|
+
});
|
|
99
|
+
if (!resp.success) {
|
|
100
|
+
const m = resp.error_message ?? 'ams.put_asset_type failed';
|
|
101
|
+
setError(m);
|
|
102
|
+
throw new Error(m);
|
|
103
|
+
}
|
|
104
|
+
setError(null);
|
|
105
|
+
await refresh();
|
|
106
|
+
}, [refresh]);
|
|
107
|
+
|
|
108
|
+
const removeType = useCallback(async (typeId: string) => {
|
|
109
|
+
const resp = await invokerRef.current('ams.remove_asset_type', { type_id: typeId });
|
|
110
|
+
if (!resp.success) {
|
|
111
|
+
const m = resp.error_message ?? 'ams.remove_asset_type failed';
|
|
112
|
+
setError(m);
|
|
113
|
+
throw new Error(m);
|
|
114
|
+
}
|
|
115
|
+
setError(null);
|
|
116
|
+
await refresh();
|
|
117
|
+
}, [refresh]);
|
|
118
|
+
|
|
119
|
+
const save = useCallback(async () => {
|
|
120
|
+
const resp = await invokerRef.current('ams.save_schema_config', {});
|
|
121
|
+
if (!resp.success) {
|
|
122
|
+
const m = resp.error_message ?? 'ams.save_schema_config failed';
|
|
123
|
+
setError(m);
|
|
124
|
+
throw new Error(m);
|
|
125
|
+
}
|
|
126
|
+
setError(null);
|
|
127
|
+
await refresh();
|
|
128
|
+
}, [refresh]);
|
|
129
|
+
|
|
130
|
+
const revert = useCallback(async () => {
|
|
131
|
+
const resp = await invokerRef.current('ams.discard_schema_changes', {});
|
|
132
|
+
if (!resp.success) {
|
|
133
|
+
const m = resp.error_message ?? 'ams.discard_schema_changes failed';
|
|
134
|
+
setError(m);
|
|
135
|
+
throw new Error(m);
|
|
136
|
+
}
|
|
137
|
+
setError(null);
|
|
138
|
+
await refresh();
|
|
139
|
+
}, [refresh]);
|
|
140
|
+
|
|
141
|
+
return { config, loading, error, refresh, putType, removeType, save, revert };
|
|
142
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* `tis.remove_method` / `tis.save_config` / `tis.discard_config_changes`
|
|
6
6
|
* IPC surface. Mirrors the server's staged-then-saved model: edits land in
|
|
7
7
|
* the server's in-memory copy (dirty = true) until `save()` persists them
|
|
8
|
-
* to project.json.
|
|
8
|
+
* to the `test_methods.json` sidecar next to project.json.
|
|
9
9
|
*
|
|
10
10
|
* Today the server hosts exactly one project (the one configured at
|
|
11
11
|
* startup), so `projectId` is informational; the hook still threads it
|