@terreno/admin-frontend 57.1.0 → 57.3.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.
Files changed (139) hide show
  1. package/.ai/guidelines/core.md +10 -7
  2. package/README.md +2 -0
  3. package/dist/AdminModelForm.js +14 -7
  4. package/dist/AdminModelForm.js.map +1 -1
  5. package/dist/AdminModelList.js +3 -1
  6. package/dist/AdminModelList.js.map +1 -1
  7. package/dist/AdminModelTable.js +2 -1
  8. package/dist/AdminModelTable.js.map +1 -1
  9. package/dist/AdminRolesList.js +67 -6
  10. package/dist/AdminRolesList.js.map +1 -1
  11. package/dist/AdminScreenPage.d.ts +18 -0
  12. package/dist/AdminScreenPage.js +35 -0
  13. package/dist/AdminScreenPage.js.map +1 -0
  14. package/dist/AdminScreenRouter.js +4 -3
  15. package/dist/AdminScreenRouter.js.map +1 -1
  16. package/dist/AdminScriptList.js +12 -10
  17. package/dist/AdminScriptList.js.map +1 -1
  18. package/dist/AdminShell.js +24 -11
  19. package/dist/AdminShell.js.map +1 -1
  20. package/dist/DocumentStorageBrowser.js +4 -3
  21. package/dist/DocumentStorageBrowser.js.map +1 -1
  22. package/dist/adminPageAccess.d.ts +5 -0
  23. package/dist/adminPageAccess.js +19 -0
  24. package/dist/adminPageAccess.js.map +1 -0
  25. package/dist/comms/CommsDashboardScreen.d.ts +10 -0
  26. package/dist/comms/CommsDashboardScreen.js +183 -0
  27. package/dist/comms/CommsDashboardScreen.js.map +1 -0
  28. package/dist/comms/CommsDashboardScreenWidget.d.ts +4 -0
  29. package/dist/comms/CommsDashboardScreenWidget.js +11 -0
  30. package/dist/comms/CommsDashboardScreenWidget.js.map +1 -0
  31. package/dist/comms/CommsMessageDetail.d.ts +8 -0
  32. package/dist/comms/CommsMessageDetail.js +50 -0
  33. package/dist/comms/CommsMessageDetail.js.map +1 -0
  34. package/dist/comms/CommsStatCard.d.ts +17 -0
  35. package/dist/comms/CommsStatCard.js +14 -0
  36. package/dist/comms/CommsStatCard.js.map +1 -0
  37. package/dist/comms/CommsStatusBadge.d.ts +5 -0
  38. package/dist/comms/CommsStatusBadge.js +14 -0
  39. package/dist/comms/CommsStatusBadge.js.map +1 -0
  40. package/dist/comms/commsDashboardParams.d.ts +17 -0
  41. package/dist/comms/commsDashboardParams.js +71 -0
  42. package/dist/comms/commsDashboardParams.js.map +1 -0
  43. package/dist/comms/commsMessagePayload.d.ts +49 -0
  44. package/dist/comms/commsMessagePayload.js +43 -0
  45. package/dist/comms/commsMessagePayload.js.map +1 -0
  46. package/dist/comms/commsRetrySummary.d.ts +4 -0
  47. package/dist/comms/commsRetrySummary.js +12 -0
  48. package/dist/comms/commsRetrySummary.js.map +1 -0
  49. package/dist/comms/useCommsDashboardApi.d.ts +78 -0
  50. package/dist/comms/useCommsDashboardApi.js +60 -0
  51. package/dist/comms/useCommsDashboardApi.js.map +1 -0
  52. package/dist/comms/useCommsDashboardUrlFilters.d.ts +5 -0
  53. package/dist/comms/useCommsDashboardUrlFilters.js +16 -0
  54. package/dist/comms/useCommsDashboardUrlFilters.js.map +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.js +8 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/types.d.ts +15 -0
  59. package/dist/types.js.map +1 -1
  60. package/dist/useAdminBackgroundTask.d.ts +10 -2
  61. package/dist/useAdminBackgroundTask.js.map +1 -1
  62. package/dist/useConfigurationApi.d.ts +13 -15
  63. package/dist/useConfigurationApi.js.map +1 -1
  64. package/dist/widgets/AIRequestsScreenWidget.js +4 -3
  65. package/dist/widgets/AIRequestsScreenWidget.js.map +1 -1
  66. package/dist/widgets/DocumentsScreenWidget.js +2 -2
  67. package/dist/widgets/DocumentsScreenWidget.js.map +1 -1
  68. package/dist/widgets/builtInWidgets.js +2 -1
  69. package/dist/widgets/builtInWidgets.js.map +1 -1
  70. package/package.json +17 -3
  71. package/src/AdminActionMenu.test.tsx +1 -1
  72. package/src/AdminBreadcrumbs.test.tsx +1 -1
  73. package/src/AdminFieldRenderer.test.tsx +6 -1
  74. package/src/AdminHome.test.tsx +1 -1
  75. package/src/AdminModelForm.test.tsx +34 -1
  76. package/src/AdminModelForm.tsx +25 -9
  77. package/src/AdminModelList.test.tsx +1 -1
  78. package/src/AdminModelList.tsx +3 -1
  79. package/src/AdminModelTable.test.tsx +1 -1
  80. package/src/AdminModelTable.tsx +3 -1
  81. package/src/AdminPrimitiveArrayField.test.tsx +1 -1
  82. package/src/AdminRolesList.test.tsx +85 -3
  83. package/src/AdminRolesList.tsx +147 -24
  84. package/src/AdminScreenPage.test.tsx +81 -0
  85. package/src/AdminScreenPage.tsx +37 -0
  86. package/src/AdminScreenRouter.test.tsx +2 -1
  87. package/src/AdminScreenRouter.tsx +18 -5
  88. package/src/AdminScriptList.test.tsx +1 -1
  89. package/src/AdminScriptList.tsx +42 -30
  90. package/src/AdminShell.test.tsx +90 -1
  91. package/src/AdminShell.tsx +31 -10
  92. package/src/AdminVersionConfig.test.tsx +1 -1
  93. package/src/CheckboxListEditor.test.tsx +1 -1
  94. package/src/ConfigurationScreen.test.tsx +1 -1
  95. package/src/ConsentFormEditor.test.tsx +1 -1
  96. package/src/ConsentFormList.test.tsx +1 -1
  97. package/src/ConsentHistory.test.tsx +1 -1
  98. package/src/ConsentResponseViewer.test.tsx +1 -1
  99. package/src/DocumentStorageBrowser.test.tsx +1 -1
  100. package/src/DocumentStorageBrowser.tsx +10 -3
  101. package/src/LocaleContentEditor.test.tsx +1 -1
  102. package/src/adminModelListQueryParams.test.ts +59 -0
  103. package/src/adminPageAccess.test.ts +18 -0
  104. package/src/adminPageAccess.ts +18 -0
  105. package/src/comms/CommsDashboardScreen.test.tsx +397 -0
  106. package/src/comms/CommsDashboardScreen.tsx +500 -0
  107. package/src/comms/CommsDashboardScreenWidget.test.tsx +62 -0
  108. package/src/comms/CommsDashboardScreenWidget.tsx +20 -0
  109. package/src/comms/CommsMessageDetail.test.tsx +245 -0
  110. package/src/comms/CommsMessageDetail.tsx +239 -0
  111. package/src/comms/CommsStatCard.test.tsx +69 -0
  112. package/src/comms/CommsStatCard.tsx +60 -0
  113. package/src/comms/CommsStatusBadge.tsx +14 -0
  114. package/src/comms/commsDashboardParams.test.ts +75 -0
  115. package/src/comms/commsDashboardParams.ts +91 -0
  116. package/src/comms/commsMessagePayload.test.ts +22 -0
  117. package/src/comms/commsMessagePayload.ts +83 -0
  118. package/src/comms/commsRetrySummary.ts +10 -0
  119. package/src/comms/useCommsDashboardApi.test.tsx +144 -0
  120. package/src/comms/useCommsDashboardApi.tsx +128 -0
  121. package/src/comms/useCommsDashboardUrlFilters.test.tsx +58 -0
  122. package/src/comms/useCommsDashboardUrlFilters.tsx +31 -0
  123. package/src/dynamicHookApi.ts +1 -1
  124. package/src/index.tsx +15 -0
  125. package/src/isolated/AdminFieldRenderer.isolated.tsx +1 -1
  126. package/src/{AdminFilterDrawer.test.tsx → isolated/AdminFilterDrawer.isolated.tsx} +8 -2
  127. package/src/isolated/AdminNestedArrayField.isolated.tsx +1 -1
  128. package/src/isolated/AdminObjectPicker.isolated.tsx +1 -1
  129. package/src/isolated/AdminRefField.isolated.tsx +1 -1
  130. package/src/isolated/AdminScriptRunModal.isolated.tsx +1 -1
  131. package/src/isolated/DocumentStorageBrowser.isolated.tsx +1 -1
  132. package/src/isolated/hooks.isolated.tsx +1 -1
  133. package/src/types.ts +16 -0
  134. package/src/useAdminBackgroundTask.ts +7 -5
  135. package/src/useConfigurationApi.ts +13 -16
  136. package/src/widgets/AIRequestsScreenWidget.tsx +5 -4
  137. package/src/widgets/DocumentsScreenWidget.tsx +9 -2
  138. package/src/widgets/builtInWidgets.ts +2 -0
  139. package/src/widgets/pluginWidgets.test.tsx +3 -1
