@terreno/admin-frontend 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai/guidelines/core.md +10 -0
- package/dist/AdminBreadcrumbs.d.ts +13 -0
- package/dist/AdminBreadcrumbs.js +22 -0
- package/dist/AdminBreadcrumbs.js.map +1 -0
- package/dist/AdminFieldRenderer.js +3 -3
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +2 -0
- package/dist/AdminFieldRendererCore.js +28 -18
- package/dist/AdminFieldRendererCore.js.map +1 -1
- package/dist/AdminHome.d.ts +22 -0
- package/dist/AdminHome.js +189 -0
- package/dist/AdminHome.js.map +1 -0
- package/dist/AdminModelForm.d.ts +24 -1
- package/dist/AdminModelForm.js +185 -14
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +4 -0
- package/dist/AdminModelList.js +19 -4
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.d.ts +2 -27
- package/dist/AdminModelTable.js +316 -60
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminNestedArrayField.d.ts +1 -0
- package/dist/AdminNestedArrayField.js +26 -6
- package/dist/AdminNestedArrayField.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +1 -0
- package/dist/AdminObjectPicker.js +6 -2
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +1 -0
- package/dist/AdminPrimitiveArrayField.js +9 -8
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminRefField.js +2 -2
- package/dist/AdminRefField.js.map +1 -1
- package/dist/AdminScriptList.js +114 -7
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminScriptRunModal.d.ts +5 -0
- package/dist/AdminScriptRunModal.js +136 -30
- package/dist/AdminScriptRunModal.js.map +1 -1
- package/dist/AdminShell.d.ts +39 -0
- package/dist/AdminShell.js +80 -0
- package/dist/AdminShell.js.map +1 -0
- package/dist/AdminShellLayout.d.ts +23 -0
- package/dist/AdminShellLayout.js +32 -0
- package/dist/AdminShellLayout.js.map +1 -0
- package/dist/AdminVersionConfig.d.ts +5 -0
- package/dist/AdminVersionConfig.js +15 -5
- package/dist/AdminVersionConfig.js.map +1 -1
- package/dist/ConfigurationScreen.js +3 -3
- package/dist/ConfigurationScreen.js.map +1 -1
- package/dist/ConsentFormEditor.js +2 -2
- package/dist/ConsentFormEditor.js.map +1 -1
- package/dist/ConsentFormList.js +1 -1
- package/dist/ConsentFormList.js.map +1 -1
- package/dist/ConsentResponseViewer.js +3 -3
- package/dist/ConsentResponseViewer.js.map +1 -1
- package/dist/DocumentStorageBrowser.js +1 -1
- package/dist/DocumentStorageBrowser.js.map +1 -1
- package/dist/adminModelListQueryParams.d.ts +14 -0
- package/dist/adminModelListQueryParams.js +51 -0
- package/dist/adminModelListQueryParams.js.map +1 -0
- package/dist/adminShellNav.d.ts +10 -0
- package/dist/adminShellNav.js +29 -0
- package/dist/adminShellNav.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/scriptRunUtils.d.ts +36 -0
- package/dist/scriptRunUtils.js +121 -0
- package/dist/scriptRunUtils.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminApi.d.ts +1 -0
- package/dist/useAdminApi.js +11 -0
- package/dist/useAdminApi.js.map +1 -1
- package/dist/useAdminBackgroundTask.d.ts +12 -0
- package/dist/useAdminBackgroundTask.js +26 -0
- package/dist/useAdminBackgroundTask.js.map +1 -0
- package/dist/useAdminScripts.d.ts +19 -1
- package/dist/useAdminScripts.js +33 -4
- package/dist/useAdminScripts.js.map +1 -1
- package/package.json +4 -3
- package/src/AdminBreadcrumbs.test.tsx +27 -0
- package/src/AdminBreadcrumbs.tsx +63 -0
- package/src/AdminFieldRenderer.tsx +3 -0
- package/src/AdminFieldRendererCore.tsx +59 -1
- package/src/AdminHome.test.tsx +208 -0
- package/src/AdminHome.tsx +474 -0
- package/src/AdminModelForm.test.tsx +81 -1
- package/src/AdminModelForm.tsx +282 -34
- package/src/AdminModelList.test.tsx +1 -1
- package/src/AdminModelList.tsx +72 -39
- package/src/AdminModelTable.test.tsx +11 -0
- package/src/AdminModelTable.tsx +530 -92
- package/src/AdminNestedArrayField.tsx +59 -9
- package/src/AdminObjectPicker.tsx +19 -1
- package/src/AdminPrimitiveArrayField.tsx +30 -15
- package/src/AdminRefField.tsx +2 -0
- package/src/AdminScriptList.tsx +307 -30
- package/src/AdminScriptRunModal.tsx +410 -95
- package/src/AdminShell.tsx +296 -0
- package/src/AdminShellLayout.tsx +34 -0
- package/src/AdminVersionConfig.tsx +120 -76
- package/src/ConfigurationScreen.tsx +4 -2
- package/src/ConsentFormEditor.tsx +3 -1
- package/src/ConsentFormList.tsx +1 -1
- package/src/ConsentResponseViewer.tsx +3 -3
- package/src/DocumentStorageBrowser.tsx +1 -1
- package/src/adminModelListQueryParams.ts +61 -0
- package/src/adminShellNav.test.ts +29 -0
- package/src/adminShellNav.ts +33 -0
- package/src/index.tsx +6 -1
- package/src/isolated/AdminScriptRunModal.isolated.tsx +152 -1
- package/src/scriptRunUtils.test.ts +146 -0
- package/src/scriptRunUtils.ts +149 -0
- package/src/types.ts +69 -0
- package/src/useAdminApi.ts +11 -0
- package/src/useAdminBackgroundTask.ts +40 -0
- package/src/useAdminScripts.ts +56 -5
package/src/types.ts
CHANGED
|
@@ -50,6 +50,12 @@ export interface AdminFieldConfig {
|
|
|
50
50
|
itemRef?: string;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
export interface AdminModelPermissions {
|
|
54
|
+
create?: boolean;
|
|
55
|
+
delete?: boolean;
|
|
56
|
+
update?: boolean;
|
|
57
|
+
}
|
|
58
|
+
|
|
53
59
|
export interface AdminModelConfig {
|
|
54
60
|
name: string;
|
|
55
61
|
routePath: string;
|
|
@@ -60,6 +66,37 @@ export interface AdminModelConfig {
|
|
|
60
66
|
fieldOrder?: string[];
|
|
61
67
|
/** Optional per-column pixel widths used by AdminModelTable when rendering listFields. */
|
|
62
68
|
listColumnWidths?: Record<string, number>;
|
|
69
|
+
/**
|
|
70
|
+
* Field key used for the edit screen title (stack / document title). When unset, the form
|
|
71
|
+
* picks a scalar label from common keys (`name`, `title`, …) then the first list column.
|
|
72
|
+
*/
|
|
73
|
+
recordTitleField?: string;
|
|
74
|
+
/** Admin UI v2 — declarative bulk actions */
|
|
75
|
+
actions?: {
|
|
76
|
+
background?: boolean;
|
|
77
|
+
confirm?: string;
|
|
78
|
+
id: string;
|
|
79
|
+
label: string;
|
|
80
|
+
patchKeys?: string[];
|
|
81
|
+
}[];
|
|
82
|
+
bulkPatchAllowlist?: string[];
|
|
83
|
+
fieldsets?: {fields: string[]; title: string}[];
|
|
84
|
+
filters?: {
|
|
85
|
+
choices?: {label: string; value: string}[];
|
|
86
|
+
field: string;
|
|
87
|
+
kind: string;
|
|
88
|
+
label?: string;
|
|
89
|
+
}[];
|
|
90
|
+
group?: string;
|
|
91
|
+
hiddenFields?: string[];
|
|
92
|
+
listDisplay?: string[];
|
|
93
|
+
listDisplayLinks?: string[];
|
|
94
|
+
pageSize?: number;
|
|
95
|
+
permissions?: AdminModelPermissions;
|
|
96
|
+
readonlyFields?: string[];
|
|
97
|
+
realtime?: boolean;
|
|
98
|
+
searchFields?: string[];
|
|
99
|
+
sortableFields?: string[];
|
|
63
100
|
}
|
|
64
101
|
|
|
65
102
|
export interface AdminCustomScreen {
|
|
@@ -73,9 +110,24 @@ export interface AdminScriptConfig {
|
|
|
73
110
|
description: string;
|
|
74
111
|
}
|
|
75
112
|
|
|
113
|
+
/** Admin UI v2 home layout slots (Django template-block analogue). */
|
|
114
|
+
export interface AdminHomeSlots {
|
|
115
|
+
contentTop?: string[];
|
|
116
|
+
main?: string[];
|
|
117
|
+
navGlobal?: string[];
|
|
118
|
+
sidebar?: string[];
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export interface AdminHome {
|
|
122
|
+
slots: AdminHomeSlots;
|
|
123
|
+
title: string;
|
|
124
|
+
}
|
|
125
|
+
|
|
76
126
|
export interface AdminConfigResponse {
|
|
77
127
|
customScreens?: AdminCustomScreen[];
|
|
128
|
+
home?: AdminHome;
|
|
78
129
|
models: AdminModelConfig[];
|
|
130
|
+
schemaVersion?: number;
|
|
79
131
|
scripts: AdminScriptConfig[];
|
|
80
132
|
}
|
|
81
133
|
|
|
@@ -106,6 +158,21 @@ export interface BackgroundTask {
|
|
|
106
158
|
updated: string;
|
|
107
159
|
}
|
|
108
160
|
|
|
161
|
+
/** A single past script run, as returned by `GET {apiBase}/scripts/runs`. */
|
|
162
|
+
export interface ScriptRun extends BackgroundTask {
|
|
163
|
+
/** Display name (or email) of the admin who triggered the run, when available. */
|
|
164
|
+
createdByName?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Paginated response from the script run-history endpoint. */
|
|
168
|
+
export interface ScriptRunListResponse {
|
|
169
|
+
data: ScriptRun[];
|
|
170
|
+
limit: number;
|
|
171
|
+
more: boolean;
|
|
172
|
+
page: number;
|
|
173
|
+
total: number;
|
|
174
|
+
}
|
|
175
|
+
|
|
109
176
|
/**
|
|
110
177
|
* Common props for admin screens.
|
|
111
178
|
*
|
|
@@ -171,6 +238,8 @@ export interface RefFieldRendererProps {
|
|
|
171
238
|
onChange: (value: string) => void;
|
|
172
239
|
errorText?: string;
|
|
173
240
|
helperText?: string;
|
|
241
|
+
/** When true, the picker is display-only and does not submit changes. */
|
|
242
|
+
readOnly?: boolean;
|
|
174
243
|
}
|
|
175
244
|
|
|
176
245
|
/**
|
package/src/useAdminApi.ts
CHANGED
|
@@ -56,6 +56,7 @@ export const useAdminApi = (api: AdminApi, routePath: string, modelName: string)
|
|
|
56
56
|
const createKey = `adminCreate_${modelName}`;
|
|
57
57
|
const updateKey = `adminUpdate_${modelName}`;
|
|
58
58
|
const deleteKey = `adminDelete_${modelName}`;
|
|
59
|
+
const bulkPatchKey = `adminBulkPatch_${modelName}`;
|
|
59
60
|
|
|
60
61
|
const tagType = `admin_${modelName}`;
|
|
61
62
|
return api.enhanceEndpoints({addTagTypes: [tagType]}).injectEndpoints({
|
|
@@ -103,6 +104,14 @@ export const useAdminApi = (api: AdminApi, routePath: string, modelName: string)
|
|
|
103
104
|
url: `${routePath}/${id}`,
|
|
104
105
|
}),
|
|
105
106
|
}),
|
|
107
|
+
[bulkPatchKey]: build.mutation({
|
|
108
|
+
invalidatesTags: [`admin_${modelName}`],
|
|
109
|
+
query: ({ids, patch}: {ids: string[]; patch: Record<string, unknown>}) => ({
|
|
110
|
+
body: {ids, patch},
|
|
111
|
+
method: "POST",
|
|
112
|
+
url: `${routePath}/bulk-patch`,
|
|
113
|
+
}),
|
|
114
|
+
}),
|
|
106
115
|
}),
|
|
107
116
|
overrideExisting: true,
|
|
108
117
|
});
|
|
@@ -115,11 +124,13 @@ export const useAdminApi = (api: AdminApi, routePath: string, modelName: string)
|
|
|
115
124
|
const createKey = `adminCreate_${modelName}`;
|
|
116
125
|
const updateKey = `adminUpdate_${modelName}`;
|
|
117
126
|
const deleteKey = `adminDelete_${modelName}`;
|
|
127
|
+
const bulkPatchKey = `adminBulkPatch_${modelName}`;
|
|
118
128
|
|
|
119
129
|
// noExplicitAny: RTK Query generates hook names dynamically from endpoint keys; not statically expressible
|
|
120
130
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
121
131
|
const enhanced = enhancedApi as any;
|
|
122
132
|
return {
|
|
133
|
+
useBulkPatchMutation: enhanced[`use${capitalize(bulkPatchKey)}Mutation`],
|
|
123
134
|
useCreateMutation: enhanced[`use${capitalize(createKey)}Mutation`],
|
|
124
135
|
useDeleteMutation: enhanced[`use${capitalize(deleteKey)}Mutation`],
|
|
125
136
|
useListQuery: enhanced[`use${capitalize(listKey)}Query`],
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {useMemo} from "react";
|
|
2
|
+
|
|
3
|
+
import type {AdminApi, EndpointBuilder} from "./types";
|
|
4
|
+
|
|
5
|
+
export interface AdminBackgroundTaskBody {
|
|
6
|
+
ids?: string[];
|
|
7
|
+
kind: string;
|
|
8
|
+
metadata?: Record<string, unknown>;
|
|
9
|
+
resourceRoute?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* RTK Query mutation hook for `POST {adminApiRoot}/background-tasks` (admin enqueue).
|
|
14
|
+
*/
|
|
15
|
+
export const useAdminBackgroundTaskMutation = (
|
|
16
|
+
api: AdminApi,
|
|
17
|
+
adminApiRoot: string
|
|
18
|
+
): ReturnType<// biome-ignore lint/suspicious/noExplicitAny: RTK mutation type from dynamic injectEndpoints
|
|
19
|
+
any> => {
|
|
20
|
+
const enhancedApi = useMemo(() => {
|
|
21
|
+
const root = adminApiRoot.replace(/\/$/, "");
|
|
22
|
+
return api.enhanceEndpoints({addTagTypes: ["AdminBackgroundTask"]}).injectEndpoints({
|
|
23
|
+
endpoints: (build: EndpointBuilder) => ({
|
|
24
|
+
adminPostBackgroundTask: build.mutation({
|
|
25
|
+
invalidatesTags: [],
|
|
26
|
+
query: (body: AdminBackgroundTaskBody) => ({
|
|
27
|
+
body,
|
|
28
|
+
method: "POST",
|
|
29
|
+
url: `${root}/background-tasks`,
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
}),
|
|
33
|
+
overrideExisting: true,
|
|
34
|
+
});
|
|
35
|
+
}, [api, adminApiRoot]);
|
|
36
|
+
|
|
37
|
+
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
38
|
+
const enhanced = enhancedApi as any;
|
|
39
|
+
return enhanced.useAdminPostBackgroundTaskMutation();
|
|
40
|
+
};
|
package/src/useAdminScripts.ts
CHANGED
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import {useMemo} from "react";
|
|
2
|
-
import type {AdminApi, BackgroundTask, EndpointBuilder} from "./types";
|
|
2
|
+
import type {AdminApi, BackgroundTask, EndpointBuilder, ScriptRunListResponse} from "./types";
|
|
3
|
+
|
|
4
|
+
export interface ScriptRunsQueryArg {
|
|
5
|
+
/** Limit history to a single script by `taskType`. Omit for all scripts. */
|
|
6
|
+
name?: string;
|
|
7
|
+
page?: number;
|
|
8
|
+
limit?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ScriptRunsQueryResult {
|
|
12
|
+
data: ScriptRunListResponse | undefined;
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
isFetching?: boolean;
|
|
15
|
+
error: unknown;
|
|
16
|
+
refetch?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const EMPTY_RUNS_HOOK = (): ScriptRunsQueryResult => ({
|
|
20
|
+
data: undefined,
|
|
21
|
+
error: null,
|
|
22
|
+
isFetching: false,
|
|
23
|
+
isLoading: false,
|
|
24
|
+
});
|
|
3
25
|
|
|
4
26
|
export const useAdminScripts = (api: AdminApi, apiBase: string) => {
|
|
5
27
|
const enhancedApi = useMemo(() => {
|
|
28
|
+
// Guard: some call sites (and tests) pass a type-erased API double without
|
|
29
|
+
// `injectEndpoints`. Return null so we can fall back to no-op hooks.
|
|
30
|
+
if (typeof api?.injectEndpoints !== "function") {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
6
33
|
return api.injectEndpoints({
|
|
7
34
|
endpoints: (build: EndpointBuilder) => ({
|
|
8
35
|
adminCancelScriptTask: build.mutation({
|
|
9
|
-
invalidatesTags: ["admin_scriptTask"],
|
|
36
|
+
invalidatesTags: ["admin_scriptTask", "admin_scriptRuns"],
|
|
10
37
|
query: (taskId: string) => ({
|
|
11
38
|
method: "DELETE",
|
|
12
39
|
url: `${apiBase}/scripts/tasks/${taskId}`,
|
|
@@ -19,7 +46,20 @@ export const useAdminScripts = (api: AdminApi, apiBase: string) => {
|
|
|
19
46
|
url: `${apiBase}/scripts/tasks/${taskId}`,
|
|
20
47
|
}),
|
|
21
48
|
}),
|
|
49
|
+
adminListScriptRuns: build.query({
|
|
50
|
+
providesTags: ["admin_scriptRuns"],
|
|
51
|
+
query: ({name, page = 1, limit = 25}: ScriptRunsQueryArg = {}) => {
|
|
52
|
+
const params = new URLSearchParams();
|
|
53
|
+
params.set("page", String(page));
|
|
54
|
+
params.set("limit", String(limit));
|
|
55
|
+
if (name) {
|
|
56
|
+
params.set("name", name);
|
|
57
|
+
}
|
|
58
|
+
return {method: "GET", url: `${apiBase}/scripts/runs?${params.toString()}`};
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
22
61
|
adminRunScript: build.mutation({
|
|
62
|
+
invalidatesTags: ["admin_scriptRuns"],
|
|
23
63
|
query: ({name, wetRun}: {name: string; wetRun: boolean}) => ({
|
|
24
64
|
method: "POST",
|
|
25
65
|
url: `${apiBase}/scripts/${name}/run?wetRun=${wetRun}`,
|
|
@@ -33,16 +73,27 @@ export const useAdminScripts = (api: AdminApi, apiBase: string) => {
|
|
|
33
73
|
// noExplicitAny: RTK Query generates hook names dynamically; not statically expressible
|
|
34
74
|
// biome-ignore lint/suspicious/noExplicitAny: dynamic hook lookup on RTK Query enhanced API
|
|
35
75
|
const enhanced = enhancedApi as any;
|
|
76
|
+
|
|
36
77
|
return {
|
|
37
|
-
useCancelScriptTaskMutation: enhanced
|
|
78
|
+
useCancelScriptTaskMutation: (enhanced?.useAdminCancelScriptTaskMutation ??
|
|
79
|
+
(() => [() => ({unwrap: () => Promise.resolve({})}), {isLoading: false}])) as () => [
|
|
38
80
|
(taskId: string) => {unwrap: () => Promise<{task: BackgroundTask; message: string}>},
|
|
39
81
|
{isLoading: boolean},
|
|
40
82
|
],
|
|
41
|
-
useGetScriptTaskQuery: enhanced
|
|
83
|
+
useGetScriptTaskQuery: (enhanced?.useAdminGetScriptTaskQuery ??
|
|
84
|
+
(() => ({data: undefined, error: null, isLoading: false}))) as (
|
|
42
85
|
taskId: string,
|
|
43
86
|
options?: {skip?: boolean; pollingInterval?: number}
|
|
44
87
|
) => {data: {task: BackgroundTask} | undefined; isLoading: boolean; error: unknown},
|
|
45
|
-
|
|
88
|
+
useListScriptRunsQuery: (enhanced?.useAdminListScriptRunsQuery ?? EMPTY_RUNS_HOOK) as (
|
|
89
|
+
arg?: ScriptRunsQueryArg,
|
|
90
|
+
options?: {skip?: boolean; pollingInterval?: number}
|
|
91
|
+
) => ScriptRunsQueryResult,
|
|
92
|
+
useRunScriptMutation: (enhanced?.useAdminRunScriptMutation ??
|
|
93
|
+
(() => [
|
|
94
|
+
() => ({unwrap: () => Promise.resolve({taskId: ""})}),
|
|
95
|
+
{isLoading: false},
|
|
96
|
+
])) as () => [
|
|
46
97
|
(args: {name: string; wetRun: boolean}) => {unwrap: () => Promise<{taskId: string}>},
|
|
47
98
|
{isLoading: boolean},
|
|
48
99
|
],
|