Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshatJawne committed Aug 22, 2024
1 parent 8c80230 commit 1cbc60d
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,11 @@ export class FormattingSectionContent extends PureComponent<
<div className="form-row mb-3" id="show_extra_group_column_div">
<label
className="col-form-label col-3"
htmlFor="default-integer-format-input"
htmlFor="default-show-extra-group-column"
>
Rollup
</label>
<div className="col pr-0 pt-2" id="show_extra_grou_column_cb">
<div className="col pr-0 pt-2" id="default-show-extra-group-column">
<Checkbox
checked={showExtraGroupColumn}
onChange={this.handleShowExtraGroupColumnChange}
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ module.exports = {
'react/jsx-uses-react': 'error',
'react/jsx-uses-vars': 'error',
'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }],
'react-hooks/exhaustive-deps': [
'warn',
{
additionalHooks: '(useOnChange)',
},
],
'react/react-in-jsx-scope': 'off',
'react/sort-comp': [
2,
Expand Down
4 changes: 2 additions & 2 deletions packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1986,8 +1986,7 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
this.integerFormatOptions,
this.truncateNumbersWithPound,
this.showEmptyStrings,
this.showNullStrings,
this.showExtraGroupColumn
this.showNullStrings
);

log.debug('updateFormatter', this.globalColumnFormats, mergedColumnFormats);
Expand Down Expand Up @@ -4866,6 +4865,7 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
frozenColumns={frozenColumns}
columnHeaderGroups={columnHeaderGroups}
partitionConfig={partitionConfig}
showExtraGroupColumn={this.showExtraGroupColumn}
/>
)}
{!isMenuShown && (
Expand Down
14 changes: 10 additions & 4 deletions packages/iris-grid/src/IrisGridModelUpdater.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
PartitionConfig,
isPartitionedGridModel,
} from './PartitionedGridModel';
import { isIrisGridTreeTableModel } from './IrisGridTreeTableModel';

const COLUMN_BUFFER_PAGES = 1;

Expand All @@ -40,6 +41,7 @@ interface IrisGridModelUpdaterProps {
pendingRowCount?: number;
pendingDataMap?: PendingDataMap;
partitionConfig?: PartitionConfig;
showExtraGroupColumn?: boolean;
}

/**
Expand Down Expand Up @@ -68,10 +70,15 @@ function IrisGridModelUpdater({
formatColumns,
columnHeaderGroups,
partitionConfig,
showExtraGroupColumn,
}: IrisGridModelUpdaterProps): JSX.Element | null {
if (model.formatter !== formatter) {
model.formatter = formatter;
}
// Check for showExtraGroupColumn before memoizing columns, since updating it will change the columns
useOnChange(() => {
if (isIrisGridTreeTableModel(model) && showExtraGroupColumn != null) {
model.showExtraGroupColumn = showExtraGroupColumn;
}
}, [model, showExtraGroupColumn]);

const columns = useMemo(
() =>
IrisGridUtils.getModelViewportColumns(
Expand All @@ -92,7 +99,6 @@ function IrisGridModelUpdater({
alwaysFetchColumns,
]
);

useOnChange(
function updateFilter() {
model.filter = filter;
Expand Down
35 changes: 19 additions & 16 deletions packages/iris-grid/src/IrisGridTreeTableModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,46 @@ function isLayoutTreeTable(table: DhType.TreeTable): table is LayoutTreeTable {
return (table as LayoutTreeTable).layoutHints !== undefined;
}

export function isIrisGridTreeTableModel(
tableModel: IrisGridModel
): tableModel is IrisGridTreeTableModel {
return (tableModel as IrisGridTreeTableModel).showExtraGroupColumn != null;
}

class IrisGridTreeTableModel extends IrisGridTableModelTemplate<
DhType.TreeTable,
UITreeRow
> {
/** We keep a virtual column at the front that tracks the "group" that is expanded */
private virtualColumns: DisplayColumn[];

private showExtraGroupCol = true;

constructor(
dh: typeof DhType,
table: DhType.TreeTable,
formatter = new Formatter(dh),
inputTable: DhType.InputTable | null = null
) {
super(dh, table, formatter, inputTable);
this.virtualColumns = this.formatter.showExtraGroupColumn
? [VirtualGroupColumn]
: [];

this.virtualColumns = this.showExtraGroupColumn ? [VirtualGroupColumn] : [];
}

set formatter(newFormatter: Formatter) {
const oldFormatter = super.formatter;
super.formatter = newFormatter;
if (
newFormatter.showExtraGroupColumn !== oldFormatter.showExtraGroupColumn
) {
this.updateVirtualColumns();
}
get showExtraGroupColumn(): boolean {
return this.showExtraGroupCol;
}

get formatter(): Formatter {
return super.formatter;
set showExtraGroupColumn(showExtraGroupCol: boolean) {
if (this.showExtraGroupCol === showExtraGroupCol) {
return;
}
this.showExtraGroupCol = showExtraGroupCol;
this.updateVirtualColumns();
}

updateVirtualColumns(): void {
this.virtualColumns = this.formatter.showExtraGroupColumn
? [VirtualGroupColumn]
: [];
this.virtualColumns = this.showExtraGroupColumn ? [VirtualGroupColumn] : [];
this.dispatchEvent(
new EventShimCustomEvent(IrisGridModel.EVENT.COLUMNS_CHANGED, {
detail: this.columns,
Expand Down
6 changes: 1 addition & 5 deletions packages/jsapi-utils/src/Formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ export class Formatter {
>[1],
truncateNumbersWithPound = false,
showEmptyStrings = true,
showNullStrings = true,
showExtraGroupColumn = true
showNullStrings = true
) {
// Formatting order:
// - columnFormatMap[type][name]
Expand Down Expand Up @@ -121,7 +120,6 @@ export class Formatter {

this.showEmptyStrings = showEmptyStrings;
this.showNullStrings = showNullStrings;
this.showExtraGroupColumn = showExtraGroupColumn;
}

defaultColumnFormatter: TableColumnFormatter;
Expand All @@ -136,8 +134,6 @@ export class Formatter {

showNullStrings: boolean;

showExtraGroupColumn: boolean;

/**
* Gets columnFormatMap indexed by name for a given column type, creates new Map entry if necessary
* @param columnType column type
Expand Down
4 changes: 1 addition & 3 deletions packages/jsapi-utils/src/FormatterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function createFormatterFromSettings(
truncateNumbersWithPound,
showEmptyStrings,
showNullStrings,
showExtraGroupColumn,
} = settings ?? {};

return new Formatter(
Expand All @@ -37,8 +36,7 @@ export function createFormatterFromSettings(
defaultIntegerFormatOptions,
truncateNumbersWithPound,
showEmptyStrings,
showNullStrings,
showExtraGroupColumn
showNullStrings
);
}

Expand Down

0 comments on commit 1cbc60d

Please sign in to comment.