@spaced-out/ui-design-system 0.3.28 → 0.3.29
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/CHANGELOG.md +7 -0
- package/lib/components/Table/Table.docs.js +12 -0
- package/lib/components/Table/Table.docs.js.flow +9 -0
- package/lib/components/Table/Table.js +3 -1
- package/lib/components/Table/Table.js.flow +5 -0
- package/lib/components/Table/hooks.js +9 -7
- package/lib/components/Table/hooks.js.flow +9 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [0.3.29](https://github.com/spaced-out/ui-design-system/compare/v0.3.28...v0.3.29) (2025-03-12)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* disabled internal sorting and handled onSOrt ([#325](https://github.com/spaced-out/ui-design-system/issues/325)) ([f43d03a](https://github.com/spaced-out/ui-design-system/commit/f43d03a135240c3dba9a91695ed3128130de63e2))
|
|
11
|
+
|
|
5
12
|
### [0.3.28](https://github.com/spaced-out/ui-design-system/compare/v0.3.27...v0.3.28) (2025-03-09)
|
|
6
13
|
|
|
7
14
|
|
|
@@ -198,6 +198,18 @@ const TABLE_DOCS = {
|
|
|
198
198
|
summary: false
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
|
+
},
|
|
202
|
+
enableInternalSorting: {
|
|
203
|
+
description: 'Enable internal sorting for the table. This would sort the table data internally and not rely on the apis sorting',
|
|
204
|
+
control: 'boolean',
|
|
205
|
+
table: {
|
|
206
|
+
type: {
|
|
207
|
+
summary: '?boolean'
|
|
208
|
+
},
|
|
209
|
+
defaultValue: {
|
|
210
|
+
summary: true
|
|
211
|
+
}
|
|
212
|
+
}
|
|
201
213
|
}
|
|
202
214
|
},
|
|
203
215
|
parameters: {
|
|
@@ -162,6 +162,15 @@ export const TABLE_DOCS = {
|
|
|
162
162
|
defaultValue: {summary: false},
|
|
163
163
|
},
|
|
164
164
|
},
|
|
165
|
+
enableInternalSorting: {
|
|
166
|
+
description:
|
|
167
|
+
'Enable internal sorting for the table. This would sort the table data internally and not rely on the apis sorting',
|
|
168
|
+
control: 'boolean',
|
|
169
|
+
table: {
|
|
170
|
+
type: {summary: '?boolean'},
|
|
171
|
+
defaultValue: {summary: true},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
165
174
|
},
|
|
166
175
|
parameters: {
|
|
167
176
|
componentSubtitle: 'Generates a Table component.',
|
|
@@ -44,6 +44,7 @@ function Table(props) {
|
|
|
44
44
|
defaultSortKey,
|
|
45
45
|
defaultSortDirection = 'original',
|
|
46
46
|
onSort,
|
|
47
|
+
enableInternalSorting,
|
|
47
48
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
48
49
|
isLoading,
|
|
49
50
|
idName = 'id',
|
|
@@ -62,7 +63,8 @@ function Table(props) {
|
|
|
62
63
|
} = (0, _hooks.useSortableEntries)(entries, idName, {
|
|
63
64
|
defaultSortKey,
|
|
64
65
|
defaultSortDirection,
|
|
65
|
-
onSort
|
|
66
|
+
onSort,
|
|
67
|
+
enableInternalSorting
|
|
66
68
|
});
|
|
67
69
|
return /*#__PURE__*/React.createElement(_StaticTable.StaticTable, _extends({}, props, sortableProps, {
|
|
68
70
|
sortable: sortable,
|
|
@@ -41,6 +41,8 @@ export type TableProps<T, U> = {
|
|
|
41
41
|
headerIconClassName?: string,
|
|
42
42
|
defaultSortKey?: string,
|
|
43
43
|
defaultSortDirection?: 'asc' | 'desc' | 'original',
|
|
44
|
+
// Please start using this prop if you want internal sorting to work in the table
|
|
45
|
+
enableInternalSorting?: boolean,
|
|
44
46
|
|
|
45
47
|
selectedKeys?: string[],
|
|
46
48
|
onSelect?: (keys: string[]) => mixed,
|
|
@@ -93,6 +95,8 @@ export function Table<Data: GenericObject, Extras: GenericObject>(
|
|
|
93
95
|
defaultSortKey,
|
|
94
96
|
defaultSortDirection = 'original',
|
|
95
97
|
onSort,
|
|
98
|
+
enableInternalSorting,
|
|
99
|
+
|
|
96
100
|
// eslint-disable-next-line unused-imports/no-unused-vars
|
|
97
101
|
isLoading,
|
|
98
102
|
idName = 'id',
|
|
@@ -111,6 +115,7 @@ export function Table<Data: GenericObject, Extras: GenericObject>(
|
|
|
111
115
|
defaultSortKey,
|
|
112
116
|
defaultSortDirection,
|
|
113
117
|
onSort,
|
|
118
|
+
enableInternalSorting,
|
|
114
119
|
},
|
|
115
120
|
);
|
|
116
121
|
|
|
@@ -15,7 +15,8 @@ function useSortableEntries(entries, idName, _ref) {
|
|
|
15
15
|
let {
|
|
16
16
|
defaultSortKey = 'id',
|
|
17
17
|
defaultSortDirection = 'original',
|
|
18
|
-
onSort
|
|
18
|
+
onSort,
|
|
19
|
+
enableInternalSorting = true
|
|
19
20
|
} = _ref;
|
|
20
21
|
const [sortKey, setSortKey] = React.useState(defaultSortKey);
|
|
21
22
|
const [sortDirection, setSortDirection] = React.useState(defaultSortDirection);
|
|
@@ -38,17 +39,18 @@ function useSortableEntries(entries, idName, _ref) {
|
|
|
38
39
|
return nextDirection;
|
|
39
40
|
};
|
|
40
41
|
const handleSortClick = React.useCallback(nextSortKey => {
|
|
41
|
-
let nextSortDirection
|
|
42
|
+
let nextSortDirection;
|
|
42
43
|
if (nextSortKey === sortKey) {
|
|
43
44
|
nextSortDirection = advanceSortDirection(sortDirection);
|
|
44
45
|
} else {
|
|
45
46
|
setSortKey(nextSortKey);
|
|
46
|
-
|
|
47
|
+
nextSortDirection = 'desc';
|
|
47
48
|
}
|
|
49
|
+
setSortDirection(nextSortDirection);
|
|
48
50
|
onSort?.(nextSortKey, nextSortDirection);
|
|
49
51
|
}, [sortKey, sortDirection, entries]);
|
|
50
52
|
const sortedEntries = React.useMemo(() => {
|
|
51
|
-
if (sortDirection === 'original') {
|
|
53
|
+
if (!enableInternalSorting || sortDirection === 'original') {
|
|
52
54
|
return entries;
|
|
53
55
|
}
|
|
54
56
|
const caseInsensitiveSortFunction = entry => {
|
|
@@ -57,9 +59,9 @@ function useSortableEntries(entries, idName, _ref) {
|
|
|
57
59
|
}
|
|
58
60
|
return entry[sortKey];
|
|
59
61
|
};
|
|
60
|
-
const
|
|
61
|
-
return sortDirection === 'asc' ?
|
|
62
|
-
}, [sortDirection, sortKey, entries]);
|
|
62
|
+
const sortedAsc = (0, _sortBy.default)(entries, caseInsensitiveSortFunction);
|
|
63
|
+
return sortDirection === 'asc' ? sortedAsc : sortedAsc.reverse();
|
|
64
|
+
}, [sortDirection, sortKey, entries, enableInternalSorting]);
|
|
63
65
|
const sortedKeys = React.useMemo(() => sortedEntries.map(ent => (0, _get.default)(ent, idName)), [sortedEntries]);
|
|
64
66
|
return {
|
|
65
67
|
sortedEntries,
|
|
@@ -16,10 +16,12 @@ export function useSortableEntries<T: GenericObject>(
|
|
|
16
16
|
defaultSortKey = 'id',
|
|
17
17
|
defaultSortDirection = 'original',
|
|
18
18
|
onSort,
|
|
19
|
+
enableInternalSorting = true,
|
|
19
20
|
}: {
|
|
20
21
|
defaultSortKey?: $Keys<T>,
|
|
21
22
|
defaultSortDirection?: SortDirection,
|
|
22
23
|
onSort?: (sortKey: string, sortDirection: SortDirection) => mixed,
|
|
24
|
+
enableInternalSorting?: boolean,
|
|
23
25
|
},
|
|
24
26
|
): {
|
|
25
27
|
handleSortClick: (sortKey: $Keys<T>) => mixed,
|
|
@@ -53,20 +55,21 @@ export function useSortableEntries<T: GenericObject>(
|
|
|
53
55
|
|
|
54
56
|
const handleSortClick = React.useCallback(
|
|
55
57
|
(nextSortKey: string) => {
|
|
56
|
-
let nextSortDirection
|
|
58
|
+
let nextSortDirection;
|
|
57
59
|
if (nextSortKey === sortKey) {
|
|
58
60
|
nextSortDirection = advanceSortDirection(sortDirection);
|
|
59
61
|
} else {
|
|
60
62
|
setSortKey(nextSortKey);
|
|
61
|
-
|
|
63
|
+
nextSortDirection = 'desc';
|
|
62
64
|
}
|
|
65
|
+
setSortDirection(nextSortDirection);
|
|
63
66
|
onSort?.(nextSortKey, nextSortDirection);
|
|
64
67
|
},
|
|
65
68
|
[sortKey, sortDirection, entries],
|
|
66
69
|
);
|
|
67
70
|
|
|
68
71
|
const sortedEntries = React.useMemo(() => {
|
|
69
|
-
if (sortDirection === 'original') {
|
|
72
|
+
if (!enableInternalSorting || sortDirection === 'original') {
|
|
70
73
|
return entries;
|
|
71
74
|
}
|
|
72
75
|
const caseInsensitiveSortFunction = (entry) => {
|
|
@@ -75,9 +78,9 @@ export function useSortableEntries<T: GenericObject>(
|
|
|
75
78
|
}
|
|
76
79
|
return entry[sortKey];
|
|
77
80
|
};
|
|
78
|
-
const
|
|
79
|
-
return sortDirection === 'asc' ?
|
|
80
|
-
}, [sortDirection, sortKey, entries]);
|
|
81
|
+
const sortedAsc = sortBy(entries, caseInsensitiveSortFunction);
|
|
82
|
+
return sortDirection === 'asc' ? sortedAsc : sortedAsc.reverse();
|
|
83
|
+
}, [sortDirection, sortKey, entries, enableInternalSorting]);
|
|
81
84
|
|
|
82
85
|
const sortedKeys = React.useMemo(
|
|
83
86
|
() => sortedEntries.map((ent) => get(ent, idName)),
|