Skip to content

Commit

Permalink
Don't allow available columns to be enhanced with properties from lef…
Browse files Browse the repository at this point in the history
…t / right column during Store field creation
  • Loading branch information
TomTirapani committed Nov 1, 2023
1 parent 06ec714 commit 968d68f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmp/grid/renderers/MultiFieldRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function renderMainField(value, renderer, context) {

function renderSubField({colId, label}, context) {
const {record, gridModel} = context,
column = gridModel.findColumn(gridModel.columns, colId);
column = gridModel.getColumn(colId);

throwIf(!column, `Subfield ${colId} not found`);

Expand Down
69 changes: 33 additions & 36 deletions cmp/zonedGrid/ZonedGridModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,7 @@ export class ZonedGridModel extends HoistModel {
groupBy: groupBy
};

this.gridModel = this.createGridModel({
...rest,
contextMenu: withDefault(rest.contextMenu, this.getDefaultContextMenu)
});
this.gridModel = this.createGridModel(rest);

this.setSortBy(sortBy);
this.setGroupBy(groupBy);
Expand Down Expand Up @@ -243,6 +240,35 @@ export class ZonedGridModel extends HoistModel {
//-----------------------
// Getters and methods trampolined from GridModel.
//-----------------------
get sortBy(): GridSorter {
const ret = this.gridModel.sortBy?.[0];
if (!ret) return null;

// Normalize 'left_column' and 'right_column' to actual underlying fields
if (ret?.colId === 'left_column') {
const colId = this.mappings.tl[0]?.field;
return colId ? new GridSorter({...ret, colId}) : null;
} else if (ret?.colId === 'right_column') {
const colId = this.mappings.tr[0]?.field;
return colId ? new GridSorter({...ret, colId}) : null;
}

return ret;
}

setSortBy(cfg: GridSorterLike) {
// If the field is mapping to the primary field in a left/right column, set
// 'left_column'/'right_column' colId instead to display the arrows in the header.
const sorter = GridSorter.parse(cfg);
if (sorter?.colId === this.mappings.tl[0]?.field) {
return this.gridModel.setSortBy({...sorter, colId: 'left_column'});
}
if (sorter?.colId === this.mappings.tr[0]?.field) {
return this.gridModel.setSortBy({...sorter, colId: 'right_column'});
}
return this.gridModel.setSortBy(sorter);
}

get store() {
return this.gridModel.store;
}
Expand Down Expand Up @@ -275,22 +301,6 @@ export class ZonedGridModel extends HoistModel {
return this.gridModel.groupBy;
}

get sortBy(): GridSorter {
const ret = this.gridModel.sortBy?.[0];
if (!ret) return null;

// Normalize 'left_column' and 'right_column' to actual underlying fields
if (ret?.colId === 'left_column') {
const colId = this.mappings.tl[0]?.field;
return colId ? new GridSorter({...ret, colId}) : null;
} else if (ret?.colId === 'right_column') {
const colId = this.mappings.tr[0]?.field;
return colId ? new GridSorter({...ret, colId}) : null;
}

return ret;
}

selectAsync(
records: Some<StoreRecordOrId>,
opts: {ensureVisible?: boolean; clearSelection?: boolean}
Expand Down Expand Up @@ -330,25 +340,13 @@ export class ZonedGridModel extends HoistModel {
return this.gridModel.setGroupBy(colIds);
}

setSortBy(cfg: GridSorterLike) {
// If the field is mapping to the primary field in a left/right column, set
// 'left_column'/'right_column' colId instead to display the arrows in the header.
const sorter = GridSorter.parse(cfg);
if (sorter?.colId === this.mappings.tl[0]?.field) {
return this.gridModel.setSortBy({...sorter, colId: 'left_column'});
}
if (sorter?.colId === this.mappings.tr[0]?.field) {
return this.gridModel.setSortBy({...sorter, colId: 'right_column'});
}
return this.gridModel.setSortBy(sorter);
}

//-----------------------
// Implementation
//-----------------------
private createGridModel(config: GridConfig): GridModel {
return new GridModel({
...config,
contextMenu: withDefault(config.contextMenu, this.getDefaultContextMenu),
sizingMode: 'standard',
cellBorders: true,
rowBorders: true,
Expand Down Expand Up @@ -390,9 +388,7 @@ export class ZonedGridModel extends HoistModel {

return {
// Controlled properties
colId: isLeft ? 'left_column' : 'right_column',
headerName: primaryCol.headerName,
field: primaryCol.field,
field: isLeft ? 'left_column' : 'right_column',
flex: isLeft ? 2 : 1,
align: isLeft ? 'left' : 'right',
renderer: multiFieldRenderer,
Expand All @@ -409,6 +405,7 @@ export class ZonedGridModel extends HoistModel {
},

// Properties inherited from primary column
headerName: primaryCol.headerName,
absSort: primaryCol.absSort,
sortingOrder: primaryCol.sortingOrder,
sortValue: primaryCol.sortValue,
Expand Down
2 changes: 0 additions & 2 deletions desktop/cmp/zonedGrid/impl/ZoneMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ class ZoneMapperLocalModel extends HoistModel {
data.push({...f, show, label});
});

console.log(data);

// 2) Load into display grid
this.gridModel.loadData(data);
}
Expand Down

0 comments on commit 968d68f

Please sign in to comment.