Skip to content

Commit

Permalink
Get hide columns working
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Jun 12, 2024
1 parent f50f8aa commit 6b6a637
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 12 deletions.
5 changes: 5 additions & 0 deletions js/core/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export namespace Transform {
*/
type: 'hide';

/**
* The column in the data schema to apply the transformation to.
*/
column: string;

/**
* The column in the data schema to apply the transformation to.
*/
Expand Down
5 changes: 5 additions & 0 deletions js/core/transformExecutors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export namespace HideExecutor {
*/
field: string;

/**
* The data type of the column associated with this transform.
*/
dType: string;

/**
* Boolean indicating if all columns should be hidden
*/
Expand Down
12 changes: 10 additions & 2 deletions js/core/transformStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class TransformStateManager {
this._state[transform.column]['filter'] = transform;
break;
case 'hide':
this._state[transform.columnIndex]['hide'] = transform;
this._state[transform.column]['hide'] = transform;
break;
default:
throw 'unreachable';
Expand Down Expand Up @@ -153,8 +153,16 @@ export class TransformStateManager {
filterExecutors.push(executor);
}
if (transform.hide) {
let dType = '';
for (const field of data.schema.fields) {
if (field.name === transform.hide.column) {
dType = field.type;
}
}

const executor = new HideExecutor({
field: data.schema.fields[transform.hide.columnIndex]['name'],
field: transform.hide.column,
dType,
hideAll: transform.hide.hideAll,
});
hideExecutors.push(executor);
Expand Down
2 changes: 0 additions & 2 deletions js/core/viewbasedjsonmodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export class ViewBasedJSONModel extends MutableDataModel {
*/
updateDataset(data: DataSource): void {
this._dataset = data;
// does not happen when selecting hide column
this._updatePrimaryKeyMap();
const view = new View(this._dataset);
this.currentView = view;
Expand Down Expand Up @@ -567,7 +566,6 @@ export class ViewBasedJSONModel extends MutableDataModel {
}
// We need to rerun the transforms, as the changed cells may change the order
// or visibility of other rows
console.log('update row value');
this.currentView = this._transformState.createView(this._dataset);
}

Expand Down
23 changes: 15 additions & 8 deletions js/feathergrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1074,14 +1074,20 @@ export class FeatherGrid extends Widget {
label: 'Hide Column',
mnemonic: -1,
execute: (args) => {
const cellClick: FeatherGridContextMenu.CommandArgs =
const command: FeatherGridContextMenu.CommandArgs =
args as FeatherGridContextMenu.CommandArgs;

const colIndex = this._dataModel.getSchemaIndex(
cellClick.region,
cellClick.columnIndex,
command.region,
command.columnIndex,
);

const column =
this.dataModel.currentView.dataset.schema.fields[colIndex];

this._dataModel.addTransform({
type: 'hide',
column: column.name,
columnIndex: colIndex,
hideAll: false,
});
Expand All @@ -1097,8 +1103,13 @@ export class FeatherGrid extends Widget {
cellClick.region,
cellClick.columnIndex,
);

const column =
this.dataModel.currentView.dataset.schema.fields[colIndex];

this._dataModel.addTransform({
type: 'hide',
column: column.name,
columnIndex: colIndex,
hideAll: true,
});
Expand All @@ -1110,14 +1121,10 @@ export class FeatherGrid extends Widget {
execute: () => {
const activeTransforms: Transform.TransformSpec[] =
this._dataModel.activeTransforms;
console.log(
'this._dataModel.activeTransforms',
this._dataModel.activeTransforms,
);

const newTransforms = activeTransforms.filter(
(val) => val.type !== 'hide',
);
console.log('newTransforms', newTransforms);
this._dataModel.replaceTransforms(newTransforms);
},
});
Expand Down

0 comments on commit 6b6a637

Please sign in to comment.