@terreno/admin-frontend 57.0.0 → 57.2.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/dist/AdminActionMenu.d.ts +15 -0
- package/dist/AdminActionMenu.js +56 -0
- package/dist/AdminActionMenu.js.map +1 -0
- package/dist/AdminFieldRenderer.js +2 -2
- package/dist/AdminFieldRenderer.js.map +1 -1
- package/dist/AdminFieldRendererCore.d.ts +2 -0
- package/dist/AdminFieldRendererCore.js +18 -47
- package/dist/AdminFieldRendererCore.js.map +1 -1
- package/dist/AdminFilterDrawer.d.ts +20 -0
- package/dist/AdminFilterDrawer.js +117 -0
- package/dist/AdminFilterDrawer.js.map +1 -0
- package/dist/AdminHome.d.ts +2 -4
- package/dist/AdminHome.js +15 -137
- package/dist/AdminHome.js.map +1 -1
- package/dist/AdminModelForm.js +29 -10
- package/dist/AdminModelForm.js.map +1 -1
- package/dist/AdminModelList.d.ts +2 -1
- package/dist/AdminModelList.js +5 -1
- package/dist/AdminModelList.js.map +1 -1
- package/dist/AdminModelTable.js +56 -98
- package/dist/AdminModelTable.js.map +1 -1
- package/dist/AdminObjectPicker.d.ts +3 -0
- package/dist/AdminObjectPicker.js +27 -7
- package/dist/AdminObjectPicker.js.map +1 -1
- package/dist/AdminPrimitiveArrayField.d.ts +2 -0
- package/dist/AdminPrimitiveArrayField.js +3 -3
- package/dist/AdminPrimitiveArrayField.js.map +1 -1
- package/dist/AdminProvider.d.ts +16 -0
- package/dist/AdminProvider.js +84 -0
- package/dist/AdminProvider.js.map +1 -0
- package/dist/AdminRefField.js +2 -2
- package/dist/AdminRefField.js.map +1 -1
- package/dist/AdminRolesField.d.ts +9 -0
- package/dist/AdminRolesField.js +45 -0
- package/dist/AdminRolesField.js.map +1 -0
- package/dist/AdminRolesList.d.ts +3 -0
- package/dist/AdminRolesList.js +187 -0
- package/dist/AdminRolesList.js.map +1 -0
- package/dist/AdminScreenRouter.d.ts +13 -0
- package/dist/AdminScreenRouter.js +52 -0
- package/dist/AdminScreenRouter.js.map +1 -0
- package/dist/AdminScriptList.js +12 -10
- package/dist/AdminScriptList.js.map +1 -1
- package/dist/AdminShell.d.ts +2 -0
- package/dist/AdminShell.js +68 -21
- package/dist/AdminShell.js.map +1 -1
- package/dist/Constants.d.ts +4 -0
- package/dist/Constants.js +5 -0
- package/dist/Constants.js.map +1 -0
- package/dist/adminModelListQueryParams.d.ts +4 -0
- package/dist/adminModelListQueryParams.js +38 -3
- package/dist/adminModelListQueryParams.js.map +1 -1
- package/dist/adminPageAccess.d.ts +5 -0
- package/dist/adminPageAccess.js +19 -0
- package/dist/adminPageAccess.js.map +1 -0
- package/dist/index.d.ts +20 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +74 -0
- package/dist/types.js.map +1 -1
- package/dist/useAdminRoles.d.ts +65 -0
- package/dist/useAdminRoles.js +84 -0
- package/dist/useAdminRoles.js.map +1 -0
- package/dist/useDocumentStorageApi.js +2 -2
- package/dist/useDocumentStorageApi.js.map +1 -1
- package/dist/widgets/AIRequestsScreenWidget.d.ts +4 -0
- package/dist/widgets/AIRequestsScreenWidget.js +54 -0
- package/dist/widgets/AIRequestsScreenWidget.js.map +1 -0
- package/dist/widgets/CustomScreensListWidget.d.ts +4 -0
- package/dist/widgets/CustomScreensListWidget.js +21 -0
- package/dist/widgets/CustomScreensListWidget.js.map +1 -0
- package/dist/widgets/DocumentsScreenWidget.d.ts +4 -0
- package/dist/widgets/DocumentsScreenWidget.js +9 -0
- package/dist/widgets/DocumentsScreenWidget.js.map +1 -0
- package/dist/widgets/FeatureFlagsOverridesWidget.d.ts +4 -0
- package/dist/widgets/FeatureFlagsOverridesWidget.js +18 -0
- package/dist/widgets/FeatureFlagsOverridesWidget.js.map +1 -0
- package/dist/widgets/MissingWidget.d.ts +7 -0
- package/dist/widgets/MissingWidget.js +6 -0
- package/dist/widgets/MissingWidget.js.map +1 -0
- package/dist/widgets/ModelsGridWidget.d.ts +3 -0
- package/dist/widgets/ModelsGridWidget.js +30 -0
- package/dist/widgets/ModelsGridWidget.js.map +1 -0
- package/dist/widgets/RecentActivityWidget.d.ts +3 -0
- package/dist/widgets/RecentActivityWidget.js +27 -0
- package/dist/widgets/RecentActivityWidget.js.map +1 -0
- package/dist/widgets/ScriptRunnerWidget.d.ts +3 -0
- package/dist/widgets/ScriptRunnerWidget.js +12 -0
- package/dist/widgets/ScriptRunnerWidget.js.map +1 -0
- package/dist/widgets/VersionConfigScreenWidget.d.ts +3 -0
- package/dist/widgets/VersionConfigScreenWidget.js +7 -0
- package/dist/widgets/VersionConfigScreenWidget.js.map +1 -0
- package/dist/widgets/VersionConfigWidget.d.ts +3 -0
- package/dist/widgets/VersionConfigWidget.js +7 -0
- package/dist/widgets/VersionConfigWidget.js.map +1 -0
- package/dist/widgets/builtInFieldWidgets.d.ts +7 -0
- package/dist/widgets/builtInFieldWidgets.js +61 -0
- package/dist/widgets/builtInFieldWidgets.js.map +1 -0
- package/dist/widgets/builtInWidgets.d.ts +6 -0
- package/dist/widgets/builtInWidgets.js +31 -0
- package/dist/widgets/builtInWidgets.js.map +1 -0
- package/dist/widgets/consentWidgets.d.ts +3 -0
- package/dist/widgets/consentWidgets.js +8 -0
- package/dist/widgets/consentWidgets.js.map +1 -0
- package/dist/widgets/homeWidgetUtils.d.ts +3 -0
- package/dist/widgets/homeWidgetUtils.js +37 -0
- package/dist/widgets/homeWidgetUtils.js.map +1 -0
- package/package.json +3 -2
- package/src/AdminActionMenu.test.tsx +78 -0
- package/src/AdminActionMenu.tsx +106 -0
- package/src/AdminFieldRenderer.tsx +2 -0
- package/src/AdminFieldRendererCore.tsx +54 -133
- package/src/AdminFilterDrawer.test.tsx +89 -0
- package/src/AdminFilterDrawer.tsx +333 -0
- package/src/AdminHome.tsx +38 -325
- package/src/AdminModelForm.test.tsx +78 -0
- package/src/AdminModelForm.tsx +49 -10
- package/src/AdminModelList.tsx +7 -2
- package/src/AdminModelTable.test.tsx +73 -0
- package/src/AdminModelTable.tsx +108 -195
- package/src/AdminObjectPicker.tsx +49 -9
- package/src/AdminPrimitiveArrayField.tsx +5 -0
- package/src/AdminProvider.test.tsx +25 -0
- package/src/AdminProvider.tsx +121 -0
- package/src/AdminRefField.tsx +4 -0
- package/src/AdminRolesField.tsx +129 -0
- package/src/AdminRolesList.test.tsx +339 -0
- package/src/AdminRolesList.tsx +434 -0
- package/src/AdminScreenRouter.test.tsx +112 -0
- package/src/AdminScreenRouter.tsx +104 -0
- package/src/AdminScriptList.tsx +42 -30
- package/src/AdminShell.test.tsx +196 -1
- package/src/AdminShell.tsx +166 -69
- package/src/Constants.ts +5 -0
- package/src/adminModelListQueryParams.test.ts +69 -0
- package/src/adminModelListQueryParams.ts +49 -3
- package/src/adminPageAccess.test.ts +18 -0
- package/src/adminPageAccess.ts +18 -0
- package/src/index.tsx +51 -0
- package/src/isolated/AdminObjectPicker.isolated.tsx +10 -1
- package/src/types.ts +79 -0
- package/src/useAdminRoles.ts +146 -0
- package/src/useDocumentStorageApi.ts +2 -2
- package/src/widgets/AIRequestsScreenWidget.tsx +93 -0
- package/src/widgets/CustomScreensListWidget.tsx +56 -0
- package/src/widgets/DocumentsScreenWidget.tsx +11 -0
- package/src/widgets/FeatureFlagsOverridesWidget.tsx +48 -0
- package/src/widgets/MissingWidget.tsx +17 -0
- package/src/widgets/ModelsGridWidget.tsx +94 -0
- package/src/widgets/RecentActivityWidget.tsx +81 -0
- package/src/widgets/ScriptRunnerWidget.tsx +26 -0
- package/src/widgets/VersionConfigScreenWidget.tsx +12 -0
- package/src/widgets/VersionConfigWidget.tsx +7 -0
- package/src/widgets/builtInFieldWidgets.tsx +180 -0
- package/src/widgets/builtInWidgets.ts +51 -0
- package/src/widgets/consentWidgets.ts +13 -0
- package/src/widgets/homeWidgetUtils.ts +38 -0
- package/src/widgets/pluginWidgets.test.tsx +29 -0
package/src/AdminScriptList.tsx
CHANGED
|
@@ -60,6 +60,8 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({
|
|
|
60
60
|
});
|
|
61
61
|
const {config, isLoading, error} = useAdminConfig(api, resolvedApiBase);
|
|
62
62
|
const {useListScriptRunsQuery} = useAdminScripts(api, resolvedApiBase);
|
|
63
|
+
const canRunScripts = isAdmin && (config?.platformTools?.runScripts ?? true);
|
|
64
|
+
const canViewScripts = config?.platformTools?.viewScripts ?? true;
|
|
63
65
|
|
|
64
66
|
const [tab, setTab] = useState<Tab>("scripts");
|
|
65
67
|
const [historyPage, setHistoryPage] = useState(1);
|
|
@@ -72,16 +74,22 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({
|
|
|
72
74
|
const [modalVisible, setModalVisible] = useState(false);
|
|
73
75
|
|
|
74
76
|
// Unfiltered most-recent runs power the per-script "Last run" badges on the Scripts tab.
|
|
75
|
-
const {data: latestRunsData} = useListScriptRunsQuery(
|
|
77
|
+
const {data: latestRunsData} = useListScriptRunsQuery(
|
|
78
|
+
{limit: HISTORY_PAGE_SIZE, page: 1},
|
|
79
|
+
{skip: !canViewScripts}
|
|
80
|
+
);
|
|
76
81
|
const latestRuns: ScriptRun[] = useMemo(() => latestRunsData?.data ?? [], [latestRunsData]);
|
|
77
82
|
const lastRuns = useMemo(() => latestRunByScript(latestRuns), [latestRuns]);
|
|
78
83
|
|
|
79
84
|
// Paginated history, optionally scoped to a single script via the per-script History link.
|
|
80
|
-
const {data: historyData} = useListScriptRunsQuery(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
const {data: historyData} = useListScriptRunsQuery(
|
|
86
|
+
{
|
|
87
|
+
limit: HISTORY_PAGE_SIZE,
|
|
88
|
+
name: historyScriptName ?? undefined,
|
|
89
|
+
page: historyPage,
|
|
90
|
+
},
|
|
91
|
+
{skip: !canViewScripts}
|
|
92
|
+
);
|
|
85
93
|
|
|
86
94
|
// Accumulate each loaded history page (de-duplicated by id) so "Load more" advances through
|
|
87
95
|
// pages instead of re-requesting a server-capped first page. Keying on the active filter lets
|
|
@@ -208,16 +216,18 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({
|
|
|
208
216
|
Last run {relativeTime(run.created)} — {run.isDryRun ? "dry run" : "live run"}{" "}
|
|
209
217
|
{meta.label.toLowerCase()}
|
|
210
218
|
</Text>
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
219
|
+
{canViewScripts ? (
|
|
220
|
+
<Box
|
|
221
|
+
accessibilityHint={`Opens run history for ${script.name}`}
|
|
222
|
+
accessibilityLabel={`View run history for ${script.name}`}
|
|
223
|
+
onClick={() => handleViewHistory(script.name)}
|
|
224
|
+
testID={`admin-script-history-${script.name}`}
|
|
225
|
+
>
|
|
226
|
+
<Text color="link" size="sm">
|
|
227
|
+
History
|
|
228
|
+
</Text>
|
|
229
|
+
</Box>
|
|
230
|
+
) : null}
|
|
221
231
|
</Box>
|
|
222
232
|
);
|
|
223
233
|
};
|
|
@@ -235,12 +245,12 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({
|
|
|
235
245
|
{renderLastRun(script)}
|
|
236
246
|
</Box>
|
|
237
247
|
<Button
|
|
238
|
-
disabled={!
|
|
248
|
+
disabled={!canRunScripts}
|
|
239
249
|
iconName="play"
|
|
240
250
|
onClick={() => handleRunScript(script)}
|
|
241
251
|
testID={`admin-script-run-${script.name}`}
|
|
242
252
|
text="Run"
|
|
243
|
-
tooltipText={!
|
|
253
|
+
tooltipText={!canRunScripts ? "You do not have permission to run scripts" : undefined}
|
|
244
254
|
variant="primary"
|
|
245
255
|
/>
|
|
246
256
|
</Box>
|
|
@@ -360,18 +370,20 @@ export const AdminScriptList: React.FC<AdminScriptListProps> = ({
|
|
|
360
370
|
|
|
361
371
|
return (
|
|
362
372
|
<Page color="transparent" maxWidth="100%" padding={0} scroll title="Scripts">
|
|
363
|
-
|
|
364
|
-
<
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
373
|
+
{canViewScripts ? (
|
|
374
|
+
<Box paddingX={4} paddingY={4}>
|
|
375
|
+
<SegmentedControl
|
|
376
|
+
items={[
|
|
377
|
+
"Scripts",
|
|
378
|
+
(latestRunsData?.total ?? latestRuns.length) > 0
|
|
379
|
+
? `Run history (${latestRunsData?.total ?? latestRuns.length})`
|
|
380
|
+
: "Run history",
|
|
381
|
+
]}
|
|
382
|
+
onChange={handleTabChange}
|
|
383
|
+
selectedIndex={tab === "history" ? 1 : 0}
|
|
384
|
+
/>
|
|
385
|
+
</Box>
|
|
386
|
+
) : null}
|
|
375
387
|
|
|
376
388
|
{tab === "scripts" ? renderScripts() : renderHistory()}
|
|
377
389
|
|
package/src/AdminShell.test.tsx
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
4
4
|
import {renderWithTheme} from "@terreno/ui/src/test-utils";
|
|
5
5
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
6
|
+
import {assert} from "chai";
|
|
6
7
|
import React from "react";
|
|
7
8
|
import type {ScaledSize} from "react-native";
|
|
8
9
|
import {useWindowDimensions} from "react-native";
|
|
9
10
|
import {SafeAreaView} from "react-native-safe-area-context";
|
|
10
|
-
import type {AdminApi, AdminConfigResponse} from "./types";
|
|
11
|
+
import type {AdminApi, AdminConfigResponse, AdminModelConfig} from "./types";
|
|
11
12
|
|
|
12
13
|
const mockRouterPush = mock((_href: string) => {});
|
|
13
14
|
|
|
@@ -79,6 +80,20 @@ const buildConfig = (): AdminConfigResponse => ({
|
|
|
79
80
|
scripts: [{description: "Seed", name: "seed"}],
|
|
80
81
|
});
|
|
81
82
|
|
|
83
|
+
const platformModel = ({
|
|
84
|
+
displayName,
|
|
85
|
+
name,
|
|
86
|
+
routePath,
|
|
87
|
+
}: Pick<AdminModelConfig, "displayName" | "name" | "routePath">): AdminModelConfig => ({
|
|
88
|
+
defaultSort: "-created",
|
|
89
|
+
displayName,
|
|
90
|
+
fields: {name: {required: true, type: "string"}},
|
|
91
|
+
group: "Platform",
|
|
92
|
+
listFields: ["name"],
|
|
93
|
+
name,
|
|
94
|
+
routePath,
|
|
95
|
+
});
|
|
96
|
+
|
|
82
97
|
const mockApi = {} as unknown as AdminApi;
|
|
83
98
|
|
|
84
99
|
describe("AdminShell", () => {
|
|
@@ -112,6 +127,23 @@ describe("AdminShell", () => {
|
|
|
112
127
|
expect(queryByTestId("admin-shell-mobile-header")).toBeNull();
|
|
113
128
|
});
|
|
114
129
|
|
|
130
|
+
it("shows a forbidden state when admin config returns 403", () => {
|
|
131
|
+
configState.config = null;
|
|
132
|
+
configState.error = {status: 403} as unknown as Error;
|
|
133
|
+
restoreWindowWidth?.();
|
|
134
|
+
restoreWindowWidth = setWindowWidth(1024);
|
|
135
|
+
|
|
136
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
137
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
138
|
+
<React.Fragment />
|
|
139
|
+
</AdminShell>
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(getByTestId("admin-shell-forbidden")).toBeTruthy();
|
|
143
|
+
expect(queryByTestId("admin-shell-error")).toBeNull();
|
|
144
|
+
expect(queryByTestId("admin-shell-sidebar")).toBeNull();
|
|
145
|
+
});
|
|
146
|
+
|
|
115
147
|
it("hides the fixed sidebar and shows a hamburger header below 768px", () => {
|
|
116
148
|
const {getByTestId, getByLabelText, queryByTestId, UNSAFE_root} = renderWithTheme(
|
|
117
149
|
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
@@ -188,4 +220,167 @@ describe("AdminShell", () => {
|
|
|
188
220
|
expect(mockRouterPush).toHaveBeenCalled();
|
|
189
221
|
expect(queryByTestId("admin-shell-drawer")).toBeNull();
|
|
190
222
|
});
|
|
223
|
+
|
|
224
|
+
it("renders the ordered Platform block last and removes its models from Models", async () => {
|
|
225
|
+
restoreWindowWidth?.();
|
|
226
|
+
restoreWindowWidth = setWindowWidth(1024);
|
|
227
|
+
configState.config = {
|
|
228
|
+
...buildConfig(),
|
|
229
|
+
models: [
|
|
230
|
+
...buildConfig().models,
|
|
231
|
+
platformModel({
|
|
232
|
+
displayName: "Audit Logs",
|
|
233
|
+
name: "AdminAuditLog",
|
|
234
|
+
routePath: "/admin/audit-logs",
|
|
235
|
+
}),
|
|
236
|
+
platformModel({
|
|
237
|
+
displayName: "Feature Flags",
|
|
238
|
+
name: "FeatureFlag",
|
|
239
|
+
routePath: "/admin/feature-flags",
|
|
240
|
+
}),
|
|
241
|
+
],
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const {getByTestId, queryByTestId, queryByText} = renderWithTheme(
|
|
245
|
+
<AdminShell
|
|
246
|
+
api={mockApi}
|
|
247
|
+
apiBase="/admin"
|
|
248
|
+
configurationPath="/admin/configuration"
|
|
249
|
+
rolesPath="/roles"
|
|
250
|
+
routeBase="/admin"
|
|
251
|
+
>
|
|
252
|
+
<React.Fragment />
|
|
253
|
+
</AdminShell>
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const platform = getByTestId("admin-shell-nav-platform");
|
|
257
|
+
const platformLinkTestIDs = platform
|
|
258
|
+
.findAll((node: ReactTestInstance) => typeof node.props.testID === "string")
|
|
259
|
+
.map((node: ReactTestInstance) => node.props.testID)
|
|
260
|
+
.filter((testID: string) => testID.startsWith("admin-shell-nav-"))
|
|
261
|
+
.filter((testID: string) => !testID.endsWith("-clickable"))
|
|
262
|
+
.filter((testID: string, index: number, testIDs: string[]) => {
|
|
263
|
+
return testIDs.indexOf(testID) === index;
|
|
264
|
+
});
|
|
265
|
+
expect(platformLinkTestIDs).toEqual([
|
|
266
|
+
"admin-shell-nav-platform",
|
|
267
|
+
"admin-shell-nav-scripts",
|
|
268
|
+
"admin-shell-nav-roles",
|
|
269
|
+
"admin-shell-nav-version",
|
|
270
|
+
"admin-shell-nav-audit-log",
|
|
271
|
+
"admin-shell-nav-feature-flags",
|
|
272
|
+
"admin-shell-nav-configuration",
|
|
273
|
+
]);
|
|
274
|
+
expect(queryByText("Tools")).toBeNull();
|
|
275
|
+
expect(queryByTestId("admin-shell-nav-model-AdminAuditLog")).toBeNull();
|
|
276
|
+
expect(queryByTestId("admin-shell-nav-model-FeatureFlag")).toBeNull();
|
|
277
|
+
|
|
278
|
+
await act(async () => {
|
|
279
|
+
fireEvent.press(getByTestId("admin-shell-nav-audit-log-clickable"));
|
|
280
|
+
});
|
|
281
|
+
expect(mockRouterPush).toHaveBeenLastCalledWith("/admin/AdminAuditLog");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it("hides built-in platform tools denied by backend RBAC metadata", () => {
|
|
285
|
+
restoreWindowWidth?.();
|
|
286
|
+
restoreWindowWidth = setWindowWidth(1024);
|
|
287
|
+
configState.config = {
|
|
288
|
+
...buildConfig(),
|
|
289
|
+
platformTools: {
|
|
290
|
+
configuration: false,
|
|
291
|
+
roles: false,
|
|
292
|
+
scripts: false,
|
|
293
|
+
version: false,
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const {queryByTestId} = renderWithTheme(
|
|
298
|
+
<AdminShell
|
|
299
|
+
api={mockApi}
|
|
300
|
+
apiBase="/admin"
|
|
301
|
+
configurationPath="/admin/configuration"
|
|
302
|
+
customScreens={[{displayName: "Denied local screen", name: "denied"}]}
|
|
303
|
+
rolesPath="/roles"
|
|
304
|
+
routeBase="/admin"
|
|
305
|
+
>
|
|
306
|
+
<React.Fragment />
|
|
307
|
+
</AdminShell>
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
assert.isNull(queryByTestId("admin-shell-nav-scripts"));
|
|
311
|
+
assert.isNull(queryByTestId("admin-shell-nav-roles"));
|
|
312
|
+
assert.isNull(queryByTestId("admin-shell-nav-version"));
|
|
313
|
+
assert.isNull(queryByTestId("admin-shell-nav-configuration"));
|
|
314
|
+
assert.isNull(queryByTestId("admin-shell-nav-screen-denied"));
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("shows only the platform tools and models granted to the current role", () => {
|
|
318
|
+
restoreWindowWidth?.();
|
|
319
|
+
restoreWindowWidth = setWindowWidth(1024);
|
|
320
|
+
configState.config = {
|
|
321
|
+
...buildConfig(),
|
|
322
|
+
models: [
|
|
323
|
+
{
|
|
324
|
+
...buildConfig().models[0],
|
|
325
|
+
permissions: {create: false, delete: false, update: false},
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
platformTools: {
|
|
329
|
+
configuration: false,
|
|
330
|
+
roles: true,
|
|
331
|
+
scripts: false,
|
|
332
|
+
version: false,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
337
|
+
<AdminShell
|
|
338
|
+
api={mockApi}
|
|
339
|
+
apiBase="/admin"
|
|
340
|
+
configurationPath="/admin/configuration"
|
|
341
|
+
rolesPath="/roles"
|
|
342
|
+
routeBase="/admin"
|
|
343
|
+
>
|
|
344
|
+
<React.Fragment />
|
|
345
|
+
</AdminShell>
|
|
346
|
+
);
|
|
347
|
+
|
|
348
|
+
assert.isNotNull(getByTestId("admin-shell-nav-model-Todo-clickable"));
|
|
349
|
+
assert.isNotNull(getByTestId("admin-shell-nav-roles-clickable"));
|
|
350
|
+
assert.isNull(queryByTestId("admin-shell-nav-scripts"));
|
|
351
|
+
assert.isNull(queryByTestId("admin-shell-nav-version"));
|
|
352
|
+
assert.isNull(queryByTestId("admin-shell-nav-configuration"));
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("hides empty Models and Screens headings", () => {
|
|
356
|
+
restoreWindowWidth?.();
|
|
357
|
+
restoreWindowWidth = setWindowWidth(1024);
|
|
358
|
+
configState.config = {
|
|
359
|
+
customScreens: [],
|
|
360
|
+
models: [
|
|
361
|
+
platformModel({
|
|
362
|
+
displayName: "Audit Logs",
|
|
363
|
+
name: "AdminAuditLog",
|
|
364
|
+
routePath: "/admin/audit-logs",
|
|
365
|
+
}),
|
|
366
|
+
platformModel({
|
|
367
|
+
displayName: "Feature Flags",
|
|
368
|
+
name: "FeatureFlag",
|
|
369
|
+
routePath: "/admin/feature-flags",
|
|
370
|
+
}),
|
|
371
|
+
],
|
|
372
|
+
scripts: [],
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
376
|
+
<AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
|
|
377
|
+
<React.Fragment />
|
|
378
|
+
</AdminShell>
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
expect(queryByText("Models")).toBeNull();
|
|
382
|
+
expect(queryByText("Screens")).toBeNull();
|
|
383
|
+
expect(queryByText("Tools")).toBeNull();
|
|
384
|
+
expect(getByText("Platform")).toBeTruthy();
|
|
385
|
+
});
|
|
191
386
|
});
|
package/src/AdminShell.tsx
CHANGED
|
@@ -5,8 +5,9 @@ import React, {useCallback, useEffect, useState} from "react";
|
|
|
5
5
|
import {useWindowDimensions} from "react-native";
|
|
6
6
|
import {SafeAreaView} from "react-native-safe-area-context";
|
|
7
7
|
import {type AdminBreadcrumbSegment, AdminBreadcrumbs} from "./AdminBreadcrumbs";
|
|
8
|
+
import {isAdminPageForbiddenError} from "./adminPageAccess";
|
|
8
9
|
import {groupAdminModelsByGroup} from "./adminShellNav";
|
|
9
|
-
import type {AdminApi, AdminCustomScreen, AdminModelConfig} from "./types";
|
|
10
|
+
import type {AdminApi, AdminConfigResponse, AdminCustomScreen, AdminModelConfig} from "./types";
|
|
10
11
|
import {resolveAdminBases} from "./types";
|
|
11
12
|
import {useAdminConfig} from "./useAdminConfig";
|
|
12
13
|
|
|
@@ -33,6 +34,8 @@ export interface AdminShellProps {
|
|
|
33
34
|
footer?: React.ReactNode;
|
|
34
35
|
/** Optional right side of the top bar (e.g. primary action for the current screen). */
|
|
35
36
|
headerActions?: React.ReactNode;
|
|
37
|
+
/** Path to RBAC roles screen (e.g. "/roles") */
|
|
38
|
+
rolesPath?: string;
|
|
36
39
|
routeBase?: string;
|
|
37
40
|
/** Extra custom screens merged with backend config for nav cards */
|
|
38
41
|
customScreens?: AdminCustomScreen[];
|
|
@@ -59,6 +62,14 @@ const NavButton: React.FC<{
|
|
|
59
62
|
</Box>
|
|
60
63
|
);
|
|
61
64
|
|
|
65
|
+
const isAuditLogModel = (model: AdminModelConfig): boolean => {
|
|
66
|
+
return model.name === "AdminAuditLog" || model.routePath.includes("audit-log");
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const isFeatureFlagModel = (model: AdminModelConfig): boolean => {
|
|
70
|
+
return model.name === "FeatureFlag" || model.displayName === "Feature Flags";
|
|
71
|
+
};
|
|
72
|
+
|
|
62
73
|
interface AdminShellSidebarNavProps {
|
|
63
74
|
allCustomScreens: AdminCustomScreen[];
|
|
64
75
|
configurationPath?: string;
|
|
@@ -66,6 +77,8 @@ interface AdminShellSidebarNavProps {
|
|
|
66
77
|
grouped: ReturnType<typeof groupAdminModelsByGroup>;
|
|
67
78
|
navigate: (path: string) => void;
|
|
68
79
|
onNavigate?: () => void;
|
|
80
|
+
platformTools: NonNullable<AdminConfigResponse["platformTools"]>;
|
|
81
|
+
rolesPath?: string;
|
|
69
82
|
scripts: {name: string}[];
|
|
70
83
|
sidebarVariant: AdminShellSidebarVariant;
|
|
71
84
|
versionConfigPath: string;
|
|
@@ -78,12 +91,31 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
|
|
|
78
91
|
grouped,
|
|
79
92
|
navigate,
|
|
80
93
|
onNavigate,
|
|
94
|
+
platformTools,
|
|
95
|
+
rolesPath,
|
|
81
96
|
scripts,
|
|
82
97
|
sidebarVariant,
|
|
83
98
|
versionConfigPath,
|
|
84
99
|
}) => {
|
|
85
100
|
const sidebarIsColorful = sidebarVariant === "colorful";
|
|
86
101
|
const sectionLabelColor = sidebarIsColorful ? "inverted" : "secondaryDark";
|
|
102
|
+
const models = grouped.flatMap(({models: groupModels}) => groupModels);
|
|
103
|
+
const auditLogModel = models.find(isAuditLogModel);
|
|
104
|
+
const featureFlagModel = models.find(isFeatureFlagModel);
|
|
105
|
+
const visibleGrouped = grouped
|
|
106
|
+
.map(({group, models: groupModels}) => ({
|
|
107
|
+
group,
|
|
108
|
+
models: groupModels.filter((model) => !isAuditLogModel(model) && !isFeatureFlagModel(model)),
|
|
109
|
+
}))
|
|
110
|
+
.filter(({models: groupModels}) => groupModels.length > 0);
|
|
111
|
+
const hasPlatformLinks = Boolean(
|
|
112
|
+
(platformTools.scripts && scripts.length > 0) ||
|
|
113
|
+
(platformTools.roles && rolesPath) ||
|
|
114
|
+
(platformTools.version && versionConfigPath) ||
|
|
115
|
+
auditLogModel ||
|
|
116
|
+
featureFlagModel ||
|
|
117
|
+
(platformTools.configuration && configurationPath)
|
|
118
|
+
);
|
|
87
119
|
|
|
88
120
|
const runNav = useCallback(
|
|
89
121
|
(action: () => void): void => {
|
|
@@ -95,71 +127,48 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
|
|
|
95
127
|
|
|
96
128
|
return (
|
|
97
129
|
<>
|
|
98
|
-
<Box direction="column" flex="grow" gap={
|
|
99
|
-
<
|
|
100
|
-
label="Home"
|
|
101
|
-
onPress={() => {
|
|
102
|
-
runNav(() => {
|
|
103
|
-
navigate("/");
|
|
104
|
-
});
|
|
105
|
-
}}
|
|
106
|
-
sidebarVariant={sidebarVariant}
|
|
107
|
-
testID="admin-shell-nav-home"
|
|
108
|
-
/>
|
|
109
|
-
<Box direction="column" gap={1}>
|
|
110
|
-
<Text bold color={sectionLabelColor} size="sm">
|
|
111
|
-
Tools
|
|
112
|
-
</Text>
|
|
113
|
-
{scripts.length > 0 ? (
|
|
114
|
-
<NavButton
|
|
115
|
-
label="Scripts"
|
|
116
|
-
onPress={() => {
|
|
117
|
-
runNav(() => {
|
|
118
|
-
navigate("/__scripts");
|
|
119
|
-
});
|
|
120
|
-
}}
|
|
121
|
-
sidebarVariant={sidebarVariant}
|
|
122
|
-
testID="admin-shell-nav-scripts"
|
|
123
|
-
/>
|
|
124
|
-
) : null}
|
|
130
|
+
<Box direction="column" flex="grow" gap={4} minHeight={0} overflow="scrollY">
|
|
131
|
+
<Box direction="column">
|
|
125
132
|
<NavButton
|
|
126
|
-
label="
|
|
133
|
+
label="Home"
|
|
127
134
|
onPress={() => {
|
|
128
135
|
runNav(() => {
|
|
129
|
-
navigate(
|
|
136
|
+
navigate("/");
|
|
130
137
|
});
|
|
131
138
|
}}
|
|
132
139
|
sidebarVariant={sidebarVariant}
|
|
133
|
-
testID="admin-shell-nav-
|
|
140
|
+
testID="admin-shell-nav-home"
|
|
134
141
|
/>
|
|
135
142
|
</Box>
|
|
136
|
-
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
<
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
143
|
+
{visibleGrouped.length > 0 ? (
|
|
144
|
+
<Box direction="column" gap={3} testID="admin-shell-nav-models">
|
|
145
|
+
<Text bold color={sectionLabelColor} size="sm">
|
|
146
|
+
Models
|
|
147
|
+
</Text>
|
|
148
|
+
{visibleGrouped.map(({group, models: groupModels}) => (
|
|
149
|
+
<Box direction="column" gap={1} key={group}>
|
|
150
|
+
<Text bold color={sectionLabelColor} size="sm">
|
|
151
|
+
{group}
|
|
152
|
+
</Text>
|
|
153
|
+
{groupModels.map((model) => (
|
|
154
|
+
<NavButton
|
|
155
|
+
key={model.name}
|
|
156
|
+
label={model.displayName}
|
|
157
|
+
onPress={() => {
|
|
158
|
+
runNav(() => {
|
|
159
|
+
navigate(`/${model.name}`);
|
|
160
|
+
});
|
|
161
|
+
}}
|
|
162
|
+
sidebarVariant={sidebarVariant}
|
|
163
|
+
testID={`admin-shell-nav-model-${model.name}`}
|
|
164
|
+
/>
|
|
165
|
+
))}
|
|
166
|
+
</Box>
|
|
167
|
+
))}
|
|
168
|
+
</Box>
|
|
169
|
+
) : null}
|
|
161
170
|
{allCustomScreens.length > 0 ? (
|
|
162
|
-
<Box direction="column" gap={1}>
|
|
171
|
+
<Box direction="column" gap={1} testID="admin-shell-nav-screens">
|
|
163
172
|
<Text bold color={sectionLabelColor} size="sm">
|
|
164
173
|
Screens
|
|
165
174
|
</Text>
|
|
@@ -178,17 +187,85 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
|
|
|
178
187
|
))}
|
|
179
188
|
</Box>
|
|
180
189
|
) : null}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
<Box flex="grow" />
|
|
191
|
+
{hasPlatformLinks ? (
|
|
192
|
+
<Box direction="column" gap={1} testID="admin-shell-nav-platform">
|
|
193
|
+
<Text bold color={sectionLabelColor} size="sm">
|
|
194
|
+
Platform
|
|
195
|
+
</Text>
|
|
196
|
+
{platformTools.scripts && scripts.length > 0 ? (
|
|
197
|
+
<NavButton
|
|
198
|
+
label="Scripts"
|
|
199
|
+
onPress={() => {
|
|
200
|
+
runNav(() => {
|
|
201
|
+
navigate("/__scripts");
|
|
202
|
+
});
|
|
203
|
+
}}
|
|
204
|
+
sidebarVariant={sidebarVariant}
|
|
205
|
+
testID="admin-shell-nav-scripts"
|
|
206
|
+
/>
|
|
207
|
+
) : null}
|
|
208
|
+
{platformTools.roles && rolesPath ? (
|
|
209
|
+
<NavButton
|
|
210
|
+
label="Roles"
|
|
211
|
+
onPress={() => {
|
|
212
|
+
runNav(() => {
|
|
213
|
+
navigate(rolesPath);
|
|
214
|
+
});
|
|
215
|
+
}}
|
|
216
|
+
sidebarVariant={sidebarVariant}
|
|
217
|
+
testID="admin-shell-nav-roles"
|
|
218
|
+
/>
|
|
219
|
+
) : null}
|
|
220
|
+
{platformTools.version && versionConfigPath ? (
|
|
221
|
+
<NavButton
|
|
222
|
+
label="Version"
|
|
223
|
+
onPress={() => {
|
|
224
|
+
runNav(() => {
|
|
225
|
+
navigate(versionConfigPath);
|
|
226
|
+
});
|
|
227
|
+
}}
|
|
228
|
+
sidebarVariant={sidebarVariant}
|
|
229
|
+
testID="admin-shell-nav-version"
|
|
230
|
+
/>
|
|
231
|
+
) : null}
|
|
232
|
+
{auditLogModel ? (
|
|
233
|
+
<NavButton
|
|
234
|
+
label="Audit Log"
|
|
235
|
+
onPress={() => {
|
|
236
|
+
runNav(() => {
|
|
237
|
+
navigate(`/${auditLogModel.name}`);
|
|
238
|
+
});
|
|
239
|
+
}}
|
|
240
|
+
sidebarVariant={sidebarVariant}
|
|
241
|
+
testID="admin-shell-nav-audit-log"
|
|
242
|
+
/>
|
|
243
|
+
) : null}
|
|
244
|
+
{featureFlagModel ? (
|
|
245
|
+
<NavButton
|
|
246
|
+
label="Feature Flags"
|
|
247
|
+
onPress={() => {
|
|
248
|
+
runNav(() => {
|
|
249
|
+
navigate(`/${featureFlagModel.name}`);
|
|
250
|
+
});
|
|
251
|
+
}}
|
|
252
|
+
sidebarVariant={sidebarVariant}
|
|
253
|
+
testID="admin-shell-nav-feature-flags"
|
|
254
|
+
/>
|
|
255
|
+
) : null}
|
|
256
|
+
{platformTools.configuration && configurationPath ? (
|
|
257
|
+
<NavButton
|
|
258
|
+
label="Configuration"
|
|
259
|
+
onPress={() => {
|
|
260
|
+
runNav(() => {
|
|
261
|
+
router.push(configurationPath as Href);
|
|
262
|
+
});
|
|
263
|
+
}}
|
|
264
|
+
sidebarVariant={sidebarVariant}
|
|
265
|
+
testID="admin-shell-nav-configuration"
|
|
266
|
+
/>
|
|
267
|
+
) : null}
|
|
268
|
+
</Box>
|
|
192
269
|
) : null}
|
|
193
270
|
</Box>
|
|
194
271
|
{footer ? <Box marginTop={4}>{footer}</Box> : null}
|
|
@@ -219,6 +296,7 @@ export const AdminShell: React.FC<AdminShellProps> = ({
|
|
|
219
296
|
customScreens: propCustomScreens,
|
|
220
297
|
footer,
|
|
221
298
|
headerActions,
|
|
299
|
+
rolesPath,
|
|
222
300
|
routeBase,
|
|
223
301
|
sidebarVariant = "colorful",
|
|
224
302
|
versionConfigPath = "/version-config",
|
|
@@ -276,6 +354,15 @@ export const AdminShell: React.FC<AdminShellProps> = ({
|
|
|
276
354
|
}
|
|
277
355
|
|
|
278
356
|
if (error || !config) {
|
|
357
|
+
if (isAdminPageForbiddenError(error)) {
|
|
358
|
+
return (
|
|
359
|
+
<Box padding={4} testID="admin-shell-forbidden">
|
|
360
|
+
<Text color="error">
|
|
361
|
+
You do not have permission to open the admin page. Grant the admin:access permission.
|
|
362
|
+
</Text>
|
|
363
|
+
</Box>
|
|
364
|
+
);
|
|
365
|
+
}
|
|
279
366
|
return (
|
|
280
367
|
<Box padding={4} testID="admin-shell-error">
|
|
281
368
|
<Text color="error">Failed to load admin configuration.</Text>
|
|
@@ -284,8 +371,16 @@ export const AdminShell: React.FC<AdminShellProps> = ({
|
|
|
284
371
|
}
|
|
285
372
|
|
|
286
373
|
const backendScreens = config.customScreens ?? [];
|
|
287
|
-
const allCustomScreens =
|
|
374
|
+
const allCustomScreens = config.platformTools
|
|
375
|
+
? backendScreens
|
|
376
|
+
: [...backendScreens, ...(propCustomScreens ?? [])];
|
|
288
377
|
const scripts = config.scripts ?? [];
|
|
378
|
+
const platformTools = config.platformTools ?? {
|
|
379
|
+
configuration: true,
|
|
380
|
+
roles: true,
|
|
381
|
+
scripts: true,
|
|
382
|
+
version: true,
|
|
383
|
+
};
|
|
289
384
|
const grouped = groupAdminModelsByGroup(config.models as AdminModelConfig[]);
|
|
290
385
|
|
|
291
386
|
const sidebarIsColorful = sidebarVariant === "colorful";
|
|
@@ -297,6 +392,8 @@ export const AdminShell: React.FC<AdminShellProps> = ({
|
|
|
297
392
|
footer,
|
|
298
393
|
grouped,
|
|
299
394
|
navigate,
|
|
395
|
+
platformTools,
|
|
396
|
+
rolesPath,
|
|
300
397
|
scripts,
|
|
301
398
|
sidebarVariant,
|
|
302
399
|
versionConfigPath,
|
package/src/Constants.ts
ADDED