Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(react-grid): rename the setColumnSorting action to changeColumnSorting #658

Merged
merged 3 commits into from
Jan 11, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const setColumnSorting = (state, {
export const changeColumnSorting = (state, {
columnName, direction, keepOther, sortIndex,
}) => {
const { sorting } = state;
Expand Down
24 changes: 12 additions & 12 deletions packages/dx-grid-core/src/plugins/sorting-state/reducers.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {
setColumnSorting,
changeColumnSorting,
} from './reducers';

describe('SortingState reducers', () => {
describe('#setColumnSorting', () => {
describe('#changeColumnSorting', () => {
it('can initiate sorting', () => {
const state = {
sorting: [],
};
const payload = { columnName: 'test' };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'asc' }],
});
Expand All @@ -22,7 +22,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test', direction: 'desc' };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'desc' }],
});
Expand All @@ -34,7 +34,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test' };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'desc' }],
});
Expand All @@ -46,7 +46,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test2' };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test2', direction: 'asc' }],
});
Expand All @@ -58,7 +58,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test2', keepOther: true };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'asc' }, { columnName: 'test2', direction: 'asc' }],
});
Expand All @@ -70,7 +70,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test2', keepOther: ['test'] };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'asc' }, { columnName: 'test2', direction: 'asc' }],
});
Expand All @@ -82,7 +82,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test', keepOther: true };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'desc' }, { columnName: 'test2', direction: 'asc' }],
});
Expand All @@ -94,7 +94,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test2', keepOther: true, direction: null };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [{ columnName: 'test', direction: 'asc' }],
});
Expand All @@ -106,7 +106,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test2', direction: null };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [],
});
Expand All @@ -118,7 +118,7 @@ describe('SortingState reducers', () => {
};
const payload = { columnName: 'test2', keepOther: true, sortIndex: 0 };

expect(setColumnSorting(state, payload))
expect(changeColumnSorting(state, payload))
.toEqual({
sorting: [
{ columnName: 'test2', direction: 'asc' },
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/docs/reference/grouping-panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ columns | Getter | Array<[Column](grid.md#column)> | Grid columns.
draftGrouping | Getter | Array<[DraftGrouping](grouping-state.md#draft-grouping)> | Grouping options used for the preview.
sorting | Getter | Array<[Sorting](sorting-state.md#sorting)> | The current sorting state.
groupByColumn | Action | ({ columnName: string, groupIndex?: number }) => void | Toggles the column's grouping state. If `groupIndex` is omitted, the group is added to the end of the group list.
setColumnSorting | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column.
changeColumnSorting | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column.
draftGroupingChange | Action | ({ columnName: string, groupIndex?: number }) => void | Sets the groupingChange state to the specified value.
cancelGroupingChange | Action | () => void | Resets the groupingChange state.
draggingEnabled | Getter | boolean | Specifies whether drag-and-drop is enabled.
Expand Down
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 @@ -56,7 +56,7 @@ Name | Plugin | Type | Description
-----|--------|------|------------
columns | Getter | Array<[Column](grid.md#column)> | Grid columns.
sorting? | Getter | Array<[Sorting](sorting-state.md#sorting)> | Applied column sorting.
setColumnSorting? | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex?: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column. If `sortIndex` is omitted, the sorting is added to the end of the sorting list.
changeColumnSorting? | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex?: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column. If `sortIndex` is omitted, the sorting is added to the end of the sorting list.

### Exports

Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/docs/reference/sorting-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ none
Name | Plugin | Type | Description
-----|--------|------|------------
sorting | Getter | Array<[Sorting](#sorting)> | Applied column sorting.
setColumnSorting | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex?: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column. If `sortIndex` is omitted, the sorting is added to the end of the sorting list.
changeColumnSorting | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex?: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column. If `sortIndex` is omitted, the sorting is added to the end of the sorting list.
2 changes: 1 addition & 1 deletion packages/dx-react-grid/docs/reference/table-header-row.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Name | Plugin | Type | Description
tableHeaderRows | Getter | Array<[TableRow](table.md#tablerow)> | Header rows to be rendered.
tableColumns | Getter | Array<[TableColumn](table.md#tablecolumn)> | Table columns.
sorting | Getter | Array<[Sorting](sorting-state.md#sorting)> | Columns' sorting state.
setColumnSorting | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex?: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column. If `sortIndex` is omitted, the sorting is added to the end of the sorting list.
changeColumnSorting | Action | ({ columnName: string, direction?: 'asc' | 'desc' | null, keepOther?: boolean | Array<String>, sortIndex?: number }) => void | Changes the column sorting direction. `keepOther` accepts `true` (keeps existing sorting), a column name array (keeps sorting by specified columns) and `false` (resets sorting). Set `direction` to `null` to cancel sorting by the current column. If `sortIndex` is omitted, the sorting is added to the end of the sorting list.
groupByColumn | Action | ({ columnName: string, groupIndex?: number }) => void | Groups a table by the specified column or cancels grouping. If `groupIndex` is omitted, the group is added to the end of the group list.
tableColumnResizingEnabled | Getter | boolean | Specifies whether table column resizing is enabled.
changeTableColumnWidths | Action | ({ shifts: { [columnName: string]: number } }) => void | Changes column widths. The initial column width increases by the `shift` value or decreases if `shift` is negative.
Expand Down
4 changes: 2 additions & 2 deletions packages/dx-react-grid/src/plugins/grouping-panel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class GroupingPanel extends React.PureComponent {
const { name: columnName } = item.column;
return (
<TemplateConnector>
{({ sorting }, { groupByColumn, setColumnSorting }) => (
{({ sorting }, { groupByColumn, changeColumnSorting }) => (
<Item
item={item}
showSortingControls={showSortingControls && sorting !== undefined}
Expand All @@ -42,7 +42,7 @@ export class GroupingPanel extends React.PureComponent {
showGroupingControls={showGroupingControls}
onGroup={() => groupByColumn({ columnName })}
onSort={({ direction, keepOther }) =>
setColumnSorting({ columnName, direction, keepOther })}
changeColumnSorting({ columnName, direction, keepOther })}
/>
)}
</TemplateConnector>
Expand Down
2 changes: 1 addition & 1 deletion packages/dx-react-grid/src/plugins/grouping-panel.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const defaultDeps = {
},
action: {
groupByColumn: jest.fn(),
setColumnSorting: jest.fn(),
changeColumnSorting: jest.fn(),
draftGroupingChange: jest.fn(),
cancelGroupingChange: jest.fn(),
},
Expand Down
18 changes: 11 additions & 7 deletions packages/dx-react-grid/src/plugins/grouping-state.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class GroupingState extends React.PureComponent {
.bind(this.stateHelper, draftGroupingChange);
this.cancelGroupingChange = this.stateHelper.applyReducer
.bind(this.stateHelper, cancelGroupingChange);
this.setColumnSorting = this.setColumnSorting.bind(this);
this.changeColumnSorting = this.changeColumnSorting.bind(this);
}
getState() {
return {
Expand All @@ -55,12 +55,16 @@ export class GroupingState extends React.PureComponent {
expandedGroups: this.props.expandedGroups || this.state.expandedGroups,
};
}
setColumnSorting({ columnName, keepOther, ...restParams }, { sorting }, { setColumnSorting }) {
changeColumnSorting(
{ columnName, keepOther, ...restParams },
{ sorting },
{ changeColumnSorting },
) {
const { grouping } = this.getState();
const groupingIndex = grouping
.findIndex(columnGrouping => columnGrouping.columnName === columnName);
if (groupingIndex === -1) {
setColumnSorting({
changeColumnSorting({
columnName,
keepOther: keepOther || grouping.map(columnGrouping => columnGrouping.columnName),
...restParams,
Expand All @@ -69,7 +73,7 @@ export class GroupingState extends React.PureComponent {
}

const sortIndex = adjustSortIndex(groupingIndex, grouping, sorting);
setColumnSorting({
changeColumnSorting({
columnName,
keepOther: true,
sortIndex,
Expand All @@ -85,7 +89,7 @@ export class GroupingState extends React.PureComponent {
const { grouping } = nextState;
const { grouping: prevGrouping } = state;
const { sorting } = getters;
const { setColumnSorting } = actions;
const { changeColumnSorting } = actions;

if (!sorting) return;

Expand All @@ -107,7 +111,7 @@ export class GroupingState extends React.PureComponent {

if (columnSortingIndex === sortIndex) return;

setColumnSorting({
changeColumnSorting({
keepOther: true,
sortIndex,
...sorting[columnSortingIndex],
Expand Down Expand Up @@ -145,7 +149,7 @@ export class GroupingState extends React.PureComponent {
<Action name="draftGroupingChange" action={this.draftGroupingChange} />
<Action name="cancelGroupingChange" action={this.cancelGroupingChange} />

<Action name="setColumnSorting" action={this.setColumnSorting} />
<Action name="changeColumnSorting" action={this.changeColumnSorting} />
</PluginContainer>
);
}
Expand Down
Loading