Skip to content

Commit

Permalink
change default sortable state
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanalvizo committed Jul 5, 2023
1 parent cddd8ce commit 00de9ce
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
38 changes: 26 additions & 12 deletions packages/iris-grid/src/AdvancedFilterCreator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import {
} from '@deephaven/jsapi-utils';
import { Button, ContextActionUtils } from '@deephaven/components';
import Log from '@deephaven/log';
import { CancelablePromise, PromiseUtils } from '@deephaven/utils';
import {
assertNotNull,
CancelablePromise,
PromiseUtils,
} from '@deephaven/utils';
import type { Column, FilterCondition, Table } from '@deephaven/jsapi-types';
import shortid from 'shortid';
import AdvancedFilterCreatorFilterItem from './AdvancedFilterCreatorFilterItem';
Expand Down Expand Up @@ -75,6 +79,8 @@ interface AdvancedFilterCreatorState {

valuesTableError: null;
valuesTable?: Table;

isSortable: boolean;
}

class AdvancedFilterCreator extends PureComponent<
Expand Down Expand Up @@ -119,7 +125,7 @@ class AdvancedFilterCreator extends PureComponent<

this.focusTrapContainer = React.createRef();

const { options } = props;
const { model, column, options } = props;
let { filterOperators, invertSelection, selectedValues } = options;

// can be null or an empty array
Expand All @@ -142,6 +148,10 @@ class AdvancedFilterCreator extends PureComponent<
selectedValues = [];
}

const columnIndex = model.getColumnIndexByName(column.name);
assertNotNull(columnIndex);
const isSortable = model.isColumnSortable(columnIndex);

this.state = {
// Filter items
filterItems,
Expand All @@ -155,6 +165,8 @@ class AdvancedFilterCreator extends PureComponent<

valuesTableError: null,
valuesTable: undefined,

isSortable,
};
}

Expand Down Expand Up @@ -202,7 +214,11 @@ class AdvancedFilterCreator extends PureComponent<
);
this.valuesTablePromise
.then(valuesTable => {
if (valuesTable.columns[0].isSortable ?? false) {
const columnIndex = model.getColumnIndexByName(
valuesTable.columns[0].name
);
assertNotNull(columnIndex);
if (model.isColumnSortable(columnIndex)) {
const sort = valuesTable.columns[0].sort().asc();
valuesTable.applySort([sort]);
}
Expand Down Expand Up @@ -385,7 +401,8 @@ class AdvancedFilterCreator extends PureComponent<
*/
sortTable(direction: SortDirection, addToExisting = false): void {
const { column, onSortChange } = this.props;
if (column.isSortable ?? false) {
const { isSortable } = this.state;
if (isSortable) {
onSortChange(column, direction, addToExisting);
}
}
Expand Down Expand Up @@ -457,6 +474,7 @@ class AdvancedFilterCreator extends PureComponent<
selectedValues,
valuesTable,
valuesTableError,
isSortable,
} = this.state;
const { dh, isValuesTableAvailable } = model;
const isBoolean = TableUtils.isBooleanType(column.type);
Expand Down Expand Up @@ -568,11 +586,9 @@ class AdvancedFilterCreator extends PureComponent<
onClick={this.handleSortDown}
icon={dhSortAmountDown}
tooltip={
column.isSortable ?? false
? `Sort ${column.name} Descending`
: 'Not sortable'
isSortable ? `Sort ${column.name} Descending` : 'Not sortable'
}
disabled={!(column.isSortable ?? false)}
disabled={!isSortable}
/>
<Button
kind="ghost"
Expand All @@ -584,11 +600,9 @@ class AdvancedFilterCreator extends PureComponent<
<FontAwesomeIcon icon={dhSortAmountDown} rotation={180} />
}
tooltip={
column.isSortable ?? false
? `Sort ${column.name} Ascending`
: 'Not sortable'
isSortable ? `Sort ${column.name} Ascending` : 'Not sortable'
}
disabled={!(column.isSortable ?? false)}
disabled={!isSortable}
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/iris-grid/src/IrisGridTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class IrisGridTableModel extends IrisGridTableModelTemplate<Table, UIRow> {
}

isColumnSortable(modelIndex: ModelIndex): boolean {
return this.columns[modelIndex].isSortable ?? false;
return this.columns[modelIndex].isSortable ?? true;
}

async delete(ranges: GridRange[]): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
model.getColumnHeaderParentGroup(modelIndex, 0) === undefined &&
!(isExpandableGridModel(model) && model.hasExpandableRows);
const isColumnFrozen = model.isColumnFrozen(modelIndex);
const isColumnSortable = column.isSortable ?? false;
const isColumnSortable = model.isColumnSortable(modelIndex);
actions.push({
title: 'Hide Column',
group: IrisGridContextMenuHandler.GROUP_HIDE_COLUMNS,
Expand Down

0 comments on commit 00de9ce

Please sign in to comment.