@rebasepro/admin 0.13.0 → 0.13.1-canary.g06dbe5b

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 (188) hide show
  1. package/dist/{CollectionEditorDialog-CjXkWZ64.js → CollectionEditorDialog-C3DbFNqp.js} +3 -3
  2. package/dist/{CollectionEditorDialog-CjXkWZ64.js.map → CollectionEditorDialog-C3DbFNqp.js.map} +1 -1
  3. package/dist/{PropertyEditView-W8I3YV89.js → PropertyEditView-DFH8rXRN.js} +5 -5
  4. package/dist/PropertyEditView-DFH8rXRN.js.map +1 -0
  5. package/dist/{RouterCollectionsStudioView-BsLTNoqX.js → RouterCollectionsStudioView-DiUDOu4b.js} +9 -13
  6. package/dist/RouterCollectionsStudioView-DiUDOu4b.js.map +1 -0
  7. package/dist/collection_editor/serializable_types.d.ts +1 -0
  8. package/dist/collection_editor_ui.js +4 -4
  9. package/dist/components/AdditionalFieldValue.d.ts +25 -0
  10. package/dist/components/ClearFilterSortButton.d.ts +7 -1
  11. package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +16 -0
  12. package/dist/components/CollectionViewBinding/EntityCardBinding.d.ts +3 -1
  13. package/dist/components/CollectionViewBinding/SearchExplanation.d.ts +48 -0
  14. package/dist/components/CollectionViewBinding/SearchHighlight.d.ts +101 -0
  15. package/dist/components/CollectionViewBinding/SlotValue.d.ts +63 -0
  16. package/dist/components/CollectionViewBinding/SortButton.d.ts +7 -1
  17. package/dist/components/CollectionViewBinding/SplitListCloseButton.d.ts +17 -4
  18. package/dist/components/CollectionViewBinding/SplitListShowButton.d.ts +12 -0
  19. package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +55 -5
  20. package/dist/components/DetailViewBinding.d.ts +15 -0
  21. package/dist/components/DrawerNavigationGroup.d.ts +9 -6
  22. package/dist/components/DrawerNavigationItem.d.ts +16 -6
  23. package/dist/components/EditViewBinding.d.ts +30 -1
  24. package/dist/components/EntityDisplayHeader.d.ts +53 -0
  25. package/dist/components/EntityIdentityBar.d.ts +43 -1
  26. package/dist/components/EntityViewBinding.d.ts +60 -6
  27. package/dist/components/RebaseLayout.d.ts +1 -1
  28. package/dist/components/RebaseShell.d.ts +1 -1
  29. package/dist/components/RelationSelector.d.ts +8 -1
  30. package/dist/components/UserSelector.d.ts +8 -1
  31. package/dist/components/app/Scaffold.d.ts +9 -3
  32. package/dist/components/index.d.ts +2 -0
  33. package/dist/data_export/export/export.d.ts +7 -0
  34. package/dist/data_export/export/fetch_export_data.d.ts +48 -0
  35. package/dist/data_export/export/index.d.ts +1 -0
  36. package/dist/data_import/utils/csv.d.ts +30 -0
  37. package/dist/data_import/utils/index.d.ts +2 -0
  38. package/dist/data_import/utils/save_entities.d.ts +38 -0
  39. package/dist/data_import/utils/transforms.d.ts +9 -0
  40. package/dist/{export-J79rMoNj.js → export-Bd5i6Uvm.js} +175 -39
  41. package/dist/export-Bd5i6Uvm.js.map +1 -0
  42. package/dist/form/components/FieldBlock.d.ts +58 -4
  43. package/dist/form/components/FormRail.d.ts +13 -0
  44. package/dist/form/components/FormSections.d.ts +15 -1
  45. package/dist/form/components/useRailVisible.d.ts +5 -4
  46. package/dist/form/form_utils.d.ts +38 -1
  47. package/dist/{history-D7L_JlLO.js → history-D9R6LUrH.js} +4 -4
  48. package/dist/{history-D7L_JlLO.js.map → history-D9R6LUrH.js.map} +1 -1
  49. package/dist/hooks/useEntityDisplay.d.ts +102 -0
  50. package/dist/hooks/useEntityDisplayTitle.d.ts +18 -9
  51. package/dist/{import-BvYl--U4.js → import-pt_j-0G3.js} +6 -5
  52. package/dist/import-pt_j-0G3.js.map +1 -0
  53. package/dist/index.d.ts +2 -2
  54. package/dist/index.js +158 -60
  55. package/dist/index.js.map +1 -1
  56. package/dist/preview/compact_text.d.ts +23 -0
  57. package/dist/preview/components/BooleanPreview.d.ts +3 -1
  58. package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
  59. package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
  60. package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
  61. package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
  62. package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
  63. package/dist/routes/RebaseRoute.d.ts +1 -1
  64. package/dist/types/components/PropertyPreviewProps.d.ts +19 -0
  65. package/dist/util/number_format.d.ts +14 -0
  66. package/dist/util/previews.d.ts +9 -2
  67. package/dist/util/view_constants.d.ts +24 -0
  68. package/dist/util/view_mode.d.ts +18 -0
  69. package/dist/{util-GiwPgxnL.js → util-nX_-JRuF.js} +3984 -1774
  70. package/dist/util-nX_-JRuF.js.map +1 -0
  71. package/package.json +10 -9
  72. package/src/collection_editor/serializable_types.ts +1 -0
  73. package/src/collection_editor/ui/collection_editor/CollectionsStudioView.tsx +9 -11
  74. package/src/collection_editor/ui/collection_editor/properties/MapPropertyField.tsx +1 -1
  75. package/src/collection_editor/ui/collection_editor/properties/advanced/AdvancedPropertyValidation.tsx +5 -2
  76. package/src/collection_editor/useLocalCollectionsConfigController.tsx +10 -3
  77. package/src/components/AdditionalFieldValue.tsx +68 -0
  78. package/src/components/ClearFilterSortButton.tsx +16 -7
  79. package/src/components/CollectionTableBinding/CollectionTableBinding.tsx +7 -8
  80. package/src/components/CollectionTableBinding/PropertyTableCell.tsx +2 -2
  81. package/src/components/CollectionTableBinding/column_utils.tsx +15 -6
  82. package/src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx +2 -2
  83. package/src/components/CollectionTableBinding/table_bindings.tsx +7 -1
  84. package/src/components/CollectionViewBinding/BoardCardBinding.tsx +26 -27
  85. package/src/components/CollectionViewBinding/CollectionBoardViewBinding.tsx +13 -7
  86. package/src/components/CollectionViewBinding/CollectionCardViewBinding.tsx +2 -1
  87. package/src/components/CollectionViewBinding/CollectionListViewBinding.tsx +822 -354
  88. package/src/components/CollectionViewBinding/CollectionViewActions.tsx +1 -1
  89. package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +51 -12
  90. package/src/components/CollectionViewBinding/CollectionViewStartActions.tsx +9 -0
  91. package/src/components/CollectionViewBinding/EntityCardBinding.tsx +51 -39
  92. package/src/components/CollectionViewBinding/SearchExplanation.tsx +106 -0
  93. package/src/components/CollectionViewBinding/SearchHighlight.tsx +311 -0
  94. package/src/components/CollectionViewBinding/SlotValue.tsx +156 -0
  95. package/src/components/CollectionViewBinding/SortButton.tsx +16 -4
  96. package/src/components/CollectionViewBinding/SplitListCloseButton.tsx +23 -7
  97. package/src/components/CollectionViewBinding/SplitListShowButton.tsx +28 -0
  98. package/src/components/CollectionViewBinding/SplitListView.tsx +47 -7
  99. package/src/components/CollectionViewBinding/ViewModeToggle.tsx +10 -5
  100. package/src/components/CollectionViewBinding/useBoardDataController.tsx +23 -6
  101. package/src/components/CollectionViewBinding/usePreviewSlots.ts +183 -64
  102. package/src/components/CollectionViewBinding/utils.ts +7 -4
  103. package/src/components/DefaultDrawer.tsx +19 -23
  104. package/src/components/DetailViewBinding.tsx +109 -62
  105. package/src/components/DrawerNavigationGroup.tsx +16 -39
  106. package/src/components/DrawerNavigationItem.tsx +44 -16
  107. package/src/components/EditViewBinding.tsx +233 -50
  108. package/src/components/EntityDisplayHeader.tsx +170 -0
  109. package/src/components/EntityIdentityBar.tsx +163 -23
  110. package/src/components/EntityInspector.tsx +24 -6
  111. package/src/components/EntityPreviewBinding.tsx +58 -18
  112. package/src/components/EntityViewBinding.tsx +344 -41
  113. package/src/components/InlineEntityPreview.tsx +10 -10
  114. package/src/components/RebaseLayout.tsx +2 -2
  115. package/src/components/RebaseShell.tsx +2 -2
  116. package/src/components/ReferenceTable/SelectionTableBinding.tsx +4 -2
  117. package/src/components/RelationSelector.tsx +35 -10
  118. package/src/components/SideDialogs.tsx +15 -3
  119. package/src/components/SidePanelBinding.tsx +122 -66
  120. package/src/components/UserSelector.tsx +67 -13
  121. package/src/components/app/Scaffold.tsx +112 -10
  122. package/src/components/history/LastEditedByIndicator.tsx +7 -12
  123. package/src/components/index.ts +3 -0
  124. package/src/data_export/export/ExportCollectionAction.tsx +101 -48
  125. package/src/data_export/export/export.ts +63 -16
  126. package/src/data_export/export/fetch_export_data.ts +90 -0
  127. package/src/data_export/export/index.ts +1 -0
  128. package/src/data_import/components/ImportSaveInProgress.tsx +35 -36
  129. package/src/data_import/import/ImportCollectionAction.tsx +13 -2
  130. package/src/data_import/utils/csv.ts +153 -0
  131. package/src/data_import/utils/data.ts +16 -2
  132. package/src/data_import/utils/file_to_json.ts +51 -5
  133. package/src/data_import/utils/index.ts +2 -0
  134. package/src/data_import/utils/save_entities.ts +138 -0
  135. package/src/data_import/utils/transforms.ts +23 -0
  136. package/src/form/EntityForm.tsx +74 -53
  137. package/src/form/EntityFormBinding.tsx +24 -11
  138. package/src/form/PropertyFieldBinding.tsx +2 -2
  139. package/src/form/components/FieldBlock.tsx +80 -10
  140. package/src/form/components/FormRail.tsx +19 -2
  141. package/src/form/components/FormSections.tsx +32 -5
  142. package/src/form/components/StorageUploadProgress.tsx +9 -3
  143. package/src/form/components/useRailVisible.tsx +5 -4
  144. package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -2
  145. package/src/form/field_bindings/BinaryFieldBinding.tsx +10 -5
  146. package/src/form/field_bindings/BlockFieldBinding.tsx +3 -3
  147. package/src/form/field_bindings/GeopointFieldBinding.tsx +23 -16
  148. package/src/form/field_bindings/MapFieldBinding.tsx +2 -2
  149. package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +13 -7
  150. package/src/form/field_bindings/MultiSelectFieldBinding.tsx +7 -1
  151. package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +21 -2
  152. package/src/form/field_bindings/ReferenceFieldBinding.tsx +1 -1
  153. package/src/form/field_bindings/RelationFieldBinding.tsx +5 -2
  154. package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -3
  155. package/src/form/field_bindings/StorageUploadFieldBinding.tsx +2 -2
  156. package/src/form/field_bindings/UserSelectFieldBinding.tsx +4 -1
  157. package/src/form/field_bindings/VectorFieldBinding.tsx +6 -4
  158. package/src/form/form_utils.ts +78 -0
  159. package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +29 -5
  160. package/src/hooks/useEntityDisplay.tsx +262 -0
  161. package/src/hooks/useEntityDisplayTitle.tsx +27 -38
  162. package/src/index.ts +9 -1
  163. package/src/preview/PropertyPreview.tsx +25 -5
  164. package/src/preview/compact_text.ts +68 -0
  165. package/src/preview/components/BooleanPreview.tsx +5 -2
  166. package/src/preview/components/ReferencePreview.tsx +5 -8
  167. package/src/preview/components/RelationPreview.tsx +8 -7
  168. package/src/preview/components/StorageThumbnail.tsx +5 -2
  169. package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +6 -3
  170. package/src/preview/property_previews/ArrayOfStringsPreview.tsx +26 -1
  171. package/src/preview/property_previews/ArrayOneOfPreview.tsx +10 -1
  172. package/src/preview/property_previews/ArrayPropertyPreview.tsx +10 -1
  173. package/src/preview/property_previews/MapPropertyPreview.tsx +52 -1
  174. package/src/preview/property_previews/NumberPropertyPreview.tsx +9 -1
  175. package/src/preview/property_previews/StringPropertyPreview.tsx +8 -5
  176. package/src/routes/RebaseRoute.tsx +62 -4
  177. package/src/types/components/PropertyPreviewProps.tsx +21 -0
  178. package/src/util/navigation_utils.ts +4 -2
  179. package/src/util/number_format.ts +46 -0
  180. package/src/util/previews.ts +8 -55
  181. package/src/util/property_utils.tsx +6 -1
  182. package/src/util/view_constants.ts +27 -0
  183. package/src/util/view_mode.ts +36 -0
  184. package/dist/PropertyEditView-W8I3YV89.js.map +0 -1
  185. package/dist/RouterCollectionsStudioView-BsLTNoqX.js.map +0 -1
  186. package/dist/export-J79rMoNj.js.map +0 -1
  187. package/dist/import-BvYl--U4.js.map +0 -1
  188. package/dist/util-GiwPgxnL.js.map +0 -1