@@ -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({limit: HISTORY_PAGE_SIZE, page: 1});
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
- limit: HISTORY_PAGE_SIZE,
82
- name: historyScriptName ?? undefined,
83
- page: historyPage,
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
- <Box
212
- accessibilityHint={`Opens run history for ${script.name}`}
213
- accessibilityLabel={`View run history for ${script.name}`}
214
- onClick={() => handleViewHistory(script.name)}
215
- testID={`admin-script-history-${script.name}`}
216
- >
217
- <Text color="link" size="sm">
218
- History
219
- </Text>
220
- </Box>
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={!isAdmin}
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={!isAdmin ? "Only admins can run scripts" : undefined}
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
- <Box paddingX={4} paddingY={4}>
364
- <SegmentedControl
365
- items={[
366
- "Scripts",
367
- (latestRunsData?.total ?? latestRuns.length) > 0
368
- ? `Run history (${latestRunsData?.total ?? latestRuns.length})`
369
- : "Run history",
370
- ]}
371
- onChange={handleTabChange}
372
- selectedIndex={tab === "history" ? 1 : 0}
373
- />
374
- </Box>
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
 
@@ -1,12 +1,13 @@
1
1
  // noExplicitAny: test harness doubles
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test harness doubles
3
3
  import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
5
+ import {assert} from "chai";
6
6
  import React from "react";
