playbook_ui 14.22.0.pre.alpha.PLAY2292advancedtablepinnedrowsloading8631 → 14.22.0.pre.alpha.PLAY2292advancedtablepinnedrowsloading8633
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50940c977e833de1ec35e25c6269e332057fc06778dd67d44d2e59ab4ddd799e
|
4
|
+
data.tar.gz: def4a38171d0f1a0a97bcf80ddb277491d34b5661bcdb2d83b5f7c53c7bc9497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492530c127fd34e4edaf65b5afea93df1c41ebe96fd62aaffc2d398ba788cd88d6703175c406c62c6e9bd024f0bdf45f7a2b5ade54e44691a86c63c01556562f
|
7
|
+
data.tar.gz: dba59d34834a6c95d44fa1253641a2d29eccc7762abe866903f30948a04260fce9bf4393e5c4f013cf4ac58252210ac40606c436be76208d2eef2db4e119573c
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { useState, useCallback, useMemo, useEffect
|
1
|
+
import { useState, useCallback, useMemo, useEffect } from 'react';
|
2
2
|
import {
|
3
3
|
useReactTable,
|
4
4
|
getCoreRowModel,
|
@@ -180,19 +180,36 @@ export function useTableState({
|
|
180
180
|
...tableOptions,
|
181
181
|
});
|
182
182
|
|
183
|
-
//
|
184
|
-
const
|
183
|
+
// Create a stable hash of the data to detect changes
|
184
|
+
const dataHash = useMemo(() => {
|
185
|
+
if (loading) return '';
|
186
|
+
const currentData = virtualizedRows ? dataChunk : tableData;
|
187
|
+
return currentData.map(row => row.id).join(',');
|
188
|
+
}, [tableData, dataChunk, virtualizedRows, loading]);
|
185
189
|
|
186
|
-
|
187
|
-
|
188
|
-
|
190
|
+
const [prevDataHash, setPrevDataHash] = useState(dataHash);
|
191
|
+
|
192
|
+
// Synchronously clear pins when data changes to prevent table errors
|
193
|
+
if (!loading && dataHash !== prevDataHash) {
|
194
|
+
setPrevDataHash(dataHash);
|
189
195
|
|
190
|
-
|
191
|
-
if (
|
192
|
-
|
193
|
-
|
196
|
+
const currentPins = pinnedRows?.value?.top ?? [];
|
197
|
+
if (currentPins.length > 0) {
|
198
|
+
try {
|
199
|
+
const currentData = virtualizedRows ? dataChunk : tableData;
|
200
|
+
const validPins = currentPins.filter(id =>
|
201
|
+
currentData.some(row => row.id === id)
|
202
|
+
);
|
203
|
+
|
204
|
+
if (validPins.length !== currentPins.length) {
|
205
|
+
onRowPinningChange({ top: validPins });
|
206
|
+
}
|
207
|
+
} catch (error) {
|
208
|
+
console.warn('Error validating pins on data change, clearing pins:', error);
|
209
|
+
onRowPinningChange({ top: [] });
|
210
|
+
}
|
194
211
|
}
|
195
|
-
}
|
212
|
+
}
|
196
213
|
|
197
214
|
// Handle row pinning changes
|
198
215
|
useEffect(() => {
|
@@ -203,17 +220,48 @@ export function useTableState({
|
|
203
220
|
onRowPinningChange({ top: [] });
|
204
221
|
return;
|
205
222
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
223
|
+
|
224
|
+
try {
|
225
|
+
const rows = table.getRowModel().rows;
|
226
|
+
|
227
|
+
const validPinnedIds = topPins.filter(id => {
|
228
|
+
try {
|
229
|
+
return rows.some(row => row.id === id && row.depth === 0);
|
230
|
+
} catch (error) {
|
231
|
+
console.warn(`Pinned row with id ${id} not found in current dataset`);
|
232
|
+
return false;
|
233
|
+
}
|
234
|
+
});
|
235
|
+
|
236
|
+
if (validPinnedIds.length === 0) {
|
237
|
+
onRowPinningChange({ top: [] });
|
238
|
+
return;
|
214
239
|
}
|
215
|
-
|
216
|
-
|
240
|
+
|
241
|
+
const collectAllDescendantIds = (subs: Row<GenericObject>[]): string[] =>
|
242
|
+
subs.flatMap(r => [r.id, ...collectAllDescendantIds(r.subRows)]);
|
243
|
+
|
244
|
+
const allPinned: string[] = [];
|
245
|
+
|
246
|
+
validPinnedIds.forEach(id => {
|
247
|
+
const parent = rows.find(r => r.id === id && r.depth === 0);
|
248
|
+
if (parent) {
|
249
|
+
allPinned.push(parent.id, ...collectAllDescendantIds(parent.subRows));
|
250
|
+
}
|
251
|
+
});
|
252
|
+
|
253
|
+
const currentPins = pinnedRows?.value?.top ?? [];
|
254
|
+
const pinsChanged = allPinned.length !== currentPins.length ||
|
255
|
+
!allPinned.every(id => currentPins.includes(id));
|
256
|
+
|
257
|
+
if (pinsChanged) {
|
258
|
+
onRowPinningChange({ top: allPinned });
|
259
|
+
}
|
260
|
+
|
261
|
+
} catch (error) {
|
262
|
+
console.error('Error in pinned rows logic:', error);
|
263
|
+
onRowPinningChange({ top: [] });
|
264
|
+
}
|
217
265
|
}, [table, pinnedRows?.value?.top?.join(','), loading]);
|
218
266
|
|
219
267
|
// Check if table has any sub-rows
|