@@ -91,7 +91,17 @@ function SideDialogView({
91
91
  const [blocked, setBlocked] = useState(false);
92
92
  const [blockedNavigationMessage, setBlockedNavigationMessage] = useState<React.ReactNode | undefined>();
93
93
 
94
- const [pendingClose, setPendingClose] = useState(false);
94
+ // Held in a ref, read through a getter, because of *when* it is written and
95
+ // read. "Save and close" raises it and submits the form in one click
96
+ // handler, and the callback that acts on it — the form's `onSaved` — was
97
+ // captured before React could re-render with the new value. As state the
98
+ // flag was therefore always read one save late: the first "save and close"
99
+ // saved and left the panel open, and the *next* save closed it.
100
+ // Nothing renders from it, so a ref loses nothing.
101
+ const pendingCloseRef = React.useRef(false);
102
+ const setPendingClose = useCallback((value: boolean) => {
103
+ pendingCloseRef.current = value;
104
+ }, []);
95
105
 
96
106
  const widthRef = React.useRef<string | undefined>(panel?.width);
97
107
  const width = widthRef.current;
@@ -142,9 +152,11 @@ function SideDialogView({
142
152
  setBlockedNavigationMessage,
143
153
  width,
144
154
  close: onCloseRequest,
145
- pendingClose,
155
+ get pendingClose() {
156
+ return pendingCloseRef.current;
157
+ },
146
158
  setPendingClose
147
- }), [blocked, setBlockedNavigationMessage, width, onCloseRequest, pendingClose]);
159
+ }), [blocked, setBlockedNavigationMessage, width, onCloseRequest, setPendingClose]);
148
160
 