7
7
  import type {ScaledSize} from "react-native";
8
8
  import {useWindowDimensions} from "react-native";
9
9
  import {SafeAreaView} from "react-native-safe-area-context";
10
+ import {renderWithTheme} from "../../ui/src/test-utils";
10
11
  import type {AdminApi, AdminConfigResponse, AdminModelConfig} from "./types";
11
12
 
12
13
  const mockRouterPush = mock((_href: string) => {});
@@ -126,6 +127,23 @@ describe("AdminShell", () => {
126
127
  expect(queryByTestId("admin-shell-mobile-header")).toBeNull();
127
128
  });
128
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
+
129
147
  it("hides the fixed sidebar and shows a hamburger header below 768px", () => {
130
148
  const {getByTestId, getByLabelText, queryByTestId, UNSAFE_root} = renderWithTheme(
131
149
  <AdminShell api={mockApi} apiBase="/admin" routeBase="/admin">
@@ -263,6 +281,77 @@ describe("AdminShell", () => {
263
281
  expect(mockRouterPush).toHaveBeenLastCalledWith("/admin/AdminAuditLog");
264
282
  });
265
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
+
266
355
  it("hides empty Models and Screens headings", () => {
267
356
  restoreWindowWidth?.();
268
357
  restoreWindowWidth = setWindowWidth(1024);
@@ -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
 
@@ -76,6 +77,7 @@ interface AdminShellSidebarNavProps {
76
77
  grouped: ReturnType<typeof groupAdminModelsByGroup>;
77
78
  navigate: (path: string) => void;
78
79
  onNavigate?: () => void;
80
+ platformTools: NonNullable<AdminConfigResponse["platformTools"]>;
79
81
  rolesPath?: string;
80
82
  scripts: {name: string}[];
81
83
  sidebarVariant: AdminShellSidebarVariant;
@@ -89,6 +91,7 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
89
91
  grouped,
90
92
  navigate,
91
93
  onNavigate,
94
+ platformTools,
92
95
  rolesPath,
93
96
  scripts,
94
97
  sidebarVariant,
@@ -106,12 +109,12 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
106
109
  }))
107
110
  .filter(({models: groupModels}) => groupModels.length > 0);
108
111
  const hasPlatformLinks = Boolean(
109
- scripts.length > 0 ||
110
- rolesPath ||
111
- versionConfigPath ||
112
+ (platformTools.scripts && scripts.length > 0) ||
113
+ (platformTools.roles && rolesPath) ||
114
+ (platformTools.version && versionConfigPath) ||
112
115
  auditLogModel ||
113
116
  featureFlagModel ||
114
- configurationPath
117
+ (platformTools.configuration && configurationPath)
115
118
  );
116
119
 
117
120
  const runNav = useCallback(
@@ -190,7 +193,7 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
190
193
  <Text bold color={sectionLabelColor} size="sm">
191
194
  Platform
192
195
  </Text>
193
- {scripts.length > 0 ? (
196
+ {platformTools.scripts && scripts.length > 0 ? (
194
197
  <NavButton
195
198
  label="Scripts"
196
199
  onPress={() => {
@@ -202,7 +205,7 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
202
205
  testID="admin-shell-nav-scripts"
203
206
  />
204
207
  ) : null}
205
- {rolesPath ? (
208
+ {platformTools.roles && rolesPath ? (
206
209
  <NavButton
207
210
  label="Roles"
208
211
  onPress={() => {
@@ -214,7 +217,7 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
214
217
  testID="admin-shell-nav-roles"
215
218
  />
216
219
  ) : null}
217
- {versionConfigPath ? (
220
+ {platformTools.version && versionConfigPath ? (
218
221
  <NavButton
219
222
  label="Version"
220
223
  onPress={() => {
@@ -250,7 +253,7 @@ const AdminShellSidebarNav: React.FC<AdminShellSidebarNavProps> = ({
250
253
  testID="admin-shell-nav-feature-flags"
251
254
  />
252
255
  ) : null}
253
- {configurationPath ? (
256
+ {platformTools.configuration && configurationPath ? (
254
257
  <NavButton
255
258
  label="Configuration"
256
259
  onPress={() => {
@@ -351,6 +354,15 @@ export const AdminShell: React.FC<AdminShellProps> = ({
351
354
  }
352
355
 
353
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
+ }
354
366
  return (
355
367
  <Box padding={4} testID="admin-shell-error">
356
368
  <Text color="error">Failed to load admin configuration.</Text>
@@ -359,8 +371,16 @@ export const AdminShell: React.FC<AdminShellProps> = ({
359
371
  }
360
372
 
361
373
  const backendScreens = config.customScreens ?? [];
362
- const allCustomScreens = [...backendScreens, ...(propCustomScreens ?? [])];
374
+ const allCustomScreens = config.platformTools
375
+ ? backendScreens
376
+ : [...backendScreens, ...(propCustomScreens ?? [])];
363
377
  const scripts = config.scripts ?? [];
378
+ const platformTools = config.platformTools ?? {
379
+ configuration: true,
380
+ roles: true,
381
+ scripts: true,
382
+ version: true,
383
+ };
364
384
  const grouped = groupAdminModelsByGroup(config.models as AdminModelConfig[]);
365
385
 
366
386
  const sidebarIsColorful = sidebarVariant === "colorful";
@@ -372,6 +392,7 @@ export const AdminShell: React.FC<AdminShellProps> = ({
372
392
  footer,
373
393
  grouped,
374
394
  navigate,
395
+ platformTools,
375
396
  rolesPath,
376
397
  scripts,
377
398
  sidebarVariant,
@@ -1,10 +1,10 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic endpoint builders
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
7
6
  import type {ReactTestInstance} from "react-test-renderer";
7
+ import {renderWithTheme} from "../../ui/src/test-utils";
8
8
  import type {AdminApi} from "./types";
9
9
 
10
10
  const routerBack = mock(() => {});
@@ -1,10 +1,10 @@
1
1
  // noExplicitAny: test mocks use type-erased mock.calls access for assertion
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
7
6
  import type {ReactTestInstance} from "react-test-renderer";
7
+ import {renderWithTheme} from "../../ui/src/test-utils";
8
8
  import {CheckboxListEditor} from "./CheckboxListEditor";
9
9
 
10
10
  const press = async (el: ReactTestInstance): Promise<void> => {
@@ -1,9 +1,9 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic mock returns
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
6
+ import {renderWithTheme} from "../../ui/src/test-utils";
7
7
  import type {AdminApi} from "./types";
8
8
 
9
9
  interface QueryState<T> {
@@ -1,10 +1,10 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and UNSAFE_root traversal
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
7
6
  import type {ReactTestInstance} from "react-test-renderer";
7
+ import {renderWithTheme} from "../../ui/src/test-utils";
8
8
  import type {AdminApi} from "./types";
9
9
 
10
10
  interface State {
@@ -1,10 +1,10 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and UNSAFE_root traversal
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
7
6
  import type {ReactTestInstance} from "react-test-renderer";
7
+ import {renderWithTheme} from "../../ui/src/test-utils";
8
8
  import type {AdminApi} from "./types";
9
9
 
10
10
  interface ListState {
@@ -1,6 +1,6 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
3
2
  import {act, fireEvent, waitFor} from "@testing-library/react-native";
3
+ import {renderWithTheme} from "../../ui/src/test-utils";
4
4
 
5
5
  import {ConsentHistory} from "./ConsentHistory";
6
6
  import type {ConsentHistoryEntry} from "./useConsentHistory";
@@ -1,9 +1,9 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic mock returns
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
6
+ import {renderWithTheme} from "../../ui/src/test-utils";
7
7
  import type {AdminApi} from "./types";
8
8
 
9
9
  interface ReadState {
@@ -1,11 +1,11 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and dynamic mock returns
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
7
6
  import {Platform} from "react-native";
8
7
  import type {ReactTestInstance} from "react-test-renderer";
8
+ import {renderWithTheme} from "../../ui/src/test-utils";
9
9
  import type {AdminApi} from "./types";
10
10
 
11
11
  mock.module("react-native-webview", () => ({
@@ -8,7 +8,6 @@ import {
8
8
  IconButton,
9
9
  Link,
10
10
  Modal,
11
- Page,
12
11
  Spinner,
13
12
  Text,
14
13
  TextField,
@@ -18,6 +17,7 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from "react";
18
17
  import {Platform, Image as RNImage, useWindowDimensions} from "react-native";
19
18
  import {WebView} from "react-native-webview";
20
19
 
20
+ import {AdminScreenPage} from "./AdminScreenPage";
21
21
  import type {DocumentFile, DocumentListResponse, DocumentStorageBrowserProps} from "./types";
22
22
  import {useDocumentStorageApi} from "./useDocumentStorageApi";
23
23
 
@@ -42,6 +42,7 @@ const formatDate = (isoDate: string): string => {
42
42
  export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
43
43
  api,
44
44
  basePath,
45
+ backHref,
45
46
  title = "Documents",
46
47
  allowDelete = true,
47
48
  allowUpload = true,
@@ -600,7 +601,13 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
600
601
  };
601
602
 
602
603
  return (
603
- <Page color="transparent" maxWidth="100%" padding={0} title={title}>
604
+ <AdminScreenPage
605
+ backHref={backHref}
606
+ color="transparent"
607
+ maxWidth="100%"
608
+ padding={0}
609
+ title={title}
610
+ >
604
611
  {headerRow}
605
612
  {renderContent()}
606
613
 
@@ -636,6 +643,6 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
636
643
  />
637
644
  </Box>
638
645
  </Modal>
639
- </Page>
646
+ </AdminScreenPage>
640
647
  );
641
648
  };
@@ -1,10 +1,10 @@
1
1
  // noExplicitAny: test mocks use UNSAFE_root traversal and mock.calls access for assertions
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {describe, expect, it, mock} from "bun:test";
4
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
5
4
  import {act, fireEvent} from "@testing-library/react-native";
6
5
  import React from "react";
7
6
  import type {ReactTestInstance} from "react-test-renderer";
7
+ import {renderWithTheme} from "../../ui/src/test-utils";
8
8
  import {LocaleContentEditor} from "./LocaleContentEditor";
9
9
 
10
10
  const press = async (el: ReactTestInstance): Promise<void> => {
@@ -66,4 +66,63 @@ describe("buildAdminListQueryParams", () => {
66
66
  assert.isUndefined(params.q);
67
67
  assert.equal(params.completed, true);
68
68
  });
69
+
70
+ it("includes sort, dateRange bounds, choice/text/ref filters, and skips empty values", () => {
71
+ const modelConfig = {
72
+ filters: [
73
+ {field: "created", kind: "dateRange"},
74
+ {field: "status", kind: "choice"},
75
+ {field: "title", kind: "text"},
76
+ {field: "ownerId", kind: "ref"},
77
+ {field: "completed", kind: "boolean"},
78
+ ],
79
+ searchFields: ["title"],
80
+ } as AdminModelConfig;
81
+ const params = buildAdminListQueryParams({
82
+ filterState: {
83
+ completed: "all",
84
+ created_gte: "2026-01-01",
85
+ created_lte: " 2026-01-31 ",
86
+ ownerId: "abc",
87
+ status: "open",
88
+ title: "hello",
89
+ },
90
+ limit: 10,
91
+ modelConfig,
92
+ page: 2,
93
+ searchDebounced: "q",
94
+ sort: "-created",
95
+ });
96
+ assert.equal(params.sort, "-created");
97
+ assert.equal(params.created_gte, "2026-01-01");
98
+ assert.equal(params.created_lte, "2026-01-31");
99
+ assert.equal(params.status, "open");
100
+ assert.equal(params.title, "hello");
101
+ assert.equal(params.ownerId, "abc");
102
+ assert.equal(params.q, "q");
103
+ assert.isUndefined(params.completed);
104
+ });
105
+
106
+ it("coerces boolean filters and skips blank date bounds", () => {
107
+ const modelConfig = {
108
+ filters: [
109
+ {field: "completed", kind: "boolean"},
110
+ {field: "created", kind: "dateRange"},
111
+ ],
112
+ } as AdminModelConfig;
113
+ const params = buildAdminListQueryParams({
114
+ filterState: {
115
+ completed: "true",
116
+ created_gte: " ",
117
+ created_lte: undefined,
118
+ },
119
+ limit: 10,
120
+ modelConfig,
121
+ page: 1,
122
+ searchDebounced: "",
123
+ });
124
+ assert.equal(params.completed, true);
125
+ assert.isUndefined(params.created_gte);
126
+ assert.isUndefined(params.created_lte);
127
+ });
69
128
  });
@@ -0,0 +1,18 @@
1
+ import {describe, it} from "bun:test";
2
+ import {assert} from "chai";
3
+
4
+ import {isAdminPageForbiddenError} from "./adminPageAccess";
5
+
6
+ describe("isAdminPageForbiddenError", () => {
7
+ it("detects RTK 403 errors", () => {
8
+ assert.isTrue(isAdminPageForbiddenError({status: 403}));
9
+ assert.isTrue(isAdminPageForbiddenError({originalStatus: 403, status: "FETCH_ERROR"}));
10
+ assert.isTrue(isAdminPageForbiddenError({status: {status: 403}}));
11
+ });
12
+
13
+ it("ignores other failures", () => {
14
+ assert.isFalse(isAdminPageForbiddenError(undefined));
15
+ assert.isFalse(isAdminPageForbiddenError({status: 500}));
16
+ assert.isFalse(isAdminPageForbiddenError(new Error("Failed to load")));
17
+ });
18
+ });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Detect a 403 from GET /admin/config. That is the single admin-page gate:
3
+ * `admin:access` when RBAC is on, otherwise `user.admin`.
4
+ */
5
+ export const isAdminPageForbiddenError = (error: unknown): boolean => {
6
+ if (!error || typeof error !== "object") {
7
+ return false;
8
+ }
9
+ const withStatus = error as {originalStatus?: unknown; status?: unknown};
10
+ if (withStatus.status === 403 || withStatus.originalStatus === 403) {
11
+ return true;
12
+ }
13
+ const nested = withStatus.status;
14
+ if (nested && typeof nested === "object" && "status" in nested) {
15
+ return (nested as {status?: unknown}).status === 403;
16
+ }
17
+ return false;
18
+ };