@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.
Files changed (158) hide show
  1. package/dist/AdminActionMenu.d.ts +15 -0
  2. package/dist/AdminActionMenu.js +56 -0
  3. package/dist/AdminActionMenu.js.map +1 -0
  4. package/dist/AdminFieldRenderer.js +2 -2
  5. package/dist/AdminFieldRenderer.js.map +1 -1
  6. package/dist/AdminFieldRendererCore.d.ts +2 -0
  7. package/dist/AdminFieldRendererCore.js +18 -47
  8. package/dist/AdminFieldRendererCore.js.map +1 -1
  9. package/dist/AdminFilterDrawer.d.ts +20 -0
  10. package/dist/AdminFilterDrawer.js +117 -0
  11. package/dist/AdminFilterDrawer.js.map +1 -0
  12. package/dist/AdminHome.d.ts +2 -4
  13. package/dist/AdminHome.js +15 -137
  14. package/dist/AdminHome.js.map +1 -1
  15. package/dist/AdminModelForm.js +29 -10
  16. package/dist/AdminModelForm.js.map +1 -1
  17. package/dist/AdminModelList.d.ts +2 -1
  18. package/dist/AdminModelList.js +5 -1
  19. package/dist/AdminModelList.js.map +1 -1
  20. package/dist/AdminModelTable.js +56 -98
  21. package/dist/AdminModelTable.js.map +1 -1
  22. package/dist/AdminObjectPicker.d.ts +3 -0
  23. package/dist/AdminObjectPicker.js +27 -7
  24. package/dist/AdminObjectPicker.js.map +1 -1
  25. package/dist/AdminPrimitiveArrayField.d.ts +2 -0
  26. package/dist/AdminPrimitiveArrayField.js +3 -3
  27. package/dist/AdminPrimitiveArrayField.js.map +1 -1
  28. package/dist/AdminProvider.d.ts +16 -0
  29. package/dist/AdminProvider.js +84 -0
  30. package/dist/AdminProvider.js.map +1 -0
  31. package/dist/AdminRefField.js +2 -2
  32. package/dist/AdminRefField.js.map +1 -1
  33. package/dist/AdminRolesField.d.ts +9 -0
  34. package/dist/AdminRolesField.js +45 -0
  35. package/dist/AdminRolesField.js.map +1 -0
  36. package/dist/AdminRolesList.d.ts +3 -0
  37. package/dist/AdminRolesList.js +187 -0
  38. package/dist/AdminRolesList.js.map +1 -0
  39. package/dist/AdminScreenRouter.d.ts +13 -0
  40. package/dist/AdminScreenRouter.js +52 -0
  41. package/dist/AdminScreenRouter.js.map +1 -0
  42. package/dist/AdminScriptList.js +12 -10
  43. package/dist/AdminScriptList.js.map +1 -1
  44. package/dist/AdminShell.d.ts +2 -0
  45. package/dist/AdminShell.js +68 -21
  46. package/dist/AdminShell.js.map +1 -1
  47. package/dist/Constants.d.ts +4 -0
  48. package/dist/Constants.js +5 -0
  49. package/dist/Constants.js.map +1 -0
  50. package/dist/adminModelListQueryParams.d.ts +4 -0
  51. package/dist/adminModelListQueryParams.js +38 -3
  52. package/dist/adminModelListQueryParams.js.map +1 -1
  53. package/dist/adminPageAccess.d.ts +5 -0
  54. package/dist/adminPageAccess.js +19 -0
  55. package/dist/adminPageAccess.js.map +1 -0
  56. package/dist/index.d.ts +20 -1
  57. package/dist/index.js +18 -0
  58. package/dist/index.js.map +1 -1
  59. package/dist/types.d.ts +74 -0
  60. package/dist/types.js.map +1 -1
  61. package/dist/useAdminRoles.d.ts +65 -0
  62. package/dist/useAdminRoles.js +84 -0
  63. package/dist/useAdminRoles.js.map +1 -0
  64. package/dist/useDocumentStorageApi.js +2 -2
  65. package/dist/useDocumentStorageApi.js.map +1 -1
  66. package/dist/widgets/AIRequestsScreenWidget.d.ts +4 -0
  67. package/dist/widgets/AIRequestsScreenWidget.js +54 -0
  68. package/dist/widgets/AIRequestsScreenWidget.js.map +1 -0
  69. package/dist/widgets/CustomScreensListWidget.d.ts +4 -0
  70. package/dist/widgets/CustomScreensListWidget.js +21 -0
  71. package/dist/widgets/CustomScreensListWidget.js.map +1 -0
  72. package/dist/widgets/DocumentsScreenWidget.d.ts +4 -0
  73. package/dist/widgets/DocumentsScreenWidget.js +9 -0
  74. package/dist/widgets/DocumentsScreenWidget.js.map +1 -0
  75. package/dist/widgets/FeatureFlagsOverridesWidget.d.ts +4 -0
  76. package/dist/widgets/FeatureFlagsOverridesWidget.js +18 -0
  77. package/dist/widgets/FeatureFlagsOverridesWidget.js.map +1 -0
  78. package/dist/widgets/MissingWidget.d.ts +7 -0
  79. package/dist/widgets/MissingWidget.js +6 -0
  80. package/dist/widgets/MissingWidget.js.map +1 -0
  81. package/dist/widgets/ModelsGridWidget.d.ts +3 -0
  82. package/dist/widgets/ModelsGridWidget.js +30 -0
  83. package/dist/widgets/ModelsGridWidget.js.map +1 -0
  84. package/dist/widgets/RecentActivityWidget.d.ts +3 -0
  85. package/dist/widgets/RecentActivityWidget.js +27 -0
  86. package/dist/widgets/RecentActivityWidget.js.map +1 -0
  87. package/dist/widgets/ScriptRunnerWidget.d.ts +3 -0
  88. package/dist/widgets/ScriptRunnerWidget.js +12 -0
  89. package/dist/widgets/ScriptRunnerWidget.js.map +1 -0
  90. package/dist/widgets/VersionConfigScreenWidget.d.ts +3 -0
  91. package/dist/widgets/VersionConfigScreenWidget.js +7 -0
  92. package/dist/widgets/VersionConfigScreenWidget.js.map +1 -0
  93. package/dist/widgets/VersionConfigWidget.d.ts +3 -0
  94. package/dist/widgets/VersionConfigWidget.js +7 -0
  95. package/dist/widgets/VersionConfigWidget.js.map +1 -0
  96. package/dist/widgets/builtInFieldWidgets.d.ts +7 -0
  97. package/dist/widgets/builtInFieldWidgets.js +61 -0
  98. package/dist/widgets/builtInFieldWidgets.js.map +1 -0
  99. package/dist/widgets/builtInWidgets.d.ts +6 -0
  100. package/dist/widgets/builtInWidgets.js +31 -0
  101. package/dist/widgets/builtInWidgets.js.map +1 -0
  102. package/dist/widgets/consentWidgets.d.ts +3 -0
  103. package/dist/widgets/consentWidgets.js +8 -0
  104. package/dist/widgets/consentWidgets.js.map +1 -0
  105. package/dist/widgets/homeWidgetUtils.d.ts +3 -0
  106. package/dist/widgets/homeWidgetUtils.js +37 -0
  107. package/dist/widgets/homeWidgetUtils.js.map +1 -0
  108. package/package.json +3 -2
  109. package/src/AdminActionMenu.test.tsx +78 -0
  110. package/src/AdminActionMenu.tsx +106 -0
  111. package/src/AdminFieldRenderer.tsx +2 -0
  112. package/src/AdminFieldRendererCore.tsx +54 -133
  113. package/src/AdminFilterDrawer.test.tsx +89 -0
  114. package/src/AdminFilterDrawer.tsx +333 -0
  115. package/src/AdminHome.tsx +38 -325
  116. package/src/AdminModelForm.test.tsx +78 -0
  117. package/src/AdminModelForm.tsx +49 -10
  118. package/src/AdminModelList.tsx +7 -2
  119. package/src/AdminModelTable.test.tsx +73 -0
  120. package/src/AdminModelTable.tsx +108 -195
  121. package/src/AdminObjectPicker.tsx +49 -9
  122. package/src/AdminPrimitiveArrayField.tsx +5 -0
  123. package/src/AdminProvider.test.tsx +25 -0
  124. package/src/AdminProvider.tsx +121 -0
  125. package/src/AdminRefField.tsx +4 -0
  126. package/src/AdminRolesField.tsx +129 -0
  127. package/src/AdminRolesList.test.tsx +339 -0
  128. package/src/AdminRolesList.tsx +434 -0
  129. package/src/AdminScreenRouter.test.tsx +112 -0
  130. package/src/AdminScreenRouter.tsx +104 -0
  131. package/src/AdminScriptList.tsx +42 -30
  132. package/src/AdminShell.test.tsx +196 -1
  133. package/src/AdminShell.tsx +166 -69
  134. package/src/Constants.ts +5 -0
  135. package/src/adminModelListQueryParams.test.ts +69 -0
  136. package/src/adminModelListQueryParams.ts +49 -3
  137. package/src/adminPageAccess.test.ts +18 -0
  138. package/src/adminPageAccess.ts +18 -0
  139. package/src/index.tsx +51 -0
  140. package/src/isolated/AdminObjectPicker.isolated.tsx +10 -1
  141. package/src/types.ts +79 -0
  142. package/src/useAdminRoles.ts +146 -0
  143. package/src/useDocumentStorageApi.ts +2 -2
  144. package/src/widgets/AIRequestsScreenWidget.tsx +93 -0
  145. package/src/widgets/CustomScreensListWidget.tsx +56 -0
  146. package/src/widgets/DocumentsScreenWidget.tsx +11 -0
  147. package/src/widgets/FeatureFlagsOverridesWidget.tsx +48 -0
  148. package/src/widgets/MissingWidget.tsx +17 -0
  149. package/src/widgets/ModelsGridWidget.tsx +94 -0
  150. package/src/widgets/RecentActivityWidget.tsx +81 -0
  151. package/src/widgets/ScriptRunnerWidget.tsx +26 -0
  152. package/src/widgets/VersionConfigScreenWidget.tsx +12 -0
  153. package/src/widgets/VersionConfigWidget.tsx +7 -0
  154. package/src/widgets/builtInFieldWidgets.tsx +180 -0
  155. package/src/widgets/builtInWidgets.ts +51 -0
  156. package/src/widgets/consentWidgets.ts +13 -0
  157. package/src/widgets/homeWidgetUtils.ts +38 -0
  158. package/src/widgets/pluginWidgets.test.tsx +29 -0
