From eb8ce1375445c379e2744569ea7907620092a30b Mon Sep 17 00:00:00 2001 From: Ethan Alvizo Date: Wed, 28 Jun 2023 15:16:30 -0400 Subject: [PATCH 1/7] wip --- packages/iris-grid/src/ColumnStatistics.tsx | 8 +++++++- packages/iris-grid/src/IrisGrid.tsx | 4 +++- packages/iris-grid/src/IrisGridModel.ts | 8 ++++++++ packages/iris-grid/src/IrisGridTableModel.ts | 4 ++++ .../src/mousehandlers/IrisGridContextMenuHandler.tsx | 5 ++++- packages/jsapi-types/src/dh.types.ts | 1 + 6 files changed, 27 insertions(+), 3 deletions(-) diff --git a/packages/iris-grid/src/ColumnStatistics.tsx b/packages/iris-grid/src/ColumnStatistics.tsx index 05a7747792..bb982d28d3 100644 --- a/packages/iris-grid/src/ColumnStatistics.tsx +++ b/packages/iris-grid/src/ColumnStatistics.tsx @@ -2,7 +2,7 @@ import React, { Component, Key } from 'react'; import classNames from 'classnames'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { Button, CopyButton, LoadingSpinner } from '@deephaven/components'; -import { dhFreeze, dhRefresh, vsLock } from '@deephaven/icons'; +import { dhFreeze, dhRefresh, dhSortSlash, vsLock } from '@deephaven/icons'; import type { Column, ColumnStatistics as APIColumnStatistics, @@ -203,6 +203,12 @@ class ColumnStatistics extends Component< {description != null && (
{description}
)} + {columnIndex != null && !model.isColumnSortable(columnIndex) && ( +
+ + Not sortable +
+ )} {columnIndex != null && !model.isColumnMovable(columnIndex) && (
{ modelColumn, addToExisting ); - this.updateSorts(sorts); + if (model.columns[columnIndex].isSortable) { + this.updateSorts(sorts); + } } updateSorts(sorts: readonly Sort[]): void { diff --git a/packages/iris-grid/src/IrisGridModel.ts b/packages/iris-grid/src/IrisGridModel.ts index 586e8342e9..d96065af87 100644 --- a/packages/iris-grid/src/IrisGridModel.ts +++ b/packages/iris-grid/src/IrisGridModel.ts @@ -291,6 +291,14 @@ abstract class IrisGridModel< return false; } + /** + * @param index The column index to check + * @returns Whether the column is sortable + */ + isColumnSortable(index: ModelIndex): boolean { + return false; + } + /** * @returns True if this model requires a filter to be set */ diff --git a/packages/iris-grid/src/IrisGridTableModel.ts b/packages/iris-grid/src/IrisGridTableModel.ts index 96e275ebfd..6fb0ca6f69 100644 --- a/packages/iris-grid/src/IrisGridTableModel.ts +++ b/packages/iris-grid/src/IrisGridTableModel.ts @@ -269,6 +269,10 @@ class IrisGridTableModel extends IrisGridTableModelTemplate { return this.frozenColumns.includes(this.columns[modelIndex].name); } + isColumnSortable(modelIndex: ModelIndex): boolean { + return this.columns[modelIndex].isSortable; + } + async delete(ranges: GridRange[]): Promise { if (!this.isDeletableRanges(ranges)) { throw new Error(`Undeletable ranges ${ranges}`); diff --git a/packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.tsx b/packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.tsx index 81d2642d20..a9a73ea5fd 100644 --- a/packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.tsx +++ b/packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.tsx @@ -203,6 +203,7 @@ class IrisGridContextMenuHandler extends GridMouseHandler { model.getColumnHeaderParentGroup(modelIndex, 0) === undefined && !(isExpandableGridModel(model) && model.hasExpandableRows); const isColumnFrozen = model.isColumnFrozen(modelIndex); + const isColumnSortable = column.isSortable; actions.push({ title: 'Hide Column', group: IrisGridContextMenuHandler.GROUP_HIDE_COLUMNS, @@ -274,6 +275,7 @@ class IrisGridContextMenuHandler extends GridMouseHandler { group: IrisGridContextMenuHandler.GROUP_SORT, order: 10, actions: this.sortByActions(column, modelIndex, columnSort), + disabled: !isColumnSortable, }); actions.push({ title: 'Add Additional Sort', @@ -289,7 +291,8 @@ class IrisGridContextMenuHandler extends GridMouseHandler { (columnSort && modelSort.length === 1) || (hasReverse && modelSort.length === 1) || (columnSort && hasReverse && modelSort.length === 2) || - modelSort.length === 0, + modelSort.length === 0 || + !isColumnSortable, group: IrisGridContextMenuHandler.GROUP_SORT, order: 20, actions: this.additionalSortActions(column, modelIndex), diff --git a/packages/jsapi-types/src/dh.types.ts b/packages/jsapi-types/src/dh.types.ts index 4d614878b8..d4b59b2766 100644 --- a/packages/jsapi-types/src/dh.types.ts +++ b/packages/jsapi-types/src/dh.types.ts @@ -558,6 +558,7 @@ export interface Column { readonly constituentType: string; readonly isPartitionColumn: boolean; + readonly isSortable: boolean; filter(): FilterValue; sort(): Sort; From dc8e06e14a1e9079adbdac7ef51857c1121b7835 Mon Sep 17 00:00:00 2001 From: Ethan Alvizo Date: Wed, 28 Jun 2023 18:00:24 -0400 Subject: [PATCH 2/7] feat: disable column sorting on unsupported types --- packages/iris-grid/src/AdvancedFilterCreator.tsx | 13 +++++++++---- packages/iris-grid/src/IrisGridProxyModel.ts | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/iris-grid/src/AdvancedFilterCreator.tsx b/packages/iris-grid/src/AdvancedFilterCreator.tsx index 927f57d7ec..1fd8e5e8e8 100644 --- a/packages/iris-grid/src/AdvancedFilterCreator.tsx +++ b/packages/iris-grid/src/AdvancedFilterCreator.tsx @@ -202,9 +202,10 @@ class AdvancedFilterCreator extends PureComponent< ); this.valuesTablePromise .then(valuesTable => { - const sort = valuesTable.columns[0].sort().asc(); - valuesTable.applySort([sort]); - + if (valuesTable.columns[0].isSortable) { + const sort = valuesTable.columns[0].sort().asc(); + valuesTable.applySort([sort]); + } this.setState({ valuesTable }); }) .catch(error => { @@ -384,7 +385,9 @@ class AdvancedFilterCreator extends PureComponent< */ sortTable(direction: SortDirection, addToExisting = false): void { const { column, onSortChange } = this.props; - onSortChange(column, direction, addToExisting); + if (column.isSortable) { + onSortChange(column, direction, addToExisting); + } } startUpdateTimer(): void { @@ -565,6 +568,7 @@ class AdvancedFilterCreator extends PureComponent< onClick={this.handleSortDown} icon={dhSortAmountDown} tooltip={`Sort ${column.name} Descending`} + disabled={!column.isSortable} />
diff --git a/packages/iris-grid/src/IrisGridProxyModel.ts b/packages/iris-grid/src/IrisGridProxyModel.ts index ff2cfe64a3..3225096bcc 100644 --- a/packages/iris-grid/src/IrisGridProxyModel.ts +++ b/packages/iris-grid/src/IrisGridProxyModel.ts @@ -273,6 +273,10 @@ class IrisGridProxyModel extends IrisGridModel { return this.model.isColumnFrozen(x); } + isColumnSortable(index: number): boolean { + return this.model.isColumnSortable(index); + } + get hasExpandableRows(): boolean { if (isExpandableGridModel(this.model)) { return this.model.hasExpandableRows; From 0e98a2b62c1b95583560d3fff37f2957ece609e2 Mon Sep 17 00:00:00 2001 From: Ethan Alvizo Date: Thu, 29 Jun 2023 13:56:41 -0400 Subject: [PATCH 3/7] PR feedback --- packages/iris-grid/src/IrisGrid.tsx | 4 +++- packages/iris-grid/src/IrisGridTableModel.ts | 2 +- packages/jsapi-types/src/dh.types.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/iris-grid/src/IrisGrid.tsx b/packages/iris-grid/src/IrisGrid.tsx index 30ae03b24b..40b1a81c1d 100644 --- a/packages/iris-grid/src/IrisGrid.tsx +++ b/packages/iris-grid/src/IrisGrid.tsx @@ -2410,8 +2410,10 @@ export class IrisGrid extends Component { modelColumn, addToExisting ); - if (model.columns[columnIndex].isSortable) { + if (model.columns[columnIndex].isSortable ?? false) { this.updateSorts(sorts); + } else { + log.debug('Column type was not sortable', model.columns[columnIndex]); } } diff --git a/packages/iris-grid/src/IrisGridTableModel.ts b/packages/iris-grid/src/IrisGridTableModel.ts index 6fb0ca6f69..72cc8b5f28 100644 --- a/packages/iris-grid/src/IrisGridTableModel.ts +++ b/packages/iris-grid/src/IrisGridTableModel.ts @@ -270,7 +270,7 @@ class IrisGridTableModel extends IrisGridTableModelTemplate { } isColumnSortable(modelIndex: ModelIndex): boolean { - return this.columns[modelIndex].isSortable; + return this.columns[modelIndex].isSortable ?? false; } async delete(ranges: GridRange[]): Promise { diff --git a/packages/jsapi-types/src/dh.types.ts b/packages/jsapi-types/src/dh.types.ts index d4b59b2766..fadc11b613 100644 --- a/packages/jsapi-types/src/dh.types.ts +++ b/packages/jsapi-types/src/dh.types.ts @@ -558,7 +558,7 @@ export interface Column { readonly constituentType: string; readonly isPartitionColumn: boolean; - readonly isSortable: boolean; + readonly isSortable?: boolean; filter(): FilterValue; sort(): Sort; From abeca3dcb14f43ff457c798f35ae81a5dfdedeeb Mon Sep 17 00:00:00 2001 From: Ethan Alvizo Date: Thu, 29 Jun 2023 15:40:19 -0400 Subject: [PATCH 4/7] handle nullish case --- packages/iris-grid/src/AdvancedFilterCreator.tsx | 8 ++++---- .../src/mousehandlers/IrisGridContextMenuHandler.tsx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/iris-grid/src/AdvancedFilterCreator.tsx b/packages/iris-grid/src/AdvancedFilterCreator.tsx index 1fd8e5e8e8..37e7f71f68 100644 --- a/packages/iris-grid/src/AdvancedFilterCreator.tsx +++ b/packages/iris-grid/src/AdvancedFilterCreator.tsx @@ -202,7 +202,7 @@ class AdvancedFilterCreator extends PureComponent< ); this.valuesTablePromise .then(valuesTable => { - if (valuesTable.columns[0].isSortable) { + if (valuesTable.columns[0].isSortable ?? false) { const sort = valuesTable.columns[0].sort().asc(); valuesTable.applySort([sort]); } @@ -385,7 +385,7 @@ class AdvancedFilterCreator extends PureComponent< */ sortTable(direction: SortDirection, addToExisting = false): void { const { column, onSortChange } = this.props; - if (column.isSortable) { + if (column.isSortable ?? false) { onSortChange(column, direction, addToExisting); } } @@ -568,7 +568,7 @@ class AdvancedFilterCreator extends PureComponent< onClick={this.handleSortDown} icon={dhSortAmountDown} tooltip={`Sort ${column.name} Descending`} - disabled={!column.isSortable} + disabled={!(column.isSortable ?? false)} />