@rebasepro/admin 0.13.0 → 0.13.1-canary.g18cfeb7
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.
- package/dist/{CollectionEditorDialog-CjXkWZ64.js → CollectionEditorDialog-CUFXevVg.js} +3 -3
- package/dist/{CollectionEditorDialog-CjXkWZ64.js.map → CollectionEditorDialog-CUFXevVg.js.map} +1 -1
- package/dist/{PropertyEditView-W8I3YV89.js → PropertyEditView-DDUC7giL.js} +2 -2
- package/dist/{PropertyEditView-W8I3YV89.js.map → PropertyEditView-DDUC7giL.js.map} +1 -1
- package/dist/{RouterCollectionsStudioView-BsLTNoqX.js → RouterCollectionsStudioView-vzS848Gf.js} +9 -13
- package/dist/RouterCollectionsStudioView-vzS848Gf.js.map +1 -0
- package/dist/collection_editor/serializable_types.d.ts +1 -0
- package/dist/collection_editor_ui.js +4 -4
- package/dist/components/AdditionalFieldValue.d.ts +25 -0
- package/dist/components/CollectionViewBinding/CollectionViewBinding.d.ts +16 -0
- package/dist/components/CollectionViewBinding/SlotValue.d.ts +63 -0
- package/dist/components/CollectionViewBinding/SplitListCloseButton.d.ts +17 -4
- package/dist/components/CollectionViewBinding/SplitListShowButton.d.ts +12 -0
- package/dist/components/CollectionViewBinding/usePreviewSlots.d.ts +55 -5
- package/dist/components/DetailViewBinding.d.ts +15 -0
- package/dist/components/DrawerNavigationGroup.d.ts +9 -6
- package/dist/components/DrawerNavigationItem.d.ts +16 -6
- package/dist/components/EditViewBinding.d.ts +30 -1
- package/dist/components/EntityDisplayHeader.d.ts +53 -0
- package/dist/components/EntityIdentityBar.d.ts +43 -1
- package/dist/components/EntityViewBinding.d.ts +60 -6
- package/dist/components/RebaseLayout.d.ts +1 -1
- package/dist/components/RebaseShell.d.ts +1 -1
- package/dist/components/RelationSelector.d.ts +8 -1
- package/dist/components/UserSelector.d.ts +8 -1
- package/dist/components/app/Scaffold.d.ts +9 -3
- package/dist/components/index.d.ts +2 -0
- package/dist/{export-J79rMoNj.js → export-5bl2EoSs.js} +2 -2
- package/dist/{export-J79rMoNj.js.map → export-5bl2EoSs.js.map} +1 -1
- package/dist/form/components/FieldBlock.d.ts +58 -4
- package/dist/form/components/FormRail.d.ts +13 -0
- package/dist/form/components/FormSections.d.ts +15 -1
- package/dist/form/components/useRailVisible.d.ts +5 -4
- package/dist/form/form_utils.d.ts +38 -1
- package/dist/{history-D7L_JlLO.js → history-BuKKAhoY.js} +4 -4
- package/dist/{history-D7L_JlLO.js.map → history-BuKKAhoY.js.map} +1 -1
- package/dist/hooks/useEntityDisplay.d.ts +102 -0
- package/dist/hooks/useEntityDisplayTitle.d.ts +18 -9
- package/dist/{import-BvYl--U4.js → import-BhdWs34H.js} +3 -3
- package/dist/{import-BvYl--U4.js.map → import-BhdWs34H.js.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +152 -57
- package/dist/index.js.map +1 -1
- package/dist/preview/compact_text.d.ts +23 -0
- package/dist/preview/components/BooleanPreview.d.ts +3 -1
- package/dist/preview/property_previews/ArrayOfStringsPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayOneOfPreview.d.ts +1 -1
- package/dist/preview/property_previews/ArrayPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/MapPropertyPreview.d.ts +1 -1
- package/dist/preview/property_previews/StringPropertyPreview.d.ts +1 -1
- package/dist/routes/RebaseRoute.d.ts +1 -1
- package/dist/types/components/PropertyPreviewProps.d.ts +19 -0
- package/dist/util/number_format.d.ts +14 -0
- package/dist/util/previews.d.ts +9 -2
- package/dist/{util-GiwPgxnL.js → util-DNG7iK0w.js} +3756 -2300
- package/dist/util-DNG7iK0w.js.map +1 -0
- package/package.json +9 -9
- package/src/collection_editor/serializable_types.ts +1 -0
- package/src/collection_editor/ui/collection_editor/CollectionsStudioView.tsx +9 -11
- package/src/components/AdditionalFieldValue.tsx +68 -0
- package/src/components/CollectionTableBinding/CollectionTableBinding.tsx +7 -8
- package/src/components/CollectionTableBinding/PropertyTableCell.tsx +2 -2
- package/src/components/CollectionTableBinding/column_utils.tsx +15 -6
- package/src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx +2 -2
- package/src/components/CollectionViewBinding/BoardCardBinding.tsx +26 -27
- package/src/components/CollectionViewBinding/CollectionListViewBinding.tsx +723 -348
- package/src/components/CollectionViewBinding/CollectionViewActions.tsx +1 -1
- package/src/components/CollectionViewBinding/CollectionViewBinding.tsx +38 -8
- package/src/components/CollectionViewBinding/EntityCardBinding.tsx +23 -36
- package/src/components/CollectionViewBinding/SlotValue.tsx +156 -0
- package/src/components/CollectionViewBinding/SplitListCloseButton.tsx +23 -7
- package/src/components/CollectionViewBinding/SplitListShowButton.tsx +28 -0
- package/src/components/CollectionViewBinding/SplitListView.tsx +33 -2
- package/src/components/CollectionViewBinding/useBoardDataController.tsx +12 -3
- package/src/components/CollectionViewBinding/usePreviewSlots.ts +183 -64
- package/src/components/CollectionViewBinding/utils.ts +7 -4
- package/src/components/DefaultDrawer.tsx +19 -23
- package/src/components/DetailViewBinding.tsx +93 -56
- package/src/components/DrawerNavigationGroup.tsx +16 -39
- package/src/components/DrawerNavigationItem.tsx +44 -16
- package/src/components/EditViewBinding.tsx +215 -42
- package/src/components/EntityDisplayHeader.tsx +170 -0
- package/src/components/EntityIdentityBar.tsx +163 -23
- package/src/components/EntityInspector.tsx +24 -6
- package/src/components/EntityPreviewBinding.tsx +58 -18
- package/src/components/EntityViewBinding.tsx +342 -41
- package/src/components/InlineEntityPreview.tsx +10 -10
- package/src/components/RebaseLayout.tsx +2 -2
- package/src/components/RebaseShell.tsx +2 -2
- package/src/components/ReferenceTable/SelectionTableBinding.tsx +4 -2
- package/src/components/RelationSelector.tsx +15 -4
- package/src/components/SideDialogs.tsx +15 -3
- package/src/components/SidePanelBinding.tsx +122 -66
- package/src/components/UserSelector.tsx +15 -4
- package/src/components/app/Scaffold.tsx +112 -10
- package/src/components/history/LastEditedByIndicator.tsx +7 -12
- package/src/components/index.ts +3 -0
- package/src/data_import/utils/data.ts +9 -1
- package/src/form/EntityForm.tsx +64 -52
- package/src/form/EntityFormBinding.tsx +24 -11
- package/src/form/PropertyFieldBinding.tsx +2 -2
- package/src/form/components/FieldBlock.tsx +80 -10
- package/src/form/components/FormRail.tsx +19 -2
- package/src/form/components/FormSections.tsx +32 -5
- package/src/form/components/StorageUploadProgress.tsx +9 -3
- package/src/form/components/useRailVisible.tsx +5 -4
- package/src/form/field_bindings/ArrayCustomShapedFieldBinding.tsx +2 -2
- package/src/form/field_bindings/BinaryFieldBinding.tsx +10 -5
- package/src/form/field_bindings/BlockFieldBinding.tsx +3 -3
- package/src/form/field_bindings/GeopointFieldBinding.tsx +23 -16
- package/src/form/field_bindings/MapFieldBinding.tsx +2 -2
- package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +13 -7
- package/src/form/field_bindings/MultiSelectFieldBinding.tsx +7 -1
- package/src/form/field_bindings/ReadOnlyFieldBinding.tsx +7 -1
- package/src/form/field_bindings/ReferenceFieldBinding.tsx +1 -1
- package/src/form/field_bindings/RelationFieldBinding.tsx +5 -2
- package/src/form/field_bindings/RepeatFieldBinding.tsx +3 -3
- package/src/form/field_bindings/StorageUploadFieldBinding.tsx +2 -2
- package/src/form/field_bindings/UserSelectFieldBinding.tsx +4 -1
- package/src/form/field_bindings/VectorFieldBinding.tsx +6 -4
- package/src/form/form_utils.ts +78 -0
- package/src/hooks/navigation/useBuildCollectionRegistryController.tsx +29 -5
- package/src/hooks/useEntityDisplay.tsx +262 -0
- package/src/hooks/useEntityDisplayTitle.tsx +27 -38
- package/src/index.ts +9 -1
- package/src/preview/PropertyPreview.tsx +25 -5
- package/src/preview/compact_text.ts +68 -0
- package/src/preview/components/BooleanPreview.tsx +5 -2
- package/src/preview/components/StorageThumbnail.tsx +5 -2
- package/src/preview/property_previews/ArrayOfRelationsPreview.tsx +6 -3
- package/src/preview/property_previews/ArrayOfStringsPreview.tsx +26 -1
- package/src/preview/property_previews/ArrayOneOfPreview.tsx +10 -1
- package/src/preview/property_previews/ArrayPropertyPreview.tsx +10 -1
- package/src/preview/property_previews/MapPropertyPreview.tsx +52 -1
- package/src/preview/property_previews/NumberPropertyPreview.tsx +9 -1
- package/src/preview/property_previews/StringPropertyPreview.tsx +8 -5
- package/src/routes/RebaseRoute.tsx +62 -4
- package/src/types/components/PropertyPreviewProps.tsx +21 -0
- package/src/util/number_format.ts +46 -0
- package/src/util/previews.ts +8 -55
- package/src/util/property_utils.tsx +6 -1
- package/dist/RouterCollectionsStudioView-BsLTNoqX.js.map +0 -1
- package/dist/util-GiwPgxnL.js.map +0 -1
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
|
|
2
|
-
import type { Property } from "@rebasepro/types";
|
|
2
|
+
import type { Properties, Property } from "@rebasepro/types";
|
|
3
3
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { Entity } from "@rebasepro/types";
|
|
5
5
|
import { CollectionSize, EntityAction, EntityTableController, SelectionController, AdminCollection } from "@rebasepro/admin-types";
|
|
6
6
|
import {
|
|
7
|
+
ArrowDownIcon,
|
|
8
|
+
ArrowUpIcon,
|
|
7
9
|
Checkbox,
|
|
8
10
|
Chip,
|
|
9
|
-
CircularProgress,
|
|
10
11
|
cls,
|
|
11
12
|
defaultBorderMixin,
|
|
12
13
|
IconButton,
|
|
@@ -20,13 +21,16 @@ import {
|
|
|
20
21
|
useCustomizationController
|
|
21
22
|
} from "@rebasepro/app";
|
|
22
23
|
import { useAnalyticsController } from "@rebasepro/app";
|
|
23
|
-
import { getEntityPreviewKeys } from "../../util/previews";
|
|
24
24
|
import { IconForView } from "@rebasepro/app";
|
|
25
25
|
import { getIcon } from "@rebasepro/app";
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
26
|
+
import { hasDeclaredDisplay } from "@rebasepro/app";
|
|
27
|
+
import { formatRelativeTime, getValueInPath } from "@rebasepro/utils";
|
|
28
|
+
import { useCollectionSlotKeys, useEntitySlots, type CollectionSlotKeys, type EntityPreviewSlots } from "./usePreviewSlots";
|
|
29
|
+
import { SlotValue, TagChips } from "./SlotValue";
|
|
28
30
|
import { useAdminContext } from "../../hooks/useAdminContext";
|
|
29
31
|
import { resolveEntityAction } from "../../util/resolutions";
|
|
32
|
+
import { getSortablePropertyOptions } from "../CollectionTableBinding/column_utils";
|
|
33
|
+
import { getResolvedPropertyInPath } from "../../util/property_utils";
|
|
30
34
|
|
|
31
35
|
export type CollectionListViewBindingProps<M extends Record<string, unknown> = Record<string, unknown>> = {
|
|
32
36
|
collection: AdminCollection<M>;
|
|
@@ -69,17 +73,79 @@ export type CollectionListViewBindingProps<M extends Record<string, unknown> = R
|
|
|
69
73
|
openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
|
|
70
74
|
};
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Which display slot fills a column, when a slot does rather than a property.
|
|
78
|
+
* A status is an enum chip and a date a relative timestamp wherever they come
|
|
79
|
+
* from, so the cell renders the slot; the column exists either way, because a
|
|
80
|
+
* header needs something to sit over.
|
|
81
|
+
*/
|
|
82
|
+
type ListColumnSlot = "tags" | "status" | "date";
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* One column of the list, in the header and in every row.
|
|
86
|
+
*
|
|
87
|
+
* The header and the cells read the same definition — the same width, the same
|
|
88
|
+
* alignment, the same decision about being shown at this container width — so a
|
|
89
|
+
* label cannot end up over a column that is not there, or over the wrong one.
|
|
90
|
+
*/
|
|
91
|
+
type ListColumn = {
|
|
73
92
|
key: string;
|
|
74
93
|
label: string;
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
isDate?: boolean;
|
|
94
|
+
/** Set when a display slot fills the cell; absent when the record does. */
|
|
95
|
+
slot?: ListColumnSlot;
|
|
96
|
+
property?: Property;
|
|
79
97
|
align: "left" | "center" | "right";
|
|
80
98
|
width: string;
|
|
99
|
+
/**
|
|
100
|
+
* What {@link width} costs in pixels, so the fit calculation can budget in
|
|
101
|
+
* the same units the row lays out in. A flat per-column estimate treated a
|
|
102
|
+
* relation (w-64) as costing the same as a date (w-28), which is where a row
|
|
103
|
+
* ran out of width for the title while still claiming everything fit.
|
|
104
|
+
*/
|
|
105
|
+
widthPx: number;
|
|
106
|
+
/** Whether clicking this header can order the collection by it. */
|
|
107
|
+
sortable: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* What survives when the row runs out of width: the lowest goes first.
|
|
110
|
+
*/
|
|
111
|
+
priority: number;
|
|
81
112
|
};
|
|
82
113
|
|
|
114
|
+
// ── Column priorities ─────────────────────────────────────────────────
|
|
115
|
+
// Read as "what a narrowing row gives up first".
|
|
116
|
+
//
|
|
117
|
+
// Three bands. The sort or filter *in force* comes first: it is the reason the
|
|
118
|
+
// rows are in the order they are in, and hiding the column it names leaves that
|
|
119
|
+
// order unexplained. The collection's own columns come next — its `listProperties`,
|
|
120
|
+
// or the status and date it was read as having. A column left over from a
|
|
121
|
+
// request since cleared comes last: it is worth keeping while there is room for
|
|
122
|
+
// it, and it is not worth the collection's own status.
|
|
123
|
+
|
|
124
|
+
/** A column left over from a sort or filter that is no longer applied. */
|
|
125
|
+
const PRIORITY_STALE_REQUEST = 1000;
|
|
126
|
+
/** The collection's own columns. Slots sit just above it, in give-way order. */
|
|
127
|
+
const PRIORITY_DECLARED = 2000;
|
|
128
|
+
const PRIORITY_DATE = PRIORITY_DECLARED;
|
|
129
|
+
const PRIORITY_STATUS = PRIORITY_DECLARED + 1;
|
|
130
|
+
const PRIORITY_TAGS = PRIORITY_DECLARED + 2;
|
|
131
|
+
/** The sort or filter currently in force. */
|
|
132
|
+
const PRIORITY_ACTIVE_REQUEST = 3000;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* How wide a column of this property wants to be — the Tailwind class the cell
|
|
136
|
+
* gets, and the pixel cost of that class. The two are returned together because
|
|
137
|
+
* they must not drift: the budget is only meaningful if it describes the widths
|
|
138
|
+
* actually rendered. `lg:` variants key off the viewport, not this panel, so a
|
|
139
|
+
* narrow split on a wide screen gets the larger of the two — the cost we budget.
|
|
140
|
+
*/
|
|
141
|
+
function getIdealColumnWidth(prop: Property): { width: string, widthPx: number } {
|
|
142
|
+
if (prop.type === "string" && "enum" in prop) return { width: "flex-shrink-0 w-32", widthPx: 128 };
|
|
143
|
+
if (prop.type === "date" || prop.type === "number" || prop.type === "boolean") return { width: "flex-shrink-0 w-28", widthPx: 112 };
|
|
144
|
+
if (prop.type === "reference" || prop.type === "relation") return { width: "flex-shrink-0 w-56 lg:w-64", widthPx: 256 };
|
|
145
|
+
if (prop.type === "string") return { width: "flex-shrink-0 w-40 lg:w-48", widthPx: 192 };
|
|
146
|
+
return { width: "flex-shrink-0 w-40", widthPx: 160 };
|
|
147
|
+
}
|
|
148
|
+
|
|
83
149
|
/**
|
|
84
150
|
* Get row padding/spacing classes based on size
|
|
85
151
|
*/
|
|
@@ -94,47 +160,47 @@ function getRowClasses(size: CollectionSize): string {
|
|
|
94
160
|
}
|
|
95
161
|
}
|
|
96
162
|
|
|
163
|
+
// ── Row layout budget ─────────────────────────────────────────────────
|
|
164
|
+
// What the row spends before a single column is placed. These mirror the
|
|
165
|
+
// classes on the row itself (`px-5`, `gap-4`, `w-8` checkbox, `w-10` image);
|
|
166
|
+
// they are the same layout described twice, so a change to one is a change to
|
|
167
|
+
// the other.
|
|
168
|
+
|
|
169
|
+
/** `px-5` on both sides. */
|
|
170
|
+
const ROW_PADDING_WIDTH = 40;
|
|
171
|
+
/** The checkbox cell (`w-8`). */
|
|
172
|
+
const CHECKBOX_WIDTH = 32;
|
|
173
|
+
/** The thumbnail / icon square (`w-10`). */
|
|
174
|
+
const IMAGE_WIDTH = 40;
|
|
175
|
+
/** `gap-4` between every cell of the row. */
|
|
176
|
+
const COLUMN_GAP = 16;
|
|
177
|
+
|
|
97
178
|
/**
|
|
98
|
-
*
|
|
179
|
+
* The title's share of a row, taken before any column bids for width.
|
|
180
|
+
*
|
|
181
|
+
* A title is a name, and a name truncated to "Lider Sr. en…" has stopped being
|
|
182
|
+
* one. Columns are a scanner's convenience; the title is the row's identity, so
|
|
183
|
+
* a narrow list spends its width on the title and simply shows fewer columns.
|
|
99
184
|
*/
|
|
100
|
-
|
|
101
|
-
switch (size) {
|
|
102
|
-
case "xs": return 44;
|
|
103
|
-
case "s": return 52;
|
|
104
|
-
case "m": return 64;
|
|
105
|
-
case "l": return 76;
|
|
106
|
-
case "xl": return 88;
|
|
107
|
-
default: return 64;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/** Number of extra rows rendered above/below the viewport. */
|
|
112
|
-
const OVERSCAN_COUNT = 8;
|
|
185
|
+
const TITLE_COMFORTABLE_WIDTH = 320;
|
|
113
186
|
|
|
114
|
-
/**
|
|
115
|
-
const
|
|
187
|
+
/** An `IconButton size="small"` (`w-8`), which is what a row action renders as. */
|
|
188
|
+
const ACTION_BUTTON_WIDTH = 32;
|
|
189
|
+
/** `gap-0.5` between row actions. */
|
|
190
|
+
const ACTION_BUTTON_GAP = 2;
|
|
191
|
+
/**
|
|
192
|
+
* How many rows are read to size the actions cell.
|
|
193
|
+
*
|
|
194
|
+
* Actions are resolved per record, so the width they need is only knowable by
|
|
195
|
+
* asking — and asking every loaded row would mean re-resolving thousands of
|
|
196
|
+
* them on every page. The first rows are representative: a collection whose
|
|
197
|
+
* actions vary at all varies within its first screenful.
|
|
198
|
+
*/
|
|
199
|
+
const ACTIONS_SAMPLE_SIZE = 20;
|
|
116
200
|
|
|
117
201
|
/** Stable empty array for when no list-view actions are available. */
|
|
118
202
|
const EMPTY_LIST_VIEW_ACTIONS: EntityAction[] = [];
|
|
119
203
|
|
|
120
|
-
/**
|
|
121
|
-
* Walk up the DOM from `element` to find the nearest scrollable ancestor.
|
|
122
|
-
*/
|
|
123
|
-
function getScrollParent(element: HTMLElement | null): HTMLElement | null {
|
|
124
|
-
let parent = element?.parentElement ?? null;
|
|
125
|
-
while (parent) {
|
|
126
|
-
const style = getComputedStyle(parent);
|
|
127
|
-
if (
|
|
128
|
-
style.overflowY === "auto" || style.overflowY === "scroll" ||
|
|
129
|
-
style.overflow === "auto" || style.overflow === "scroll"
|
|
130
|
-
) {
|
|
131
|
-
return parent;
|
|
132
|
-
}
|
|
133
|
-
parent = parent.parentElement;
|
|
134
|
-
}
|
|
135
|
-
return document.documentElement;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
204
|
/**
|
|
139
205
|
* Returns true if a property type should NOT be rendered via
|
|
140
206
|
* PropertyPreview in list row columns (because it would blow up height).
|
|
@@ -235,9 +301,15 @@ function compactValueSummary(value: unknown, property: Property): string | null
|
|
|
235
301
|
}
|
|
236
302
|
|
|
237
303
|
/**
|
|
238
|
-
* Format a date value for display in the list
|
|
304
|
+
* Format a date value for display in the list.
|
|
305
|
+
*
|
|
306
|
+
* A date column holds whatever the developer put in it, so the value is as
|
|
307
|
+
* likely to be ahead of now as behind it. The relative phrase therefore comes
|
|
308
|
+
* from {@link formatRelativeTime}, which reads the sign: a row due this
|
|
309
|
+
* afternoon says "in 2h" rather than the "-1d ago" that flooring a negative
|
|
310
|
+
* difference used to produce.
|
|
239
311
|
*/
|
|
240
|
-
function formatDateValue(value: unknown): string | null {
|
|
312
|
+
function formatDateValue(value: unknown, now: Date = new Date()): string | null {
|
|
241
313
|
if (!value) return null;
|
|
242
314
|
let date: Date | null = null;
|
|
243
315
|
if (value instanceof Date) {
|
|
@@ -247,22 +319,25 @@ function formatDateValue(value: unknown): string | null {
|
|
|
247
319
|
}
|
|
248
320
|
if (!date || isNaN(date.getTime())) return null;
|
|
249
321
|
|
|
250
|
-
const now = new Date();
|
|
251
322
|
const diffMs = now.getTime() - date.getTime();
|
|
252
323
|
const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
|
|
253
324
|
|
|
325
|
+
// Today and yesterday get their own wording; both are strictly in the past,
|
|
326
|
+
// because a negative difference floors to -1 and falls through to below.
|
|
254
327
|
if (diffDays === 0) {
|
|
255
328
|
return date.toLocaleTimeString(undefined, { hour: "2-digit",
|
|
256
329
|
minute: "2-digit" });
|
|
257
|
-
} else if (diffDays === 1) {
|
|
258
|
-
return "Yesterday";
|
|
259
|
-
} else if (diffDays < 7) {
|
|
260
|
-
return `${diffDays}d ago`;
|
|
261
|
-
} else {
|
|
262
|
-
return date.toLocaleDateString(undefined, { month: "short",
|
|
263
|
-
day: "numeric",
|
|
264
|
-
year: diffDays > 365 ? "numeric" : undefined });
|
|
265
330
|
}
|
|
331
|
+
if (diffDays === 1) return "Yesterday";
|
|
332
|
+
|
|
333
|
+
const relative = formatRelativeTime(date, { now });
|
|
334
|
+
if (relative) return relative;
|
|
335
|
+
|
|
336
|
+
// Comparing years rather than counting days: a date six weeks back across a
|
|
337
|
+
// new year needs the year, and one 400 days ahead needs it just as much.
|
|
338
|
+
return date.toLocaleDateString(undefined, { month: "short",
|
|
339
|
+
day: "numeric",
|
|
340
|
+
year: date.getFullYear() !== now.getFullYear() ? "numeric" : undefined });
|
|
266
341
|
}
|
|
267
342
|
|
|
268
343
|
/**
|
|
@@ -293,14 +368,21 @@ export function CollectionListViewBinding<M extends Record<string, unknown> = Re
|
|
|
293
368
|
const context = useAdminContext();
|
|
294
369
|
|
|
295
370
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
296
|
-
|
|
371
|
+
// `undefined` is "not measured yet", and it renders the title alone. The
|
|
372
|
+
// seed used to be a 1200px guess, which is a claim about a list that may be
|
|
373
|
+
// a 300px column of a split — and, because the ref below was never attached
|
|
374
|
+
// to anything, a guess nothing ever corrected.
|
|
375
|
+
const [containerWidth, setContainerWidth] = useState<number | undefined>(undefined);
|
|
297
376
|
|
|
298
377
|
// Track container width for responsive column visibility
|
|
299
378
|
useEffect(() => {
|
|
300
379
|
const el = containerRef.current;
|
|
301
380
|
if (!el) return;
|
|
381
|
+
const measure = (width: number) => setContainerWidth(width > 0 ? width : undefined);
|
|
382
|
+
measure(el.getBoundingClientRect().width);
|
|
383
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
302
384
|
const ro = new ResizeObserver(([entry]) => {
|
|
303
|
-
if (entry)
|
|
385
|
+
if (entry) measure(entry.contentRect.width);
|
|
304
386
|
});
|
|
305
387
|
ro.observe(el);
|
|
306
388
|
return () => ro.disconnect();
|
|
@@ -314,16 +396,13 @@ export function CollectionListViewBinding<M extends Record<string, unknown> = Re
|
|
|
314
396
|
itemCount,
|
|
315
397
|
setItemCount,
|
|
316
398
|
pageSize = 50,
|
|
317
|
-
paginationEnabled
|
|
399
|
+
paginationEnabled,
|
|
400
|
+
sortBy,
|
|
401
|
+
setSortBy,
|
|
402
|
+
filterValues,
|
|
403
|
+
checkFilterCombination
|
|
318
404
|
} = tableController;
|
|
319
405
|
|
|
320
|
-
const isLoadingMore = useRef(false);
|
|
321
|
-
|
|
322
|
-
// Reset the loading-more gate when new data arrives
|
|
323
|
-
useEffect(() => {
|
|
324
|
-
if (!dataLoading) isLoadingMore.current = false;
|
|
325
|
-
}, [dataLoading]);
|
|
326
|
-
|
|
327
406
|
const resolvedCollection = collection;
|
|
328
407
|
|
|
329
408
|
// ── Shared slot resolution (replaces 4 individual useMemo calls) ──
|
|
@@ -334,158 +413,278 @@ export function CollectionListViewBinding<M extends Record<string, unknown> = Re
|
|
|
334
413
|
);
|
|
335
414
|
const { titleKey: titlePropertyKey, imageKey: imagePropertyKey, subtitleKey, statusKey: statusPropertyKey, dateKey: datePropertyKey } = slotKeys;
|
|
336
415
|
|
|
337
|
-
const
|
|
338
|
-
() => getEntityPreviewKeys(authController, resolvedCollection, customizationController.propertyConfigs, undefined, 10)
|
|
339
|
-
.filter(key => key !== titlePropertyKey && key !== imagePropertyKey && key !== statusPropertyKey && key !== datePropertyKey),
|
|
340
|
-
[authController, resolvedCollection, customizationController.propertyConfigs, titlePropertyKey, imagePropertyKey, statusPropertyKey, datePropertyKey]
|
|
341
|
-
);
|
|
416
|
+
const columnMode = !!resolvedCollection.listProperties && resolvedCollection.listProperties.length > 0;
|
|
342
417
|
|
|
343
|
-
|
|
344
|
-
|
|
418
|
+
/**
|
|
419
|
+
* The properties an `ORDER BY` can be written for, under the same authority
|
|
420
|
+
* the table headers and the sort menu ask — so a header that offers a sort
|
|
421
|
+
* here offers it there, and none of the three invents one the driver would
|
|
422
|
+
* silently drop.
|
|
423
|
+
*/
|
|
424
|
+
const sortableKeys = useMemo(
|
|
425
|
+
() => new Set(getSortablePropertyOptions(resolvedCollection.properties as Properties).map(option => option.key)),
|
|
426
|
+
[resolvedCollection.properties]
|
|
427
|
+
);
|
|
345
428
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
429
|
+
/** The row's identity cell: the leading column, or the title slot. */
|
|
430
|
+
const titleColumn = useMemo<ListColumn | undefined>(() => {
|
|
431
|
+
const key = columnMode ? resolvedCollection.listProperties?.[0] : titlePropertyKey;
|
|
432
|
+
if (!key) return undefined;
|
|
433
|
+
const property = resolvedCollection.properties[key] as Property | undefined;
|
|
434
|
+
return {
|
|
435
|
+
key,
|
|
436
|
+
label: property?.name || (columnMode ? key : "Name"),
|
|
437
|
+
property,
|
|
438
|
+
align: "left",
|
|
439
|
+
width: "flex-1 min-w-0",
|
|
440
|
+
widthPx: TITLE_COMFORTABLE_WIDTH,
|
|
441
|
+
sortable: sortableKeys.has(key),
|
|
442
|
+
priority: Number.MAX_SAFE_INTEGER
|
|
352
443
|
};
|
|
444
|
+
}, [columnMode, resolvedCollection, titlePropertyKey, sortableKeys]);
|
|
353
445
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
446
|
+
/**
|
|
447
|
+
* The trailing columns the collection itself implies: the developer's
|
|
448
|
+
* `listProperties` when there are any, otherwise the display slots the row
|
|
449
|
+
* has always shown to the right of the title.
|
|
450
|
+
*/
|
|
451
|
+
const declaredColumns = useMemo<ListColumn[]>(() => {
|
|
452
|
+
if (columnMode) {
|
|
453
|
+
const keys = resolvedCollection.listProperties!.slice(1);
|
|
454
|
+
return keys.flatMap((key, index) => {
|
|
455
|
+
const property = resolvedCollection.properties[key] as Property | undefined;
|
|
456
|
+
if (!property) return [];
|
|
457
|
+
return [{
|
|
360
458
|
key,
|
|
361
|
-
label:
|
|
362
|
-
property
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
459
|
+
label: property.name || key,
|
|
460
|
+
property,
|
|
461
|
+
align: (property.type === "number" || property.type === "date" ? "right" : "left") as ListColumn["align"],
|
|
462
|
+
...getIdealColumnWidth(property),
|
|
463
|
+
sortable: sortableKeys.has(key),
|
|
464
|
+
// Declared order is a statement of importance: the first
|
|
465
|
+
// column after the title outlives the last one.
|
|
466
|
+
priority: PRIORITY_DECLARED + (keys.length - index)
|
|
467
|
+
}];
|
|
367
468
|
});
|
|
368
|
-
return cols;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Smart default
|
|
372
|
-
if (titlePropertyKey) {
|
|
373
|
-
const prop = resolvedCollection.properties[titlePropertyKey] as Property;
|
|
374
|
-
if (prop) {
|
|
375
|
-
cols.push({
|
|
376
|
-
key: titlePropertyKey,
|
|
377
|
-
label: prop.name || "Name",
|
|
378
|
-
property: prop,
|
|
379
|
-
isTitle: true,
|
|
380
|
-
align: "left",
|
|
381
|
-
width: "flex-1 min-w-[200px]"
|
|
382
|
-
});
|
|
383
|
-
}
|
|
384
469
|
}
|
|
385
470
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
//
|
|
391
|
-
|
|
471
|
+
const cols: ListColumn[] = [];
|
|
472
|
+
|
|
473
|
+
// A slot column exists when the collection has something to put in it —
|
|
474
|
+
// a property to read, or a resolver that computes one. Whether a given
|
|
475
|
+
// record fills it is a per-row question, and the wrong one to ask here:
|
|
476
|
+
// a column that came and went with the values under it would leave its
|
|
477
|
+
// header over a different cell on every row.
|
|
478
|
+
const slotColumn = (
|
|
479
|
+
slot: ListColumnSlot,
|
|
480
|
+
key: string | undefined,
|
|
481
|
+
fallbackLabel: string,
|
|
482
|
+
layout: { align: ListColumn["align"], width: string, widthPx: number },
|
|
483
|
+
priority: number
|
|
484
|
+
): ListColumn | undefined => {
|
|
485
|
+
const declared = hasDeclaredDisplay(resolvedCollection, slot);
|
|
486
|
+
if (!key && !declared) return undefined;
|
|
487
|
+
const property = key ? resolvedCollection.properties[key] as Property | undefined : undefined;
|
|
488
|
+
return {
|
|
489
|
+
key: key ?? `display:${slot}`,
|
|
490
|
+
label: property?.name || fallbackLabel,
|
|
491
|
+
slot,
|
|
492
|
+
property,
|
|
493
|
+
...layout,
|
|
494
|
+
// A computed slot has no column to order by, whatever it renders.
|
|
495
|
+
sortable: !!key && sortableKeys.has(key),
|
|
496
|
+
priority
|
|
497
|
+
};
|
|
498
|
+
};
|
|
392
499
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
500
|
+
const tags = slotColumn(
|
|
501
|
+
"tags",
|
|
502
|
+
slotKeys.tagsKey,
|
|
503
|
+
"Tags",
|
|
504
|
+
{ align: "left", width: "flex-shrink-0 w-40", widthPx: 160 },
|
|
505
|
+
PRIORITY_TAGS
|
|
506
|
+
);
|
|
507
|
+
if (tags) cols.push(tags);
|
|
508
|
+
|
|
509
|
+
const status = slotColumn(
|
|
510
|
+
"status",
|
|
398
511
|
statusPropertyKey,
|
|
512
|
+
"Status",
|
|
513
|
+
{ align: "left", width: "flex-shrink-0 w-32", widthPx: 128 },
|
|
514
|
+
PRIORITY_STATUS
|
|
515
|
+
);
|
|
516
|
+
if (status) cols.push(status);
|
|
517
|
+
|
|
518
|
+
const date = slotColumn(
|
|
519
|
+
"date",
|
|
399
520
|
datePropertyKey,
|
|
400
|
-
|
|
401
|
-
"
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
if (usedKeys.has(k)) return false;
|
|
406
|
-
const prop = resolvedCollection.properties[k] as Property | undefined;
|
|
407
|
-
if (!prop) return false;
|
|
408
|
-
// Exclude storage/image properties — they are already rendered in the image slot
|
|
409
|
-
if (prop.type === "string" && (prop.storage || prop.admin?.urlPreview === "image")) return false;
|
|
410
|
-
if (prop.type === "array" && prop.of && !Array.isArray(prop.of)) {
|
|
411
|
-
const inner = prop.of;
|
|
412
|
-
if (inner.type === "string" && (inner.storage || inner.admin?.urlPreview === "image")) return false;
|
|
413
|
-
}
|
|
414
|
-
return true;
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
availableExtraKeys.forEach(key => {
|
|
418
|
-
const prop = resolvedCollection.properties[key] as Property;
|
|
419
|
-
cols.push({
|
|
420
|
-
key,
|
|
421
|
-
label: prop.name || key,
|
|
422
|
-
property: prop,
|
|
423
|
-
align: prop.type === "number" || prop.type === "date" ? "right" : "left",
|
|
424
|
-
width: getIdealColumnWidth(prop)
|
|
425
|
-
});
|
|
426
|
-
});
|
|
521
|
+
"Modified",
|
|
522
|
+
{ align: "right", width: "flex-shrink-0 w-20", widthPx: 80 },
|
|
523
|
+
PRIORITY_DATE
|
|
524
|
+
);
|
|
525
|
+
if (date) cols.push(date);
|
|
427
526
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
527
|
+
return cols;
|
|
528
|
+
}, [columnMode, resolvedCollection, slotKeys.tagsKey, statusPropertyKey, datePropertyKey, sortableKeys]);
|
|
529
|
+
|
|
530
|
+
/** What the row already shows without a column of its own. */
|
|
531
|
+
const shownKeys = useMemo(() => new Set<string | undefined>([
|
|
532
|
+
titleColumn?.key,
|
|
533
|
+
imagePropertyKey,
|
|
534
|
+
subtitleKey,
|
|
535
|
+
...declaredColumns.map(col => col.key),
|
|
536
|
+
// The relation chips under the title are as visible as any column.
|
|
537
|
+
...(columnMode ? [] : slotKeys.relationKeys)
|
|
538
|
+
]), [titleColumn, imagePropertyKey, subtitleKey, declaredColumns, columnMode, slotKeys.relationKeys]);
|
|
539
|
+
|
|
540
|
+
/** The property the sort names, when no cell already shows it. */
|
|
541
|
+
const sortedKey = useMemo(() => {
|
|
542
|
+
const key = sortBy?.[0];
|
|
543
|
+
return key && !shownKeys.has(key) ? key : undefined;
|
|
544
|
+
}, [sortBy, shownKeys]);
|
|
545
|
+
|
|
546
|
+
/** The properties the filters name, minus the ones a cell already shows. */
|
|
547
|
+
const filteredKeys = useMemo(
|
|
548
|
+
() => Object.keys(filterValues ?? {}).filter(key => !shownKeys.has(key)),
|
|
549
|
+
[filterValues, shownKeys]
|
|
550
|
+
);
|
|
441
551
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
552
|
+
/**
|
|
553
|
+
* The last property the sort named, and the last set the filters named.
|
|
554
|
+
*
|
|
555
|
+
* A column earns its place when a sort or a filter names it, and keeps it
|
|
556
|
+
* once that sort or filter is cleared: taking it back would move every
|
|
557
|
+
* column right of it at the moment the user is comparing values across rows,
|
|
558
|
+
* and clearing a sort says nothing about wanting to stop seeing the property
|
|
559
|
+
* it sorted on.
|
|
560
|
+
*
|
|
561
|
+
* What it does *not* do is accumulate. There is only ever one sort, so
|
|
562
|
+
* ordering by four properties in turn is changing one's mind four times, not
|
|
563
|
+
* asking for four columns — and asking for four is how the row lost its
|
|
564
|
+
* status and its date to a wall of numbers. A new sort therefore replaces
|
|
565
|
+
* the property the last one left behind, and a new set of filters replaces
|
|
566
|
+
* the set before it. At most one sort column and one set of filter columns
|
|
567
|
+
* outlive their request.
|
|
568
|
+
*
|
|
569
|
+
* The list remounts per collection (it is keyed by path), so this is the
|
|
570
|
+
* memory of one visit to one collection, not a preference.
|
|
571
|
+
*/
|
|
572
|
+
const [lastSortedKey, setLastSortedKey] = useState<string | undefined>(undefined);
|
|
573
|
+
const [lastFilteredKeys, setLastFilteredKeys] = useState<string[]>([]);
|
|
455
574
|
|
|
456
|
-
|
|
457
|
-
|
|
575
|
+
useEffect(() => {
|
|
576
|
+
if (sortedKey) setLastSortedKey(sortedKey);
|
|
577
|
+
}, [sortedKey]);
|
|
458
578
|
|
|
459
|
-
|
|
579
|
+
useEffect(() => {
|
|
580
|
+
if (filteredKeys.length === 0) return;
|
|
581
|
+
// Same members, same array: `filteredKeys` is rebuilt every render, and
|
|
582
|
+
// storing an equal copy would re-render every consumer of the columns.
|
|
583
|
+
setLastFilteredKeys(previous =>
|
|
584
|
+
previous.length === filteredKeys.length && previous.every((key, i) => key === filteredKeys[i])
|
|
585
|
+
? previous
|
|
586
|
+
: filteredKeys);
|
|
587
|
+
}, [filteredKeys]);
|
|
460
588
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
589
|
+
/**
|
|
590
|
+
* Columns for what the user asked to sort or filter by and cannot see.
|
|
591
|
+
*
|
|
592
|
+
* Ordering a list by a property no cell shows produces a shuffle with no
|
|
593
|
+
* explanation in it — the rows move and nothing on screen says why. So the
|
|
594
|
+
* property joins the row as its own column, last: the filters' first, in
|
|
595
|
+
* their own order, then the sort's.
|
|
596
|
+
*/
|
|
597
|
+
const requestedColumns = useMemo<ListColumn[]>(() => {
|
|
598
|
+
// The live request where there is one, the remembered one otherwise —
|
|
599
|
+
// read in that order rather than from state alone, because the effects
|
|
600
|
+
// above have not run yet on the render that first sees a request, and
|
|
601
|
+
// waiting a frame would flash the row without its new column.
|
|
602
|
+
const active = new Set([...filteredKeys, ...(sortedKey ? [sortedKey] : [])]);
|
|
603
|
+
const keys: string[] = [];
|
|
604
|
+
const request = (key: string | undefined) => {
|
|
605
|
+
if (!key || keys.includes(key) || shownKeys.has(key)) return;
|
|
606
|
+
keys.push(key);
|
|
607
|
+
};
|
|
608
|
+
(filteredKeys.length > 0 ? filteredKeys : lastFilteredKeys).forEach(request);
|
|
609
|
+
request(sortedKey ?? lastSortedKey);
|
|
467
610
|
|
|
468
|
-
|
|
469
|
-
|
|
611
|
+
return keys.flatMap((key, index) => {
|
|
612
|
+
const property = getResolvedPropertyInPath(resolvedCollection.properties, key) as Property | undefined;
|
|
613
|
+
if (!property) return [];
|
|
614
|
+
return [{
|
|
615
|
+
key,
|
|
616
|
+
label: property.name || key,
|
|
617
|
+
property,
|
|
618
|
+
align: (property.type === "number" || property.type === "date" ? "right" : "left") as ListColumn["align"],
|
|
619
|
+
...getIdealColumnWidth(property),
|
|
620
|
+
sortable: sortableKeys.has(key),
|
|
621
|
+
priority: (active.has(key) ? PRIORITY_ACTIVE_REQUEST : PRIORITY_STALE_REQUEST) - index
|
|
622
|
+
}];
|
|
623
|
+
});
|
|
624
|
+
}, [filteredKeys, sortedKey, lastFilteredKeys, lastSortedKey, shownKeys, resolvedCollection, sortableKeys]);
|
|
470
625
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
626
|
+
// ── Compute list-view-visible actions per entity ──
|
|
627
|
+
const getListViewActions = useCallback((entity: Entity<M>): EntityAction[] => {
|
|
628
|
+
if (!getActionsForEntity) return EMPTY_LIST_VIEW_ACTIONS;
|
|
629
|
+
const customEntityActions = (collection.entityActions ?? [])
|
|
630
|
+
.map(action => resolveEntityAction(action, customizationController.entityActions))
|
|
631
|
+
.filter(Boolean) as EntityAction<M>[];
|
|
632
|
+
const allActions = getActionsForEntity({ entity,
|
|
633
|
+
customEntityActions });
|
|
634
|
+
return allActions.filter(a => a.showActionsInListView);
|
|
635
|
+
}, [getActionsForEntity, collection.entityActions, customizationController.entityActions]);
|
|
474
636
|
|
|
475
|
-
|
|
476
|
-
const FIRST_COL_THRESHOLD = 500;
|
|
477
|
-
const EXTRA_COL_WIDTH = 160;
|
|
637
|
+
const showImage = size !== "xs";
|
|
478
638
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
639
|
+
/**
|
|
640
|
+
* How much room the action buttons take, reserved identically in the header
|
|
641
|
+
* and in every row so the columns line up above one another whether or not a
|
|
642
|
+
* given record has actions.
|
|
643
|
+
*/
|
|
644
|
+
const actionsWidth = useMemo(() => {
|
|
645
|
+
if (!getActionsForEntity) return 0;
|
|
646
|
+
let most = 0;
|
|
647
|
+
for (const entity of data.slice(0, ACTIONS_SAMPLE_SIZE)) {
|
|
648
|
+
most = Math.max(most, getListViewActions(entity).length);
|
|
482
649
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
650
|
+
return most === 0 ? 0 : most * ACTION_BUTTON_WIDTH + (most - 1) * ACTION_BUTTON_GAP;
|
|
651
|
+
}, [data, getActionsForEntity, getListViewActions]);
|
|
652
|
+
|
|
653
|
+
// Responsive: keep only the columns the row can actually pay for.
|
|
654
|
+
//
|
|
655
|
+
// The title is what a row is *for* — it is the one cell that identifies the
|
|
656
|
+
// record — so it is not one competitor among the columns: it takes its
|
|
657
|
+
// comfortable share off the top, and the columns divide what is left. What
|
|
658
|
+
// gives way when there is not enough is decided by `priority` rather than by
|
|
659
|
+
// position, so the column the user just sorted by outlives the inferred
|
|
660
|
+
// ones; the survivors keep their declared order, because a row that
|
|
661
|
+
// reordered itself as it resized would be unreadable.
|
|
662
|
+
const visibleColumns = useMemo(() => {
|
|
663
|
+
const columns = [...declaredColumns, ...requestedColumns];
|
|
664
|
+
if (columns.length === 0) return columns;
|
|
665
|
+
|
|
666
|
+
// Unmeasured: the title alone, which is the answer we would rather flash
|
|
667
|
+
// than a row of columns squeezing it down to an ellipsis.
|
|
668
|
+
if (containerWidth === undefined) return [];
|
|
669
|
+
|
|
670
|
+
const chrome = ROW_PADDING_WIDTH
|
|
671
|
+
+ (selectionEnabled ? CHECKBOX_WIDTH + COLUMN_GAP : 0)
|
|
672
|
+
+ (showImage ? IMAGE_WIDTH + COLUMN_GAP : 0)
|
|
673
|
+
+ (actionsWidth > 0 ? actionsWidth + COLUMN_GAP : 0);
|
|
674
|
+
const available = containerWidth - chrome - TITLE_COMFORTABLE_WIDTH;
|
|
675
|
+
|
|
676
|
+
const cost = (col: ListColumn) => col.widthPx + COLUMN_GAP;
|
|
677
|
+
let total = columns.reduce((acc, col) => acc + cost(col), 0);
|
|
678
|
+
if (total <= available) return columns;
|
|
679
|
+
|
|
680
|
+
const dropped = new Set<string>();
|
|
681
|
+
for (const col of [...columns].sort((a, b) => a.priority - b.priority)) {
|
|
682
|
+
if (total <= available) break;
|
|
683
|
+
dropped.add(col.key);
|
|
684
|
+
total -= cost(col);
|
|
685
|
+
}
|
|
686
|
+
return columns.filter(col => !dropped.has(col.key));
|
|
687
|
+
}, [declaredColumns, requestedColumns, containerWidth, selectionEnabled, showImage, actionsWidth]);
|
|
489
688
|
|
|
490
689
|
const handleEntityClick = useCallback((entity: Entity<M>) => {
|
|
491
690
|
analyticsController.onAnalyticsEvent?.("entity_click", {
|
|
@@ -507,16 +706,6 @@ export function CollectionListViewBinding<M extends Record<string, unknown> = Re
|
|
|
507
706
|
return highlightedEntities?.some(e => e.id === entity.id && e.path === entity.path) ?? false;
|
|
508
707
|
}, [highlightedEntities]);
|
|
509
708
|
|
|
510
|
-
// ── Compute list-view-visible actions per entity ──
|
|
511
|
-
const getListViewActions = useCallback((entity: Entity<M>): EntityAction[] => {
|
|
512
|
-
if (!getActionsForEntity) return EMPTY_LIST_VIEW_ACTIONS;
|
|
513
|
-
const customEntityActions = (collection.entityActions ?? [])
|
|
514
|
-
.map(action => resolveEntityAction(action, customizationController.entityActions))
|
|
515
|
-
.filter(Boolean) as EntityAction<M>[];
|
|
516
|
-
const allActions = getActionsForEntity({ entity,
|
|
517
|
-
customEntityActions });
|
|
518
|
-
return allActions.filter(a => a.showActionsInListView);
|
|
519
|
-
}, [getActionsForEntity, collection.entityActions, customizationController.entityActions]);
|
|
520
709
|
|
|
521
710
|
const rowClasses = getRowClasses(size);
|
|
522
711
|
|
|
@@ -527,56 +716,109 @@ customEntityActions });
|
|
|
527
716
|
handleSelectionChange(entity, selected);
|
|
528
717
|
}, [handleSelectionChange]);
|
|
529
718
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
719
|
+
/**
|
|
720
|
+
* Order by a column, on the same cycle a table header runs: unordered →
|
|
721
|
+
* ascending → descending → unordered. Clicking a header here and clicking it
|
|
722
|
+
* in the table view have to mean the same thing, because they are the same
|
|
723
|
+
* collection under the same controller.
|
|
724
|
+
*/
|
|
725
|
+
const onColumnSort = useCallback((key: string) => {
|
|
726
|
+
if (!setSortBy) return;
|
|
727
|
+
const active = sortBy?.[0] === key ? sortBy[1] : undefined;
|
|
728
|
+
const next: [string, "asc" | "desc"] | undefined = active === "asc"
|
|
729
|
+
? [key, "desc"]
|
|
730
|
+
: active === "desc"
|
|
731
|
+
? undefined
|
|
732
|
+
: [key, "asc"];
|
|
733
|
+
setSortBy(next);
|
|
734
|
+
// Re-ordering a partially loaded collection invalidates the pages
|
|
735
|
+
// already fetched — they are no longer the rows the query answers with —
|
|
736
|
+
// so pagination starts over, as it does for the table and the sort menu.
|
|
737
|
+
setItemCount?.(pageSize);
|
|
738
|
+
}, [setSortBy, sortBy, setItemCount, pageSize]);
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Whether a sort can be offered at all next to the filter already applied.
|
|
742
|
+
* A driver may refuse the combination; the table clears the filter to make
|
|
743
|
+
* room, which is a heavier answer than a header click asks for, so the
|
|
744
|
+
* header simply stops offering it — the same choice the sort menu makes.
|
|
745
|
+
*/
|
|
746
|
+
const sortIsAvailable = useCallback((key: string) => {
|
|
747
|
+
if (!setSortBy) return false;
|
|
748
|
+
if (!checkFilterCombination) return true;
|
|
749
|
+
const active = sortBy?.[0] === key ? sortBy[1] : undefined;
|
|
750
|
+
// Clearing the sort is always available: it asks nothing of the driver.
|
|
751
|
+
if (active === "desc") return true;
|
|
752
|
+
return checkFilterCombination(filterValues ?? {}, [key, active === "asc" ? "desc" : "asc"]);
|
|
753
|
+
}, [setSortBy, checkFilterCombination, filterValues, sortBy]);
|
|
754
|
+
|
|
755
|
+
const header = (titleColumn || visibleColumns.length > 0) && (
|
|
756
|
+
<ListHeader
|
|
757
|
+
titleColumn={titleColumn}
|
|
758
|
+
columns={visibleColumns}
|
|
543
759
|
selectionEnabled={selectionEnabled}
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
<div
|
|
550
|
-
key={entity.id}
|
|
551
|
-
style={style}
|
|
552
|
-
className={className}
|
|
553
|
-
>
|
|
554
|
-
<ListRow
|
|
555
|
-
entity={entity}
|
|
556
|
-
collection={resolvedCollection}
|
|
557
|
-
onClick={handleEntityClick}
|
|
558
|
-
selected={selected}
|
|
559
|
-
highlighted={highlighted}
|
|
560
|
-
onSelectionChange={handleRowSelectionChange}
|
|
561
|
-
selectionEnabled={selectionEnabled}
|
|
562
|
-
columns={visibleColumns}
|
|
563
|
-
slotKeys={slotKeys}
|
|
564
|
-
rowClasses={rowClasses}
|
|
565
|
-
showImage={showImage}
|
|
566
|
-
size={size}
|
|
567
|
-
isLast={isLast}
|
|
568
|
-
isActive={selectedEntityId !== undefined && entity.id === selectedEntityId}
|
|
569
|
-
listViewActions={getListViewActions(entity)}
|
|
570
|
-
context={context}
|
|
571
|
-
path={path}
|
|
572
|
-
selectionController={selectionController}
|
|
573
|
-
openEntityMode={openEntityMode}
|
|
574
|
-
/>
|
|
575
|
-
</div>
|
|
576
|
-
);
|
|
577
|
-
}, [resolvedCollection, selectionEnabled, visibleColumns, slotKeys, rowClasses, showImage, size, selectedEntityId, getListViewActions, context, path, selectionController, openEntityMode, handleRowSelectionChange, handleEntityClick])}
|
|
760
|
+
showImage={showImage}
|
|
761
|
+
actionsWidth={actionsWidth}
|
|
762
|
+
sortBy={sortBy as [string, "asc" | "desc"] | undefined}
|
|
763
|
+
onColumnSort={onColumnSort}
|
|
764
|
+
sortIsAvailable={sortIsAvailable}
|
|
578
765
|
/>
|
|
579
766
|
);
|
|
767
|
+
|
|
768
|
+
return (
|
|
769
|
+
<div ref={containerRef} className="w-full">
|
|
770
|
+
<ListView<Entity<M>>
|
|
771
|
+
data={data}
|
|
772
|
+
dataLoading={dataLoading}
|
|
773
|
+
noMoreToLoad={noMoreToLoad}
|
|
774
|
+
dataLoadingError={dataLoadingError}
|
|
775
|
+
itemCount={itemCount}
|
|
776
|
+
setItemCount={setItemCount}
|
|
777
|
+
pageSize={pageSize}
|
|
778
|
+
paginationEnabled={paginationEnabled}
|
|
779
|
+
onItemClick={handleEntityClick}
|
|
780
|
+
selectedIds={selectedIds}
|
|
781
|
+
highlightedIds={highlightedIds}
|
|
782
|
+
selectionEnabled={selectionEnabled}
|
|
783
|
+
emptyComponent={emptyComponent}
|
|
784
|
+
size={size}
|
|
785
|
+
selectedEntityId={selectedEntityId}
|
|
786
|
+
header={header}
|
|
787
|
+
renderRow={useCallback(({ item: entity, style, className, selected, highlighted, isLast, onClick, onSelectionChange }) => {
|
|
788
|
+
return (
|
|
789
|
+
<div
|
|
790
|
+
key={entity.id}
|
|
791
|
+
style={style}
|
|
792
|
+
className={className}
|
|
793
|
+
>
|
|
794
|
+
<ListRow
|
|
795
|
+
entity={entity}
|
|
796
|
+
collection={resolvedCollection}
|
|
797
|
+
onClick={handleEntityClick}
|
|
798
|
+
selected={selected}
|
|
799
|
+
highlighted={highlighted}
|
|
800
|
+
onSelectionChange={handleRowSelectionChange}
|
|
801
|
+
selectionEnabled={selectionEnabled}
|
|
802
|
+
columns={visibleColumns}
|
|
803
|
+
slotKeys={slotKeys}
|
|
804
|
+
rowClasses={rowClasses}
|
|
805
|
+
showImage={showImage}
|
|
806
|
+
size={size}
|
|
807
|
+
isLast={isLast}
|
|
808
|
+
isActive={selectedEntityId !== undefined && entity.id === selectedEntityId}
|
|
809
|
+
listViewActions={getListViewActions(entity)}
|
|
810
|
+
actionsWidth={actionsWidth}
|
|
811
|
+
context={context}
|
|
812
|
+
path={path}
|
|
813
|
+
selectionController={selectionController}
|
|
814
|
+
openEntityMode={openEntityMode}
|
|
815
|
+
/>
|
|
816
|
+
</div>
|
|
817
|
+
);
|
|
818
|
+
}, [resolvedCollection, selectionEnabled, visibleColumns, slotKeys, rowClasses, showImage, size, selectedEntityId, getListViewActions, actionsWidth, context, path, selectionController, openEntityMode, handleRowSelectionChange, handleEntityClick])}
|
|
819
|
+
/>
|
|
820
|
+
</div>
|
|
821
|
+
);
|
|
580
822
|
}
|
|
581
823
|
|
|
582
824
|
/**
|
|
@@ -603,6 +845,7 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
603
845
|
isLast,
|
|
604
846
|
isActive = false,
|
|
605
847
|
listViewActions = [],
|
|
848
|
+
actionsWidth = 0,
|
|
606
849
|
context,
|
|
607
850
|
path,
|
|
608
851
|
selectionController,
|
|
@@ -615,7 +858,7 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
615
858
|
highlighted?: boolean;
|
|
616
859
|
onSelectionChange?: (entity: Entity<M>, selected: boolean) => void;
|
|
617
860
|
selectionEnabled?: boolean;
|
|
618
|
-
columns:
|
|
861
|
+
columns: ListColumn[];
|
|
619
862
|
slotKeys: CollectionSlotKeys;
|
|
620
863
|
rowClasses: string;
|
|
621
864
|
showImage: boolean;
|
|
@@ -623,13 +866,18 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
623
866
|
isLast: boolean;
|
|
624
867
|
isActive?: boolean;
|
|
625
868
|
listViewActions?: EntityAction[];
|
|
869
|
+
/** Reserved width of the actions cell, shared with the header. */
|
|
870
|
+
actionsWidth?: number;
|
|
626
871
|
context?: ReturnType<typeof useAdminContext>;
|
|
627
872
|
path?: string;
|
|
628
873
|
selectionController?: SelectionController<M>;
|
|
629
874
|
openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
|
|
630
875
|
}) {
|
|
631
|
-
// ── Resolve slots
|
|
632
|
-
|
|
876
|
+
// ── Resolve slots ──
|
|
877
|
+
// A hook now, not a pure call: a `display` resolver may have to fetch what
|
|
878
|
+
// fills a slot, so the row subscribes to the result and re-renders when it
|
|
879
|
+
// lands. `ListRow` is memoized, which is what keeps that to the one row.
|
|
880
|
+
const slots = useEntitySlots(
|
|
633
881
|
entity as Entity<Record<string, unknown>>,
|
|
634
882
|
collection as AdminCollection<Record<string, unknown>>,
|
|
635
883
|
slotKeys
|
|
@@ -655,7 +903,6 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
655
903
|
|
|
656
904
|
// Developer-defined column mode (listProperties is explicitly set)
|
|
657
905
|
const useColumnMode = !!collection.listProperties && collection.listProperties.length > 0;
|
|
658
|
-
const extraColumns = useColumnMode ? columns.filter(c => !c.isTitle) : [];
|
|
659
906
|
|
|
660
907
|
return (
|
|
661
908
|
<div
|
|
@@ -696,7 +943,7 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
696
943
|
<div className="flex-shrink-0">
|
|
697
944
|
{slots.image ? (
|
|
698
945
|
<div className={cls("w-10 h-10 rounded-lg border relative overflow-hidden bg-surface-100 dark:bg-surface-900", defaultBorderMixin)}>
|
|
699
|
-
<
|
|
946
|
+
<SlotValue slot={slots.image} size="small" fill={true}/>
|
|
700
947
|
</div>
|
|
701
948
|
) : (
|
|
702
949
|
<div className={cls("w-10 h-10 rounded-lg bg-surface-100 dark:bg-surface-900 flex items-center justify-center border", defaultBorderMixin)}>
|
|
@@ -711,17 +958,11 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
711
958
|
)}
|
|
712
959
|
|
|
713
960
|
{/* PRIMARY slot → Title + subtitle + byline */}
|
|
714
|
-
<div className=
|
|
961
|
+
<div className="flex-1 min-w-0 overflow-hidden">
|
|
715
962
|
<div className="truncate">
|
|
716
963
|
{slots.title?.value !== undefined ? (
|
|
717
964
|
<Typography component="div" variant="body2" className="font-semibold text-surface-900 dark:text-surface-50 truncate transition-colors group-hover:text-primary-600 dark:group-hover:text-primary-400">
|
|
718
|
-
<
|
|
719
|
-
propertyKey={slots.title.propertyKey}
|
|
720
|
-
value={slots.title.value}
|
|
721
|
-
property={slots.title.property}
|
|
722
|
-
size="small"
|
|
723
|
-
textOnly={true}
|
|
724
|
-
/>
|
|
965
|
+
<SlotValue slot={slots.title} size="small"/>
|
|
725
966
|
</Typography>
|
|
726
967
|
) : (
|
|
727
968
|
<Typography component="div" variant="body2" className="font-semibold text-surface-500 dark:text-surface-400 font-mono text-xs transition-colors group-hover:text-primary-600 dark:group-hover:text-primary-400">
|
|
@@ -734,13 +975,7 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
734
975
|
{slots.subtitle && (
|
|
735
976
|
<div className="truncate mt-0.5">
|
|
736
977
|
<Typography variant="caption" component="div" className="text-surface-500 dark:text-surface-400 truncate">
|
|
737
|
-
<
|
|
738
|
-
propertyKey={slots.subtitle.propertyKey}
|
|
739
|
-
value={slots.subtitle.value}
|
|
740
|
-
property={slots.subtitle.property}
|
|
741
|
-
size="small"
|
|
742
|
-
textOnly={true}
|
|
743
|
-
/>
|
|
978
|
+
<SlotValue slot={slots.subtitle} size="small"/>
|
|
744
979
|
</Typography>
|
|
745
980
|
</div>
|
|
746
981
|
)}
|
|
@@ -769,85 +1004,34 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
769
1004
|
)}
|
|
770
1005
|
</div>
|
|
771
1006
|
|
|
772
|
-
{
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
const value = getValueInPath(entity.values, col.key);
|
|
777
|
-
|
|
778
|
-
if (col.isStatus || (col.property.type === "string" && "enum" in col.property)) {
|
|
779
|
-
return (
|
|
780
|
-
<div key={col.key} className={cls(col.width, "flex", col.align === "center" ? "justify-center" : col.align === "right" ? "justify-end" : "justify-start")}>
|
|
781
|
-
{value ? (
|
|
782
|
-
<PropertyPreview propertyKey={col.key} value={value} property={col.property} size="small"/>
|
|
783
|
-
) : <span className="text-surface-400">—</span>}
|
|
784
|
-
</div>
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
if (col.isDate || col.property.type === "date") {
|
|
789
|
-
return (
|
|
790
|
-
<div key={col.key} className={cls(col.width, col.align === "center" ? "text-center" : col.align === "right" ? "text-right" : "text-left")}>
|
|
791
|
-
<Typography variant="caption" className="whitespace-nowrap text-surface-400 dark:text-surface-500 font-medium">
|
|
792
|
-
{formatDateValue(value) ?? "—"}
|
|
793
|
-
</Typography>
|
|
794
|
-
</div>
|
|
795
|
-
);
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
// Complex types → compact single-line summary
|
|
799
|
-
if (isComplexPropertyType(col.property)) {
|
|
800
|
-
const summary = compactValueSummary(value, col.property);
|
|
801
|
-
return (
|
|
802
|
-
<div key={col.key} className={cls(col.width, "truncate", col.align === "center" ? "text-center" : col.align === "right" ? "text-right" : "text-left")}>
|
|
803
|
-
<Typography variant="caption" className="text-surface-500 dark:text-surface-400 truncate">
|
|
804
|
-
{summary ?? "—"}
|
|
805
|
-
</Typography>
|
|
806
|
-
</div>
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
// Simple scalar → PropertyPreview (single-line)
|
|
811
|
-
return (
|
|
812
|
-
<div key={col.key} className={cls(col.width, "truncate", col.align === "center" ? "text-center" : col.align === "right" ? "text-right" : "text-left")}>
|
|
813
|
-
<Typography component="div" variant="body2" className="text-surface-600 dark:text-surface-300 truncate">
|
|
814
|
-
{value !== undefined ? (
|
|
815
|
-
<PropertyPreview propertyKey={col.key} value={value} property={col.property} size="small"/>
|
|
816
|
-
) : "—"}
|
|
817
|
-
</Typography>
|
|
818
|
-
</div>
|
|
819
|
-
);
|
|
820
|
-
})}
|
|
821
|
-
</>
|
|
822
|
-
) : (
|
|
823
|
-
/* ── SLOT MODE (editorial scanner layout) ── */
|
|
1007
|
+
{/* TRAILING COLUMNS — the same definitions the header labels, in the
|
|
1008
|
+
same order and at the same widths, so a label and the values
|
|
1009
|
+
under it cannot come apart. */}
|
|
1010
|
+
{columns.length > 0 && (
|
|
824
1011
|
<div className="flex items-center gap-4 flex-shrink-0 ml-auto">
|
|
825
|
-
{
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
1012
|
+
{columns.map((col) => (
|
|
1013
|
+
<div
|
|
1014
|
+
key={col.key}
|
|
1015
|
+
className={cls(
|
|
1016
|
+
col.width,
|
|
1017
|
+
"flex items-center overflow-hidden",
|
|
1018
|
+
col.align === "center" ? "justify-center" : col.align === "right" ? "justify-end" : "justify-start"
|
|
1019
|
+
)}
|
|
1020
|
+
>
|
|
1021
|
+
<ListCell column={col} entity={entity} slots={slots}/>
|
|
834
1022
|
</div>
|
|
835
|
-
)}
|
|
836
|
-
|
|
837
|
-
{/* DATE slot */}
|
|
838
|
-
{slots.date && (
|
|
839
|
-
<div className="flex-shrink-0 text-right w-[80px] @max-[500px]:hidden">
|
|
840
|
-
<Typography variant="caption" className="whitespace-nowrap text-surface-400 dark:text-surface-500 font-medium">
|
|
841
|
-
{slots.date.formatted ?? "—"}
|
|
842
|
-
</Typography>
|
|
843
|
-
</div>
|
|
844
|
-
)}
|
|
1023
|
+
))}
|
|
845
1024
|
</div>
|
|
846
1025
|
)}
|
|
847
1026
|
|
|
848
|
-
{/* LIST VIEW ACTIONS — always visible on each row
|
|
849
|
-
|
|
850
|
-
|
|
1027
|
+
{/* LIST VIEW ACTIONS — always visible on each row.
|
|
1028
|
+
Width is reserved from the widest row rather than taken from
|
|
1029
|
+
this one, so a record with fewer actions does not slide its
|
|
1030
|
+
columns out from under the header. */}
|
|
1031
|
+
{actionsWidth > 0 && (
|
|
1032
|
+
<div className="flex items-center justify-end gap-0.5 flex-shrink-0 ml-auto"
|
|
1033
|
+
style={{ minWidth: actionsWidth }}
|
|
1034
|
+
onClick={(e) => e.stopPropagation()}>
|
|
851
1035
|
{listViewActions.map((action, index) => (
|
|
852
1036
|
<Tooltip key={action.key ?? index} title={action.name} asChild>
|
|
853
1037
|
<IconButton
|
|
@@ -881,7 +1065,7 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
881
1065
|
highlighted?: boolean;
|
|
882
1066
|
onSelectionChange?: (entity: Entity<M>, selected: boolean) => void;
|
|
883
1067
|
selectionEnabled?: boolean;
|
|
884
|
-
columns:
|
|
1068
|
+
columns: ListColumn[];
|
|
885
1069
|
slotKeys: CollectionSlotKeys;
|
|
886
1070
|
rowClasses: string;
|
|
887
1071
|
showImage: boolean;
|
|
@@ -889,9 +1073,200 @@ const ListRow = React.memo(function ListRow<M extends Record<string, unknown>>({
|
|
|
889
1073
|
isLast: boolean;
|
|
890
1074
|
isActive?: boolean;
|
|
891
1075
|
listViewActions?: EntityAction[];
|
|
1076
|
+
/** Reserved width of the actions cell, shared with the header. */
|
|
1077
|
+
actionsWidth?: number;
|
|
892
1078
|
context?: ReturnType<typeof useAdminContext>;
|
|
893
1079
|
path?: string;
|
|
894
1080
|
selectionController?: SelectionController<M>;
|
|
895
1081
|
openEntityMode?: "side_panel" | "full_screen" | "split" | "dialog";
|
|
896
1082
|
}) => React.ReactElement;
|
|
897
1083
|
|
|
1084
|
+
/**
|
|
1085
|
+
* One cell of one row: whatever the column says fills it.
|
|
1086
|
+
*
|
|
1087
|
+
* A slot column renders the slot — a status keeps its coloured chip and a date
|
|
1088
|
+
* its relative wording wherever the value came from — and a property column
|
|
1089
|
+
* reads the record. Both go through here so the header above them is labelling
|
|
1090
|
+
* one thing, not two that happen to line up.
|
|
1091
|
+
*/
|
|
1092
|
+
function ListCell<M extends Record<string, unknown>>({
|
|
1093
|
+
column,
|
|
1094
|
+
entity,
|
|
1095
|
+
slots
|
|
1096
|
+
}: {
|
|
1097
|
+
column: ListColumn;
|
|
1098
|
+
entity: Entity<M>;
|
|
1099
|
+
slots: EntityPreviewSlots;
|
|
1100
|
+
}) {
|
|
1101
|
+
if (column.slot === "tags") {
|
|
1102
|
+
if (!slots.tags) return null;
|
|
1103
|
+
return (
|
|
1104
|
+
<div className="flex items-center gap-1 overflow-hidden">
|
|
1105
|
+
<TagChips slot={slots.tags} max={3}/>
|
|
1106
|
+
</div>
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
if (column.slot === "status") {
|
|
1111
|
+
if (!slots.status) return <EmptyCell/>;
|
|
1112
|
+
return <SlotValue slot={slots.status} size="small"/>;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (column.slot === "date") {
|
|
1116
|
+
return (
|
|
1117
|
+
<Typography variant="caption" className="whitespace-nowrap text-surface-400 dark:text-surface-500 font-medium">
|
|
1118
|
+
{slots.date?.formatted ?? "—"}
|
|
1119
|
+
</Typography>
|
|
1120
|
+
);
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
const property = column.property;
|
|
1124
|
+
if (!property) return null;
|
|
1125
|
+
|
|
1126
|
+
const value = getValueInPath(entity.values, column.key);
|
|
1127
|
+
|
|
1128
|
+
if (property.type === "date") {
|
|
1129
|
+
return (
|
|
1130
|
+
<Typography variant="caption" className="whitespace-nowrap text-surface-400 dark:text-surface-500 font-medium">
|
|
1131
|
+
{formatDateValue(value) ?? "—"}
|
|
1132
|
+
</Typography>
|
|
1133
|
+
);
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1136
|
+
// Complex types → compact single-line summary, so a row keeps its height.
|
|
1137
|
+
if (isComplexPropertyType(property)) {
|
|
1138
|
+
const summary = compactValueSummary(value, property);
|
|
1139
|
+
return (
|
|
1140
|
+
<Typography variant="caption" className="text-surface-500 dark:text-surface-400 truncate">
|
|
1141
|
+
{summary ?? "—"}
|
|
1142
|
+
</Typography>
|
|
1143
|
+
);
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
if (value === undefined || value === null) return <EmptyCell/>;
|
|
1147
|
+
|
|
1148
|
+
return (
|
|
1149
|
+
<Typography component="div" variant="body2" className="text-surface-600 dark:text-surface-300 truncate">
|
|
1150
|
+
<PropertyPreview propertyKey={column.key} value={value} property={property} size="small"/>
|
|
1151
|
+
</Typography>
|
|
1152
|
+
);
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
/** What a column shows for a record that has nothing in it. */
|
|
1156
|
+
function EmptyCell() {
|
|
1157
|
+
return <span className="text-surface-400 dark:text-surface-600">—</span>;
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* The list's column header.
|
|
1162
|
+
*
|
|
1163
|
+
* Quiet by design: a list is read row by row, and the header is there to name
|
|
1164
|
+
* the columns and to be clicked, not to compete with the rows. It lays out
|
|
1165
|
+
* against the same widths the rows do, and skips the checkbox and the image —
|
|
1166
|
+
* neither is a column, and neither has anything to be called.
|
|
1167
|
+
*/
|
|
1168
|
+
function ListHeader({
|
|
1169
|
+
titleColumn,
|
|
1170
|
+
columns,
|
|
1171
|
+
selectionEnabled,
|
|
1172
|
+
showImage,
|
|
1173
|
+
actionsWidth,
|
|
1174
|
+
sortBy,
|
|
1175
|
+
onColumnSort,
|
|
1176
|
+
sortIsAvailable
|
|
1177
|
+
}: {
|
|
1178
|
+
titleColumn?: ListColumn;
|
|
1179
|
+
columns: ListColumn[];
|
|
1180
|
+
selectionEnabled?: boolean;
|
|
1181
|
+
showImage: boolean;
|
|
1182
|
+
actionsWidth: number;
|
|
1183
|
+
sortBy?: [string, "asc" | "desc"];
|
|
1184
|
+
onColumnSort: (key: string) => void;
|
|
1185
|
+
sortIsAvailable: (key: string) => boolean;
|
|
1186
|
+
}) {
|
|
1187
|
+
const headerCell = (column: ListColumn) => (
|
|
1188
|
+
<ListHeaderLabel
|
|
1189
|
+
column={column}
|
|
1190
|
+
direction={sortBy?.[0] === column.key ? sortBy[1] : undefined}
|
|
1191
|
+
onSort={column.sortable && sortIsAvailable(column.key) ? () => onColumnSort(column.key) : undefined}
|
|
1192
|
+
/>
|
|
1193
|
+
);
|
|
1194
|
+
|
|
1195
|
+
return (
|
|
1196
|
+
<div className={cls(
|
|
1197
|
+
"flex items-center gap-4 px-5 py-1.5 select-none border-b bg-surface-50 dark:bg-surface-900",
|
|
1198
|
+
defaultBorderMixin
|
|
1199
|
+
)}>
|
|
1200
|
+
{selectionEnabled && <div className="flex-shrink-0 w-8"/>}
|
|
1201
|
+
{showImage && <div className="flex-shrink-0 w-10"/>}
|
|
1202
|
+
|
|
1203
|
+
<div className="flex-1 min-w-0 flex items-center">
|
|
1204
|
+
{titleColumn && headerCell(titleColumn)}
|
|
1205
|
+
</div>
|
|
1206
|
+
|
|
1207
|
+
{columns.length > 0 && (
|
|
1208
|
+
<div className="flex items-center gap-4 flex-shrink-0 ml-auto">
|
|
1209
|
+
{columns.map(column => (
|
|
1210
|
+
<div
|
|
1211
|
+
key={column.key}
|
|
1212
|
+
className={cls(
|
|
1213
|
+
column.width,
|
|
1214
|
+
"flex items-center overflow-hidden",
|
|
1215
|
+
column.align === "center" ? "justify-center" : column.align === "right" ? "justify-end" : "justify-start"
|
|
1216
|
+
)}
|
|
1217
|
+
>
|
|
1218
|
+
{headerCell(column)}
|
|
1219
|
+
</div>
|
|
1220
|
+
))}
|
|
1221
|
+
</div>
|
|
1222
|
+
)}
|
|
1223
|
+
|
|
1224
|
+
{actionsWidth > 0 && <div className="flex-shrink-0 ml-auto" style={{ minWidth: actionsWidth }}/>}
|
|
1225
|
+
</div>
|
|
1226
|
+
);
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* One header label, clickable when the collection can be ordered by it.
|
|
1231
|
+
*
|
|
1232
|
+
* The arrow shows only on the column currently ordering the list: three arrows
|
|
1233
|
+
* in a header row are three invitations, and only one of them is ever the
|
|
1234
|
+
* answer to "how is this sorted".
|
|
1235
|
+
*/
|
|
1236
|
+
function ListHeaderLabel({
|
|
1237
|
+
column,
|
|
1238
|
+
direction,
|
|
1239
|
+
onSort
|
|
1240
|
+
}: {
|
|
1241
|
+
column: ListColumn;
|
|
1242
|
+
direction?: "asc" | "desc";
|
|
1243
|
+
onSort?: () => void;
|
|
1244
|
+
}) {
|
|
1245
|
+
const content = (
|
|
1246
|
+
<>
|
|
1247
|
+
<span className="truncate">{column.label}</span>
|
|
1248
|
+
{direction === "asc" && <ArrowUpIcon size={12} className="flex-shrink-0"/>}
|
|
1249
|
+
{direction === "desc" && <ArrowDownIcon size={12} className="flex-shrink-0"/>}
|
|
1250
|
+
</>
|
|
1251
|
+
);
|
|
1252
|
+
|
|
1253
|
+
const base = "inline-flex items-center gap-1 max-w-full text-[11px] leading-none uppercase tracking-wider font-medium";
|
|
1254
|
+
const tone = direction
|
|
1255
|
+
? "text-surface-600 dark:text-surface-300"
|
|
1256
|
+
: "text-surface-400 dark:text-surface-500";
|
|
1257
|
+
|
|
1258
|
+
if (!onSort) {
|
|
1259
|
+
return <span className={cls(base, tone)}>{content}</span>;
|
|
1260
|
+
}
|
|
1261
|
+
|
|
1262
|
+
return (
|
|
1263
|
+
<button
|
|
1264
|
+
type="button"
|
|
1265
|
+
title={`Sort by ${column.label}`}
|
|
1266
|
+
onClick={onSort}
|
|
1267
|
+
className={cls(base, tone, "cursor-pointer hover:text-surface-700 dark:hover:text-surface-200 transition-colors")}
|
|
1268
|
+
>
|
|
1269
|
+
{content}
|
|
1270
|
+
</button>
|
|
1271
|
+
);
|
|
1272
|
+
}
|