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: cc8c480032767b70d345545bb050a1a402e25edc0533e7f241d07e8c448eba1b
4
- data.tar.gz: 0b791da24dd14a9e71467272645c86449fde0d2433e72774c8a77db84cf378fb
3
+ metadata.gz: 50940c977e833de1ec35e25c6269e332057fc06778dd67d44d2e59ab4ddd799e
4
+ data.tar.gz: def4a38171d0f1a0a97bcf80ddb277491d34b5661bcdb2d83b5f7c53c7bc9497
5
5
  SHA512:
6
- metadata.gz: 7b01d8af55ae4645022e7121aaf51b11f89e0afdd149ab498a18d90fae59942e0da55f049bf6a06d9757c2108a8e1c45baf11cc1d521d4c84db1591374a33580
7
- data.tar.gz: 2c87fbf4597479a6590baa63eb3a06f8789d6f28be225db1347213f381ccfb744d05735c81e6727d548e997f76af5c08782dbc08951bde4225b69a79099a2cec
6
+ metadata.gz: 492530c127fd34e4edaf65b5afea93df1c41ebe96fd62aaffc2d398ba788cd88d6703175c406c62c6e9bd024f0bdf45f7a2b5ade54e44691a86c63c01556562f
7
+ data.tar.gz: dba59d34834a6c95d44fa1253641a2d29eccc7762abe866903f30948a04260fce9bf4393e5c4f013cf4ac58252210ac40606c436be76208d2eef2db4e119573c
@@ -1,4 +1,4 @@
1
- import { useState, useCallback, useMemo, useEffect, useRef } from 'react';
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
- // Store a reference to the current data to detect changes
184
- const dataRef = useRef(tableData);
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
- // Clear pins when data changes (detected by reference change)
187
- useEffect(() => {
188
- if (loading) return;
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
- // If the data reference changed, clear pins
191
- if (dataRef.current !== tableData) {
192
- dataRef.current = tableData;
193
- onRowPinningChange({ top: [] });
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
- }, [tableData, loading, onRowPinningChange]);
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
- const rows = table.getRowModel().rows;
207
- const collectAllDescendantIds = (subs: Row<GenericObject>[]): string[] =>
208
- subs.flatMap(r => [r.id, ...collectAllDescendantIds(r.subRows)]);
209
- const allPinned: string[] = [];
210
- topPins.forEach(id => {
211
- const parent = rows.find(r => r.id === id && r.depth === 0);
212
- if (parent) {
213
- allPinned.push(parent.id, ...collectAllDescendantIds(parent.subRows));
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
- onRowPinningChange({ top: allPinned });
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