Skip to content

Commit

Permalink
refactor(react-grid): change the 'expandedGroups' Getter data type (#661
Browse files Browse the repository at this point in the history
)

BREAKING CHANGE:

We changed the `expandedGroups` getter's data type from `Set` to `Array` to improve the API consistency.
  • Loading branch information
SergeyAlexeev authored Jan 10, 2018
1 parent ae78d23 commit f078d3a
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export const expandedGroupRows = (rows, grouping, expandedGroups) => {
if (!grouping.length) return rows;

const groupingColumnNames = grouping.map(columnGrouping => columnGrouping.columnName);
const expandedGroupsSet = new Set(expandedGroups);
let currentGroupExpanded = true;
let currentGroupLevel = 0;

Expand All @@ -87,7 +88,7 @@ export const expandedGroupRows = (rows, grouping, expandedGroups) => {
return acc;
}

currentGroupExpanded = expandedGroups.has(row.compoundKey);
currentGroupExpanded = expandedGroupsSet.has(row.compoundKey);
currentGroupLevel = groupLevel;

if (currentGroupExpanded) {
Expand Down
4 changes: 2 additions & 2 deletions packages/dx-react-grid/docs/reference/custom-grouping.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Name | Plugin | Type | Description
-----|--------|------|------------
rows | Getter | Array<any> | Rows to be grouped.
grouping | Getter | Array<[Grouping](grouping-state.md#grouping)> | The current grouping state.
expandedGroups | Getter | Set<[GroupKey](grouping-state.md#group-key)> | Groups to be expanded.
expandedGroups | Getter | Array<[GroupKey](grouping-state.md#group-key)> | Groups to be expanded.

### Exports

Name | Plugin | Type | Description
-----|--------|------|------------
rows | Getter | Array<any> | Rows with the applied grouping and expanded groups.
grouping | Getter | Array<[Grouping](grouping-state.md#grouping)> | The specified data's current grouping state.
expandedGroups | Getter | Set<[GroupKey](grouping-state.md#group-key)> | Groups expanded in the specified data.
expandedGroups | Getter | Array<[GroupKey](grouping-state.md#group-key)> | Groups expanded in the specified data.
isGroupRow | Getter | (row: any) => boolean | A function used to identify a group row within ordinary rows.
getRowLevelKey | Getter | (row: any) => string? | A function used to get a group row level key.
2 changes: 1 addition & 1 deletion packages/dx-react-grid/docs/reference/grouping-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Name | Plugin | Type | Description
-----|--------|------|------------
grouping | Getter | Array<[Grouping](#grouping)> | The current grouping state.
draftGrouping | Getter | Array<[DraftGrouping](#draft-grouping)> | Grouping options used for the preview.
expandedGroups | Getter | Set<[GroupKey](#group-key)> | Expanded groups.
expandedGroups | Getter | Array<[GroupKey](#group-key)> | Expanded groups.
groupByColumn | Action | ({ columnName: string, groupIndex?: number }) => void | Groups by a specified column or cancels grouping. If `groupIndex` is omitted, the group is added to the last position.
toggleGroupExpanded | Action | ({ groupKey: [GroupKey](#group-key) }) => void | Toggles the expanded group state.
draftGroupingChange | Action | ({ columnName: string, groupIndex?: number }) => void | Updates `dratfGrouping`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Name | Plugin | Type | Description
-----|--------|------|------------
rows | Getter | Array<any> | Rows to be grouped.
grouping | Getter | Array<[Grouping](grouping-state.md#grouping)> | The current grouping state.
expandedGroups | Getter | Set<[GroupKey](grouping-state.md#group-key)> | Groups to be expanded.
expandedGroups | Getter | Array<[GroupKey](grouping-state.md#group-key)> | Groups to be expanded.
getCellValue | Getter | (row: any, columnName: string) => any | A function that returns a cell value.

### Exports
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/docs/reference/table-group-row.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ tableColumns | Getter | Array<[TableColumn](table.md#tablecolumn)> | Table
tableBodyRows | Getter | Array<[TableRow](table.md#tablerow)> | Table body rows.
grouping | Getter | Array<[Grouping](grouping-state.md#grouping)> | Current grouping options.
draftGrouping | Getter | Array<[DraftGrouping](grouping-state.md#draft-grouping)> | Grouping options used for preview.
expandedGroups | Getter | Set<[GroupKey](grouping-state.md#group-key)> | Expanded groups.
expandedGroups | Getter | Array<[GroupKey](grouping-state.md#group-key)> | Expanded groups.
isGroupRow | Getter | (row: any) => boolean | A function used to identify a group row within ordinary rows.
toggleGroupExpanded | Action | ({ groupKey: [GroupKey](grouping-state.md#group-key) }) => void | Toggles the group's expanded state.
tableCell | Template | [TableCellProps](table.md#tablecellprops) | A template that renders a table cell.
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/src/plugins/custom-grouping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class CustomGrouping extends React.PureComponent {
<Getter name="grouping" value={appliedGrouping} />
)}
{appliedExpandedGroups && (
<Getter name="expandedGroups" value={new Set(appliedExpandedGroups)} />
<Getter name="expandedGroups" value={appliedExpandedGroups} />
)}
<Getter name="isGroupRow" value={groupRowChecker} />
<Getter name="getRowLevelKey" value={groupRowLevelKeyGetter} />
Expand Down
4 changes: 2 additions & 2 deletions packages/dx-react-grid/src/plugins/custom-grouping.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ describe('CustomGrouping', () => {
expect(getComputedState(tree).grouping)
.toBe(grouping);
expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(expandedGroups));
.toEqual(expandedGroups);
});

it('should provide rows getter based on grouping and expandedGroups properties', () => {
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('CustomGrouping', () => {
.toBeCalledWith(
customGroupedRows(),
grouping,
new Set(expandedGroups),
expandedGroups,
);

expect(getComputedState(tree).rows)
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/src/plugins/grouping-state.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class GroupingState extends React.PureComponent {
>
<Getter name="grouping" value={grouping} />
<Getter name="draftGrouping" value={draftGrouping(grouping, groupingChange)} />
<Getter name="expandedGroups" value={new Set(expandedGroups)} />
<Getter name="expandedGroups" value={expandedGroups} />

<Action name="groupByColumn" action={this.groupByColumn} />
<Action name="toggleGroupExpanded" action={this.toggleGroupExpanded} />
Expand Down
12 changes: 6 additions & 6 deletions packages/dx-react-grid/src/plugins/grouping-state.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('GroupingState', () => {
));

expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(defaultExpandedGroups));
.toEqual(defaultExpandedGroups);
});

it('should provide expandedGroups defined in expandedGroups property', () => {
Expand All @@ -170,7 +170,7 @@ describe('GroupingState', () => {
));

expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(expandedGroups));
.toEqual(expandedGroups);
});

it('should fire "onExpandedGroupsChange" and should change expandedGroups in uncontrolled mode "toggleExpandedGroups"', () => {
Expand Down Expand Up @@ -199,7 +199,7 @@ describe('GroupingState', () => {
);

expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(newExpandedGroups));
.toEqual(newExpandedGroups);

expect(expandedGroupsChange)
.toBeCalledWith(newExpandedGroups);
Expand Down Expand Up @@ -231,7 +231,7 @@ describe('GroupingState', () => {
);

expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(newExpandedGroups));
.toEqual(newExpandedGroups);

expect(expandedGroupsChange)
.toBeCalledWith(newExpandedGroups);
Expand Down Expand Up @@ -260,7 +260,7 @@ describe('GroupingState', () => {
.toBeCalledWith(expect.objectContaining({ expandedGroups }), payload);

expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(expandedGroups));
.toEqual(expandedGroups);

expect(expandedGroupsChange)
.toBeCalledWith(newExpandedGroups);
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('GroupingState', () => {
);

expect(getComputedState(tree).expandedGroups)
.toEqual(new Set(expandedGroups));
.toEqual(expandedGroups);

expect(expandedGroupsChange)
.toBeCalledWith(newExpandedGroups);
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/src/plugins/table-group-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class TableGroupRow extends React.PureComponent {
{...params}
row={params.tableRow.row}
column={params.tableColumn.column}
expanded={expandedGroups.has(params.tableRow.row.compoundKey)}
expanded={expandedGroups.indexOf(params.tableRow.row.compoundKey) !== -1}
onToggle={() =>
toggleGroupExpanded({ groupKey: params.tableRow.row.compoundKey })}
>
Expand Down
10 changes: 5 additions & 5 deletions packages/dx-react-grid/src/plugins/table-group-row.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const defaultDeps = {
tableBodyRows: [{ type: 'undefined', id: 1, row: 'row' }],
grouping: [{ columnName: 'a' }],
draftGrouping: [{ columnName: 'a' }, { columnName: 'b', draft: GROUP_ADD_MODE }],
expandedGroups: new Map(),
expandedGroups: [],
isGroupRow: () => false,
},
action: {
Expand Down Expand Up @@ -226,7 +226,7 @@ describe('TableGroupRow', () => {

const deps = {
getter: {
expandedGroups: new Set(),
expandedGroups: [],
},
template: {
tableCell: {
Expand All @@ -235,7 +235,7 @@ describe('TableGroupRow', () => {
},
},
};
jest.spyOn(deps.getter.expandedGroups, 'has').mockReturnValue('hasTest');
jest.spyOn(deps.getter.expandedGroups, 'indexOf').mockReturnValue(1);

const tree = mount((
<PluginHost>
Expand All @@ -247,10 +247,10 @@ describe('TableGroupRow', () => {
));
expect(tree.find(defaultProps.cellComponent).props())
.toMatchObject({
expanded: 'hasTest',
expanded: true,
onToggle: expect.any(Function),
});
expect(deps.getter.expandedGroups.has)
expect(deps.getter.expandedGroups.indexOf)
.toBeCalledWith('1');

tree.find(defaultProps.cellComponent).props().onToggle();
Expand Down

0 comments on commit f078d3a

Please sign in to comment.