@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
@@ -7,6 +7,7 @@ import type {
7
7
  AdminFieldConfig,
8
8
  AdminFieldValue,
9
9
  AdminModelConfig,
10
+ AdminRecordCapabilities,
10
11
  RefRendererMap,
11
12
  } from "./types";
12
13
  import {resolveAdminBases, SYSTEM_FIELDS} from "./types";
@@ -457,6 +458,14 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
457
458
  }, [itemId, deleteItem, toast, modelName]);
458
459
 
459
460
  const isSaving = isCreating || isUpdating;
461
+ const recordCapabilities = (
462
+ itemData as {_adminCapabilities?: AdminRecordCapabilities} | undefined
463
+ )?._adminCapabilities;
464
+ const isFormWritable =
465
+ mode === "create"
466
+ ? modelConfig?.permissions?.create !== false
467
+ : (recordCapabilities?.update ?? modelConfig?.permissions?.update !== false);
468
+ const canDeleteRecord = recordCapabilities?.delete ?? modelConfig?.permissions?.delete !== false;
460
469
 
461
470
  const navigationTitle = useMemo((): string => {
462
471
  if (!modelConfig) {
@@ -512,16 +521,18 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
512
521
  navigation.setOptions({
513
522
  headerRight: () => (
514
523
  <Box alignItems="center" direction="row" gap={2} justifyContent="center" marginRight={3}>
515
- {mode === "edit" && modelConfig.permissions?.delete !== false ? (
524
+ {mode === "edit" && canDeleteRecord ? (
516
525
  <DeleteButton loading={isDeleting} onDelete={handleDelete} />
517
526
  ) : null}
518
- <Button
519
- loading={isSaving}
520
- onClick={handleSave}
521
- testID="admin-save-button"
522
- text={mode === "create" ? "Create" : "Save"}
523
- variant="primary"
524
- />
527
+ {isFormWritable ? (
528
+ <Button
529
+ loading={isSaving}
530
+ onClick={handleSave}
531
+ testID="admin-save-button"
532
+ text={mode === "create" ? "Create" : "Save"}
533
+ variant="primary"
534
+ />
535
+ ) : null}
525
536
  </Box>
526
537
  ),
527
538
  title: navigationTitle,
@@ -535,6 +546,8 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
535
546
  isDeleting,
536
547
  handleSave,
537
548
  handleDelete,
549
+ isFormWritable,
550
+ canDeleteRecord,
538
551
  ]);
539
552
 
540
553
  const visibleFields = useMemo((): [string, AdminFieldConfig][] => {
@@ -552,8 +565,11 @@ export const AdminModelForm: React.FC<AdminModelFormProps> = ({
552
565
  if (!modelConfig) {
553
566
  return new Set<string>();
554
567
  }
568
+ if (!isFormWritable) {
569
+ return new Set(Object.keys(modelConfig.fields));
570
+ }
555
571
  return new Set(modelConfig.readonlyFields ?? []);
556
- }, [modelConfig]);
572
+ }, [isFormWritable, modelConfig]);
557
573
 
558
574
  const fieldSections = useMemo(() => {
559
575
  if (!modelConfig?.fieldsets?.length) {
@@ -1,9 +1,9 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles
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, AdminConfigResponse} from "./types";
8
8
 
9
9
  const routerPush = mock(() => {});
@@ -190,7 +190,9 @@ export const AdminModelList: React.FC<AdminModelListProps> = ({
190
190
  }
191
191
 
192
192
  const backendScreens = config.customScreens ?? [];
193
- const allCustomScreens = [...backendScreens, ...(propCustomScreens ?? [])];
193
+ const allCustomScreens = config.platformTools
194
+ ? backendScreens
195
+ : [...backendScreens, ...(propCustomScreens ?? [])];
194
196
  const scripts = config.scripts ?? [];
195
197
  const hasToolCards = allCustomScreens.length > 0 || scripts.length > 0 || !!configurationPath;
196
198
 
@@ -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, AdminConfigResponse} from "./types";
9
9
 
10
10
  const routerPush = mock(() => {});
@@ -596,9 +596,11 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
596
596
  fieldConfig?.type === "boolean" && modelConfig.permissions?.update !== false;
597
597
 
598
598
  if (isInlineBool) {
599
+ const recordCapabilities = item._adminCapabilities as {update?: boolean} | undefined;
599
600
  return {
600
601
  value: {
601
- disabled: modelConfig.permissions?.update === false,
602
+ disabled:
603
+ recordCapabilities?.update === false || modelConfig.permissions?.update === false,
602
604
  onToggle: () => handleInlineBooleanToggle(id, fieldKey, !item[fieldKey]),
603
605
  value: Boolean(item[fieldKey]),
604
606
  },
@@ -1,10 +1,10 @@
1
1
  // noExplicitAny: test mocks use type-erased RTK Query API doubles and mock.calls access
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 {AdminPrimitiveArrayField} from "./AdminPrimitiveArrayField";
9
9
  import type {AdminApi} from "./types";
10
10
 
@@ -2,9 +2,10 @@
2
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
4
4
  import {SelectField} from "@terreno/ui";
5
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
6
5
  import {act, fireEvent} from "@testing-library/react-native";
6
+ import {assert} from "chai";
7
7
  import React from "react";
8
+ import {renderWithTheme} from "../../ui/src/test-utils";
8
9
  import {AdminRolesField} from "./AdminRolesField";
9
10
  import {AdminRolesList} from "./AdminRolesList";
10
11
  import type {AdminApi} from "./types";
@@ -17,7 +18,13 @@ const mockRefetch = mock(() => {});
17
18
  const mockCreateRole = mock(() => ({unwrap: async () => ({})}));
18
19
  const mockUpdateRole = mock(() => ({unwrap: async () => ({})}));
19
20
  const mockUseListStatementsQuery = mock(() => ({
20
- data: {statements: {admin: ["access", "runScripts"], todo: ["read", "update"]}},
21
+ data: {
22
+ statements: {
23
+ admin: ["access", "runScripts"],
24
+ adminTodo: ["read", "write", "writeOwned"],
25
+ todo: ["read", "update"],
26
+ },
27
+ },
21
28
  error: null,
22
29
  isLoading: false,
23
30
  }));
@@ -49,7 +56,12 @@ const collectTestIDs = (node: unknown): string[] => {
49
56
 
50
57
  const ROLES = [
51
58
  {displayName: "Super Admin", isLocked: true, isSealed: true, name: "superadmin"},
52
- {description: "Baseline role for signed-up users", displayName: "Todo User", name: "todoUser"},
59
+ {
60
+ description: "Baseline role for signed-up users",
61
+ displayName: "Todo User",
62
+ name: "todoUser",
63
+ permissions: {adminTodo: ["read", "writeOwned"]},
64
+ },
53
65
  ];
54
66
 
55
67
  describe("AdminRolesList", () => {
@@ -129,6 +141,76 @@ describe("AdminRolesList", () => {
129
141
  expect(getByTestId("admin-roles-edit-superadmin").props.disabled).toBeTruthy();
130
142
  });
131
143
 
144
+ it("edits standard model access with a single access-level selector", async () => {
145
+ mockUseListRolesQuery.mockReturnValue({
146
+ data: ROLES,
147
+ error: null,
148
+ isLoading: false,
149
+ refetch: mockRefetch,
150
+ });
151
+ const {getByTestId, UNSAFE_root} = renderWithTheme(
152
+ <AdminRolesList api={mockApi} apiBase="/admin" />
153
+ );
154
+
155
+ await act(async () => {
156
+ fireEvent.press(getByTestId("admin-roles-edit-todoUser"));
157
+ });
158
+ const accessSelect = UNSAFE_root.findAllByType(SelectField).find(
159
+ (field) => field.props.testID === "admin-role-access-adminTodo"
160
+ );
161
+ assert.equal(accessSelect?.props.value, "writeOwned");
162
+
163
+ await act(async () => {
164
+ accessSelect?.props.onChange("write");
165
+ });
166
+ await act(async () => {
167
+ fireEvent.press(getByTestId("admin-role-save-button"));
168
+ });
169
+
170
+ const updateInput = mockUpdateRole.mock.calls[0]?.[0] as {
171
+ changes?: {permissions?: Record<string, string[]>};
172
+ roleName?: string;
173
+ };
174
+ assert.equal(updateInput.roleName, "todoUser");
175
+ assert.deepEqual(updateInput.changes?.permissions, {adminTodo: ["read", "write"]});
176
+ });
177
+
178
+ it("edits admin page access with a dedicated toggle", async () => {
179
+ mockUseListRolesQuery.mockReturnValue({
180
+ data: ROLES,
181
+ error: null,
182
+ isLoading: false,
183
+ refetch: mockRefetch,
184
+ });
185
+ const {getByTestId, getByText} = renderWithTheme(
186
+ <AdminRolesList api={mockApi} apiBase="/admin" />
187
+ );
188
+
189
+ await act(async () => {
190
+ fireEvent.press(getByTestId("admin-roles-edit-todoUser"));
191
+ });
192
+
193
+ expect(getByTestId("admin-role-page-access")).toBeTruthy();
194
+ expect(getByText("Allow access to the admin page")).toBeTruthy();
195
+
196
+ await act(async () => {
197
+ fireEvent.press(getByTestId("admin-role-permission-admin-access-clickable"));
198
+ });
199
+ await act(async () => {
200
+ fireEvent.press(getByTestId("admin-role-save-button"));
201
+ });
202
+
203
+ const updateInput = mockUpdateRole.mock.calls[0]?.[0] as {
204
+ changes?: {permissions?: Record<string, string[]>};
205
+ roleName?: string;
206
+ };
207
+ assert.equal(updateInput.roleName, "todoUser");
208
+ assert.deepEqual(updateInput.changes?.permissions, {
209
+ admin: ["access"],
210
+ adminTodo: ["read", "writeOwned"],
211
+ });
212
+ });
213
+
132
214
  it("scrolls the role list body while keeping the add button outside the scroll area", () => {
133
215
  mockUseListRolesQuery.mockReturnValue({
134
216
  data: ROLES,
@@ -1,4 +1,15 @@
1
- import {Badge, Box, Button, CheckBox, Heading, Modal, Spinner, Text, TextField} from "@terreno/ui";
1
+ import {
2
+ Badge,
3
+ Box,
4
+ Button,
5
+ CheckBox,
6
+ Heading,
7
+ Modal,
8
+ SelectField,
9
+ Spinner,
10
+ Text,
11
+ TextField,
12
+ } from "@terreno/ui";
2
13
  import React, {useCallback, useMemo, useState} from "react";
3
14
 
4
15
  import type {AdminScreenProps} from "./types";
@@ -24,6 +35,50 @@ const EMPTY_ROLE_FORM: RoleFormState = {
24
35
  permissions: {},
25
36
  };
26
37
 
38
+ const STANDARD_ACCESS_ACTIONS = ["read", "write", "writeOwned"] as const;
39
+ const STANDARD_ACCESS_OPTIONS = [
40
+ {label: "No access", value: "none"},
41
+ {label: "Read only", value: "read"},
42
+ {label: "Read + write owned", value: "writeOwned"},
43
+ {label: "Read + write all", value: "write"},
44
+ ];
45
+ const ADMIN_PAGE_RESOURCE = "admin";
46
+ const ADMIN_PAGE_ACTION = "access";
47
+
48
+ const editorActionsForResource = ({
49
+ actions,
50
+ hasStandardAccess,
51
+ resource,
52
+ }: {
53
+ actions: readonly string[];
54
+ hasStandardAccess: boolean;
55
+ resource: string;
56
+ }): readonly string[] => {
57
+ const withoutStandard = hasStandardAccess
58
+ ? actions.filter(
59
+ (action) =>
60
+ !STANDARD_ACCESS_ACTIONS.includes(action as (typeof STANDARD_ACCESS_ACTIONS)[number])
61
+ )
62
+ : actions;
63
+ if (resource === ADMIN_PAGE_RESOURCE) {
64
+ return withoutStandard.filter((action) => action !== ADMIN_PAGE_ACTION);
65
+ }
66
+ return withoutStandard;
67
+ };
68
+
69
+ const standardAccessValue = (actions: string[]): string => {
70
+ if (actions.includes("write")) {
71
+ return "write";
72
+ }
73
+ if (actions.includes("writeOwned")) {
74
+ return "writeOwned";
75
+ }
76
+ if (actions.includes("read")) {
77
+ return "read";
78
+ }
79
+ return "none";
80
+ };
81
+
27
82
  const clonePermissions = (permissions?: Record<string, string[]>): Record<string, string[]> => {
28
83
  return Object.fromEntries(
29
84
  Object.entries(permissions ?? {}).map(([resource, actions]) => [resource, [...actions]])
@@ -45,6 +100,8 @@ export const AdminRolesList: React.FC<AdminScreenProps> = ({api, apiBase, baseUr
45
100
  const roles = normalizeRoles(data);
46
101
  const statements = normalizeStatements(statementsData);
47
102
  const resources = useMemo(() => Object.keys(statements).sort(), [statements]);
103
+ const hasAdminPageStatement =
104
+ statements[ADMIN_PAGE_RESOURCE]?.includes(ADMIN_PAGE_ACTION) ?? false;
48
105
  const [editingRole, setEditingRole] = useState<RbacRoleRow | null>(null);
49
106
  const [form, setForm] = useState<RoleFormState>(EMPTY_ROLE_FORM);
50
107
  const [isFormVisible, setIsFormVisible] = useState(false);
@@ -99,6 +156,24 @@ export const AdminRolesList: React.FC<AdminScreenProps> = ({api, apiBase, baseUr
99
156
  });
100
157
  }, []);
101
158
 
159
+ const handleStandardAccessChange = useCallback((resource: string, value: string): void => {
160
+ setForm((current) => {
161
+ const customActions = (current.permissions[resource] ?? []).filter(
162
+ (action) =>
163
+ !STANDARD_ACCESS_ACTIONS.includes(action as (typeof STANDARD_ACCESS_ACTIONS)[number])
164
+ );
165
+ const standardActions = value === "none" ? [] : value === "read" ? ["read"] : ["read", value];
166
+ const nextActions = [...customActions, ...standardActions];
167
+ const permissions = {...current.permissions};
168
+ if (nextActions.length === 0) {
169
+ Reflect.deleteProperty(permissions, resource);
170
+ } else {
171
+ permissions[resource] = nextActions;
172
+ }
173
+ return {...current, permissions};
174
+ });
175
+ }, []);
176
+
102
177
  const handleSave = useCallback(async (): Promise<void> => {
103
178
  const name = form.name.trim();
104
179
  const displayName = form.displayName.trim();
@@ -277,31 +352,79 @@ export const AdminRolesList: React.FC<AdminScreenProps> = ({api, apiBase, baseUr
277
352
  />
278
353
  <Box gap={2} testID="admin-role-permissions">
279
354
  <Heading size="sm">Permissions</Heading>
280
- {resources.map((resource) => (
281
- <Box gap={1} key={resource}>
282
- <Text bold>{resource}</Text>
283
- <Box direction="row" gap={3} wrap>
284
- {statements[resource].map((action) => {
285
- const isSelected = form.permissions[resource]?.includes(action) ?? false;
286
- return (
287
- <Box
288
- accessibilityHint={`Toggles the ${action} permission for ${resource}`}
289
- accessibilityLabel={`${resource} ${action}`}
290
- alignItems="center"
291
- direction="row"
292
- gap={1}
293
- key={`${resource}:${action}`}
294
- onClick={() => handlePermissionToggle(resource, action)}
295
- testID={`admin-role-permission-${resource}-${action}`}
296
- >
297
- <CheckBox selected={isSelected} />
298
- <Text>{action}</Text>
299
- </Box>
300
- );
301
- })}
355
+ {hasAdminPageStatement ? (
356
+ <Box gap={2} testID="admin-role-page-access">
357
+ <Heading size="sm">Admin page</Heading>
358
+ <Text>
359
+ This is the only permission that opens the admin panel. Model and tool
360
+ permissions do not apply until it is granted.
361
+ </Text>
362
+ <Box
363
+ accessibilityHint="Toggles whether this role can open the admin page"
364
+ accessibilityLabel="Allow access to the admin page"
365
+ alignItems="center"
366
+ direction="row"
367
+ gap={1}
368
+ onClick={() => handlePermissionToggle(ADMIN_PAGE_RESOURCE, ADMIN_PAGE_ACTION)}
369
+ testID={`admin-role-permission-${ADMIN_PAGE_RESOURCE}-${ADMIN_PAGE_ACTION}`}
370
+ >
371
+ <CheckBox
372
+ selected={
373
+ form.permissions[ADMIN_PAGE_RESOURCE]?.includes(ADMIN_PAGE_ACTION) ?? false
374
+ }
375
+ />
376
+ <Text>Allow access to the admin page</Text>
302
377
  </Box>
303
378
  </Box>
304
- ))}
379
+ ) : null}
380
+ {resources.map((resource) => {
381
+ const actions = statements[resource];
382
+ const hasStandardAccess = STANDARD_ACCESS_ACTIONS.every((action) =>
383
+ actions.includes(action)
384
+ );
385
+ const customActions = editorActionsForResource({
386
+ actions,
387
+ hasStandardAccess,
388
+ resource,
389
+ });
390
+ if (!hasStandardAccess && customActions.length === 0) {
391
+ return null;
392
+ }
393
+ return (
394
+ <Box gap={1} key={resource}>
395
+ <Text bold>{resource}</Text>
396
+ {hasStandardAccess ? (
397
+ <SelectField
398
+ onChange={(value: string) => handleStandardAccessChange(resource, value)}
399
+ options={STANDARD_ACCESS_OPTIONS}
400
+ testID={`admin-role-access-${resource}`}
401
+ title="Access level"
402
+ value={standardAccessValue(form.permissions[resource] ?? [])}
403
+ />
404
+ ) : null}
405
+ <Box direction="row" gap={3} wrap>
406
+ {customActions.map((action) => {
407
+ const isSelected = form.permissions[resource]?.includes(action) ?? false;
408
+ return (
409
+ <Box
410
+ accessibilityHint={`Toggles the ${action} permission for ${resource}`}
411
+ accessibilityLabel={`${resource} ${action}`}
412
+ alignItems="center"
413
+ direction="row"
414
+ gap={1}
415
+ key={`${resource}:${action}`}
416
+ onClick={() => handlePermissionToggle(resource, action)}
417
+ testID={`admin-role-permission-${resource}-${action}`}
418
+ >
419
+ <CheckBox selected={isSelected} />
420
+ <Text>{action}</Text>
421
+ </Box>
422
+ );
423
+ })}
424
+ </Box>
425
+ </Box>
426
+ );
427
+ })}
305
428
  </Box>
306
429
  </Box>
307
430
  </Box>
@@ -0,0 +1,81 @@
1
+ import {beforeEach, describe, it, mock} from "bun:test";
2
+ import {Page} from "@terreno/ui";
3
+ import {act} from "@testing-library/react-native";
4
+ import {assert} from "chai";
5
+ import React from "react";
6
+ import {renderWithTheme} from "../../ui/src/test-utils";
7
+ import {AdminScreenPage} from "./AdminScreenPage";
8
+
9
+ const pushMock = mock(() => {});
10
+ const backMock = mock(() => {});
11
+
12
+ mock.module("expo-router", () => ({
13
+ router: {back: backMock, push: pushMock},
14
+ }));
15
+
16
+ describe("AdminScreenPage", () => {
17
+ beforeEach(() => {
18
+ pushMock.mockClear();
19
+ backMock.mockClear();
20
+ });
21
+
22
+ it("shows a back arrow by default", (): void => {
23
+ const {UNSAFE_root} = renderWithTheme(<AdminScreenPage title="Example" />);
24
+
25
+ assert.isTrue(UNSAFE_root.findByType(Page).props.backButton);
26
+ });
27
+
28
+ it("allows hosts to disable the back arrow", (): void => {
29
+ const {UNSAFE_root} = renderWithTheme(<AdminScreenPage backButton={false} title="Example" />);
30
+
31
+ assert.isFalse(UNSAFE_root.findByType(Page).props.backButton);
32
+ });
33
+
34
+ it("navigates to admin home when the back arrow is pressed", (): void => {
35
+ const {UNSAFE_root} = renderWithTheme(<AdminScreenPage title="Example" />);
36
+
37
+ act(() => {
38
+ UNSAFE_root.findByType(Page).props.onBack();
39
+ });
40
+
41
+ assert.equal(pushMock.mock.calls.length, 1);
42
+ assert.equal(pushMock.mock.calls[0]?.[0], "/admin");
43
+ assert.equal(backMock.mock.calls.length, 0);
44
+ });
45
+
46
+ it("uses backHref when provided", (): void => {
47
+ const {UNSAFE_root} = renderWithTheme(
48
+ <AdminScreenPage backHref="/admin/comms" title="Example" />
49
+ );
50
+
51
+ act(() => {
52
+ UNSAFE_root.findByType(Page).props.onBack();
53
+ });
54
+
55
+ assert.equal(pushMock.mock.calls[0]?.[0], "/admin/comms");
56
+ });
57
+
58
+ it("maps an empty standalone-admin route base to the root route", (): void => {
59
+ const {UNSAFE_root} = renderWithTheme(<AdminScreenPage backHref="" title="Example" />);
60
+
61
+ act(() => {
62
+ UNSAFE_root.findByType(Page).props.onBack();
63
+ });
64
+
65
+ assert.equal(pushMock.mock.calls[0]?.[0], "/");
66
+ });
67
+
68
+ it("prefers onBack over backHref", (): void => {
69
+ const onBack = mock(() => {});
70
+ const {UNSAFE_root} = renderWithTheme(
71
+ <AdminScreenPage backHref="/admin/comms" onBack={onBack} title="Example" />
72
+ );
73
+
74
+ act(() => {
75
+ UNSAFE_root.findByType(Page).props.onBack();
76
+ });
77
+
78
+ assert.equal(onBack.mock.calls.length, 1);
79
+ assert.equal(pushMock.mock.calls.length, 0);
80
+ });
81
+ });
@@ -0,0 +1,37 @@
1
+ import {Page, type PageProps} from "@terreno/ui";
2
+ import type {Href} from "expo-router";
3
+ import {router} from "expo-router";
4
+ import React, {useCallback} from "react";
5
+
6
+ export interface AdminScreenPageProps extends PageProps {
7
+ /**
8
+ * Route to open when the back arrow is pressed. Defaults to `/admin`.
9
+ * Pass the host `routeBase` when admin is mounted under a different prefix.
10
+ */
11
+ backHref?: string;
12
+ }
13
+
14
+ /**
15
+ * Standard page shell for custom admin screens.
16
+ *
17
+ * Admin screens are reached from the sidebar, so they show a back arrow by default.
18
+ * The arrow navigates to admin home rather than `router.back()` because sidebar
19
+ * navigation does not always leave a reliable history entry on web.
20
+ * Set `backButton={false}` only when the host provides equivalent navigation.
21
+ */
22
+ export const AdminScreenPage: React.FC<AdminScreenPageProps> = ({
23
+ backButton = true,
24
+ backHref = "/admin",
25
+ onBack,
26
+ ...pageProps
27
+ }) => {
28
+ const handleBack = useCallback((): void => {
29
+ if (onBack) {
30
+ onBack();
31
+ return;
32
+ }
33
+ router.push((backHref || "/") as Href);
34
+ }, [backHref, onBack]);
35
+
36
+ return <Page backButton={backButton} onBack={handleBack} {...pageProps} />;
37
+ };
@@ -1,7 +1,8 @@
1
+ // noExplicitAny: test harness doubles for AdminScreenRouter routing and config mocks
1
2
  // biome-ignore-all lint/suspicious/noExplicitAny: test harness doubles
2
3
  import {beforeEach, describe, expect, it, mock} from "bun:test";
3
- import {renderWithTheme} from "@terreno/ui/src/test-utils";
4
4
  import React from "react";
5
+ import {renderWithTheme} from "../../ui/src/test-utils";
5
6
  import type {AdminApi, AdminConfigResponse} from "./types";
6
7
 
7
8
  mock.module("expo-router", () => ({
@@ -1,7 +1,8 @@
1
- import {Box, Page, Spinner, Text} from "@terreno/ui";
1
+ import {Box, Spinner, Text} from "@terreno/ui";
2
2
  import React, {useMemo} from "react";
3
3
  import {AdminModelTable} from "./AdminModelTable";
4
4
  import {useAdminWidgetRegistry} from "./AdminProvider";
5
+ import {AdminScreenPage} from "./AdminScreenPage";
5
6
  import {AdminScriptList} from "./AdminScriptList";
6
7
  import type {AdminScreenProps} from "./types";
7
8
  import {resolveAdminBases} from "./types";
@@ -88,17 +89,29 @@ export const AdminScreenRouter: React.FC<AdminScreenRouterProps> = ({
88
89
 
89
90
  if (customScreen) {
90
91
  return (
91
- <Page color="transparent" maxWidth="100%" padding={4} title={customScreen.displayName}>
92
+ <AdminScreenPage
93
+ backHref={resolvedRouteBase}
94
+ color="transparent"
95
+ maxWidth="100%"
96
+ padding={4}
97
+ title={customScreen.displayName}
98
+ >
92
99
  <MissingWidget bucket="screens" widgetId={name} />
93
- </Page>
100
+ </AdminScreenPage>
94
101
  );
95
102
  }
96
103
 
97
104
  return (
98
- <Page color="transparent" maxWidth="100%" padding={4} title="Not found">
105
+ <AdminScreenPage
106
+ backHref={resolvedRouteBase}
107
+ color="transparent"
108
+ maxWidth="100%"
109
+ padding={4}
110
+ title="Not found"
111
+ >
99
112
  <Box testID="admin-screen-not-found">
100
113
  <Text color="error">{`No admin screen or model registered for "${name}".`}</Text>
101
114
  </Box>
102
- </Page>
115
+ </AdminScreenPage>
103
116
  );
104
117
  };
@@ -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 {AdminScriptList} from "./AdminScriptList";
8
8
  import type {AdminApi, AdminConfigResponse} from "./types";
9
9