@trackunit/react-table 2.10.3 → 2.10.4-alpha-cb9408e01a9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +38 -18
- package/index.esm.js +39 -19
- package/package.json +10 -10
- package/src/hooks/useTablePersistence/useTablePersistence.d.ts +9 -6
package/index.cjs.js
CHANGED
|
@@ -395,20 +395,22 @@ const compactPinningSchema = zod.z.object({
|
|
|
395
395
|
*/
|
|
396
396
|
const compactForUrl = (state) => {
|
|
397
397
|
const compact = {};
|
|
398
|
-
const columnVisibilityEntries = state.columnVisibility
|
|
398
|
+
const columnVisibilityEntries = state.columnVisibility
|
|
399
|
+
? Object.entries(state.columnVisibility).filter(([key]) => key !== sharedUtils.VISIBLE_ONLY_COLUMN_VISIBILITY_KEY)
|
|
400
|
+
: undefined;
|
|
399
401
|
const visibleColumns = columnVisibilityEntries?.filter(([, visible]) => visible).map(([key]) => key) ?? [];
|
|
400
402
|
const visibleColumnSet = new Set(visibleColumns);
|
|
401
|
-
|
|
403
|
+
const hasColumnVisibility = (columnVisibilityEntries?.length ?? 0) > 0;
|
|
404
|
+
if (hasColumnVisibility) {
|
|
402
405
|
compact[URL_KEY_MAP.columnVisibility] = visibleColumns;
|
|
403
406
|
}
|
|
404
407
|
if (state.columnOrder && state.columnOrder.length > 0) {
|
|
405
|
-
compact[URL_KEY_MAP.columnOrder] =
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
: state.columnOrder;
|
|
408
|
+
compact[URL_KEY_MAP.columnOrder] = hasColumnVisibility
|
|
409
|
+
? [
|
|
410
|
+
...state.columnOrder.filter(columnId => visibleColumnSet.has(columnId)),
|
|
411
|
+
...visibleColumns.filter(columnId => !state.columnOrder?.includes(columnId)),
|
|
412
|
+
]
|
|
413
|
+
: state.columnOrder;
|
|
412
414
|
}
|
|
413
415
|
if (state.sorting && state.sorting.length > 0) {
|
|
414
416
|
compact[URL_KEY_MAP.sorting] = state.sorting;
|
|
@@ -560,9 +562,12 @@ const isOwnedByCurrentUser = (ownerId, clientSideUserId) => ownerId === undefine
|
|
|
560
562
|
*
|
|
561
563
|
* On mount, state is loaded from the hash (or legacy search param as a
|
|
562
564
|
* one-shot fallback) and merged with localStorage so fields omitted from
|
|
563
|
-
* the URL, such as `expanded`, still survive reloads.
|
|
564
|
-
*
|
|
565
|
-
*
|
|
565
|
+
* the URL, such as `expanded`, still survive reloads. Opening that URL
|
|
566
|
+
* saves the merged layout for the account that loaded the page, so a
|
|
567
|
+
* pasted link sticks without a further edit. An account that becomes
|
|
568
|
+
* current later, while the same URL is still open, does not receive that
|
|
569
|
+
* write — their storage changes only when they edit the table. Switching
|
|
570
|
+
* back to the opener does not write the hash that is on screen then.
|
|
566
571
|
*
|
|
567
572
|
* `onTableStateChange` takes a *partial* state and merges it into whatever
|
|
568
573
|
* was reported earlier in the session, so a consumer can report a single
|
|
@@ -572,9 +577,9 @@ const isOwnedByCurrentUser = (ownerId, clientSideUserId) => ownerId === undefine
|
|
|
572
577
|
*
|
|
573
578
|
* Reported state is scoped to the identity that reported it: when the current
|
|
574
579
|
* user changes, state reported by the previous user is discarded instead of
|
|
575
|
-
* being written to the new user's storage.
|
|
576
|
-
*
|
|
577
|
-
*
|
|
580
|
+
* being written to the new user's storage. A layout shared through the URL
|
|
581
|
+
* renders for anyone. It is saved for the account that opened the page, and
|
|
582
|
+
* only becomes a later account's layout once that account changes the table.
|
|
578
583
|
*
|
|
579
584
|
* The hash always wins on load so a link or bookmark renders the same layout
|
|
580
585
|
* for whoever opens it. Each hash write is stamped with the identity that
|
|
@@ -597,7 +602,7 @@ const useTablePersistence = (persistenceKey) => {
|
|
|
597
602
|
const { clientSideUserId } = reactCoreHooks.useCurrentUser();
|
|
598
603
|
const localStorageEnabled = clientSideUserId !== undefined;
|
|
599
604
|
const { toUrlValue, fromUrlValue } = useCompactTableUrl();
|
|
600
|
-
const { initialState, persistState, clearState } = reactComponents.usePersistedState({
|
|
605
|
+
const { initialState, persistState, clearState, commitHydratedState } = reactComponents.usePersistedState({
|
|
601
606
|
key: `${persistenceKey}Tp`,
|
|
602
607
|
validate: validateTableState,
|
|
603
608
|
toUrlValue,
|
|
@@ -621,6 +626,20 @@ const useTablePersistence = (persistenceKey) => {
|
|
|
621
626
|
});
|
|
622
627
|
// Identity that reported the state currently held in `pendingState`.
|
|
623
628
|
const pendingOwnerIdRef = react.useRef(undefined);
|
|
629
|
+
// Set after the account that opened this page has had its one commit.
|
|
630
|
+
// A later account, and a switch back to the opener, must not write the
|
|
631
|
+
// hash that is on screen at that moment into storage. The ref stays empty
|
|
632
|
+
// until the commit succeeds, so a stale snapshot can still retry.
|
|
633
|
+
const openingUserIdRef = react.useRef(undefined);
|
|
634
|
+
react.useEffect(() => {
|
|
635
|
+
if (clientSideUserId === undefined || openingUserIdRef.current !== undefined) {
|
|
636
|
+
return;
|
|
637
|
+
}
|
|
638
|
+
if (!commitHydratedState()) {
|
|
639
|
+
return;
|
|
640
|
+
}
|
|
641
|
+
openingUserIdRef.current = clientSideUserId;
|
|
642
|
+
}, [clientSideUserId, commitHydratedState]);
|
|
624
643
|
const [pendingState, setPendingState] = react.useState(null);
|
|
625
644
|
const debouncedPending = reactComponents.useDebounce(pendingState, { delay: 300 });
|
|
626
645
|
const hasReportedChange = debouncedPending !== null;
|
|
@@ -680,8 +699,9 @@ const useTablePersistence = (persistenceKey) => {
|
|
|
680
699
|
}));
|
|
681
700
|
}, [clientSideUserId]);
|
|
682
701
|
react.useEffect(() => {
|
|
683
|
-
//
|
|
684
|
-
// `
|
|
702
|
+
// User edits write the URL and storage. Opening a shared URL writes
|
|
703
|
+
// storage on its own, via `commitHydratedState`, and must not be echoed
|
|
704
|
+
// through here — `persistState` treats the hydrated value as already saved.
|
|
685
705
|
if (!hasReportedChange || !currentState) {
|
|
686
706
|
return;
|
|
687
707
|
}
|
package/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { registerTranslations, useNamespaceTranslation, NamespaceTrans } from '@
|
|
|
3
3
|
import { Icon, MenuItem, Button, Tooltip, useOverflowItems, MoreMenu, MenuContent, Spacer, usePersistedState, useDebounce, Text, cvaInteractableItem, Popover, PopoverTrigger, IconButton, PopoverContent, cvaMenuList, cvaMenu, useBidirectionalScroll, noPagination, Card, HorizontalOverflowScroller, Spinner, EmptyState, SkeletonLabel } from '@trackunit/react-components';
|
|
4
4
|
import { Link } from '@tanstack/react-router';
|
|
5
5
|
import { objectValues, VISIBLE_ONLY_COLUMN_VISIBILITY_KEY, objectKeys, nonNullable, objectEntries } from '@trackunit/shared-utils';
|
|
6
|
-
import { useMemo, Children, cloneElement, useCallback, useRef,
|
|
6
|
+
import { useMemo, Children, cloneElement, useCallback, useRef, useEffect, useState, createElement } from 'react';
|
|
7
7
|
import { cva } from '@trackunit/css-class-variance-utilities';
|
|
8
8
|
import { useCurrentUser } from '@trackunit/react-core-hooks';
|
|
9
9
|
import { z } from 'zod';
|
|
@@ -394,20 +394,22 @@ const compactPinningSchema = z.object({
|
|
|
394
394
|
*/
|
|
395
395
|
const compactForUrl = (state) => {
|
|
396
396
|
const compact = {};
|
|
397
|
-
const columnVisibilityEntries = state.columnVisibility
|
|
397
|
+
const columnVisibilityEntries = state.columnVisibility
|
|
398
|
+
? Object.entries(state.columnVisibility).filter(([key]) => key !== VISIBLE_ONLY_COLUMN_VISIBILITY_KEY)
|
|
399
|
+
: undefined;
|
|
398
400
|
const visibleColumns = columnVisibilityEntries?.filter(([, visible]) => visible).map(([key]) => key) ?? [];
|
|
399
401
|
const visibleColumnSet = new Set(visibleColumns);
|
|
400
|
-
|
|
402
|
+
const hasColumnVisibility = (columnVisibilityEntries?.length ?? 0) > 0;
|
|
403
|
+
if (hasColumnVisibility) {
|
|
401
404
|
compact[URL_KEY_MAP.columnVisibility] = visibleColumns;
|
|
402
405
|
}
|
|
403
406
|
if (state.columnOrder && state.columnOrder.length > 0) {
|
|
404
|
-
compact[URL_KEY_MAP.columnOrder] =
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
: state.columnOrder;
|
|
407
|
+
compact[URL_KEY_MAP.columnOrder] = hasColumnVisibility
|
|
408
|
+
? [
|
|
409
|
+
...state.columnOrder.filter(columnId => visibleColumnSet.has(columnId)),
|
|
410
|
+
...visibleColumns.filter(columnId => !state.columnOrder?.includes(columnId)),
|
|
411
|
+
]
|
|
412
|
+
: state.columnOrder;
|
|
411
413
|
}
|
|
412
414
|
if (state.sorting && state.sorting.length > 0) {
|
|
413
415
|
compact[URL_KEY_MAP.sorting] = state.sorting;
|
|
@@ -559,9 +561,12 @@ const isOwnedByCurrentUser = (ownerId, clientSideUserId) => ownerId === undefine
|
|
|
559
561
|
*
|
|
560
562
|
* On mount, state is loaded from the hash (or legacy search param as a
|
|
561
563
|
* one-shot fallback) and merged with localStorage so fields omitted from
|
|
562
|
-
* the URL, such as `expanded`, still survive reloads.
|
|
563
|
-
*
|
|
564
|
-
*
|
|
564
|
+
* the URL, such as `expanded`, still survive reloads. Opening that URL
|
|
565
|
+
* saves the merged layout for the account that loaded the page, so a
|
|
566
|
+
* pasted link sticks without a further edit. An account that becomes
|
|
567
|
+
* current later, while the same URL is still open, does not receive that
|
|
568
|
+
* write — their storage changes only when they edit the table. Switching
|
|
569
|
+
* back to the opener does not write the hash that is on screen then.
|
|
565
570
|
*
|
|
566
571
|
* `onTableStateChange` takes a *partial* state and merges it into whatever
|
|
567
572
|
* was reported earlier in the session, so a consumer can report a single
|
|
@@ -571,9 +576,9 @@ const isOwnedByCurrentUser = (ownerId, clientSideUserId) => ownerId === undefine
|
|
|
571
576
|
*
|
|
572
577
|
* Reported state is scoped to the identity that reported it: when the current
|
|
573
578
|
* user changes, state reported by the previous user is discarded instead of
|
|
574
|
-
* being written to the new user's storage.
|
|
575
|
-
*
|
|
576
|
-
*
|
|
579
|
+
* being written to the new user's storage. A layout shared through the URL
|
|
580
|
+
* renders for anyone. It is saved for the account that opened the page, and
|
|
581
|
+
* only becomes a later account's layout once that account changes the table.
|
|
577
582
|
*
|
|
578
583
|
* The hash always wins on load so a link or bookmark renders the same layout
|
|
579
584
|
* for whoever opens it. Each hash write is stamped with the identity that
|
|
@@ -596,7 +601,7 @@ const useTablePersistence = (persistenceKey) => {
|
|
|
596
601
|
const { clientSideUserId } = useCurrentUser();
|
|
597
602
|
const localStorageEnabled = clientSideUserId !== undefined;
|
|
598
603
|
const { toUrlValue, fromUrlValue } = useCompactTableUrl();
|
|
599
|
-
const { initialState, persistState, clearState } = usePersistedState({
|
|
604
|
+
const { initialState, persistState, clearState, commitHydratedState } = usePersistedState({
|
|
600
605
|
key: `${persistenceKey}Tp`,
|
|
601
606
|
validate: validateTableState,
|
|
602
607
|
toUrlValue,
|
|
@@ -620,6 +625,20 @@ const useTablePersistence = (persistenceKey) => {
|
|
|
620
625
|
});
|
|
621
626
|
// Identity that reported the state currently held in `pendingState`.
|
|
622
627
|
const pendingOwnerIdRef = useRef(undefined);
|
|
628
|
+
// Set after the account that opened this page has had its one commit.
|
|
629
|
+
// A later account, and a switch back to the opener, must not write the
|
|
630
|
+
// hash that is on screen at that moment into storage. The ref stays empty
|
|
631
|
+
// until the commit succeeds, so a stale snapshot can still retry.
|
|
632
|
+
const openingUserIdRef = useRef(undefined);
|
|
633
|
+
useEffect(() => {
|
|
634
|
+
if (clientSideUserId === undefined || openingUserIdRef.current !== undefined) {
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
if (!commitHydratedState()) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
openingUserIdRef.current = clientSideUserId;
|
|
641
|
+
}, [clientSideUserId, commitHydratedState]);
|
|
623
642
|
const [pendingState, setPendingState] = useState(null);
|
|
624
643
|
const debouncedPending = useDebounce(pendingState, { delay: 300 });
|
|
625
644
|
const hasReportedChange = debouncedPending !== null;
|
|
@@ -679,8 +698,9 @@ const useTablePersistence = (persistenceKey) => {
|
|
|
679
698
|
}));
|
|
680
699
|
}, [clientSideUserId]);
|
|
681
700
|
useEffect(() => {
|
|
682
|
-
//
|
|
683
|
-
// `
|
|
701
|
+
// User edits write the URL and storage. Opening a shared URL writes
|
|
702
|
+
// storage on its own, via `commitHydratedState`, and must not be echoed
|
|
703
|
+
// through here — `persistState` treats the hydrated value as already saved.
|
|
684
704
|
if (!hasReportedChange || !currentState) {
|
|
685
705
|
return;
|
|
686
706
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-table",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.4-alpha-cb9408e01a9.0",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
"react-dnd": "16.0.1",
|
|
12
12
|
"react-dnd-html5-backend": "16.0.1",
|
|
13
13
|
"tailwind-merge": "^2.0.0",
|
|
14
|
-
"@trackunit/react-components": "3.5.
|
|
15
|
-
"@trackunit/react-core-hooks": "1.24.
|
|
16
|
-
"@trackunit/shared-utils": "1.18.
|
|
17
|
-
"@trackunit/css-class-variance-utilities": "2.2.
|
|
18
|
-
"@trackunit/ui-icons": "1.16.
|
|
19
|
-
"@trackunit/react-table-base-components": "2.11.
|
|
20
|
-
"@trackunit/react-form-components": "2.9.
|
|
21
|
-
"@trackunit/i18n-library-translation": "2.7.
|
|
22
|
-
"@trackunit/iris-app-runtime-core-api": "1.20.
|
|
14
|
+
"@trackunit/react-components": "3.5.4-alpha-cb9408e01a9.0",
|
|
15
|
+
"@trackunit/react-core-hooks": "1.24.3-alpha-cb9408e01a9.0",
|
|
16
|
+
"@trackunit/shared-utils": "1.18.3-alpha-cb9408e01a9.0",
|
|
17
|
+
"@trackunit/css-class-variance-utilities": "2.2.3-alpha-cb9408e01a9.0",
|
|
18
|
+
"@trackunit/ui-icons": "1.16.3-alpha-cb9408e01a9.0",
|
|
19
|
+
"@trackunit/react-table-base-components": "2.11.4-alpha-cb9408e01a9.0",
|
|
20
|
+
"@trackunit/react-form-components": "2.9.4-alpha-cb9408e01a9.0",
|
|
21
|
+
"@trackunit/i18n-library-translation": "2.7.3-alpha-cb9408e01a9.0",
|
|
22
|
+
"@trackunit/iris-app-runtime-core-api": "1.20.3-alpha-cb9408e01a9.0",
|
|
23
23
|
"zod": "^3.25.76"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -81,9 +81,12 @@ type UseTablePersistenceResult = {
|
|
|
81
81
|
*
|
|
82
82
|
* On mount, state is loaded from the hash (or legacy search param as a
|
|
83
83
|
* one-shot fallback) and merged with localStorage so fields omitted from
|
|
84
|
-
* the URL, such as `expanded`, still survive reloads.
|
|
85
|
-
*
|
|
86
|
-
*
|
|
84
|
+
* the URL, such as `expanded`, still survive reloads. Opening that URL
|
|
85
|
+
* saves the merged layout for the account that loaded the page, so a
|
|
86
|
+
* pasted link sticks without a further edit. An account that becomes
|
|
87
|
+
* current later, while the same URL is still open, does not receive that
|
|
88
|
+
* write — their storage changes only when they edit the table. Switching
|
|
89
|
+
* back to the opener does not write the hash that is on screen then.
|
|
87
90
|
*
|
|
88
91
|
* `onTableStateChange` takes a *partial* state and merges it into whatever
|
|
89
92
|
* was reported earlier in the session, so a consumer can report a single
|
|
@@ -93,9 +96,9 @@ type UseTablePersistenceResult = {
|
|
|
93
96
|
*
|
|
94
97
|
* Reported state is scoped to the identity that reported it: when the current
|
|
95
98
|
* user changes, state reported by the previous user is discarded instead of
|
|
96
|
-
* being written to the new user's storage.
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
+
* being written to the new user's storage. A layout shared through the URL
|
|
100
|
+
* renders for anyone. It is saved for the account that opened the page, and
|
|
101
|
+
* only becomes a later account's layout once that account changes the table.
|
|
99
102
|
*
|
|
100
103
|
* The hash always wins on load so a link or bookmark renders the same layout
|
|
101
104
|
* for whoever opens it. Each hash write is stamped with the identity that
|