149
161
  const additionalProps = panel?.additional as SidePanelBindingProps | undefined;
150
162
  const isDialogMode = additionalProps?.collection?.openEntityMode === "dialog";
@@ -9,7 +9,7 @@ import { EditViewBinding } from "./EditViewBinding";
9
9
  import { DetailViewBinding } from "./DetailViewBinding";
10
10
  import { useSideDialogContext } from "./SideDialogs";
11
11
  import { useNavigate } from "react-router";
12
- import { saveEntityToMemoryCache, useComponentOverride } from "@rebasepro/app";
12
+ import { useComponentOverride } from "@rebasepro/app";
13
13
  import { useCollectionRegistryController } from "../hooks/navigation/contexts/CollectionRegistryContext";
14
14
  import { useSidePanel } from "../hooks/useSidePanel";
15
15
  import { useUrlController } from "../hooks/navigation/contexts/UrlContext";
@@ -49,21 +49,60 @@ export function SidePanelBinding(props: SidePanelBindingProps) {
49
49
  const sideDialogsController = useSideDialogContext();
50
50
  const urlController = useUrlController();
51
51
 
52
+ /**
53
+ * The X in the identity bar.
54
+ *
55
+ * Unforced, so it stops at the same unsaved-changes prompt that Escape and
56
+ * a click outside already do. It used to clear `blocked` and force the
57
+ * close, which made the one control actually labelled "close" the only way
58
+ * out of the panel that dropped an edit without asking.
59
+ *
60
+ * `props.onClose` is not called here: the panel carries the same callback
61
+ * (see `propsToSidePanel`) and {@link SideDialogs} fires it once the panel
62
+ * really closes — which is after the prompt, not before it.
63
+ */
52
64
  const onClose = () => {
53
- if (props.onClose) {
54
- props.onClose();
55
- }
65
+ close();
66
+ }
56
67
 
68
+ /**
69
+ * Closing because the record was just saved, which is the one case that has
70
+ * to force. `blocked` is driven by an effect on the form's dirty flag and is
71
+ * still true for a tick after a save; prompting about unsaved changes here
72
+ * would be asking about values that are already on the server.
73
+ */
74
+ const closeAfterSave = () => {
57
75
  setBlocked(false);
58
76
  close(true);
59
77
  }
60
78
 
79
+ /**
80
+ * The panel's response to a save, and the one place it decides where the
81
+ * panel goes next.
82
+ *
83
+ * Exactly **one** panel navigation is raised here. These branches used to
84
+ * run independently — a `replace` onto the saved record's address *and* a
85
+ * close — and because the last navigation is the one that survives, which
86
+ * of them the user got was settled by statement order rather than by
87
+ * intent. Closing wins by construction now: moving a panel to a new address
88
+ * it is about to leave is work whose only effect is to fight the close.
89
+ *
90
+ * `props.onUpdate` runs last for the same reason. It belongs to whoever
91
+ * opened the panel and it is free to navigate — the reference picker's
92
+ * selects the record and closes the picker — so the opener's intent should
93
+ * be the final word, not something this panel overwrites on its way out.
94
+ */
61
95
  const onUpdate = (params: OnUpdateParams) => {
62
- if (props.onUpdate) {
63
- props.onUpdate(params);
64
- }
65
96
  setEditInDialog(false);
66
- if (params.status !== "existing") {
97
+
98
+ // Either "save and close" was clicked, or the opener asked for it when
99
+ // it opened the panel.
100
+ const closeRequested = sideDialogsController.pendingClose || props.closeOnSave;
101
+
102
+ if (closeRequested) {
103
+ sideDialogsController.setPendingClose(false);
104
+ closeAfterSave();
105
+ } else if (params.status !== "existing") {
67
106
  // A newly created entity replaces the panel with its own address,
68
107
  // which already leaves the edit view behind.
69
108
  sidePanelController.replace({
@@ -77,11 +116,7 @@ export function SidePanelBinding(props: SidePanelBindingProps) {
77
116
  closeEditView();
78
117
  }
79
118
 
80
- if (sideDialogsController.pendingClose) {
81
- sideDialogsController.setPendingClose(false);
82
- onClose();
83
- }
84
-
119
+ props.onUpdate?.(params);
85
120
  }
86
121
 
87
122
  const parentCollectionSlugs = useMemo(() => {
@@ -181,6 +216,43 @@ entityId }
181
216
  return <div className={"w-full"}/>;
182
217
  }
183
218
 
219
+ const closeButton = (
220
+ <IconButton
221
+ className="self-center"
222
+ size={"small"}
223
+ onClick={onClose}>
224
+ <XIcon/>
225
+ </IconButton>
226
+ );
227
+
228
+ /**
229
+ * Where the panel's own two controls sit, which is not the same question in
230
+ * the two layouts that have them.
231
+ *
232
+ * A **side panel** slides in over the list from the right, and its leading
233
+ * edge is the seam between the two. Close belongs on that seam — it points
234
+ * back at the thing still visible behind it — and it is where the eye
235
+ * already is, because the breadcrumb starts there.
236
+ *
237
+ * A **dialog** has no seam and nothing behind it to point at. It is a box
238
+ * centred on a dimmed screen, and every box like it on every platform is
239
+ * dismissed from its top-right corner. Close was sitting at the far left
240
+ * of the bar, a full dialog's width from the expand button it belongs
241
+ * beside, in the one corner that means "back" in a layout with no back.
242
+ *
243
+ * So in a dialog the two travel together at the trailing edge, expand then
244
+ * close: the window controls, after the record's actions and its overflow
245
+ * menu, in the corner a dialog is closed from.
246
+ */
247
+ const barActionsStart = isDialogMode ? undefined : closeButton;
248
+
249
+ const windowControls = (expandButton: React.ReactNode) => (
250
+ <div className="flex gap-1 items-center">
251
+ {expandButton}
252
+ {isDialogMode && closeButton}
253
+ </div>
254
+ );
255
+
184
256
  return (
185
257
  <>
186
258
  <ErrorBoundary>
@@ -193,31 +265,20 @@ entityId }
193
265
  parentCollectionSlugs={parentCollectionSlugs}
194
266
  parentEntityIds={parentEntityIds}
195
267
  onEditClick={openEditView}
196
- barActionsStart={
197
- // At the bar's leading edge, where the breadcrumb
198
- // starts: the corner of the panel it closes.
199
- <IconButton
268
+ barActionsStart={barActionsStart}
269
+ barActions={() => windowControls(
270
+ allowFullScreen && <IconButton
200
271
  className="self-center"
201
272
  size={"small"}
202
- onClick={onClose}>
203
- <XIcon/>
204
- </IconButton>}
205
- barActions={({
206
- status,
207
- values
208
- }) => <div className="flex gap-1">
209
- {allowFullScreen && <IconButton
210
- className="self-center"
211
- size={"small"}
212
- onClick={() => {
213
- if (entityId) {
214
- const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
215
- navigate(fullScreenUrl, { state: null });
216
- }
217
- }}>
218
- <Maximize2Icon/>
219
- </IconButton>}
220
- </div>}
273
+ onClick={() => {
274
+ if (entityId) {
275
+ const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
276
+ navigate(fullScreenUrl, { state: null });
277
+ }
278
+ }}>
279
+ <Maximize2Icon/>
280
+ </IconButton>
281
+ )}
221
282
  onTabChange={({
222
283
  entityId: tabEntityId,
223
284
  selectedTab,
@@ -245,38 +306,33 @@ entityId }
245
306
  onValuesModified={onValuesModified}
246
307
  onSaved={onUpdate}
247
308
  navigateBack={closeEditView}
248
- barActionsStart={
249
- // At the bar's leading edge, where the breadcrumb
250
- // starts: the corner of the panel it closes.
251
- <IconButton
309
+ barActionsStart={barActionsStart}
310
+ barActions={({ carryEdit }) => windowControls(
311
+ allowFullScreen && <IconButton
252
312
  className="self-center"
253
313
  size={"small"}
254
- onClick={onClose}>
255
- <XIcon/>
256
- </IconButton>}
257
- barActions={({
258
- status,
259
- values
260
- }) => <div className="flex gap-1">
261
- {allowFullScreen && <IconButton
262
- className="self-center"
263
- size={"small"}
264
- onClick={() => {
265
- const key = (status === "new" || status === "copy") ? path + "#new" : path + "/" + entityId;
266
- saveEntityToMemoryCache(key, values);
267
- setBlocked(false);
268
- setBlockedNavigationMessage(undefined);
269
- if (entityId) {
270
- const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
271
- navigate(fullScreenUrl, { state: null });
272
- } else {
273
- const fullScreenUrl = urlController.buildUrlCollectionPath(path);
274
- navigate(fullScreenUrl + "#new", { state: null });
275
- }
276
- }}>
277
- <Maximize2Icon/>
278
- </IconButton>}
279
- </div>}
314
+ onClick={() => {
315
+ // The form's own handoff, rather than a second
316
+ // copy of the rules for it here: only an edit in
317
+ // progress is worth carrying (a clean record
318
+ // stashed anyway arrived announcing unsaved
319
+ // changes to someone who had only looked at it),
320
+ // and only the fields that were edited (carrying
321
+ // the whole record marked every field touched).
322
+ carryEdit?.();
323
+ setBlocked(false);
324
+ setBlockedNavigationMessage(undefined);
325
+ if (entityId) {
326
+ const fullScreenUrl = urlController.buildUrlCollectionPath(`${path}/${entityId}`);
327
+ navigate(fullScreenUrl, { state: null });
328
+ } else {
329
+ const fullScreenUrl = urlController.buildUrlCollectionPath(path);
330
+ navigate(fullScreenUrl + "#new", { state: null });
331
+ }
332
+ }}>
333
+ <Maximize2Icon/>
334
+ </IconButton>
335
+ )}
280
336
  onTabChange={({
281
337
  entityId: tabEntityId,
282
338
  selectedTab,
@@ -14,7 +14,7 @@ import {
14
14
  PopoverPrimitive,
15
15
  SearchIcon,
16
16
  Separator,
17
- useInjectStyles,
17
+ usePortalContainer,
18
18
  XIcon
19
19
  } from "@rebasepro/ui";
20
20
  import * as React from "react";
@@ -23,6 +23,7 @@ import { Command as CommandPrimitive } from "cmdk";
23
23
  import { User } from "@rebasepro/types";
24
24
  import { apiBaseOf, useRebaseClient, useAuthController, UserDisplay } from "@rebasepro/app";
25
25
  import { EmptyValue } from "../preview";
26
+ import { useResolvedUser } from "../hooks/useResolvedUsers";
26
27
 
27
28
  interface UserSelectorItem {
28
29
  uid: string;
@@ -46,10 +47,19 @@ function useUserSelector({ pageSize = DEFAULT_PAGE_SIZE }: { pageSize?: number }
46
47
  const [currentSearch, setCurrentSearch] = useState("");
47
48
  const offsetRef = useRef(0);
48
49
  const userCacheRef = useRef<Map<string, User>>(new Map());
50
+ // Stamped by every request; only the newest one is allowed to write state.
51
+ // Typing "alice" issues one request per keystroke and nothing cancels them,
52
+ // so the response for "al" landing after the response for "alice" replaced
53
+ // the list — and `offsetRef` — with results for a string the user had
54
+ // already moved past. Same shape as `useRelationSelector`.
55
+ const requestIdRef = useRef(0);
56
+ const searchTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
49
57
 
50
58
  const fetchUsers = useCallback(async (searchStr: string, offset: number, append: boolean) => {
51
59
  const apiBase = apiBaseOf(client);
52
60
  if (!apiBase) return;
61
+ const requestId = ++requestIdRef.current;
62
+ const superseded = () => requestId !== requestIdRef.current;
53
63
  setIsLoading(true);
54
64
  try {
55
65
  const token = await getAuthToken?.();
@@ -68,6 +78,7 @@ function useUserSelector({ pageSize = DEFAULT_PAGE_SIZE }: { pageSize?: number }
68
78
  });
69
79
  if (!response.ok) throw new Error("Failed to fetch users");
70
80
  const data = await response.json();
81
+ if (superseded()) return;
71
82
  const rows: Record<string, unknown>[] = data.data ?? data.users ?? [];
72
83
  const newItems: UserSelectorItem[] = rows.map((r: Record<string, unknown>) => {
73
84
  const user: User = {
@@ -88,9 +99,10 @@ user };
88
99
  setHasMore(newItems.length >= pageSize);
89
100
  offsetRef.current = offset + newItems.length;
90
101
  } catch {
102
+ if (superseded()) return;
91
103
  setHasMore(false);
92
104
  } finally {
93
- setIsLoading(false);
105
+ if (!superseded()) setIsLoading(false);
94
106
  }
95
107
  }, [client?.baseUrl, client?.apiPath, getAuthToken, pageSize]);
96
108
 
@@ -100,11 +112,23 @@ user };
100
112
  }, [fetchUsers]);
101
113
 
102
114
  const search = useCallback((searchStr: string) => {
103
- setCurrentSearch(searchStr);
104
- offsetRef.current = 0;
105
- fetchUsers(searchStr, 0, false);
115
+ // Debounced like the relation picker's type-ahead: a request per
116
+ // keystroke is both wasteful and the thing that makes an out-of-order
117
+ // response likely in the first place.
118
+ if (searchTimeoutRef.current) clearTimeout(searchTimeoutRef.current);
119
+ searchTimeoutRef.current = setTimeout(() => {
120
+ setCurrentSearch(searchStr);
121
+ offsetRef.current = 0;
122
+ fetchUsers(searchStr, 0, false);
123
+ }, searchStr.trim() ? 300 : 0);
106
124
  }, [fetchUsers]);
107
125
 
126
+ useEffect(() => {
127
+ return () => {
128
+ if (searchTimeoutRef.current) clearTimeout(searchTimeoutRef.current);
129
+ };
130
+ }, []);
131
+
108
132
  const loadMore = useCallback(() => {
109
133
  fetchUsers(currentSearch, offsetRef.current, true);
110
134
  }, [fetchUsers, currentSearch]);
@@ -128,7 +152,14 @@ export interface UserSelectorProps {
128
152
  value?: string | null;
129
153
  onValueChange?: (userId: string | null) => void;
130
154
  placeholder?: React.ReactNode;
131
- size?: "small" | "medium";
155
+ /**
156
+ * `large` is the form's size and is on the shared 28/32/40/48 control
157
+ * scale, so a user picker lines up with the text field beside it.
158
+ *
159
+ * `small` and `medium` predate that scale (42 and 56) and are kept as they
160
+ * are because the table cells and the filter row are built around them.
161
+ */
162
+ size?: "small" | "medium" | "large";
132
163
  disabled?: boolean;
133
164
  invisible?: boolean;
134
165
  clearable?: boolean;
@@ -171,6 +202,7 @@ export const UserSelector = React.forwardRef<
171
202
 
172
203
  const [isPopoverOpen, setIsPopoverOpen] = useState(false);
173
204
  const [searchString, setSearchString] = useState<string>("");
205
+ const contextPortalContainer = usePortalContainer();
174
206
 
175
207
  const scrollContainerRef = useRef<HTMLDivElement>(null);
176
208
  const sentinelRef = useRef<HTMLDivElement>(null);
@@ -192,9 +224,19 @@ export const UserSelector = React.forwardRef<
192
224
  const selectedUser: User | null = value ? getUser(value) ?? null : null;
193
225
 
194
226
  // If the user isn't in the cache, try to find in available items
195
- const resolvedUser: User | null = selectedUser
227
+ const listedUser: User | null = selectedUser
196
228
  ?? (value ? availableItems.find(i => i.uid === value)?.user ?? null : null);
197
229
 
230
+ // Neither the loaded page nor the cache holds it: ask for that uid
231
+ // specifically. The list is one page of ten, so any installation with
232
+ // more users than that rendered an assigned field as *empty* — and an
233
+ // editor who is shown "no value" sets one, overwriting an assignment
234
+ // the UI never admitted was there. Lookups are coalesced and cached
235
+ // per API base by `useResolvedUser`, so a table of these costs one
236
+ // request.
237
+ const fetchedUser = useResolvedUser(value && !listedUser ? value : undefined);
238
+ const resolvedUser: User | null = listedUser ?? fetchedUser;
239
+
198
240
  // IntersectionObserver for infinite scroll
199
241
  const sentinelCallbackRef = useCallback((node: HTMLDivElement | null) => {
200
242
  if (observerRef.current) {
@@ -294,10 +336,10 @@ export const UserSelector = React.forwardRef<
294
336
  };
295
337
  }, [isPopoverOpen]);
296
338
 
297
- useInjectStyles("UserSelector", " [cmdk-group] { max-height: 40vh; overflow-y: auto; } ");
298
-
299
339
  const resolvedPlaceholder = placeholder || <EmptyValue className={"ml-2"}/>;
300
- const portalContainer = (typeof document !== "undefined" ? document.body : undefined);
340
+ // See RelationSelector: a modal dialog cancels wheel events outside its
341
+ // own content, so a list portaled to the body opens unscrollable.
342
+ const portalContainer = (contextPortalContainer ?? (typeof document !== "undefined" ? document.body : undefined)) ?? undefined;
301
343
 
302
344
  return (
303
345
  <>
@@ -317,9 +359,13 @@ export const UserSelector = React.forwardRef<
317
359
  className={cls(
318
360
  {
319
361
  "min-h-[42px] py-1 px-2": size === "small",
320
- "min-h-[56px] py-2 px-4": size === "medium"
362
+ "min-h-[56px] py-2 px-4": size === "medium",
363
+ "min-h-[48px] py-1 px-4": size === "large"
321
364
  },
322
- "w-full select-none rounded-md text-sm relative flex items-center",
365
+ // `rounded-lg` like every other field box —
366
+ // `rounded-md` made this the one control in a
367
+ // row with a different corner.
368
+ "w-full select-none rounded-lg text-sm relative flex items-center",
323
369
  invisible ? fieldBackgroundInvisibleMixin : fieldBackgroundMixin,
324
370
  disabled ? fieldBackgroundDisabledMixin : fieldBackgroundHoverMixin,
325
371
  className
@@ -330,6 +376,14 @@ export const UserSelector = React.forwardRef<
330
376
  <div className="flex flex-row items-center gap-1 truncate flex-1 min-w-0 mr-2">
331
377
  <UserDisplay user={resolvedUser}/>
332
378
  </div>
379
+ ) : value ? (
380
+ // A uid we could not resolve — deleted, or
381
+ // hidden from this viewer. Show it raw: the
382
+ // placeholder here would claim the field is
383
+ // unset, which is the one thing it is not.
384
+ <span className="text-sm truncate text-text-primary dark:text-text-primary-dark">
385
+ {value}
386
+ </span>
333
387
  ) : (
334
388
  <span className="text-sm text-text-secondary dark:text-text-secondary-dark">
335
389
  {resolvedPlaceholder}
@@ -345,7 +399,7 @@ export const UserSelector = React.forwardRef<
345
399
  </IconButton>
346
400
  )}
347
401
  <ChevronDownIcon
348
- size={size === "medium" ? iconSize.medium : iconSize.small}
402
+ size={size === "small" ? iconSize.small : iconSize.medium}
349
403
  className={cls("transition", isPopoverOpen ? "rotate-180" : "")}
350
404
  />
351
405
  </div>
@@ -4,17 +4,48 @@ import { ChevronLeftIcon, ErrorBoundary, MenuIcon } from "@rebasepro/ui";
4
4
  import { deepEqual as equal } from "fast-equals"
5
5
 
6
6
  import { useLargeLayout, useAdminModeController, useTranslation } from "@rebasepro/app";
7
+ import { useUrlController } from "../../hooks/navigation/contexts/UrlContext";
7
8
  import { AppContext } from "./useApp";
8
9
 
9
10
  export const DRAWER_WIDTH = 280;
10
11
 
12
+ /**
13
+ * Namespaced by base path: two admins served from one origin are two different
14
+ * navigations, and a single key would have them overwrite each other's drawer.
15
+ */
16
+ export function drawerOpenStorageKey(basePath: string | undefined) {
17
+ return `rebase-drawer-open:${basePath || "/"}`;
18
+ }
19
+
20
+ /** `null` when the user has never toggled the drawer, or storage is unavailable. */
21
+ function readStoredDrawerOpen(key: string): boolean | null {
22
+ if (typeof window === "undefined") return null;
23
+ try {
24
+ const stored = window.localStorage.getItem(key);
25
+ return stored === null ? null : stored === "true";
26
+ } catch (e) {
27
+ // Storage can be blocked: private mode, sandboxed iframe, cookie policy.
28
+ return null;
29
+ }
30
+ }
31
+
32
+ function writeStoredDrawerOpen(key: string, open: boolean) {
33
+ if (typeof window === "undefined") return;
34
+ try {
35
+ window.localStorage.setItem(key, String(open));
36
+ } catch (e) {
37
+ // Same as above: a drawer that forgets is better than a crash.
38
+ }
39
+ }
40
+
11
41
  /**
12
42
  * @group Core
13
43
  */
14
44
  export interface ScaffoldProps {
15
45
 
16
46
  /**
17
- * Open the drawer on hover
47
+ * Expand the collapsed drawer while the pointer is over it. On by default —
48
+ * pass `false` to keep the rail a rail until the user clicks the toggle.
18
49
  */
19
50
  autoOpenDrawer?: boolean;
20
51
 
@@ -22,8 +53,8 @@ export interface ScaffoldProps {
22
53
  * Start with the drawer expanded rather than collapsed to icons.
23
54
  *
24
55
  * Distinct from {@link autoOpenDrawer}, which is a hover behaviour: this one
25
- * only seeds the initial state, so the user's own toggle still wins for the
26
- * rest of the session.
56
+ * only seeds the very first visit. Once the user toggles the drawer, that
57
+ * choice is stored in `localStorage` and wins over this prop on every load.
27
58
  *
28
59
  * Ignored on small layouts, where an expanded drawer covers the content it is
29
60
  * meant to navigate.
@@ -62,7 +93,7 @@ export const Scaffold = React.memo<PropsWithChildren<ScaffoldProps>>(
62
93
 
63
94
  const {
64
95
  children,
65
- autoOpenDrawer,
96
+ autoOpenDrawer = true,
66
97
  defaultDrawerOpen = false,
67
98
  logo,
68
99
  className,
@@ -83,25 +114,96 @@ export const Scaffold = React.memo<PropsWithChildren<ScaffoldProps>>(
83
114
  const includeDrawer = drawerChildren.length > 0;
84
115
  const largeLayout = useLargeLayout();
85
116
 
117
+ const storageKey = drawerOpenStorageKey(useUrlController().basePath);
118
+
86
119
  // Seeded once, deliberately: a `useEffect` syncing this to the prop would
87
120
  // re-expand the drawer under a user who had just collapsed it.
88
- const [drawerOpen, setDrawerOpen] = React.useState(defaultDrawerOpen && largeLayout);
121
+ const [drawerOpen, setDrawerOpenState] = React.useState(defaultDrawerOpen && largeLayout);
89
122
  const [onHover, setOnHover] = React.useState(false);
90
123
 
91
- const setOnHoverTrue = useCallback(() => setOnHover(true), []);
124
+ // The stored choice is a client-only fact, so it is applied after the first
125
+ // render rather than seeded into it: reading storage while rendering would
126
+ // make the client disagree with server-rendered HTML. A layout effect runs
127
+ // before paint, so the drawer still arrives in its remembered state.
128
+ // `defaultDrawerOpen` seeds the very first visit and is ignored after that.
129
+ React.useLayoutEffect(() => {
130
+ const stored = readStoredDrawerOpen(storageKey);
131
+ if (stored === null) return;
132
+ setDrawerOpenState(stored && largeLayout);
133
+ // Deliberately not re-run on `largeLayout`: crossing the breakpoint is
134
+ // the effect below, and re-running here would undo a user's toggle.
135
+ // eslint-disable-next-line react-hooks/exhaustive-deps
136
+ }, [storageKey]);
137
+
138
+ // One piece of state drives two different things: the expanded rail on
139
+ // large layouts, and the modal sheet on small ones. Carrying an expanded
140
+ // rail across the breakpoint would drop that sheet, overlay and all, over
141
+ // the content — so the crossing resets it, and widening again restores
142
+ // whatever the user last chose.
143
+ const wasLargeLayout = React.useRef(largeLayout);
144
+ React.useEffect(() => {
145
+ if (wasLargeLayout.current === largeLayout) return;
146
+ wasLargeLayout.current = largeLayout;
147
+ setDrawerOpenState(largeLayout ? (readStoredDrawerOpen(storageKey) ?? defaultDrawerOpen) : false);
148
+ }, [largeLayout, defaultDrawerOpen, storageKey]);
149
+
150
+ const setDrawerOpen = useCallback((open: boolean) => {
151
+ setDrawerOpenState(open);
152
+ // Small layouts render the drawer as a modal sheet. Remembering that
153
+ // one would greet the next load with an overlay over the content.
154
+ if (!largeLayout) return;
155
+ writeStoredDrawerOpen(storageKey, open);
156
+ }, [largeLayout, storageKey]);
157
+
158
+ // The pointer has left, but a popover the drawer opened is still up, so the
159
+ // collapse is owed rather than cancelled. See `setOnHoverFalse`.
160
+ const collapseWhenPopoverCloses = React.useRef(false);
161
+
162
+ const setOnHoverTrue = useCallback(() => {
163
+ // Hover expansion is the default; `autoOpenDrawer={false}` opts out for
164
+ // admins that want the rail to stay a rail until the toggle is clicked.
165
+ if (!autoOpenDrawer) return;
166
+ collapseWhenPopoverCloses.current = false;
167
+ setOnHover(true);
168
+ }, [autoOpenDrawer]);
92
169
  const setOnHoverFalse = useCallback(() => {
93
- // Don't collapse the drawer while a popover/dropdown is open
94
- if (document.querySelector("[data-radix-popper-content-wrapper]")) return;
170
+ // Don't collapse the drawer out from under an open popover/dropdown —
171
+ // its content is portalled outside the drawer, so reaching for it reads
172
+ // as a mouseleave. The collapse is owed until that popover closes.
173
+ if (document.querySelector("[data-radix-popper-content-wrapper]")) {
174
+ collapseWhenPopoverCloses.current = true;
175
+ return;
176
+ }
177
+ collapseWhenPopoverCloses.current = false;
95
178
  setOnHover(false);
96
179
  }, []);
97
180
 
181
+ // Nothing fires a second mouseleave when the popover finally closes, so the
182
+ // owed collapse has to be noticed rather than waited for. Only mounted
183
+ // while the drawer is actually floating open.
184
+ React.useEffect(() => {
185
+ if (!onHover) return;
186
+ const collapseIfOwed = () => {
187
+ if (!collapseWhenPopoverCloses.current) return;
188
+ if (document.querySelector("[data-radix-popper-content-wrapper]")) return;
189
+ collapseWhenPopoverCloses.current = false;
190
+ setOnHover(false);
191
+ };
192
+ const observer = new MutationObserver(collapseIfOwed);
193
+ observer.observe(document.body, {
194
+ childList: true,
195
+ subtree: true
196
+ });
197
+ return () => observer.disconnect();
198
+ }, [onHover]);
199
+
98
200
  const handleDrawerOpen = useCallback(() => {
99
201
  setDrawerOpen(true);
100
- }, []);
202
+ }, [setDrawerOpen]);
101
203
 
102
204
  const handleDrawerClose = useCallback(() => {
103
205
  setDrawerOpen(false);
104
- }, []);
206
+ }, [setDrawerOpen]);
105
207
 
106
208
  const computedDrawerOpen: boolean = drawerOpen;
107
209
  const computedDrawerHovered = Boolean(largeLayout && onHover);
@@ -3,22 +3,17 @@ import React, { useEffect, useState, useCallback } from "react";
3
3
  ;
4
4
  import { useApiBase, useApiConfig } from "@rebasepro/app";
5
5
  import { useAuthController } from "@rebasepro/app";
6
+ import { formatRelativeTime } from "@rebasepro/utils";
6
7
  import { HistoryEntryData } from "../../hooks";
7
8
  import type { AdminCollection } from "@rebasepro/admin-types";
8
9
 
9
- function getRelativeTimeString(date: Date): string {
10
- const now = new Date();
11
- const diffMs = now.getTime() - date.getTime();
12
- const diffSeconds = Math.floor(diffMs / 1000);
13
- const diffMinutes = Math.floor(diffSeconds / 60);
14
- const diffHours = Math.floor(diffMinutes / 60);
15
- const diffDays = Math.floor(diffHours / 24);
10
+ const THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1000;
16
11
 
17
- if (diffSeconds < 60) return "just now";
18
- if (diffMinutes < 60) return `${diffMinutes}m ago`;
19
- if (diffHours < 24) return `${diffHours}h ago`;
20
- if (diffDays < 30) return `${diffDays}d ago`;
21
- return date.toLocaleDateString();
12
+ function getRelativeTimeString(date: Date): string {
13
+ // An edit is in the past, but the timestamp comes from the server and the
14
+ // phrase is rendered against the browser's clock — a few seconds of skew
15
+ // used to be enough to make a fresh edit read as the wrong thing entirely.
16
+ return formatRelativeTime(date, { maxMs: THIRTY_DAYS_MS }) ?? date.toLocaleDateString();
22
17
  }
23
18
 
24
19
  /**