@@ -420,4 +420,77 @@ describe("AdminModelTable", () => {
420
420
  const rows = (tables[0] as ReactTestInstance).props.data as {value: {href?: string}}[][];
421
421
  expect(rows[0][0].value.href).toBe("/admin/User/u1");
422
422
  });
423
+
424
+ it("hides create button when permissions.create is false", async () => {
425
+ configState.config = {
426
+ customScreens: [],
427
+ models: [
428
+ {
429
+ ...fullConfig.models[0],
430
+ permissions: {create: false},
431
+ },
432
+ ],
433
+ scripts: [],
434
+ };
435
+ let headerRight: React.ReactElement | null = null;
436
+ setOptions.mockImplementation((opts: Record<string, unknown>) => {
437
+ if (opts?.headerRight) {
438
+ headerRight = opts.headerRight();
439
+ }
440
+ });
441
+ renderWithTheme(
442
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
443
+ );
444
+ expect(headerRight).not.toBeNull();
445
+ const header = renderWithTheme(headerRight as unknown as React.ReactElement);
446
+ expect(header.queryByTestId("admin-create-button")).toBeNull();
447
+ });
448
+
449
+ it("marks only sortableFields as sortable columns", () => {
450
+ configState.config = {
451
+ customScreens: [],
452
+ models: [
453
+ {
454
+ ...fullConfig.models[0],
455
+ listFields: ["email", "active"],
456
+ sortableFields: ["email"],
457
+ },
458
+ ],
459
+ scripts: [],
460
+ };
461
+ listState.data = {data: [{_id: "u1", active: true, email: "a@b.com"}], total: 1};
462
+ const {UNSAFE_root} = renderWithTheme(
463
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
464
+ );
465
+ const tables = UNSAFE_root.findAll((n: ReactTestInstance) => Array.isArray(n.props?.columns));
466
+ const cols = (tables[0] as ReactTestInstance).props.columns as {
467
+ sortable?: boolean;
468
+ title: string;
469
+ }[];
470
+ const emailCol = cols.find((c) => c.title === "Email");
471
+ const activeCol = cols.find((c) => c.title === "Active");
472
+ expect(emailCol?.sortable).toBe(true);
473
+ expect(activeCol?.sortable).toBe(false);
474
+ });
475
+
476
+ it("uses pageSize from model config for pagination", () => {
477
+ configState.config = {
478
+ customScreens: [],
479
+ models: [
480
+ {
481
+ ...fullConfig.models[0],
482
+ pageSize: 50,
483
+ },
484
+ ],
485
+ scripts: [],
486
+ };
487
+ listState.data = {data: [{_id: "u1", email: "a@b.com"}], total: 100};
488
+ const {UNSAFE_root} = renderWithTheme(
489
+ <AdminModelTable api={{} as unknown as AdminApi} baseUrl="/admin" modelName="User" />
490
+ );
491
+ const tables = UNSAFE_root.findAll(
492
+ (n: ReactTestInstance) => typeof n.props?.totalPages === "number"
493
+ );
494
+ expect((tables[0] as ReactTestInstance).props.totalPages).toBe(2);
495
+ });
423
496
  });
