@terreno/admin-frontend 57.3.0 → 57.4.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 (334) hide show
  1. package/.ai/guidelines/core.md +5 -1
  2. package/README.md +4 -2
  3. package/dist/AdminConflictSheet.d.ts +16 -0
  4. package/dist/AdminConflictSheet.js +52 -0
  5. package/dist/AdminConflictSheet.js.map +1 -0
  6. package/dist/AdminHome.js +2 -1
  7. package/dist/AdminHome.js.map +1 -1
  8. package/dist/AdminMigrations.d.ts +3 -0
  9. package/dist/AdminMigrations.js +19 -0
  10. package/dist/AdminMigrations.js.map +1 -0
  11. package/dist/AdminMigrationsView.d.ts +10 -0
  12. package/dist/AdminMigrationsView.js +94 -0
  13. package/dist/AdminMigrationsView.js.map +1 -0
  14. package/dist/AdminModelForm.js +190 -44
  15. package/dist/AdminModelForm.js.map +1 -1
  16. package/dist/AdminModelTable.js +315 -27
  17. package/dist/AdminModelTable.js.map +1 -1
  18. package/dist/AdminObjectPicker.js +30 -6
  19. package/dist/AdminObjectPicker.js.map +1 -1
  20. package/dist/AdminProvider.d.ts +6 -2
  21. package/dist/AdminProvider.js +29 -7
  22. package/dist/AdminProvider.js.map +1 -1
  23. package/dist/AdminScreenRouter.d.ts +1 -1
  24. package/dist/AdminScreenRouter.js +4 -0
  25. package/dist/AdminScreenRouter.js.map +1 -1
  26. package/dist/AdminShell.d.ts +7 -3
  27. package/dist/AdminShell.js +53 -24
  28. package/dist/AdminShell.js.map +1 -1
  29. package/dist/AdminVersionConfig.js +21 -2
  30. package/dist/AdminVersionConfig.js.map +1 -1
  31. package/dist/AnnouncementEditor.d.ts +45 -0
  32. package/dist/AnnouncementEditor.js +370 -0
  33. package/dist/AnnouncementEditor.js.map +1 -0
  34. package/dist/AnnouncementList.d.ts +15 -0
  35. package/dist/AnnouncementList.js +97 -0
  36. package/dist/AnnouncementList.js.map +1 -0
  37. package/dist/AnnouncementOverview.d.ts +46 -0
  38. package/dist/AnnouncementOverview.js +101 -0
  39. package/dist/AnnouncementOverview.js.map +1 -0
  40. package/dist/AnnouncementOverviewScreenWidget.d.ts +4 -0
  41. package/dist/AnnouncementOverviewScreenWidget.js +28 -0
  42. package/dist/AnnouncementOverviewScreenWidget.js.map +1 -0
  43. package/dist/ConsentFormEditor.js +20 -3
  44. package/dist/ConsentFormEditor.js.map +1 -1
  45. package/dist/DocumentStorageBrowser.js +3 -87
  46. package/dist/DocumentStorageBrowser.js.map +1 -1
  47. package/dist/adminApiQueryParams.d.ts +5 -0
  48. package/dist/adminApiQueryParams.js +25 -0
  49. package/dist/adminApiQueryParams.js.map +1 -0
  50. package/dist/adminConflictSheetStack.d.ts +17 -0
  51. package/dist/adminConflictSheetStack.js +64 -0
  52. package/dist/adminConflictSheetStack.js.map +1 -0
  53. package/dist/adminContext.d.ts +3 -0
  54. package/dist/adminContext.js +6 -0
  55. package/dist/adminContext.js.map +1 -0
  56. package/dist/adminModelListQueryParams.d.ts +3 -2
  57. package/dist/adminModelListQueryParams.js +74 -27
  58. package/dist/adminModelListQueryParams.js.map +1 -1
  59. package/dist/adminRequest.d.ts +51 -0
  60. package/dist/adminRequest.js +161 -0
  61. package/dist/adminRequest.js.map +1 -0
  62. package/dist/adminRpc.d.ts +7 -0
  63. package/dist/adminRpc.js +21 -0
  64. package/dist/adminRpc.js.map +1 -0
  65. package/dist/adminShellNav.d.ts +17 -1
  66. package/dist/adminShellNav.js +41 -9
  67. package/dist/adminShellNav.js.map +1 -1
  68. package/dist/adminWindowRefresh.d.ts +31 -0
  69. package/dist/adminWindowRefresh.js +48 -0
  70. package/dist/adminWindowRefresh.js.map +1 -0
  71. package/dist/adminWindowedTable.d.ts +13 -0
  72. package/dist/adminWindowedTable.js +33 -0
  73. package/dist/adminWindowedTable.js.map +1 -0
  74. package/dist/comms/commsDashboardParams.d.ts +0 -4
  75. package/dist/comms/commsDashboardParams.js +1 -1
  76. package/dist/comms/commsDashboardParams.js.map +1 -1
  77. package/dist/comms/commsMessagePayload.d.ts +2 -1
  78. package/dist/comms/useCommsDashboardApi.d.ts +3 -3
  79. package/dist/comms/useCommsDashboardApi.js +41 -0
  80. package/dist/comms/useCommsDashboardApi.js.map +1 -1
  81. package/dist/index.d.ts +24 -2
  82. package/dist/index.js +23 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/isAuditLogModel.d.ts +2 -0
  85. package/dist/isAuditLogModel.js +8 -0
  86. package/dist/isAuditLogModel.js.map +1 -0
  87. package/dist/jobs/JobsDashboardScreen.d.ts +10 -0
  88. package/dist/jobs/JobsDashboardScreen.js +155 -0
  89. package/dist/jobs/JobsDashboardScreen.js.map +1 -0
  90. package/dist/jobs/JobsDashboardScreenWidget.d.ts +4 -0
  91. package/dist/jobs/JobsDashboardScreenWidget.js +11 -0
  92. package/dist/jobs/JobsDashboardScreenWidget.js.map +1 -0
  93. package/dist/jobs/JobsHomeWidget.d.ts +4 -0
  94. package/dist/jobs/JobsHomeWidget.js +21 -0
  95. package/dist/jobs/JobsHomeWidget.js.map +1 -0
  96. package/dist/jobs/JobsJobDetail.d.ts +8 -0
  97. package/dist/jobs/JobsJobDetail.js +78 -0
  98. package/dist/jobs/JobsJobDetail.js.map +1 -0
  99. package/dist/jobs/JobsStatusBadge.d.ts +5 -0
  100. package/dist/jobs/JobsStatusBadge.js +16 -0
  101. package/dist/jobs/JobsStatusBadge.js.map +1 -0
  102. package/dist/jobs/jobPayload.d.ts +62 -0
  103. package/dist/jobs/jobPayload.js +54 -0
  104. package/dist/jobs/jobPayload.js.map +1 -0
  105. package/dist/jobs/jobsDashboardParams.d.ts +11 -0
  106. package/dist/jobs/jobsDashboardParams.js +70 -0
  107. package/dist/jobs/jobsDashboardParams.js.map +1 -0
  108. package/dist/jobs/useJobsDashboardApi.d.ts +60 -0
  109. package/dist/jobs/useJobsDashboardApi.js +88 -0
  110. package/dist/jobs/useJobsDashboardApi.js.map +1 -0
  111. package/dist/jobs/useJobsDashboardUrlFilters.d.ts +5 -0
  112. package/dist/jobs/useJobsDashboardUrlFilters.js +16 -0
  113. package/dist/jobs/useJobsDashboardUrlFilters.js.map +1 -0
  114. package/dist/orgs/OrgDirectoryScreen.d.ts +16 -0
  115. package/dist/orgs/OrgDirectoryScreen.js +81 -0
  116. package/dist/orgs/OrgDirectoryScreen.js.map +1 -0
  117. package/dist/orgs/OrgMembersScreen.d.ts +9 -0
  118. package/dist/orgs/OrgMembersScreen.js +115 -0
  119. package/dist/orgs/OrgMembersScreen.js.map +1 -0
  120. package/dist/orgs/OrgSettingsScreen.d.ts +9 -0
  121. package/dist/orgs/OrgSettingsScreen.js +80 -0
  122. package/dist/orgs/OrgSettingsScreen.js.map +1 -0
  123. package/dist/orgs/OrgSwitcher.d.ts +8 -0
  124. package/dist/orgs/OrgSwitcher.js +58 -0
  125. package/dist/orgs/OrgSwitcher.js.map +1 -0
  126. package/dist/orgs/adminModelEndpoints.d.ts +18 -0
  127. package/dist/orgs/adminModelEndpoints.js +73 -0
  128. package/dist/orgs/adminModelEndpoints.js.map +1 -0
  129. package/dist/orgs/normalizeListData.d.ts +9 -0
  130. package/dist/orgs/normalizeListData.js +8 -0
  131. package/dist/orgs/normalizeListData.js.map +1 -0
  132. package/dist/orgs/organizationSettings.d.ts +17 -0
  133. package/dist/orgs/organizationSettings.js +6 -0
  134. package/dist/orgs/organizationSettings.js.map +1 -0
  135. package/dist/orgs/shouldSkipOrgScopedAdminQuery.d.ts +4 -0
  136. package/dist/orgs/shouldSkipOrgScopedAdminQuery.js +2 -0
  137. package/dist/orgs/shouldSkipOrgScopedAdminQuery.js.map +1 -0
  138. package/dist/orgs/sortOrganizations.d.ts +6 -0
  139. package/dist/orgs/sortOrganizations.js +9 -0
  140. package/dist/orgs/sortOrganizations.js.map +1 -0
  141. package/dist/orgs/useOrgContext.d.ts +20 -0
  142. package/dist/orgs/useOrgContext.js +57 -0
  143. package/dist/orgs/useOrgContext.js.map +1 -0
  144. package/dist/orgs/useOrganizationsApi.d.ts +14 -0
  145. package/dist/orgs/useOrganizationsApi.js +103 -0
  146. package/dist/orgs/useOrganizationsApi.js.map +1 -0
  147. package/dist/pdfUtils.d.ts +0 -2
  148. package/dist/pdfUtils.js +2 -2
  149. package/dist/pdfUtils.js.map +1 -1
  150. package/dist/types.d.ts +100 -4
  151. package/dist/types.js.map +1 -1
  152. package/dist/useAdminApi.js +7 -61
  153. package/dist/useAdminApi.js.map +1 -1
  154. package/dist/useAdminBackgroundTask.d.ts +1 -1
  155. package/dist/useAdminBackgroundTask.js +18 -3
  156. package/dist/useAdminBackgroundTask.js.map +1 -1
  157. package/dist/useAdminConfig.js +16 -1
  158. package/dist/useAdminConfig.js.map +1 -1
  159. package/dist/useAdminMigrations.d.ts +40 -0
  160. package/dist/useAdminMigrations.js +43 -0
  161. package/dist/useAdminMigrations.js.map +1 -0
  162. package/dist/useAdminRoles.d.ts +1 -0
  163. package/dist/useAdminRoles.js +34 -0
  164. package/dist/useAdminRoles.js.map +1 -1
  165. package/dist/useAdminRpc.d.ts +28 -0
  166. package/dist/useAdminRpc.js +128 -0
  167. package/dist/useAdminRpc.js.map +1 -0
  168. package/dist/useAdminScripts.js +51 -0
  169. package/dist/useAdminScripts.js.map +1 -1
  170. package/dist/useConfigurationApi.js +23 -0
  171. package/dist/useConfigurationApi.js.map +1 -1
  172. package/dist/useConsentHistory.js +9 -1
  173. package/dist/useConsentHistory.js.map +1 -1
  174. package/dist/useDocumentStorageApi.js +72 -0
  175. package/dist/useDocumentStorageApi.js.map +1 -1
  176. package/dist/widgets/AIRequestsScreenWidget.js +17 -7
  177. package/dist/widgets/AIRequestsScreenWidget.js.map +1 -1
  178. package/dist/widgets/ModelsGridWidget.js +10 -3
  179. package/dist/widgets/ModelsGridWidget.js.map +1 -1
  180. package/dist/widgets/RecentActivityWidget.js +11 -4
  181. package/dist/widgets/RecentActivityWidget.js.map +1 -1
  182. package/dist/widgets/builtInWidgets.js +5 -9
  183. package/dist/widgets/builtInWidgets.js.map +1 -1
  184. package/dist/widgets/homeWidgetUtils.d.ts +0 -1
  185. package/dist/widgets/homeWidgetUtils.js +0 -8
  186. package/dist/widgets/homeWidgetUtils.js.map +1 -1
  187. package/package.json +6 -4
  188. package/src/AdminActionMenu.test.tsx +167 -0
  189. package/src/AdminBreadcrumbs.test.tsx +21 -1
  190. package/src/AdminConflictSheet.test.tsx +173 -0
  191. package/src/AdminConflictSheet.tsx +102 -0
  192. package/src/AdminHome.test.tsx +10 -11
  193. package/src/AdminHome.tsx +2 -4
  194. package/src/AdminMigrations.tsx +45 -0
  195. package/src/AdminMigrationsView.tsx +225 -0
  196. package/src/{AdminModelForm.test.tsx → AdminModelForm.isolated.tsx} +461 -154
  197. package/src/AdminModelForm.orgSkip.test.tsx +81 -0
  198. package/src/AdminModelForm.tsx +227 -56
  199. package/src/AdminModelForm.updateDepth.test.tsx +427 -0
  200. package/src/AdminModelList.test.tsx +12 -2
  201. package/src/AdminModelTable.test.tsx +560 -57
  202. package/src/AdminModelTable.tsx +430 -73
  203. package/src/AdminModelTable.windowed.test.tsx +897 -0
  204. package/src/AdminObjectPicker.tsx +32 -6
  205. package/src/AdminPrimitiveArrayField.test.tsx +178 -0
  206. package/src/AdminProvider.test.tsx +213 -3
  207. package/src/AdminProvider.tsx +39 -7
  208. package/src/AdminRolesList.test.tsx +197 -0
  209. package/src/AdminScreenRouter.test.tsx +393 -36
  210. package/src/AdminScreenRouter.tsx +6 -1
  211. package/src/AdminScriptList.test.tsx +180 -0
  212. package/src/AdminShell.test.tsx +595 -1
  213. package/src/AdminShell.tsx +110 -22
  214. package/src/AdminVersionConfig.tsx +31 -3
  215. package/src/AnnouncementEditor.test.tsx +603 -0
  216. package/src/AnnouncementEditor.tsx +673 -0
  217. package/src/AnnouncementList.test.tsx +198 -0
  218. package/src/AnnouncementList.tsx +214 -0
  219. package/src/AnnouncementOverview.test.tsx +325 -0
  220. package/src/AnnouncementOverview.tsx +325 -0
  221. package/src/AnnouncementOverviewScreenWidget.test.tsx +69 -0
  222. package/src/AnnouncementOverviewScreenWidget.tsx +51 -0
  223. package/src/CheckboxListEditor.test.tsx +8 -1
  224. package/src/ConsentFormEditor.test.tsx +28 -29
  225. package/src/ConsentFormEditor.tsx +27 -3
  226. package/src/ConsentFormList.test.tsx +12 -11
  227. package/src/ConsentResponseViewer.test.tsx +10 -11
  228. package/src/DocumentStorageBrowser.tsx +2 -139
  229. package/src/adminApiQueryParams.ts +33 -0
  230. package/src/adminConflictSheetStack.ts +87 -0
  231. package/src/adminContext.ts +8 -0
  232. package/src/adminModelListQueryParams.test.ts +60 -1
  233. package/src/adminModelListQueryParams.ts +89 -30
  234. package/src/adminRequest.test.ts +216 -0
  235. package/src/adminRequest.ts +213 -0
  236. package/src/adminRpc.test.ts +18 -0
  237. package/src/adminRpc.ts +31 -0
  238. package/src/adminScriptsHarness.test.ts +21 -0
  239. package/src/adminShellNav.test.ts +72 -6
  240. package/src/adminShellNav.ts +55 -10
  241. package/src/adminWindowRefresh.test.ts +65 -0
  242. package/src/adminWindowRefresh.ts +76 -0
  243. package/src/adminWindowedTable.test.ts +90 -0
  244. package/src/adminWindowedTable.ts +55 -0
  245. package/src/comms/CommsDashboardScreen.test.tsx +2 -2
  246. package/src/comms/commsDashboardParams.ts +1 -1
  247. package/src/comms/commsMessagePayload.ts +1 -1
  248. package/src/comms/useCommsDashboardApi.tsx +57 -4
  249. package/src/index.tsx +79 -1
  250. package/src/isAuditLogModel.test.ts +14 -0
  251. package/src/isAuditLogModel.ts +11 -0
  252. package/src/isolated/AIRequestsScreenWidget.isolated.tsx +84 -0
  253. package/src/isolated/AdminFieldRenderer.isolated.tsx +160 -0
  254. package/src/isolated/AdminFilterDrawer.isolated.tsx +215 -2
  255. package/src/isolated/AdminFilterDrawerMobile.isolated.tsx +172 -0
  256. package/src/isolated/AdminHomeWidgets.isolated.tsx +73 -0
  257. package/src/isolated/AdminObjectPicker.isolated.tsx +7 -0
  258. package/src/isolated/AdminScriptList.isolated.tsx +124 -0
  259. package/src/isolated/AdminScriptRunModal.isolated.tsx +274 -4
  260. package/src/isolated/DocumentStorageBrowser.isolated.tsx +13 -0
  261. package/src/isolated/RecentActivityWidget.isolated.tsx +138 -0
  262. package/src/isolated/adminWidgets.isolated.tsx +190 -0
  263. package/src/isolated/generateConsentHistoryPdf.isolated.ts +251 -0
  264. package/src/isolated/generateConsentPdfMobile.isolated.ts +87 -0
  265. package/src/isolated/generateConsentPdfsMobile.isolated.ts +129 -0
  266. package/src/isolated/hooks.isolated.tsx +245 -3
  267. package/src/isolated/rpcDualRun.isolated.tsx +449 -0
  268. package/src/isolated/useAdminScripts.isolated.tsx +156 -0
  269. package/src/isolated/useJobsDashboardApi.isolated.tsx +60 -0
  270. package/src/jobs/JobsDashboardScreen.test.tsx +310 -0
  271. package/src/jobs/JobsDashboardScreen.tsx +461 -0
  272. package/src/jobs/JobsDashboardScreenWidget.test.tsx +83 -0
  273. package/src/jobs/JobsDashboardScreenWidget.tsx +20 -0
  274. package/src/jobs/JobsHomeWidget.test.tsx +92 -0
  275. package/src/jobs/JobsHomeWidget.tsx +53 -0
  276. package/src/jobs/JobsJobDetail.test.tsx +253 -0
  277. package/src/jobs/JobsJobDetail.tsx +278 -0
  278. package/src/jobs/JobsStatusBadge.tsx +16 -0
  279. package/src/jobs/jobPayload.ts +114 -0
  280. package/src/jobs/jobsDashboardParams.test.ts +80 -0
  281. package/src/jobs/jobsDashboardParams.ts +84 -0
  282. package/src/jobs/useJobsDashboardApi.test.tsx +152 -0
  283. package/src/jobs/useJobsDashboardApi.tsx +132 -0
  284. package/src/jobs/useJobsDashboardUrlFilters.test.tsx +31 -0
  285. package/src/jobs/useJobsDashboardUrlFilters.tsx +31 -0
  286. package/src/orgs/OrgDirectoryScreen.test.tsx +184 -0
  287. package/src/orgs/OrgDirectoryScreen.tsx +200 -0
  288. package/src/orgs/OrgManagementScreens.test.tsx +270 -0
  289. package/src/orgs/OrgMembersScreen.tsx +254 -0
  290. package/src/orgs/OrgSettingsScreen.tsx +145 -0
  291. package/src/orgs/OrgSwitcher.test.tsx +145 -0
  292. package/src/orgs/OrgSwitcher.tsx +101 -0
  293. package/src/orgs/adminModelEndpoints.test.ts +156 -0
  294. package/src/orgs/adminModelEndpoints.ts +96 -0
  295. package/src/orgs/normalizeListData.test.ts +17 -0
  296. package/src/orgs/normalizeListData.ts +13 -0
  297. package/src/orgs/orgSwitcherOscillation.test.tsx +107 -0
  298. package/src/orgs/organizationSettings.test.ts +11 -0
  299. package/src/orgs/organizationSettings.ts +22 -0
  300. package/src/orgs/shouldSkipOrgScopedAdminQuery.test.ts +22 -0
  301. package/src/orgs/shouldSkipOrgScopedAdminQuery.ts +7 -0
  302. package/src/orgs/sortOrganizations.test.ts +13 -0
  303. package/src/orgs/sortOrganizations.ts +14 -0
  304. package/src/orgs/useOrgContext.test.tsx +94 -0
  305. package/src/orgs/useOrgContext.tsx +90 -0
  306. package/src/orgs/useOrganizationsApi.test.tsx +165 -0
  307. package/src/orgs/useOrganizationsApi.ts +118 -0
  308. package/src/pdfUtils.test.ts +37 -0
  309. package/src/pdfUtils.ts +2 -2
  310. package/src/testing/useAdminApiDouble.ts +70 -0
  311. package/src/types.ts +92 -4
  312. package/src/useAdminApi.test.ts +88 -0
  313. package/src/useAdminApi.ts +7 -65
  314. package/src/useAdminBackgroundTask.ts +20 -4
  315. package/src/useAdminConfig.ts +20 -2
  316. package/src/useAdminMigrations.test.tsx +75 -0
  317. package/src/useAdminMigrations.ts +77 -0
  318. package/src/useAdminRoles.test.ts +28 -0
  319. package/src/useAdminRoles.ts +40 -0
  320. package/src/useAdminRpc.test.tsx +250 -0
  321. package/src/useAdminRpc.ts +173 -0
  322. package/src/useAdminScripts.ts +67 -0
  323. package/src/useConfigurationApi.ts +24 -0
  324. package/src/useConsentHistory.ts +15 -2
  325. package/src/useDocumentStorageApi.ts +77 -0
  326. package/src/widgets/AIRequestsScreenWidget.test.tsx +154 -0
  327. package/src/widgets/AIRequestsScreenWidget.tsx +21 -7
  328. package/src/widgets/ModelsGridWidget.test.tsx +91 -0
  329. package/src/widgets/ModelsGridWidget.tsx +11 -1
  330. package/src/widgets/RecentActivityWidget.tsx +10 -3
  331. package/src/widgets/builtInFieldWidgets.test.tsx +166 -0
  332. package/src/widgets/builtInWidgets.ts +6 -0
  333. package/src/widgets/homeWidgetUtils.ts +0 -9
  334. package/src/widgets/pluginWidgets.test.tsx +10 -1
