From c2d589ba785342ee31f3bcda72f5bc0365d0d99f Mon Sep 17 00:00:00 2001 From: Yury Orlov Date: Wed, 10 Jan 2018 14:17:24 +0300 Subject: [PATCH 1/2] refactor(react-grid): rename the setColumnSorting action to changeColumnSorting --- .../src/plugins/sorting-state/reducers.js | 2 +- .../plugins/sorting-state/reducers.test.js | 24 +++---- .../docs/reference/grouping-panel.md | 2 +- .../docs/reference/grouping-state.md | 2 +- .../docs/reference/sorting-state.md | 2 +- .../docs/reference/table-header-row.md | 2 +- .../src/plugins/grouping-panel.jsx | 4 +- .../src/plugins/grouping-panel.test.jsx | 2 +- .../src/plugins/grouping-state.jsx | 14 ++-- .../src/plugins/grouping-state.test.jsx | 72 +++++++++---------- .../src/plugins/sorting-state.jsx | 8 +-- .../src/plugins/sorting-state.test.jsx | 42 +++++------ .../src/plugins/table-header-row.jsx | 4 +- 13 files changed, 90 insertions(+), 90 deletions(-) diff --git a/packages/dx-grid-core/src/plugins/sorting-state/reducers.js b/packages/dx-grid-core/src/plugins/sorting-state/reducers.js index ec3b7ec136..8fb4bbde70 100644 --- a/packages/dx-grid-core/src/plugins/sorting-state/reducers.js +++ b/packages/dx-grid-core/src/plugins/sorting-state/reducers.js @@ -1,4 +1,4 @@ -export const setColumnSorting = (state, { +export const changeColumnSorting = (state, { columnName, direction, keepOther, sortIndex, }) => { const { sorting } = state; diff --git a/packages/dx-grid-core/src/plugins/sorting-state/reducers.test.js b/packages/dx-grid-core/src/plugins/sorting-state/reducers.test.js index 1a07261c0d..b679426a8f 100644 --- a/packages/dx-grid-core/src/plugins/sorting-state/reducers.test.js +++ b/packages/dx-grid-core/src/plugins/sorting-state/reducers.test.js @@ -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' }], }); @@ -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' }], }); @@ -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' }], }); @@ -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' }], }); @@ -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' }], }); @@ -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' }], }); @@ -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' }], }); @@ -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' }], }); @@ -106,7 +106,7 @@ describe('SortingState reducers', () => { }; const payload = { columnName: 'test2', direction: null }; - expect(setColumnSorting(state, payload)) + expect(changeColumnSorting(state, payload)) .toEqual({ sorting: [], }); @@ -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' }, diff --git a/packages/dx-react-grid/docs/reference/grouping-panel.md b/packages/dx-react-grid/docs/reference/grouping-panel.md index 8f0358d030..3ad5d91db1 100644 --- a/packages/dx-react-grid/docs/reference/grouping-panel.md +++ b/packages/dx-react-grid/docs/reference/grouping-panel.md @@ -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. diff --git a/packages/dx-react-grid/docs/reference/grouping-state.md b/packages/dx-react-grid/docs/reference/grouping-state.md index 289a589a05..399b0b9024 100644 --- a/packages/dx-react-grid/docs/reference/grouping-state.md +++ b/packages/dx-react-grid/docs/reference/grouping-state.md @@ -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 diff --git a/packages/dx-react-grid/docs/reference/sorting-state.md b/packages/dx-react-grid/docs/reference/sorting-state.md index 2d60a3b6ba..5668ee46bf 100644 --- a/packages/dx-react-grid/docs/reference/sorting-state.md +++ b/packages/dx-react-grid/docs/reference/sorting-state.md @@ -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. diff --git a/packages/dx-react-grid/docs/reference/table-header-row.md b/packages/dx-react-grid/docs/reference/table-header-row.md index 20b9c41ce8..36221cbd65 100644 --- a/packages/dx-react-grid/docs/reference/table-header-row.md +++ b/packages/dx-react-grid/docs/reference/table-header-row.md @@ -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. diff --git a/packages/dx-react-grid/src/plugins/grouping-panel.jsx b/packages/dx-react-grid/src/plugins/grouping-panel.jsx index 9d65030a84..40a3ce77a8 100644 --- a/packages/dx-react-grid/src/plugins/grouping-panel.jsx +++ b/packages/dx-react-grid/src/plugins/grouping-panel.jsx @@ -33,7 +33,7 @@ export class GroupingPanel extends React.PureComponent { const { name: columnName } = item.column; return ( - {({ sorting }, { groupByColumn, setColumnSorting }) => ( + {({ sorting }, { groupByColumn, changeColumnSorting }) => ( groupByColumn({ columnName })} onSort={({ direction, keepOther }) => - setColumnSorting({ columnName, direction, keepOther })} + changeColumnSorting({ columnName, direction, keepOther })} /> )} diff --git a/packages/dx-react-grid/src/plugins/grouping-panel.test.jsx b/packages/dx-react-grid/src/plugins/grouping-panel.test.jsx index 701dac7fe4..d46eeeb135 100644 --- a/packages/dx-react-grid/src/plugins/grouping-panel.test.jsx +++ b/packages/dx-react-grid/src/plugins/grouping-panel.test.jsx @@ -24,7 +24,7 @@ const defaultDeps = { }, action: { groupByColumn: jest.fn(), - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), draftGroupingChange: jest.fn(), cancelGroupingChange: jest.fn(), }, diff --git a/packages/dx-react-grid/src/plugins/grouping-state.jsx b/packages/dx-react-grid/src/plugins/grouping-state.jsx index a1bab40ba0..735b94b13b 100644 --- a/packages/dx-react-grid/src/plugins/grouping-state.jsx +++ b/packages/dx-react-grid/src/plugins/grouping-state.jsx @@ -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 { @@ -55,12 +55,12 @@ 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, @@ -69,7 +69,7 @@ export class GroupingState extends React.PureComponent { } const sortIndex = adjustSortIndex(groupingIndex, grouping, sorting); - setColumnSorting({ + changeColumnSorting({ columnName, keepOther: true, sortIndex, @@ -85,7 +85,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; @@ -107,7 +107,7 @@ export class GroupingState extends React.PureComponent { if (columnSortingIndex === sortIndex) return; - setColumnSorting({ + changeColumnSorting({ keepOther: true, sortIndex, ...sorting[columnSortingIndex], @@ -145,7 +145,7 @@ export class GroupingState extends React.PureComponent { - + ); } diff --git a/packages/dx-react-grid/src/plugins/grouping-state.test.jsx b/packages/dx-react-grid/src/plugins/grouping-state.test.jsx index fa0159743f..7b5dd0b635 100644 --- a/packages/dx-react-grid/src/plugins/grouping-state.test.jsx +++ b/packages/dx-react-grid/src/plugins/grouping-state.test.jsx @@ -365,14 +365,14 @@ describe('GroupingState', () => { }); }); - describe('setColumnSorting action extending', () => { - it('should modify setColumnSorting action payload when sorted column is grouped', () => { + describe('changeColumnSorting action extending', () => { + it('should modify changeColumnSorting action payload when sorted column is grouped', () => { const deps = { getter: { sorting: [], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -385,8 +385,8 @@ describe('GroupingState', () => { )); - executeComputedAction(tree, actions => actions.setColumnSorting({ columnName: 'a', direction: 'asc' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + executeComputedAction(tree, actions => actions.changeColumnSorting({ columnName: 'a', direction: 'asc' })); + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'a', direction: 'asc', @@ -395,13 +395,13 @@ describe('GroupingState', () => { }); }); - it('should modify setColumnSorting action payload when several grouped columns is sorted', () => { + it('should modify changeColumnSorting action payload when several grouped columns is sorted', () => { const deps = { getter: { sorting: [{ columnName: 'a', direction: 'asc' }, { columnName: 'b', direction: 'asc' }, { columnName: 'c', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -414,8 +414,8 @@ describe('GroupingState', () => { )); - executeComputedAction(tree, actions => actions.setColumnSorting({ columnName: 'c' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + executeComputedAction(tree, actions => actions.changeColumnSorting({ columnName: 'c' })); + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'c', keepOther: true, @@ -423,13 +423,13 @@ describe('GroupingState', () => { }); }); - it('should correctly set sortIndex for setColumnSorting action when some grouped columns is not sorted', () => { + it('should correctly set sortIndex for changeColumnSorting action when some grouped columns is not sorted', () => { const deps = { getter: { sorting: [{ columnName: 'a', direction: 'asc' }, { columnName: 'c', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -442,8 +442,8 @@ describe('GroupingState', () => { )); - executeComputedAction(tree, actions => actions.setColumnSorting({ columnName: 'c' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + executeComputedAction(tree, actions => actions.changeColumnSorting({ columnName: 'c' })); + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'c', keepOther: true, @@ -451,13 +451,13 @@ describe('GroupingState', () => { }); }); - it('should modify setColumnSorting action payload when one grouped column is sorted', () => { + it('should modify changeColumnSorting action payload when one grouped column is sorted', () => { const deps = { getter: { sorting: [], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -470,8 +470,8 @@ describe('GroupingState', () => { )); - executeComputedAction(tree, actions => actions.setColumnSorting({ columnName: 'b' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + executeComputedAction(tree, actions => actions.changeColumnSorting({ columnName: 'b' })); + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'b', keepOther: true, @@ -479,13 +479,13 @@ describe('GroupingState', () => { }); }); - it('should modify setColumnSorting action payload when sorted column is not grouped', () => { + it('should modify changeColumnSorting action payload when sorted column is not grouped', () => { const deps = { getter: { sorting: [], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -498,8 +498,8 @@ describe('GroupingState', () => { )); - executeComputedAction(tree, actions => actions.setColumnSorting({ columnName: 'c', direction: 'asc' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + executeComputedAction(tree, actions => actions.changeColumnSorting({ columnName: 'c', direction: 'asc' })); + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'c', direction: 'asc', @@ -508,14 +508,14 @@ describe('GroupingState', () => { }); }); - describe('setColumnSorting action on groupByColumn action', () => { - it('should fire setColumnSorting action when grouped by sorted column', () => { + describe('changeColumnSorting action on groupByColumn action', () => { + it('should fire changeColumnSorting action when grouped by sorted column', () => { const deps = { getter: { sorting: [{ columnName: 'b', direction: 'asc' }, { columnName: 'a', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -530,7 +530,7 @@ describe('GroupingState', () => { groupByColumn.mockReturnValue({ grouping: [{ columnName: 'a' }] }); executeComputedAction(tree, actions => actions.groupByColumn({ columnName: 'a' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'a', direction: 'asc', @@ -539,13 +539,13 @@ describe('GroupingState', () => { }); }); - it('should fire setColumnSorting action when ungrouped by sorted column', () => { + it('should fire changeColumnSorting action when ungrouped by sorted column', () => { const deps = { getter: { sorting: [{ columnName: 'a', direction: 'asc' }, { columnName: 'b', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -560,7 +560,7 @@ describe('GroupingState', () => { groupByColumn.mockReturnValue({ grouping: [{ columnName: 'b' }] }); executeComputedAction(tree, actions => actions.groupByColumn({ columnName: 'a' })); - expect(deps.action.setColumnSorting.mock.calls[0][0]) + expect(deps.action.changeColumnSorting.mock.calls[0][0]) .toEqual({ columnName: 'a', direction: 'asc', @@ -575,7 +575,7 @@ describe('GroupingState', () => { sorting: [{ columnName: 'a', direction: 'asc' }, { columnName: 'c', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -590,17 +590,17 @@ describe('GroupingState', () => { groupByColumn.mockReturnValue({ grouping: [{ columnName: 'a' }, { columnName: 'c' }, { columnName: 'b' }] }); executeComputedAction(tree, actions => actions.groupByColumn({ columnName: 'a', groupIndex: 1 })); - expect(deps.action.setColumnSorting) + expect(deps.action.changeColumnSorting) .not.toBeCalled(); }); - it('should not fire setColumnSorting action when ungrouped last sorted column', () => { + it('should not fire changeColumnSorting action when ungrouped last sorted column', () => { const deps = { getter: { sorting: [{ columnName: 'a', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -615,17 +615,17 @@ describe('GroupingState', () => { groupByColumn.mockReturnValue({ grouping: [] }); executeComputedAction(tree, actions => actions.groupByColumn({ columnName: 'a' })); - expect(deps.action.setColumnSorting) + expect(deps.action.changeColumnSorting) .not.toBeCalled(); }); - it('should not fire setColumnSorting action when grouped column sorting index is correct', () => { + it('should not fire changeColumnSorting action when grouped column sorting index is correct', () => { const deps = { getter: { sorting: [{ columnName: 'a', direction: 'asc' }, { columnName: 'b', direction: 'asc' }], }, action: { - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), }, }; @@ -640,7 +640,7 @@ describe('GroupingState', () => { groupByColumn.mockReturnValue({ grouping: [{ columnName: 'a' }, { columnName: 'b' }] }); executeComputedAction(tree, actions => actions.groupByColumn({ columnName: 'a' })); - expect(deps.action.setColumnSorting) + expect(deps.action.changeColumnSorting) .not.toBeCalled(); }); }); diff --git a/packages/dx-react-grid/src/plugins/sorting-state.jsx b/packages/dx-react-grid/src/plugins/sorting-state.jsx index 5f5c1af1bb..b525ccc623 100644 --- a/packages/dx-react-grid/src/plugins/sorting-state.jsx +++ b/packages/dx-react-grid/src/plugins/sorting-state.jsx @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Getter, Action, PluginContainer } from '@devexpress/dx-react-core'; -import { setColumnSorting } from '@devexpress/dx-grid-core'; +import { changeColumnSorting } from '@devexpress/dx-grid-core'; import { createStateHelper } from '../utils/state-helper'; export class SortingState extends React.PureComponent { @@ -14,8 +14,8 @@ export class SortingState extends React.PureComponent { const stateHelper = createStateHelper(this); - this.setColumnSorting = stateHelper.applyReducer - .bind(stateHelper, setColumnSorting); + this.changeColumnSorting = stateHelper.applyReducer + .bind(stateHelper, changeColumnSorting); } getState() { return { @@ -38,7 +38,7 @@ export class SortingState extends React.PureComponent { pluginName="SortingState" > - + ); } diff --git a/packages/dx-react-grid/src/plugins/sorting-state.test.jsx b/packages/dx-react-grid/src/plugins/sorting-state.test.jsx index e9c497b16d..65a1a68636 100644 --- a/packages/dx-react-grid/src/plugins/sorting-state.test.jsx +++ b/packages/dx-react-grid/src/plugins/sorting-state.test.jsx @@ -2,12 +2,12 @@ import React from 'react'; import { mount } from 'enzyme'; import { setupConsole } from '@devexpress/dx-testing'; import { PluginHost } from '@devexpress/dx-react-core'; -import { setColumnSorting } from '@devexpress/dx-grid-core'; +import { changeColumnSorting } from '@devexpress/dx-grid-core'; import { pluginDepsToComponents, getComputedState, executeComputedAction } from './test-utils'; import { SortingState } from './sorting-state'; jest.mock('@devexpress/dx-grid-core', () => ({ - setColumnSorting: jest.fn(), + changeColumnSorting: jest.fn(), })); const defaultDeps = { @@ -28,7 +28,7 @@ describe('SortingState', () => { }); beforeEach(() => { - setColumnSorting.mockImplementation(() => ({})); + changeColumnSorting.mockImplementation(() => ({})); }); afterEach(() => { jest.resetAllMocks(); @@ -66,7 +66,7 @@ describe('SortingState', () => { .toBe(sorting); }); - it('should fire the "onSortingChange" callback and should change sorting in uncontrolled mode after the "setColumnSorting" action is fired', () => { + it('should fire the "onSortingChange" callback and should change sorting in uncontrolled mode after the "changeColumnSorting" action is fired', () => { const defaultSorting = [{ columnName: 'a', direction: 'asc' }]; const newSorting = [{ columnName: 'b', direction: 'asc' }]; @@ -82,10 +82,10 @@ describe('SortingState', () => { )); const payload = {}; - setColumnSorting.mockReturnValue({ sorting: newSorting }); - executeComputedAction(tree, actions => actions.setColumnSorting(payload)); + changeColumnSorting.mockReturnValue({ sorting: newSorting }); + executeComputedAction(tree, actions => actions.changeColumnSorting(payload)); - expect(setColumnSorting) + expect(changeColumnSorting) .toBeCalledWith(expect.objectContaining({ sorting: defaultSorting }), payload); expect(getComputedState(tree).sorting) @@ -95,7 +95,7 @@ describe('SortingState', () => { .toBeCalledWith(newSorting); }); - it('should fire the "onSortingChange" callback and should change sorting in controlled mode after the "setColumnSorting" action is fired', () => { + it('should fire the "onSortingChange" callback and should change sorting in controlled mode after the "changeColumnSorting" action is fired', () => { const sorting = [{ columnName: 'a', direction: 'asc' }]; const newSorting = [{ columnName: 'b', direction: 'asc' }]; @@ -111,10 +111,10 @@ describe('SortingState', () => { )); const payload = {}; - setColumnSorting.mockReturnValue({ sorting: newSorting }); - executeComputedAction(tree, actions => actions.setColumnSorting(payload)); + changeColumnSorting.mockReturnValue({ sorting: newSorting }); + executeComputedAction(tree, actions => actions.changeColumnSorting(payload)); - expect(setColumnSorting) + expect(changeColumnSorting) .toBeCalledWith(expect.objectContaining({ sorting }), payload); expect(getComputedState(tree).sorting) @@ -142,14 +142,14 @@ describe('SortingState', () => { )); - setColumnSorting.mockReturnValueOnce({ sorting: transitionalSorting }); - setColumnSorting.mockReturnValueOnce({ sorting: newSorting }); + changeColumnSorting.mockReturnValueOnce({ sorting: transitionalSorting }); + changeColumnSorting.mockReturnValueOnce({ sorting: newSorting }); executeComputedAction(tree, (actions) => { - actions.setColumnSorting(payload); - actions.setColumnSorting(payload); + actions.changeColumnSorting(payload); + actions.changeColumnSorting(payload); }); - expect(setColumnSorting) + expect(changeColumnSorting) .lastCalledWith( expect.objectContaining({ sorting: transitionalSorting }), payload, @@ -176,14 +176,14 @@ describe('SortingState', () => { )); - setColumnSorting.mockReturnValueOnce({ sorting: transitionalSorting }); - setColumnSorting.mockReturnValueOnce({ sorting: newSorting }); + changeColumnSorting.mockReturnValueOnce({ sorting: transitionalSorting }); + changeColumnSorting.mockReturnValueOnce({ sorting: newSorting }); executeComputedAction(tree, (actions) => { - actions.setColumnSorting(payload); - actions.setColumnSorting(payload); + actions.changeColumnSorting(payload); + actions.changeColumnSorting(payload); }); - expect(setColumnSorting) + expect(changeColumnSorting) .lastCalledWith( expect.objectContaining({ sorting: transitionalSorting }), payload, diff --git a/packages/dx-react-grid/src/plugins/table-header-row.jsx b/packages/dx-react-grid/src/plugins/table-header-row.jsx index 263aaa3182..76fb946e61 100644 --- a/packages/dx-react-grid/src/plugins/table-header-row.jsx +++ b/packages/dx-react-grid/src/plugins/table-header-row.jsx @@ -47,7 +47,7 @@ export class TableHeaderRow extends React.PureComponent { {({ sorting, tableColumns, draggingEnabled, tableColumnResizingEnabled, }, { - setColumnSorting, groupByColumn, + changeColumnSorting, groupByColumn, changeTableColumnWidths, changeDraftTableColumnWidths, }) => { const { name: columnName } = params.tableColumn.column; @@ -66,7 +66,7 @@ export class TableHeaderRow extends React.PureComponent { sortingDirection={showSortingControls && sorting !== undefined ? getColumnSortingDirection(sorting, columnName) : undefined} onSort={({ direction, keepOther }) => - setColumnSorting({ columnName, direction, keepOther })} + changeColumnSorting({ columnName, direction, keepOther })} onGroup={() => groupByColumn({ columnName })} onWidthChange={({ shift }) => From 2a2298fbce7090ad011f87e2bc99f46fe0747197 Mon Sep 17 00:00:00 2001 From: Yury Orlov Date: Wed, 10 Jan 2018 14:38:57 +0300 Subject: [PATCH 2/2] fix lint --- packages/dx-react-grid/src/plugins/grouping-state.jsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/dx-react-grid/src/plugins/grouping-state.jsx b/packages/dx-react-grid/src/plugins/grouping-state.jsx index 735b94b13b..571be9f6b7 100644 --- a/packages/dx-react-grid/src/plugins/grouping-state.jsx +++ b/packages/dx-react-grid/src/plugins/grouping-state.jsx @@ -55,7 +55,11 @@ export class GroupingState extends React.PureComponent { expandedGroups: this.props.expandedGroups || this.state.expandedGroups, }; } - changeColumnSorting({ columnName, keepOther, ...restParams }, { sorting }, { changeColumnSorting }) { + changeColumnSorting( + { columnName, keepOther, ...restParams }, + { sorting }, + { changeColumnSorting }, + ) { const { grouping } = this.getState(); const groupingIndex = grouping .findIndex(columnGrouping => columnGrouping.columnName === columnName);