@@ -7,13 +7,10 @@ import {
7
7
  type DataTableCellData,
8
8
  type DataTableColumn,
9
9
  type DataTableCustomComponentMap,
10
- Heading,
11
10
  IconButton,
12
11
  Link,
13
- Modal,
14
12
  Page,
15
13
  printDateAndTime,
16
- SelectField,
17
14
  Spinner,
18
15
  Text,
19
16
  TextField,
@@ -24,11 +21,14 @@ import {router, useNavigation} from "expo-router";
24
21
  import startCase from "lodash/startCase";
25
22
  import React, {useCallback, useEffect, useMemo, useState} from "react";
26
23
  import {Pressable} from "react-native";
24
+ import {AdminActionMenu} from "./AdminActionMenu";
25
+ import {AdminFilterDrawer} from "./AdminFilterDrawer";
27
26
  import {
28
27
  ADMIN_LIST_MAX_SELECTION,
29
28
  type AdminListFilterState,
30
29
  buildAdminListQueryParams,
31
30
  } from "./adminModelListQueryParams";
31
+ import {ADMIN_SEARCH_DEBOUNCE_MS} from "./Constants";
32
32
  import {
33
33
  type AdminApi,
34
34
  type AdminFieldConfig,
@@ -197,6 +197,7 @@ const AdminSelectCell: React.FC<{column: DataTableColumn; cellData: DataTableCel
197
197
  accessibilityRole="checkbox"
198
198
  accessibilityState={{checked: selected}}
199
199
  onPress={() => onToggle(id, !selected)}
200
+ testID={`admin-table-row-checkbox-${id}`}
200
201
  >
201
202
  <Box alignItems="center" justifyContent="center" padding={1}>
202
203
  <Text size="lg">{selected ? "\u2611" : "\u2610"}</Text>
@@ -267,7 +268,6 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
267
268
  const [debouncedSearch, setDebouncedSearch] = useState("");
268
269
  const [filterState, setFilterState] = useState<AdminListFilterState>({});
269
270
  const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
270
- const [confirmActionId, setConfirmActionId] = useState<string | null>(null);
271
271
  const navigation = useNavigation();
272
272
 
273
273
  const modelConfig: AdminModelConfig | undefined = useMemo(
@@ -279,12 +279,25 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
279
279
  useEffect(() => {
280
280
  const t = setTimeout(() => {
281
281
  setDebouncedSearch(searchText);
282
- }, 300);
282
+ }, ADMIN_SEARCH_DEBOUNCE_MS);
283
283
  return () => {
284
284
  clearTimeout(t);
285
285
  };
286
286
  }, [searchText]);
287
287
 
288
+ const filterSignature = useMemo(() => JSON.stringify(filterState), [filterState]);
289
+ const sortSignature = useMemo(() => JSON.stringify(sortColumn), [sortColumn]);
290
+
291
+ // Clear bulk selection when filters, search, or sort change.
292
+ useEffect(() => {
293
+ setSelectedIds(new Set());
294
+ }, [debouncedSearch, filterSignature, sortSignature]);
295
+
296
+ // Reset to page 1 when search changes.
297
+ useEffect(() => {
298
+ setPage(1);
299
+ }, [debouncedSearch]);
300
+
288
301
  // Reset filter UI when switching models.
289
302
  useEffect(() => {
290
303
  if (!modelConfig) {
@@ -364,7 +377,21 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
364
377
 
365
378
  const deleteEnabled = modelConfig?.permissions?.delete !== false;
366
379
  const createEnabled = modelConfig?.permissions?.create !== false;
367
- const showSelectColumn = Boolean(modelConfig?.actions?.length);
380
+ const visibleActions = useMemo(
381
+ () => (modelConfig?.actions ?? []).filter((action) => action.allowed !== false),
382
+ [modelConfig?.actions]
383
+ );
384
+ const showSelectColumn = visibleActions.length > 0;
385
+
386
+ const modelConfigs = useMemo(
387
+ () => config?.models.map((m) => ({name: m.name, routePath: m.routePath})) ?? [],
388
+ [config]
389
+ );
390
+
391
+ const handleApplyFilters = useCallback((next: AdminListFilterState) => {
392
+ setFilterState(next);
393
+ setPage(1);
394
+ }, []);
368
395
 
369
396
  const handleDelete = useCallback(
370
397
  async (id: string) => {
@@ -429,7 +456,7 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
429
456
  if (!modelConfig) {
430
457
  return;
431
458
  }
432
- const action = modelConfig.actions?.find((a) => a.id === actionId);
459
+ const action = visibleActions.find((a) => a.id === actionId);
433
460
  if (!action) {
434
461
  return;
435
462
  }
@@ -437,32 +464,34 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
437
464
  if (ids.length === 0) {
438
465
  return;
439
466
  }
440
- try {
441
- if (action.background) {
442
- await enqueueBackground({
443
- ids,
444
- kind: action.id,
445
- metadata: {actionId: action.id},
446
- resourceRoute: modelConfig.routePath,
447
- }).unwrap();
448
- toast.success("Background task queued");
449
- } else if (action.patchKeys && action.patchKeys.length > 0) {
450
- const patch: Record<string, unknown> = {};
451
- for (const k of action.patchKeys) {
452
- patch[k] = true;
453
- }
454
- await bulkPatch({ids, patch}).unwrap();
455
- toast.success("Bulk update applied");
456
- } else {
457
- toast.warn("This action has no bulk handler configured.");
467
+ if (action.background) {
468
+ await enqueueBackground({
469
+ ids,
470
+ kind: action.id,
471
+ metadata: {actionId: action.id},
472
+ resourceRoute: modelConfig.routePath,
473
+ }).unwrap();
474
+ toast.success("Background task queued");
475
+ } else if (action.patchKeys && action.patchKeys.length > 0) {
476
+ const patch: Record<string, unknown> = {};
477
+ for (const k of action.patchKeys) {
478
+ patch[k] = true;
458
479
  }
459
- setSelectedIds(new Set());
460
- setConfirmActionId(null);
461
- } catch (err) {
462
- toast.catch(err, "Bulk action failed");
480
+ const result = (await bulkPatch({ids, patch}).unwrap()) as {
481
+ failures?: {id: string; title: string}[];
482
+ updated?: number;
483
+ };
484
+ if (Array.isArray(result.failures) && result.failures.length > 0) {
485
+ toast.error(`Updated ${result.updated ?? 0}; ${result.failures.length} failed`);
486
+ return;
487
+ }
488
+ toast.success("Bulk update applied");
489
+ } else {
490
+ toast.warn("This action has no bulk handler configured.");
463
491
  }
492
+ setSelectedIds(new Set());
464
493
  },
465
- [bulkPatch, enqueueBackground, modelConfig, selectedIds, toast]
494
+ [bulkPatch, enqueueBackground, modelConfig, selectedIds, toast, visibleActions]
466
495
  );
467
496
 
468
497
  const handleInlineBooleanToggle = useCallback(
@@ -567,9 +596,11 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
567
596
  fieldConfig?.type === "boolean" && modelConfig.permissions?.update !== false;
568
597
 
569
598
  if (isInlineBool) {
599
+ const recordCapabilities = item._adminCapabilities as {update?: boolean} | undefined;
570
600
  return {
571
601
  value: {
572
- disabled: modelConfig.permissions?.update === false,
602
+ disabled:
603
+ recordCapabilities?.update === false || modelConfig.permissions?.update === false,
573
604
  onToggle: () => handleInlineBooleanToggle(id, fieldKey, !item[fieldKey]),
574
605
  value: Boolean(item[fieldKey]),
575
606
  },
@@ -604,54 +635,51 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
604
635
 
605
636
  const totalPages = listData ? Math.ceil((listData.total as number) / pageLimit) : 1;
606
637
 
607
- const pendingAction = modelConfig.actions?.find((a) => a.id === confirmActionId);
638
+ const searchHelperText =
639
+ modelConfig.searchFields && modelConfig.searchFields.length > 0
640
+ ? `Searching ${modelConfig.searchFields.map((f) => startCase(f)).join(", ")}`
641
+ : undefined;
608
642
 
609
- const hasFilterRail =
610
- Boolean(modelConfig.searchFields?.length) || Boolean((modelConfig.filters ?? []).length);
643
+ const pageIds = listItems.map((row) => String(row._id));
644
+ const allPageSelected = pageIds.length > 0 && pageIds.every((id: string) => selectedIds.has(id));
611
645
 
612
646
  return (
613
647
  <Page color="transparent" maxWidth="100%" padding={0}>
614
648
  <Box gap={3} padding={0} testID={`admin-list-${modelName}`}>
649
+ {modelConfig.searchFields && modelConfig.searchFields.length > 0 ? (
650
+ <Card padding={3}>
651
+ <TextField
652
+ helperText={searchHelperText}
653
+ onChange={setSearchText}
654
+ testID="admin-table-search"
655
+ title="Search"
656
+ value={searchText}
657
+ />
658
+ </Card>
659
+ ) : null}
660
+
615
661
  <Box alignItems="stretch" direction="column" gap={3} mdDirection="row">
616
662
  <Box direction="column" flex="grow" gap={3} minWidth={0} width="100%">
617
- {selectColumn ? (
663
+ {showSelectColumn ? (
618
664
  <Card padding={3}>
619
- <Box direction="column" gap={3} testID="bulk-action">
620
- <Box alignItems="end" direction="row" gap={3} wrap>
621
- {modelConfig.actions && modelConfig.actions.length > 0 ? (
622
- <Box minWidth={260}>
623
- <SelectField
624
- onChange={(next: string) => {
625
- if (next === "__none__" || !next) {
626
- return;
627
- }
628
- const act = modelConfig.actions?.find((a) => a.id === next);
629
- if (!act) {
630
- return;
631
- }
632
- if (act.confirm) {
633
- setConfirmActionId(act.id);
634
- } else {
635
- void runBulkAction(act.id);
636
- }
637
- }}
638
- options={[
639
- {label: "Bulk actions\u2026", value: "__none__"},
640
- ...modelConfig.actions.map((a) => ({label: a.label, value: a.id})),
641
- ]}
642
- title="Actions"
643
- value="__none__"
644
- />
645
- </Box>
646
- ) : null}
647
- <Text color="secondaryDark" size="sm">
648
- {selectedIds.size} selected
649
- </Text>
650
- </Box>
651
- <Button
652
- onClick={toggleSelectPage}
653
- text="Toggle page selection"
654
- variant="outline"
665
+ <Box alignItems="center" direction="row" gap={3} wrap>
666
+ <Pressable
667
+ accessibilityRole="checkbox"
668
+ accessibilityState={{checked: allPageSelected}}
669
+ onPress={toggleSelectPage}
670
+ testID="admin-table-select-all"
671
+ >
672
+ <Box alignItems="center" justifyContent="center" padding={1}>
673
+ <Text size="lg">{allPageSelected ? "\u2611" : "\u2610"}</Text>
674
+ </Box>
675
+ </Pressable>
676
+ <Text color="secondaryDark" size="sm" testID="admin-table-selection-count">
677
+ {selectedIds.size} selected
678
+ </Text>
679
+ <AdminActionMenu
680
+ actions={visibleActions}
681
+ onRunAction={runBulkAction}
682
+ selectedCount={selectedIds.size}
655
683
  />
656
684
  </Box>
657
685
  </Card>
@@ -678,133 +706,18 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
678
706
  </Card>
679
707
  </Box>
680
708
 
681
- {hasFilterRail ? (
682
- <Box alignSelf="stretch" maxWidth={360} minWidth={260}>
683
- <Card padding={3}>
684
- <Heading size="sm">Filters</Heading>
685
- <Box direction="column" gap={3} marginTop={2} width="100%">
686
- {modelConfig.searchFields && modelConfig.searchFields.length > 0 ? (
687
- <Box width="100%">
688
- <TextField
689
- helperText={`Filter by ${modelConfig.searchFields[0]} (exact match)`}
690
- onChange={setSearchText}
691
- title="Search"
692
- value={searchText}
693
- />
694
- </Box>
695
- ) : null}
696
- {(modelConfig.filters ?? []).map((f) => {
697
- if (f.kind === "boolean") {
698
- const v = filterState[f.field];
699
- return (
700
- <Box key={f.field} width="100%">
701
- <SelectField
702
- onChange={(next: string) => {
703
- setFilterState((prev) => ({...prev, [f.field]: next}));
704
- setPage(1);
705
- }}
706
- options={[
707
- {label: f.label ?? startCase(f.field), value: "all"},
708
- {label: "Yes", value: "true"},
709
- {label: "No", value: "false"},
710
- ]}
711
- title={f.label ?? startCase(f.field)}
712
- value={v === true ? "true" : v === false ? "false" : "all"}
713
- />
714
- </Box>
715
- );
716
- }
717
- if (f.kind === "dateRange") {
718
- const gteKey = `${f.field}_gte`;
719
- const lteKey = `${f.field}_lte`;
720
- return (
721
- <Box direction="column" gap={2} key={f.field} width="100%">
722
- <Box width="100%">
723
- <TextField
724
- helperText="ISO date or datetime"
725
- onChange={(next: string) => {
726
- setFilterState((prev) => ({...prev, [gteKey]: next}));
727
- setPage(1);
728
- }}
729
- title={`${f.label ?? startCase(f.field)} from`}
730
- value={String(filterState[gteKey] ?? "")}
731
- />
732
- </Box>
733
- <Box width="100%">
734
- <TextField
735
- helperText="ISO date or datetime"
736
- onChange={(next: string) => {
737
- setFilterState((prev) => ({...prev, [lteKey]: next}));
738
- setPage(1);
739
- }}
740
- title={`${f.label ?? startCase(f.field)} to`}
741
- value={String(filterState[lteKey] ?? "")}
742
- />
743
- </Box>
744
- </Box>
745
- );
746
- }
747
- if (f.kind === "choice") {
748
- return (
749
- <Box key={f.field} width="100%">
750
- <SelectField
751
- onChange={(next: string) => {
752
- setFilterState((prev) => ({
753
- ...prev,
754
- [f.field]: next === "__all__" ? "" : next,
755
- }));
756
- setPage(1);
757
- }}
758
- options={[
759
- {label: "All", value: "__all__"},
760
- ...((f.choices ?? []) as {label: string; value: string}[]).map(
761
- (c) => ({
762
- label: c.label,
763
- value: c.value,
764
- })
765
- ),
766
- ]}
767
- title={f.label ?? startCase(f.field)}
768
- value={String(filterState[f.field] ?? "__all__")}
769
- />
770
- </Box>
771
- );
772
- }
773
- return (
774
- <Box key={f.field} width="100%">
775
- <TextField
776
- onChange={(next: string) => {
777
- setFilterState((prev) => ({...prev, [f.field]: next}));
778
- setPage(1);
779
- }}
780
- title={f.label ?? startCase(f.field)}
781
- value={String(filterState[f.field] ?? "")}
782
- />
783
- </Box>
784
- );
785
- })}
786
- </Box>
787
- </Card>
788
- </Box>
709
+ {(modelConfig.filters ?? []).length > 0 ? (
710
+ <AdminFilterDrawer
711
+ api={api}
712
+ appliedFilterState={filterState}
713
+ fields={modelConfig.fields}
714
+ filters={modelConfig.filters ?? []}
715
+ modelConfigs={modelConfigs}
716
+ onApply={handleApplyFilters}
717
+ />
789
718
  ) : null}
790
719
  </Box>
791
720
  </Box>
792
-
793
- <Modal
794
- onDismiss={() => setConfirmActionId(null)}
795
- primaryButtonOnClick={() => {
796
- if (confirmActionId) {
797
- void runBulkAction(confirmActionId);
798
- }
799
- }}
800
- primaryButtonText="Continue"
801
- secondaryButtonOnClick={() => setConfirmActionId(null)}
802
- secondaryButtonText="Cancel"
803
- title="Confirm bulk action"
804
- visible={Boolean(pendingAction?.confirm)}
805
- >
806
- <Text>{pendingAction?.confirm}</Text>
807
- </Modal>
808
721
  </Page>
809
722
  );
810
723
  };
@@ -24,6 +24,9 @@ interface AdminObjectPickerProps {
24
24
  errorText?: string;
25
25
  helperText?: string;
26
26
  readOnly?: boolean;
27
+ /** When true, search as the user types; otherwise prefetch the first page on open. */
28
+ autocomplete?: boolean;
29
+ testID?: string;
27
30
  }
28
31
 
29
32
  const DISPLAY_FIELDS = ["name", "title", "email", "label", "displayName"] as const;
@@ -68,6 +71,8 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
68
71
  errorText,
69
72
  helperText,
70
73
  readOnly,
74
+ autocomplete = false,
75
+ testID,
71
76
  }) => {
72
77
  const [searchText, setSearchText] = useState("");
73
78
  const [isOpen, setIsOpen] = useState(false);
@@ -87,6 +92,7 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
87
92
 
88
93
  const searchEndpointKey = `adminSearch_${refModelName}`;
89
94
  const readEndpointKey = `adminSearchRead_${refModelName}`;
95
+ const listEndpointKey = `adminPickerList_${refModelName}`;
90
96
 
91
97
  const enhancedApi = useMemo(() => {
92
98
  return api.injectEndpoints({
@@ -104,18 +110,30 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
104
110
  url: `${routePath}/${id}`,
105
111
  }),
106
112
  }),
113
+ [listEndpointKey]: build.query({
114
+ query: () => ({
115
+ method: "GET",
116
+ params: {limit: 100, page: 1},
117
+ url: routePath,
118
+ }),
119
+ }),
107
120
  }),
108
121
  overrideExisting: true,
109
122
  });
110
- }, [api, routePath, searchEndpointKey, readEndpointKey]);
123
+ }, [api, routePath, searchEndpointKey, readEndpointKey, listEndpointKey]);
111
124
 
112
125
  const capitalize = (s: string) => s.charAt(0).toUpperCase() + s.slice(1);
113
126
  const enhanced = asDynamicHookApi(enhancedApi);
114
127
  const useSearchQuery = enhanced[`use${capitalize(searchEndpointKey)}Query`];
115
128
  const useReadQuery = enhanced[`use${capitalize(readEndpointKey)}Query`];
129
+ const useListQuery = enhanced[`use${capitalize(listEndpointKey)}Query`];
116
130
 
117
131
  const {data: searchData, isFetching: isSearching} = useSearchQuery(debouncedQuery, {
118
- skip: !debouncedQuery,
132
+ skip: !autocomplete || !debouncedQuery,
133
+ });
134
+
135
+ const {data: listData, isFetching: isListLoading} = useListQuery(undefined, {
136
+ skip: autocomplete || !isOpen,
119
137
  });
120
138
 
121
139
  // Fetch the currently selected item to display its name
@@ -172,10 +190,24 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
172
190
 
173
191
  // emptyApi unwraps `{data: T}` unless the body has `more` (paginated list). Search returns only
174
192
  // `{data: [...]}`, so `searchData` is already the result array.
175
- const results = Array.isArray(searchData)
193
+ const searchResults = Array.isArray(searchData)
176
194
  ? searchData
177
195
  : ((searchData as {data?: unknown[]} | undefined)?.data ?? []);
178
196
 
197
+ const listPayload = listData as {data?: PickerItem[]} | undefined;
198
+ const listItems: PickerItem[] = listPayload?.data ?? [];
199
+
200
+ const normalizedQuery = searchText.trim().toLowerCase();
201
+ const prefetchResults =
202
+ normalizedQuery.length === 0
203
+ ? listItems
204
+ : listItems.filter((item: PickerItem) =>
205
+ getDisplayValue(item).toLowerCase().includes(normalizedQuery)
206
+ );
207
+
208
+ const results = autocomplete ? searchResults : prefetchResults;
209
+ const isResultsLoading = autocomplete ? isSearching : isListLoading;
210
+
179
211
  if (readOnly) {
180
212
  const roValue =
181
213
  selectedDisplay || (value && isSelectedLoading ? "Loading…" : value ? String(value) : "");
@@ -224,10 +256,10 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
224
256
  ) : (
225
257
  <TextField
226
258
  errorText={errorText}
227
- helperText={isOpen ? "Type to search" : helperText}
259
+ helperText={isOpen ? (autocomplete ? "Type to search" : "Pick from list") : helperText}
228
260
  onChange={handleSearchChange}
229
261
  onFocus={() => setIsOpen(true)}
230
- testID={`admin-picker-${refModelName}-search`}
262
+ testID={testID ?? `admin-picker-${refModelName}-search`}
231
263
  title={title}
232
264
  value={searchText}
233
265
  />
@@ -235,13 +267,13 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
235
267
 
236
268
  {isOpen && (
237
269
  <Box border="default" maxHeight={250} overflow="scrollY" rounding="md">
238
- {isSearching && (
270
+ {isResultsLoading && (
239
271
  <Box alignItems="center" padding={3}>
240
272
  <Spinner />
241
273
  </Box>
242
274
  )}
243
275
 
244
- {!isSearching && debouncedQuery && results.length === 0 && (
276
+ {!isResultsLoading && autocomplete && debouncedQuery && results.length === 0 && (
245
277
  <Box padding={3}>
246
278
  <Text color="secondaryDark" size="sm">
247
279
  No results found
@@ -249,7 +281,7 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
249
281
  </Box>
250
282
  )}
251
283
 
252
- {!isSearching &&
284
+ {!isResultsLoading &&
253
285
  (results as PickerItem[]).map((item) => {
254
286
  const primaryField = getPrimaryField(item);
255
287
  const secondary = getSecondaryText(item, primaryField);
@@ -275,13 +307,21 @@ export const AdminObjectPicker: React.FC<AdminObjectPickerProps> = ({
275
307
  );
276
308
  })}
277
309
 
278
- {!isSearching && !debouncedQuery && (
310
+ {!isResultsLoading && autocomplete && !debouncedQuery && (
279
311
  <Box padding={3}>
280
312
  <Text color="secondaryDark" size="sm">
281
313
  Start typing to search
282
314
  </Text>
283
315
  </Box>
284
316
  )}
317
+
318
+ {!isResultsLoading && !autocomplete && results.length === 0 && (
319
+ <Box padding={3}>
320
+ <Text color="secondaryDark" size="sm">
321
+ No items available
322
+ </Text>
323
+ </Box>
324
+ )}
285
325
  </Box>
286
326
  )}
287
327
  </Box>
@@ -37,6 +37,8 @@ interface AdminPrimitiveArrayFieldProps {
37
37
  */
38
38
  refRenderers?: RefRendererMap;
39
39
  readOnly?: boolean;
40
+ /** When true, each ref item uses async search instead of first-page prefetch. */
41
+ autocomplete?: boolean;
40
42
  }
41
43
 
42
44
  type PrimitiveItem = string | number | boolean;
@@ -72,6 +74,7 @@ export const AdminPrimitiveArrayField: React.FC<AdminPrimitiveArrayFieldProps> =
72
74
  modelConfigs,
73
75
  refRenderers,
74
76
  readOnly,
77
+ autocomplete = false,
75
78
  }) => {
76
79
  const isReadOnly = Boolean(readOnly);
77
80
  const arrayValue = Array.isArray(value) ? value : [];
@@ -128,6 +131,7 @@ export const AdminPrimitiveArrayField: React.FC<AdminPrimitiveArrayFieldProps> =
128
131
  <CustomRenderer
129
132
  api={api}
130
133
  apiBase={apiBase}
134
+ autocomplete={autocomplete}
131
135
  baseUrl={baseUrl}
132
136
  onChange={(val: string) => handleUpdate(index, val)}
133
137
  readOnly={isReadOnly}
@@ -144,6 +148,7 @@ export const AdminPrimitiveArrayField: React.FC<AdminPrimitiveArrayFieldProps> =
144
148
  <AdminRefField
145
149
  api={api}
146
150
  apiBase={apiBase}
151
+ autocomplete={autocomplete}
147
152
  baseUrl={baseUrl}
148
153
  onChange={(val: string) => handleUpdate(index, val)}
149
154
  readOnly={isReadOnly}