@@ -0,0 +1,69 @@
1
+ // noExplicitAny: test mocks use type-erased RTK Query API doubles
2
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
3
+ import {beforeEach, describe, it, mock} from "bun:test";
4
+ import {assert} from "chai";
5
+ import React from "react";
6
+ import {renderWithTheme} from "../../ui/src/test-utils";
7
+ import type {AnnouncementOverviewProps} from "./AnnouncementOverview";
8
+ import type {AdminApi} from "./types";
9
+
10
+ const pushMock = mock((_path: string) => {});
11
+
12
+ mock.module("expo-router", () => ({
13
+ useRouter: () => ({push: pushMock}),
14
+ }));
15
+
16
+ let capturedOverviewProps: AnnouncementOverviewProps | undefined;
17
+
18
+ mock.module("./AnnouncementOverview", () => ({
19
+ AnnouncementOverview: (props: AnnouncementOverviewProps) => {
20
+ capturedOverviewProps = props;
21
+ return null;
22
+ },
23
+ }));
24
+
25
+ import {
26
+ ANNOUNCEMENTS_ADMIN_WIDGETS,
27
+ AnnouncementOverviewScreenWidget,
28
+ } from "./AnnouncementOverviewScreenWidget";
29
+
30
+ describe("AnnouncementOverviewScreenWidget", () => {
31
+ beforeEach(() => {
32
+ pushMock.mockClear();
33
+ capturedOverviewProps = undefined;
34
+ });
35
+
36
+ it("registers the announcements overview widget", () => {
37
+ assert.strictEqual(ANNOUNCEMENTS_ADMIN_WIDGETS.announcements, AnnouncementOverviewScreenWidget);
38
+ });
39
+
40
+ it("routes create, edit, and analytics table actions through expo-router", () => {
41
+ renderWithTheme(
42
+ <AnnouncementOverviewScreenWidget api={{} as unknown as AdminApi} routeBase="/admin" />
43
+ );
44
+
45
+ assert.strictEqual(capturedOverviewProps?.routeBase, "/admin");
46
+ assert.isFunction(capturedOverviewProps?.onCreate);
47
+ assert.isFunction(capturedOverviewProps?.onEdit);
48
+ assert.isFunction(capturedOverviewProps?.onOpenAcknowledgements);
49
+ assert.isFunction(capturedOverviewProps?.onOpenImpressions);
50
+ assert.isFunction(capturedOverviewProps?.onOpenClickEvents);
51
+
52
+ capturedOverviewProps?.onCreate?.();
53
+ capturedOverviewProps?.onEdit?.("ann-1");
54
+ capturedOverviewProps?.onOpenAcknowledgements?.();
55
+ capturedOverviewProps?.onOpenImpressions?.();
56
+ capturedOverviewProps?.onOpenClickEvents?.();
57
+
58
+ assert.deepEqual(
59
+ pushMock.mock.calls.map((call) => call[0]),
60
+ [
61
+ "/admin/announcements/create",
62
+ "/admin/announcements/ann-1",
63
+ "/admin/AnnouncementAcknowledgement",
64
+ "/admin/AnnouncementImpression",
65
+ "/admin/AnnouncementClickEvent",
66
+ ]
67
+ );
68
+ });
69
+ });
@@ -0,0 +1,51 @@
1
+ import {useRouter} from "expo-router";
2
+ import React, {useCallback} from "react";
3
+ import {AnnouncementOverview} from "./AnnouncementOverview";
4
+ import type {AdminScreenWidgetProps, ScreenWidgetComponent} from "./types";
5
+
6
+ export const AnnouncementOverviewScreenWidget: React.FC<AdminScreenWidgetProps> = ({
7
+ api,
8
+ routeBase,
9
+ }) => {
10
+ const router = useRouter();
11
+ const announcementsBase = `${routeBase}/announcements`;
12
+
13
+ const handleCreate = useCallback((): void => {
14
+ router.push(`${announcementsBase}/create` as never);
15
+ }, [announcementsBase, router]);
16
+
17
+ const handleEdit = useCallback(
18
+ (id: string): void => {
19
+ router.push(`${announcementsBase}/${id}` as never);
20
+ },
21
+ [announcementsBase, router]
22
+ );
23
+
24
+ const handleOpenAcknowledgements = useCallback((): void => {
25
+ router.push(`${routeBase}/AnnouncementAcknowledgement` as never);
26
+ }, [routeBase, router]);
27
+
28
+ const handleOpenImpressions = useCallback((): void => {
29
+ router.push(`${routeBase}/AnnouncementImpression` as never);
30
+ }, [routeBase, router]);
31
+
32
+ const handleOpenClickEvents = useCallback((): void => {
33
+ router.push(`${routeBase}/AnnouncementClickEvent` as never);
34
+ }, [routeBase, router]);
35
+
36
+ return (
37
+ <AnnouncementOverview
38
+ api={api}
39
+ onCreate={handleCreate}
40
+ onEdit={handleEdit}
41
+ onOpenAcknowledgements={handleOpenAcknowledgements}
42
+ onOpenClickEvents={handleOpenClickEvents}
43
+ onOpenImpressions={handleOpenImpressions}
44
+ routeBase={routeBase}
45
+ />
46
+ );
47
+ };
48
+
49
+ export const ANNOUNCEMENTS_ADMIN_WIDGETS: Record<string, ScreenWidgetComponent> = {
50
+ announcements: AnnouncementOverviewScreenWidget,
51
+ };
@@ -69,7 +69,7 @@ describe("CheckboxListEditor", () => {
69
69
 
70
70
  it("updates a field when label/prompt changes", () => {
71
71
  const onChange = mock((_: unknown) => undefined);
72
- const {getByTestId} = renderWithTheme(
72
+ const {getByTestId, UNSAFE_root} = renderWithTheme(
73
73
  <CheckboxListEditor onChange={onChange} value={[{label: "a", required: false}]} />
74
74
  );
75
75
  fireEvent.changeText(getByTestId("checkbox-label-0"), "new-label");
@@ -79,5 +79,12 @@ describe("CheckboxListEditor", () => {
79
79
  fireEvent.changeText(getByTestId("checkbox-prompt-0"), "prompt?");
80
80
  const second = (onChange.mock.calls[1] as unknown[])[0];
81
81
  expect(second[0].confirmationPrompt).toBe("prompt?");
82
+
83
+ const requiredField = UNSAFE_root.find(
84
+ (node: ReactTestInstance) => node.props?.title === "Required"
85
+ );
86
+ requiredField.props.onChange(true);
87
+ const third = (onChange.mock.calls[2] as unknown[])[0];
88
+ expect(third[0].required).toBe(true);
82
89
  });
83
90
  });
@@ -5,6 +5,7 @@ import {act, fireEvent} from "@testing-library/react-native";
5
5
  import React from "react";
6
6
  import type {ReactTestInstance} from "react-test-renderer";
7
7
  import {renderWithTheme} from "../../ui/src/test-utils";
8
+ import {configureUseAdminApiDouble, resetUseAdminApiDouble} from "./testing/useAdminApiDouble";
8
9
  import type {AdminApi} from "./types";
9
10
 
10
11
  interface State {
@@ -32,35 +33,6 @@ let translateImpl: (body: unknown) => Promise<unknown> = async () => ({
32
33
  data: {content: "translated"},
33
34
  });
34
35
 
35
- mock.module("./useAdminApi", () => ({
36
- useAdminApi: () => ({
37
- useCreateMutation: () => [
38
- (body: unknown) => ({
39
- unwrap: async () => {
40
- createCalls.push(body);
41
- return createImpl(body);
42
- },
43
- }),
44
- {isLoading: false},
45
- ],
46
- useReadQuery: (_id: string, opts: {skip?: boolean}) => {
47
- if (opts?.skip) {
48
- return {data: undefined, isLoading: false};
49
- }
50
- return {data: state.formData, isLoading: state.isFormLoading};
51
- },
52
- useUpdateMutation: () => [
53
- (args: unknown) => ({
54
- unwrap: async () => {
55
- updateCalls.push(args);
56
- return updateImpl(args);
57
- },
58
- }),
59
- {isLoading: false},
60
- ],
61
- }),
62
- }));
63
-
64
36
  const mutationSpecs: unknown[] = [];
65
37
  const makeApi = () => ({
66
38
  injectEndpoints: ({endpoints}: {endpoints: (b: unknown) => Record<string, unknown>}) => {
@@ -129,6 +101,33 @@ const press = async (el: ReactTestInstance): Promise<void> => {
129
101
 
130
102
  describe("ConsentFormEditor", () => {
131
103
  beforeEach(() => {
104
+ resetUseAdminApiDouble();
105
+ configureUseAdminApiDouble({
106
+ useCreateMutation: () => [
107
+ (body: unknown) => ({
108
+ unwrap: async () => {
109
+ createCalls.push(body);
110
+ return createImpl(body);
111
+ },
112
+ }),
113
+ {isLoading: false},
114
+ ],
115
+ useReadQuery: (_id: string, opts: {skip?: boolean}) => {
116
+ if (opts?.skip) {
117
+ return {data: undefined, isLoading: false};
118
+ }
119
+ return {data: state.formData, isLoading: state.isFormLoading};
120
+ },
121
+ useUpdateMutation: () => [
122
+ (args: unknown) => ({
123
+ unwrap: async () => {
124
+ updateCalls.push(args);
125
+ return updateImpl(args);
126
+ },
127
+ }),
128
+ {isLoading: false},
129
+ ],
130
+ });
132
131
  state.formData = null;
133
132
  state.isFormLoading = false;
134
133
  createCalls.length = 0;
@@ -18,6 +18,7 @@ import React, {useCallback, useEffect, useMemo, useState} from "react";
18
18
  import {asDynamicHookApi} from "./dynamicHookApi";
19
19
  import {type AdminApi, type EndpointBuilder, resolveAdminBases} from "./types";
20
20
  import {useAdminApi} from "./useAdminApi";
21
+ import {useAdminRpc, useAdminRpcMutation} from "./useAdminRpc";
21
22
 
22
23
  interface CheckboxConfig {
23
24
  label: string;
@@ -184,12 +185,35 @@ export const ConsentFormEditor: React.FC<ConsentFormEditorProps> = ({
184
185
  "ConsentForm"
185
186
  );
186
187
 
188
+ const rpc = useAdminRpc();
189
+ const [publishRpc, publishRpcState] = useAdminRpcMutation(rpc);
190
+ const [generateRpc, generateRpcState] = useAdminRpcMutation(rpc);
191
+ const [translateRpc, translateRpcState] = useAdminRpcMutation(rpc);
192
+
187
193
  const enhanced = asDynamicHookApi(getEnhancedApi(api));
188
- const [publishConsentForm, {isLoading: isPublishing}] = enhanced.usePublishConsentFormMutation();
189
- const [generateContent, {isLoading: isGenerating}] = enhanced.useGenerateConsentContentMutation();
190
- const [translateContent, {isLoading: isTranslating}] =
194
+ const [publishConsentFormRtk, {isLoading: isPublishingRtk}] =
195
+ enhanced.usePublishConsentFormMutation();
196
+ const [generateContentRtk, {isLoading: isGeneratingRtk}] =
197
+ enhanced.useGenerateConsentContentMutation();
198
+ const [translateContentRtk, {isLoading: isTranslatingRtk}] =
191
199
  enhanced.useTranslateConsentContentMutation();
192
200
 
201
+ const publishConsentForm = rpc
202
+ ? (formId: string) =>
203
+ publishRpc({method: "POST", url: `${CONSENT_FORM_ROUTE}/${formId}/publish`})
204
+ : publishConsentFormRtk;
205
+ const generateContent = rpc
206
+ ? (body: {type: string; description: string; locale: string}) =>
207
+ generateRpc({body, method: "POST", url: `${CONSENT_FORM_ROUTE}/generate`})
208
+ : generateContentRtk;
209
+ const translateContent = rpc
210
+ ? (body: {content: string; fromLocale: string; toLocale: string}) =>
211
+ translateRpc({body, method: "POST", url: `${CONSENT_FORM_ROUTE}/translate`})
212
+ : translateContentRtk;
213
+ const isPublishing = rpc ? publishRpcState.isLoading : isPublishingRtk;
214
+ const isGenerating = rpc ? generateRpcState.isLoading : isGeneratingRtk;
215
+ const isTranslating = rpc ? translateRpcState.isLoading : isTranslatingRtk;
216
+
193
217
  const {data: formData, isLoading: isFormLoading} = useReadQuery(id ?? "", {
194
218
  skip: !isEditMode || !id,
195
219
  });
@@ -5,6 +5,7 @@ import {act, fireEvent} from "@testing-library/react-native";
5
5
  import React from "react";
6
6
  import type {ReactTestInstance} from "react-test-renderer";
7
7
  import {renderWithTheme} from "../../ui/src/test-utils";
8
+ import {configureUseAdminApiDouble, resetUseAdminApiDouble} from "./testing/useAdminApiDouble";
8
9
  import type {AdminApi} from "./types";
9
10
 
10
11
  interface ListState {
@@ -14,20 +15,18 @@ interface ListState {
14
15
  }
15
16
  const listState: ListState = {data: undefined, error: null, isLoading: false};
16
17
 
17
- mock.module("./useAdminApi", () => ({
18
- useAdminApi: () => ({
19
- useListQuery: () => ({
20
- data: listState.data,
21
- error: listState.error,
22
- isLoading: listState.isLoading,
23
- }),
24
- }),
25
- }));
26
-
27
18
  import {ConsentFormList} from "./ConsentFormList";
28
19
 
29
20
  describe("ConsentFormList", () => {
30
21
  beforeEach(() => {
22
+ resetUseAdminApiDouble();
23
+ configureUseAdminApiDouble({
24
+ useListQuery: () => ({
25
+ data: listState.data,
26
+ error: listState.error,
27
+ isLoading: listState.isLoading,
28
+ }),
29
+ });
31
30
  listState.data = undefined;
32
31
  listState.isLoading = false;
33
32
  listState.error = null;
@@ -86,7 +85,7 @@ describe("ConsentFormList", () => {
86
85
  };
87
86
  const onCreateNew = mock(() => undefined);
88
87
  const onRowClick = mock((_: string) => undefined);
89
- const {getByTestId} = renderWithTheme(
88
+ const {getAllByLabelText, getByTestId} = renderWithTheme(
90
89
  <ConsentFormList
91
90
  api={{} as unknown as AdminApi}
92
91
  baseUrl="/admin"
@@ -96,9 +95,11 @@ describe("ConsentFormList", () => {
96
95
  );
97
96
  await act(async () => {
98
97
  fireEvent.press(getByTestId("consent-form-list-create-button"));
98
+ fireEvent.press(getAllByLabelText("Edit")[0]);
99
99
  await new Promise((r) => setTimeout(r, 50));
100
100
  });
101
101
  expect(onCreateNew).toHaveBeenCalled();
102
+ expect(onRowClick).toHaveBeenCalledWith("a");
102
103
  });
103
104
 
104
105
  it("falls back when sort column is out of range (buildSortString returns undefined)", async () => {
@@ -4,6 +4,7 @@ import {beforeEach, describe, expect, it, mock} from "bun:test";
4
4
  import {act, fireEvent} from "@testing-library/react-native";
5
5
  import React from "react";
6
6
  import {renderWithTheme} from "../../ui/src/test-utils";
7
+ import {configureUseAdminApiDouble, resetUseAdminApiDouble} from "./testing/useAdminApiDouble";
7
8
  import type {AdminApi} from "./types";
8
9
 
9
10
  interface ReadState {
@@ -12,17 +13,6 @@ interface ReadState {
12
13
  }
13
14
  const readState: ReadState = {data: undefined, isLoading: false};
14
15
 
15
- mock.module("./useAdminApi", () => ({
16
- useAdminApi: () => ({
17
- useReadQuery: (_id: string, opts: {skip?: boolean}) => {
18
- if (opts?.skip) {
19
- return {data: undefined, isLoading: false};
20
- }
21
- return {data: readState.data, isLoading: readState.isLoading};
22
- },
23
- }),
24
- }));
25
-
26
16
  const pdfCalls: unknown[] = [];
27
17
  let pdfImpl: (r: unknown) => Promise<void> = async () => {};
28
18
  mock.module("./generateConsentPdf", () => ({
@@ -36,6 +26,15 @@ import {ConsentResponseViewer} from "./ConsentResponseViewer";
36
26
 
37
27
  describe("ConsentResponseViewer", () => {
38
28
  beforeEach(() => {
29
+ resetUseAdminApiDouble();
30
+ configureUseAdminApiDouble({
31
+ useReadQuery: (_id: string, opts: {skip?: boolean}) => {
32
+ if (opts?.skip) {
33
+ return {data: undefined, isLoading: false};
34
+ }
35
+ return {data: readState.data, isLoading: readState.isLoading};
36
+ },
37
+ });
39
38
  readState.data = undefined;
40
39
  readState.isLoading = false;
41
40
  pdfCalls.length = 0;
@@ -14,8 +14,7 @@ import {
14
14
  } from "@terreno/ui";
15
15
  import {DateTime} from "luxon";
16
16
  import React, {useCallback, useEffect, useMemo, useRef, useState} from "react";
17
- import {Platform, Image as RNImage, useWindowDimensions} from "react-native";
18
- import {WebView} from "react-native-webview";
17
+ import {Platform} from "react-native";
19
18
 
20
19
  import {AdminScreenPage} from "./AdminScreenPage";
21
20
  import type {DocumentFile, DocumentListResponse, DocumentStorageBrowserProps} from "./types";
@@ -55,11 +54,7 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
55
54
  const [showNewFolderModal, setShowNewFolderModal] = useState(false);
56
55
  const [newFolderName, setNewFolderName] = useState("");
57
56
  const [isCreatingFolder, setIsCreatingFolder] = useState(false);
58
- const [viewerFile, setViewerFile] = useState<DocumentFile | null>(null);
59
- const [viewerBlobUrl, setViewerBlobUrl] = useState<string | null>(null);
60
- const [isViewLoading, setIsViewLoading] = useState(false);
61
57
  const fileInputRef = useRef<HTMLInputElement>(null);
62
- const viewerBlobUrlRef = useRef<string | null>(null);
63
58
 
64
59
  const {
65
60
  useListQuery,
@@ -89,15 +84,6 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
89
84
  const [createFolder] = useCreateFolderMutation();
90
85
  const [downloadFile] = useLazyDownloadQuery();
91
86
 
92
- // Revoke blob URL on unmount
93
- useEffect(() => {
94
- return () => {
95
- if (viewerBlobUrlRef.current) {
96
- URL.revokeObjectURL(viewerBlobUrlRef.current);
97
- }
98
- };
99
- }, []);
100
-
101
87
  // Detect 503 "not configured" responses
102
88
  useEffect(() => {
103
89
  if (isError && error) {
@@ -126,46 +112,6 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
126
112
  setCurrentPrefix(prefix);
127
113
  }, []);
128
114
 
129
- const handleViewFile = useCallback(
130
- async (file: DocumentFile) => {
131
- setViewerFile(file);
132
- setViewerBlobUrl(null);
133
- setIsViewLoading(true);
134
- try {
135
- const blob = await downloadFile(file.fullPath).unwrap();
136
- if (Platform.OS === "web") {
137
- const url = URL.createObjectURL(blob as Blob);
138
- viewerBlobUrlRef.current = url;
139
- setViewerBlobUrl(url);
140
- } else {
141
- // Convert to base64 data URI for React Native
142
- const dataUri = await new Promise<string>((resolve, reject) => {
143
- const reader = new FileReader();
144
- reader.onloadend = () => resolve(reader.result as string);
145
- reader.onerror = reject;
146
- reader.readAsDataURL(blob as Blob);
147
- });
148
- setViewerBlobUrl(dataUri);
149
- }
150
- } catch (err) {
151
- console.error("Failed to load file preview:", err);
152
- } finally {
153
- setIsViewLoading(false);
154
- }
155
- },
156
- [downloadFile]
157
- );
158
-
159
- const handleViewerClose = useCallback(() => {
160
- // Only blob: URLs need revocation; base64 data URIs do not
161
- if (Platform.OS === "web" && viewerBlobUrlRef.current) {
162
- URL.revokeObjectURL(viewerBlobUrlRef.current);
163
- viewerBlobUrlRef.current = null;
164
- }
165
- setViewerFile(null);
166
- setViewerBlobUrl(null);
167
- }, []);
168
-
169
115
  const handleDownload = useCallback(
170
116
  async (filePath: string) => {
171
117
  console.info("[DocumentStorageBrowser] handleDownload filePath:", filePath);
@@ -308,13 +254,9 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
308
254
  if (file && onFileSelect) {
309
255
  return <Link onClick={() => onFileSelect(file)} text={name} />;
310
256
  }
311
- // TODO: re-enable file preview in a follow-up PR
312
- // if (file && Platform.OS === "web" && isViewable(file.contentType)) {
313
- // return <Link onClick={() => handleViewFile(file)} text={name} />;
314
- // }
315
257
  return <Text>{name}</Text>;
316
258
  },
317
- [handleFolderClick, handleViewFile, onFileSelect]
259
+ [handleFolderClick, onFileSelect]
318
260
  );
319
261
 
320
262
  const DocumentActionsCell: React.FC<{
@@ -418,74 +360,6 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
418
360
  return rows;
419
361
  }, [listData]);
420
362
 
421
- const {height: windowHeight} = useWindowDimensions();
422
- const nativeViewerHeight = Math.floor(windowHeight * 0.6);
423
-
424
- const renderViewerContent = () => {
425
- if (isViewLoading) {
426
- return (
427
- <Box alignItems="center" justifyContent="center" padding={6}>
428
- <Spinner />
429
- </Box>
430
- );
431
- }
432
- if (!viewerBlobUrl) {
433
- return (
434
- <Box alignItems="center" padding={4}>
435
- <Text color="error">Failed to load preview.</Text>
436
- </Box>
437
- );
438
- }
439
-
440
- const contentType = viewerFile?.contentType ?? "";
441
-
442
- if (Platform.OS === "web") {
443
- if (contentType.startsWith("image/")) {
444
- return (
445
- <Box alignItems="center">
446
- <img
447
- alt={viewerFile?.name}
448
- src={viewerBlobUrl}
449
- style={{maxHeight: "70vh", maxWidth: "100%", objectFit: "contain"}}
450
- />
451
- </Box>
452
- );
453
- }
454
- if (contentType.startsWith("video/")) {
455
- return (
456
- <Box alignItems="center">
457
- <video controls src={viewerBlobUrl} style={{maxHeight: "70vh", maxWidth: "100%"}}>
458
- <track kind="captions" />
459
- </video>
460
- </Box>
461
- );
462
- }
463
- // PDF and text/plain — render in iframe
464
- return (
465
- <iframe
466
- src={viewerBlobUrl}
467
- style={{border: "none", height: "70vh", width: "100%"}}
468
- title={viewerFile?.name}
469
- />
470
- );
471
- }
472
-
473
- // React Native
474
- if (contentType.startsWith("image/")) {
475
- return (
476
- <RNImage
477
- resizeMode="contain"
478
- source={{uri: viewerBlobUrl}}
479
- style={{height: nativeViewerHeight, width: "100%"}}
480
- />
481
- );
482
- }
483
- // PDFs, videos, and text — use WebView with the data URI
484
- return (
485
- <WebView source={{uri: viewerBlobUrl}} style={{height: nativeViewerHeight, width: "100%"}} />
486
- );
487
- };
488
-
489
363
  const headerRow = (
490
364
  <Box alignItems="center" direction="row" padding={2}>
491
365
  {/* Breadcrumbs */}
@@ -611,17 +485,6 @@ export const DocumentStorageBrowser: React.FC<DocumentStorageBrowserProps> = ({
611
485
  {headerRow}
612
486
  {renderContent()}
613
487
 
614
- <Modal
615
- onDismiss={handleViewerClose}
616
- primaryButtonOnClick={handleViewerClose}
617
- primaryButtonText="Close"
618
- size="lg"
619
- title={viewerFile?.name ?? "Preview"}
620
- visible={viewerFile !== null}
621
- >
622
- {renderViewerContent()}
623
- </Modal>
624
-
625
488
  <Modal
626
489
  onDismiss={handleNewFolderModalDismiss}
627
490
  primaryButtonOnClick={handleCreateFolder}
@@ -0,0 +1,33 @@
1
+ import qs from "qs";
2
+
3
+ /**
4
+ * Serializes admin list query params for modelRouter-compatible GET requests.
5
+ * Uses bracket notation for nested operators (`$in`, `$regex`, ranges).
6
+ */
7
+ const serializeAdminApiQueryParams = (params: Record<string, unknown>): string => {
8
+ return qs.stringify(params);
9
+ };
10
+
11
+ /** Builds a list URL with a pre-serialized query string (avoids base-query object coercion). */
12
+ const buildAdminApiListQueryUrl = (
13
+ routePath: string,
14
+ params: Record<string, unknown> | undefined
15
+ ): string => {
16
+ if (!params || Object.keys(params).length === 0) {
17
+ return routePath;
18
+ }
19
+ const queryString = serializeAdminApiQueryParams(params);
20
+ if (queryString === "") {
21
+ return routePath;
22
+ }
23
+ return `${routePath}?${queryString}`;
24
+ };
25
+
26
+ /** RTK Query list request shape for admin model routes. */
27
+ export const buildAdminApiListQueryRequest = (
28
+ routePath: string,
29
+ params: Record<string, unknown> | undefined
30
+ ): {method: "GET"; url: string} => ({
31
+ method: "GET",
32
+ url: buildAdminApiListQueryUrl(routePath, params),
33
+ });
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Admin stacks keep the changelist mounted under the form, so both screens can render an
3
+ * `AdminConflictSheet` for the same collection. Only the topmost (most recently mounted)
4
+ * instance may show the modal; otherwise one conflict opens two sheets with duplicate
5
+ * `conflict-*` test ids.
6
+ */
7
+ const mountedSheetIdsByCollection = new Map<string, string[]>();
8
+ const listeners = new Set<() => void>();
9
+
10
+ let nextSheetId = 0;
11
+
12
+ const notify = (): void => {
13
+ for (const listener of listeners) {
14
+ listener();
15
+ }
16
+ };
17
+
18
+ export const nextAdminConflictSheetId = (): string => {
19
+ nextSheetId += 1;
20
+ return `admin-conflict-sheet-${nextSheetId}`;
21
+ };
22
+
23
+ export const subscribeAdminConflictSheetStack = (listener: () => void): (() => void) => {
24
+ listeners.add(listener);
25
+ return (): void => {
26
+ listeners.delete(listener);
27
+ };
28
+ };
29
+
30
+ export const pushAdminConflictSheet = ({
31
+ collection,
32
+ sheetId,
33
+ }: {
34
+ collection: string;
35
+ sheetId: string;
36
+ }): void => {
37
+ const mounted = mountedSheetIdsByCollection.get(collection) ?? [];
38
+ if (mounted.includes(sheetId)) {
39
+ return;
40
+ }
41
+ mountedSheetIdsByCollection.set(collection, [...mounted, sheetId]);
42
+ notify();
43
+ };
44
+
45
+ export const popAdminConflictSheet = ({
46
+ collection,
47
+ sheetId,
48
+ }: {
49
+ collection: string;
50
+ sheetId: string;
51
+ }): void => {
52
+ const mounted = mountedSheetIdsByCollection.get(collection);
53
+ if (!mounted) {
54
+ return;
55
+ }
56
+ const remaining = mounted.filter((id) => id !== sheetId);
57
+ if (remaining.length === mounted.length) {
58
+ return;
59
+ }
60
+ if (remaining.length === 0) {
61
+ mountedSheetIdsByCollection.delete(collection);
62
+ } else {
63
+ mountedSheetIdsByCollection.set(collection, remaining);
64
+ }
65
+ notify();
66
+ };
67
+
68
+ /** True while this sheet is the topmost mounted instance for its collection. */
69
+ export const isTopAdminConflictSheet = ({
70
+ collection,
71
+ sheetId,
72
+ }: {
73
+ collection: string;
74
+ sheetId: string;
75
+ }): boolean => {
76
+ const mounted = mountedSheetIdsByCollection.get(collection);
77
+ if (!mounted || mounted.length === 0) {
78
+ return false;
79
+ }
80
+ return mounted[mounted.length - 1] === sheetId;
81
+ };
82
+
83
+ /** @internal Test helper — drops every registered sheet. */
84
+ export const resetAdminConflictSheetStackForTests = (): void => {
85
+ mountedSheetIdsByCollection.clear();
86
+ notify();
87
+ };
@@ -0,0 +1,8 @@
1
+ import {createContext, useContext} from "react";
2
+ import type {AdminProviderValue} from "./types";
3
+
4
+ export const AdminWidgetContext = createContext<AdminProviderValue | null>(null);
5
+
6
+ export const useAdminContext = (): AdminProviderValue | null => {
7
+ return useContext(AdminWidgetContext);
8
+ };