Skip to content

Commit 11df934

Browse files
authored
fix: DH-21407: Dehydrate/hydrate pending data correctly (#2606)
- We were tryin to dehydrate the CellData object instead of the value itself - Just dehydrate the value itself - Fix the tests - This seems to have been broken for a long time, and only now it's being caught when attempting to persist deephaven.ui data
1 parent ec1192b commit 11df934

2 files changed

Lines changed: 21 additions & 26 deletions

File tree

packages/iris-grid/src/IrisGridUtils.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ describe('pendingDataMap hydration/dehydration', () => {
226226
1,
227227
{
228228
data: new Map([
229-
[3, 'Foo'],
230-
[4, 'Bar'],
229+
[3, { value: 'Foo' }],
230+
[4, { value: 'Bar' }],
231231
]),
232232
},
233233
],
234234
[
235235
10,
236236
{
237-
data: new Map([[7, 'Baz']]),
237+
data: new Map([[7, { value: 'Baz' }]]),
238238
},
239239
],
240240
]);
@@ -267,10 +267,16 @@ describe('pendingDataMap hydration/dehydration', () => {
267267
);
268268
expect(hydratedMap.size).toBe(2);
269269
expect(hydratedMap.get(1)?.data.size).toBe(2);
270-
expect(hydratedMap.get(1)?.data.get(3)).toEqual('Foo');
271-
expect(hydratedMap.get(1)?.data.get(4)).toEqual('Bar');
270+
expect(hydratedMap.get(1)?.data.get(3)).toEqual(
271+
expect.objectContaining({ value: 'Foo' })
272+
);
273+
expect(hydratedMap.get(1)?.data.get(4)).toEqual(
274+
expect.objectContaining({ value: 'Bar' })
275+
);
272276
expect(hydratedMap.get(10)?.data.size).toBe(1);
273-
expect(hydratedMap.get(10)?.data.get(7)).toEqual('Baz');
277+
expect(hydratedMap.get(10)?.data.get(7)).toEqual(
278+
expect.objectContaining({ value: 'Baz' })
279+
);
274280
});
275281
});
276282

packages/iris-grid/src/IrisGridUtils.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export interface DehydratedIrisGridState {
148148
selectDistinctColumns: readonly ColumnName[];
149149
selectedSearchColumns: readonly ColumnName[];
150150
invertSearchColumns: boolean;
151-
pendingDataMap: DehydratedPendingDataMap<string | CellData | null>;
151+
pendingDataMap: DehydratedPendingDataMap<unknown>;
152152
frozenColumns: readonly ColumnName[];
153153
columnHeaderGroups?: readonly DhType.ColumnGroup[];
154154
partitionConfig?: DehydratedPartitionConfig;
@@ -1495,36 +1495,28 @@ class IrisGridUtils {
14951495

14961496
dehydratePendingDataMap(
14971497
columns: readonly DhType.Column[],
1498-
pendingDataMap: ReadonlyMap<
1499-
ModelIndex,
1500-
{
1501-
data: Map<ModelIndex | ColumnName, CellData | string>;
1502-
}
1503-
>
1504-
): DehydratedPendingDataMap<CellData | string | null> {
1498+
pendingDataMap: PendingDataMap
1499+
): DehydratedPendingDataMap<unknown> {
15051500
return [...pendingDataMap].map(([rowIndex, { data }]) => [
15061501
rowIndex,
15071502
{
15081503
data: [...data]
15091504
.filter(([c]) => typeof c === 'number')
1510-
.map(([c, value]) => [
1505+
.map(([c, cellData]) => [
15111506
columns[c as number].name,
1512-
this.dehydrateValue(value, columns[c as number].type),
1507+
this.dehydrateValue(cellData.value, columns[c as number].type),
15131508
]),
15141509
},
15151510
]);
15161511
}
15171512

15181513
hydratePendingDataMap(
15191514
columns: readonly DhType.Column[],
1520-
pendingDataMap: DehydratedPendingDataMap<CellData | string | null>
1515+
pendingDataMap: DehydratedPendingDataMap<unknown>
15211516
): Map<
15221517
number,
15231518
{
1524-
data: Map<
1525-
ModelIndex | null,
1526-
string | CellData | DhType.LongWrapper | null
1527-
>;
1519+
data: Map<ModelIndex | null, CellData>;
15281520
}
15291521
> {
15301522
const columnMap = new Map<ColumnName, number>();
@@ -1540,10 +1532,7 @@ class IrisGridUtils {
15401532

15411533
return new Map(
15421534
pendingDataMap.map(
1543-
([rowIndex, { data }]: [
1544-
number,
1545-
{ data: [string, CellData | string | null][] },
1546-
]) => [
1535+
([rowIndex, { data }]: [number, { data: [string, unknown][] }]) => [
15471536
rowIndex,
15481537
{
15491538
data: new Map(
@@ -1552,7 +1541,7 @@ class IrisGridUtils {
15521541
assertNotNull(index);
15531542
return [
15541543
getColumnIndex(columnName) ?? null,
1555-
this.hydrateValue(value, columns[index].type),
1544+
{ value: this.hydrateValue(value, columns[index].type) },
15561545
];
15571546
})
15581547
),

0 commit comments

Comments
 (0)