From 9610545fef2c5129702d0d32528d06efd9233230 Mon Sep 17 00:00:00 2001 From: georgecwan Date: Wed, 25 Oct 2023 10:35:12 -0700 Subject: [PATCH] Add legacy format for dehydrated state --- .../src/styleguide/MockIrisGridTreeModel.ts | 2 +- .../src/panels/IrisGridPanel.tsx | 18 ++--- .../src/IrisGridPartitionSelector.tsx | 5 +- packages/iris-grid/src/IrisGridUtils.ts | 73 +++++++++++++------ 4 files changed, 59 insertions(+), 39 deletions(-) diff --git a/packages/code-studio/src/styleguide/MockIrisGridTreeModel.ts b/packages/code-studio/src/styleguide/MockIrisGridTreeModel.ts index 429719758f..e28f8d77aa 100644 --- a/packages/code-studio/src/styleguide/MockIrisGridTreeModel.ts +++ b/packages/code-studio/src/styleguide/MockIrisGridTreeModel.ts @@ -321,7 +321,7 @@ class MockIrisGridTreeModel throw new Error('Not defined in mock'); } - valuesTable(columns: Column[]): Promise { + valuesTable(columns: Column | Column[]): Promise { throw new Error('Not defined in mock'); } diff --git a/packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx b/packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx index 275fde6ad9..c99424a502 100644 --- a/packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx +++ b/packages/dashboard-core-plugins/src/panels/IrisGridPanel.tsx @@ -39,6 +39,7 @@ import { IrisGridState, ChartBuilderSettings, DehydratedIrisGridState, + DehydratedIrisGridPanelState, ColumnHeaderGroup, IrisGridContextMenuData, IrisGridTableModel, @@ -114,12 +115,7 @@ export interface PanelState { movedRows: MoveOperation[]; }; irisGridState: DehydratedIrisGridState; - irisGridPanelState: { - partitionColumns: ColumnName[]; - partitions: (string | null)[]; - isSelectingPartition: boolean; - advancedSettings: [AdvancedSettingsType, boolean][]; - }; + irisGridPanelState: DehydratedIrisGridPanelState; pluginState: unknown; } @@ -127,10 +123,12 @@ export interface PanelState { // even though they can't be undefined in the dehydrated state. // This can happen when loading the state saved before the properties were added. type LoadedPanelState = PanelState & { - irisGridPanelState: PanelState['irisGridPanelState'] & - Partial< - Pick - >; + irisGridPanelState: PanelState['irisGridPanelState'] & { + partitions?: (string | null)[]; + partitionColumns?: ColumnName[]; + partition?: string | null; + partitionColumn?: ColumnName; + }; }; export interface IrisGridPanelProps extends DashboardPanelProps { diff --git a/packages/iris-grid/src/IrisGridPartitionSelector.tsx b/packages/iris-grid/src/IrisGridPartitionSelector.tsx index c75f627b66..268149f497 100644 --- a/packages/iris-grid/src/IrisGridPartitionSelector.tsx +++ b/packages/iris-grid/src/IrisGridPartitionSelector.tsx @@ -140,10 +140,7 @@ class IrisGridPartitionSelector extends Component< } const newPartitions = [...partitions]; - newPartitions[index] = - TableUtils.isCharType(columns[index].type) && partition.length > 0 - ? partition.charCodeAt(0).toString() - : partition; + newPartitions[index] = partition; if (partitionTables) { this.updatePartitionFilters(newPartitions, partitionTables); } diff --git a/packages/iris-grid/src/IrisGridUtils.ts b/packages/iris-grid/src/IrisGridUtils.ts index fd8c19264e..39172fb60c 100644 --- a/packages/iris-grid/src/IrisGridUtils.ts +++ b/packages/iris-grid/src/IrisGridUtils.ts @@ -143,6 +143,38 @@ export interface DehydratedIrisGridState { columnHeaderGroups?: readonly ColumnGroup[]; } +export interface DehydratedIrisGridPanelStateV1 { + isSelectingPartition: boolean; + partition: string | null; + partitionColumn: ColumnName; + advancedSettings: [AdvancedSettingsType, boolean][]; +} + +export interface DehydratedIrisGridPanelStateV2 { + isSelectingPartition: boolean; + partitions: (string | null)[]; + partitionColumns: ColumnName[]; + advancedSettings: [AdvancedSettingsType, boolean][]; +} + +export type DehydratedIrisGridPanelState = + | DehydratedIrisGridPanelStateV1 + | DehydratedIrisGridPanelStateV2; + +export function isPanelStateV1( + state: DehydratedIrisGridPanelState +): state is DehydratedIrisGridPanelStateV1 { + return (state as DehydratedIrisGridPanelStateV1).partitionColumn != null; +} + +export function isPanelStateV2( + state: DehydratedIrisGridPanelState +): state is DehydratedIrisGridPanelStateV2 { + return Array.isArray( + (state as DehydratedIrisGridPanelStateV2).partitionColumns + ); +} + /** * Checks if an index is valid for the given array * @param x The index to check @@ -279,12 +311,7 @@ class IrisGridUtils { partitionColumns: Column[]; advancedSettings: Map; } - ): { - isSelectingPartition: boolean; - partitions: (string | null)[]; - partitionColumns: ColumnName[]; - advancedSettings: [AdvancedSettingsType, boolean][]; - } { + ): DehydratedIrisGridPanelState { const { isSelectingPartition, partitions, @@ -311,25 +338,21 @@ class IrisGridUtils { */ static hydrateIrisGridPanelState( model: IrisGridModel, - irisGridPanelState: { - // This needs to be changed after IrisGridPanel is done - isSelectingPartition: boolean; - partitions: (string | null)[]; - partitionColumns: ColumnName[]; - advancedSettings: [AdvancedSettingsType, boolean][]; - } + irisGridPanelState: DehydratedIrisGridPanelState ): { isSelectingPartition: boolean; partitions: (string | null)[]; partitionColumns: Column[]; advancedSettings: Map; } { - const { - isSelectingPartition, - partitions, - partitionColumns, - advancedSettings, - } = irisGridPanelState; + const { isSelectingPartition, advancedSettings } = irisGridPanelState; + + const { partitionColumns, partitions } = isPanelStateV2(irisGridPanelState) + ? irisGridPanelState + : { + partitionColumns: [irisGridPanelState.partitionColumn], + partitions: [irisGridPanelState.partition], + }; const { columns } = model; return { @@ -391,10 +414,7 @@ class IrisGridUtils { static extractTableSettings( panelState: { irisGridState: { advancedFilters: AF; quickFilters: QF; sorts: S }; - irisGridPanelState: { - partitionColumns: ColumnName[]; - partitions: unknown[]; - }; + irisGridPanelState: DehydratedIrisGridPanelState; }, inputFilters: InputFilter[] = [] ): { @@ -406,7 +426,12 @@ class IrisGridUtils { sorts: S; } { const { irisGridPanelState, irisGridState } = panelState; - const { partitionColumns, partitions } = irisGridPanelState; + const { partitionColumns, partitions } = isPanelStateV2(irisGridPanelState) + ? irisGridPanelState + : { + partitionColumns: [irisGridPanelState.partitionColumn], + partitions: [irisGridPanelState.partition], + }; const { advancedFilters, quickFilters, sorts } = irisGridState; return {