@terreno/admin-frontend 57.0.0 → 57.1.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 (150) 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 +15 -3
  16. package/dist/AdminModelForm.js.map +1 -1
  17. package/dist/AdminModelList.d.ts +2 -1
  18. package/dist/AdminModelList.js +2 -0
  19. package/dist/AdminModelList.js.map +1 -1
  20. package/dist/AdminModelTable.js +54 -97
  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 +126 -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/AdminShell.d.ts +2 -0
  43. package/dist/AdminShell.js +53 -19
  44. package/dist/AdminShell.js.map +1 -1
  45. package/dist/Constants.d.ts +4 -0
  46. package/dist/Constants.js +5 -0
  47. package/dist/Constants.js.map +1 -0
  48. package/dist/adminModelListQueryParams.d.ts +4 -0
  49. package/dist/adminModelListQueryParams.js +38 -3
  50. package/dist/adminModelListQueryParams.js.map +1 -1
  51. package/dist/index.d.ts +19 -1
  52. package/dist/index.js +17 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/types.d.ts +61 -0
  55. package/dist/types.js.map +1 -1
  56. package/dist/useAdminRoles.d.ts +65 -0
  57. package/dist/useAdminRoles.js +84 -0
  58. package/dist/useAdminRoles.js.map +1 -0
  59. package/dist/useDocumentStorageApi.js +2 -2
  60. package/dist/useDocumentStorageApi.js.map +1 -1
  61. package/dist/widgets/AIRequestsScreenWidget.d.ts +4 -0
  62. package/dist/widgets/AIRequestsScreenWidget.js +54 -0
  63. package/dist/widgets/AIRequestsScreenWidget.js.map +1 -0
  64. package/dist/widgets/CustomScreensListWidget.d.ts +4 -0
  65. package/dist/widgets/CustomScreensListWidget.js +21 -0
  66. package/dist/widgets/CustomScreensListWidget.js.map +1 -0
  67. package/dist/widgets/DocumentsScreenWidget.d.ts +4 -0
  68. package/dist/widgets/DocumentsScreenWidget.js +9 -0
  69. package/dist/widgets/DocumentsScreenWidget.js.map +1 -0
  70. package/dist/widgets/FeatureFlagsOverridesWidget.d.ts +4 -0
  71. package/dist/widgets/FeatureFlagsOverridesWidget.js +18 -0
  72. package/dist/widgets/FeatureFlagsOverridesWidget.js.map +1 -0
  73. package/dist/widgets/MissingWidget.d.ts +7 -0
  74. package/dist/widgets/MissingWidget.js +6 -0
  75. package/dist/widgets/MissingWidget.js.map +1 -0
  76. package/dist/widgets/ModelsGridWidget.d.ts +3 -0
  77. package/dist/widgets/ModelsGridWidget.js +30 -0
  78. package/dist/widgets/ModelsGridWidget.js.map +1 -0
  79. package/dist/widgets/RecentActivityWidget.d.ts +3 -0
  80. package/dist/widgets/RecentActivityWidget.js +27 -0
  81. package/dist/widgets/RecentActivityWidget.js.map +1 -0
  82. package/dist/widgets/ScriptRunnerWidget.d.ts +3 -0
  83. package/dist/widgets/ScriptRunnerWidget.js +12 -0
  84. package/dist/widgets/ScriptRunnerWidget.js.map +1 -0
  85. package/dist/widgets/VersionConfigScreenWidget.d.ts +3 -0
  86. package/dist/widgets/VersionConfigScreenWidget.js +7 -0
  87. package/dist/widgets/VersionConfigScreenWidget.js.map +1 -0
  88. package/dist/widgets/VersionConfigWidget.d.ts +3 -0
  89. package/dist/widgets/VersionConfigWidget.js +7 -0
  90. package/dist/widgets/VersionConfigWidget.js.map +1 -0
  91. package/dist/widgets/builtInFieldWidgets.d.ts +7 -0
  92. package/dist/widgets/builtInFieldWidgets.js +61 -0
  93. package/dist/widgets/builtInFieldWidgets.js.map +1 -0
  94. package/dist/widgets/builtInWidgets.d.ts +6 -0
  95. package/dist/widgets/builtInWidgets.js +31 -0
  96. package/dist/widgets/builtInWidgets.js.map +1 -0
  97. package/dist/widgets/consentWidgets.d.ts +3 -0
  98. package/dist/widgets/consentWidgets.js +8 -0
  99. package/dist/widgets/consentWidgets.js.map +1 -0
  100. package/dist/widgets/homeWidgetUtils.d.ts +3 -0
  101. package/dist/widgets/homeWidgetUtils.js +37 -0
  102. package/dist/widgets/homeWidgetUtils.js.map +1 -0
  103. package/package.json +3 -2
  104. package/src/AdminActionMenu.test.tsx +78 -0
  105. package/src/AdminActionMenu.tsx +106 -0
  106. package/src/AdminFieldRenderer.tsx +2 -0
  107. package/src/AdminFieldRendererCore.tsx +54 -133
  108. package/src/AdminFilterDrawer.test.tsx +89 -0
  109. package/src/AdminFilterDrawer.tsx +333 -0
  110. package/src/AdminHome.tsx +38 -325
  111. package/src/AdminModelForm.test.tsx +45 -0
  112. package/src/AdminModelForm.tsx +24 -1
  113. package/src/AdminModelList.tsx +4 -1
  114. package/src/AdminModelTable.test.tsx +73 -0
  115. package/src/AdminModelTable.tsx +105 -194
  116. package/src/AdminObjectPicker.tsx +49 -9
  117. package/src/AdminPrimitiveArrayField.tsx +5 -0
  118. package/src/AdminProvider.test.tsx +25 -0
  119. package/src/AdminProvider.tsx +121 -0
  120. package/src/AdminRefField.tsx +4 -0
  121. package/src/AdminRolesField.tsx +129 -0
  122. package/src/AdminRolesList.test.tsx +257 -0
  123. package/src/AdminRolesList.tsx +311 -0
  124. package/src/AdminScreenRouter.test.tsx +112 -0
  125. package/src/AdminScreenRouter.tsx +104 -0
  126. package/src/AdminShell.test.tsx +107 -1
  127. package/src/AdminShell.tsx +143 -67
  128. package/src/Constants.ts +5 -0
  129. package/src/adminModelListQueryParams.test.ts +69 -0
  130. package/src/adminModelListQueryParams.ts +49 -3
  131. package/src/index.tsx +50 -0
  132. package/src/isolated/AdminObjectPicker.isolated.tsx +10 -1
  133. package/src/types.ts +65 -0
  134. package/src/useAdminRoles.ts +146 -0
  135. package/src/useDocumentStorageApi.ts +2 -2
  136. package/src/widgets/AIRequestsScreenWidget.tsx +93 -0
  137. package/src/widgets/CustomScreensListWidget.tsx +56 -0
  138. package/src/widgets/DocumentsScreenWidget.tsx +11 -0
  139. package/src/widgets/FeatureFlagsOverridesWidget.tsx +48 -0
  140. package/src/widgets/MissingWidget.tsx +17 -0
  141. package/src/widgets/ModelsGridWidget.tsx +94 -0
  142. package/src/widgets/RecentActivityWidget.tsx +81 -0
  143. package/src/widgets/ScriptRunnerWidget.tsx +26 -0
  144. package/src/widgets/VersionConfigScreenWidget.tsx +12 -0
  145. package/src/widgets/VersionConfigWidget.tsx +7 -0
  146. package/src/widgets/builtInFieldWidgets.tsx +180 -0
  147. package/src/widgets/builtInWidgets.ts +51 -0
  148. package/src/widgets/consentWidgets.ts +13 -0
  149. package/src/widgets/homeWidgetUtils.ts +38 -0
  150. package/src/widgets/pluginWidgets.test.tsx +29 -0
