playbook_ui 14.22.0.pre.alpha.PLAY2292advancedtablepinnedrowsloading8632 → 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: 1a87d5a3b0f1ba4c0e20a6d286acb82d538fb5bd2cb68700d81df41cf44f1449
4
- data.tar.gz: 507e84e412dc50c8020a636f6c46e1fa326605de6ba7ffbd60499790770d6c54
3
+ metadata.gz: 50940c977e833de1ec35e25c6269e332057fc06778dd67d44d2e59ab4ddd799e
4
+ data.tar.gz: def4a38171d0f1a0a97bcf80ddb277491d34b5661bcdb2d83b5f7c53c7bc9497
5
5
  SHA512:
6
- metadata.gz: 90f4a2e682d5d0575ea805a1adc4a0bde6aaf65bb592093c4c98a8122eab250960f90547c9c64ac17724331933ba040a5fb4d60b7bab8b800cc87d01af6cbbf5
7
- data.tar.gz: 2a44d15f9f3d820cd44c807cdaab752bd116b2e0ba30dac1dcfdee66f5e1e47828b9c507008948d2baef396cf5ccb780ae4b0c328bf650081ad2f3c5feaa8c78
6
+ metadata.gz: 492530c127fd34e4edaf65b5afea93df1c41ebe96fd62aaffc2d398ba788cd88d6703175c406c62c6e9bd024f0bdf45f7a2b5ade54e44691a86c63c01556562f
7
+ data.tar.gz: dba59d34834a6c95d44fa1253641a2d29eccc7762abe866903f30948a04260fce9bf4393e5c4f013cf4ac58252210ac40606c436be76208d2eef2db4e119573c
@@ -188,16 +188,28 @@ export function useTableState({
188
188
  }, [tableData, dataChunk, virtualizedRows, loading]);
189
189
 
190
190
  const [prevDataHash, setPrevDataHash] = useState(dataHash);
191
-
192
- // Clear pins when data actually changes (by ID composition)
193
- useEffect(() => {
194
- if (loading) return;
191
+
192
+ // Synchronously clear pins when data changes to prevent table errors
193
+ if (!loading && dataHash !== prevDataHash) {
194
+ setPrevDataHash(dataHash);
195
195
 
196
- if (dataHash !== prevDataHash) {
197
- setPrevDataHash(dataHash);
198
- 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
+ }
199
211
  }
200
- }, [dataHash, prevDataHash, loading, onRowPinningChange]);
212
+ }
201
213
 
202
214
  // Handle row pinning changes
203
215
  useEffect(() => {
@@ -208,17 +220,48 @@ export function useTableState({
208
220
  onRowPinningChange({ top: [] });
209
221
  return;
210
222
  }
211
- const rows = table.getRowModel().rows;
212
- const collectAllDescendantIds = (subs: Row<GenericObject>[]): string[] =>
213
- subs.flatMap(r => [r.id, ...collectAllDescendantIds(r.subRows)]);
214
- const allPinned: string[] = [];
215
- topPins.forEach(id => {
216
- const parent = rows.find(r => r.id === id && r.depth === 0);
217
- if (parent) {
218
- 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;
219
239
  }
220
- });
221
- 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
+ }
222
265
  }, [table, pinnedRows?.value?.top?.join(','), loading]);
223
266
 
224
267
  // Check if table has any sub-rows