@@ -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(
@@ -604,54 +633,51 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
604
633
 
605
634
  const totalPages = listData ? Math.ceil((listData.total as number) / pageLimit) : 1;
606
635
 
607
- const pendingAction = modelConfig.actions?.find((a) => a.id === confirmActionId);
636
+ const searchHelperText =
637
+ modelConfig.searchFields && modelConfig.searchFields.length > 0
638
+ ? `Searching ${modelConfig.searchFields.map((f) => startCase(f)).join(", ")}`
639
+ : undefined;
608
640
 
609
- const hasFilterRail =
610
- Boolean(modelConfig.searchFields?.length) || Boolean((modelConfig.filters ?? []).length);
641
+ const pageIds = listItems.map((row) => String(row._id));
642
+ const allPageSelected = pageIds.length > 0 && pageIds.every((id: string) => selectedIds.has(id));
611
643
 
612
644
  return (
613
645
  <Page color="transparent" maxWidth="100%" padding={0}>
614
646
  <Box gap={3} padding={0} testID={`admin-list-${modelName}`}>
647
+ {modelConfig.searchFields && modelConfig.searchFields.length > 0 ? (
648
+ <Card padding={3}>
649
+ <TextField
650
+ helperText={searchHelperText}
651
+ onChange={setSearchText}
652
+ testID="admin-table-search"
653
+ title="Search"
654
+ value={searchText}
655
+ />
656
+ </Card>
657
+ ) : null}
658
+
615
659
  <Box alignItems="stretch" direction="column" gap={3} mdDirection="row">
616
660
  <Box direction="column" flex="grow" gap={3} minWidth={0} width="100%">
617
- {selectColumn ? (
661
+ {showSelectColumn ? (
618
662
  <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"
663
+ <Box alignItems="center" direction="row" gap={3} wrap>
664
+ <Pressable
665
+ accessibilityRole="checkbox"
666
+ accessibilityState={{checked: allPageSelected}}
667
+ onPress={toggleSelectPage}
668
+ testID="admin-table-select-all"
669
+ >
670
+ <Box alignItems="center" justifyContent="center" padding={1}>
671
+ <Text size="lg">{allPageSelected ? "\u2611" : "\u2610"}</Text>
672
+ </Box>
673
+ </Pressable>
674
+ <Text color="secondaryDark" size="sm" testID="admin-table-selection-count">
675
+ {selectedIds.size} selected
676
+ </Text>
677
+ <AdminActionMenu
678
+ actions={visibleActions}
679
+ onRunAction={runBulkAction}
680
+ selectedCount={selectedIds.size}
655
681
  />
656
682
  </Box>
657
683
  </Card>
@@ -678,133 +704,18 @@ export const AdminModelTable: React.FC<AdminModelTableProps> = ({
678
704
  </Card>
679
705
  </Box>
680
706
 
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>
707
+ {(modelConfig.filters ?? []).length > 0 ? (
708
+ <AdminFilterDrawer
709
+ api={api}
710
+ appliedFilterState={filterState}
711
+ fields={modelConfig.fields}
712
+ filters={modelConfig.filters ?? []}
713
+ modelConfigs={modelConfigs}
714
+ onApply={handleApplyFilters}
715
+ />
789
716
  ) : null}
790
717
  </Box>
791
718
  </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
719
  </Page>
809
720
  );
810
721
  };
@@ -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}
@@ -0,0 +1,25 @@
1
+ import {beforeEach, describe, expect, it} from "bun:test";
2
+ import {resetAdminWidgetWarningsForTests} from "./AdminProvider";
3
+ import type {HomeWidgetComponent} from "./types";
4
+ import {BUILT_IN_HOME_WIDGETS, mergeWidgetRegistry} from "./widgets/builtInWidgets";
5
+
6
+ describe("AdminProvider widget registry", () => {
7
+ beforeEach(() => {
8
+ resetAdminWidgetWarningsForTests();
9
+ });
10
+
11
+ it("merges user home widgets over built-ins", () => {
12
+ const Custom: HomeWidgetComponent = () => null;
13
+ const merged = mergeWidgetRegistry({
14
+ home: {modelsGrid: Custom},
15
+ });
16
+ expect(merged.home.modelsGrid).toBe(Custom);
17
+ expect(merged.home.scriptRunner).toBe(BUILT_IN_HOME_WIDGETS.scriptRunner);
18
+ });
19
+
20
+ it("includes all built-in home widget ids", () => {
21
+ expect(BUILT_IN_HOME_WIDGETS.modelsGrid).toBeDefined();
22
+ expect(BUILT_IN_HOME_WIDGETS.scriptRunner).toBeDefined();
23
+ expect(BUILT_IN_HOME_WIDGETS.recentActivity).toBeDefined();
24
+ });
25
+ });