From 4ad7684b02ccf401d8d9881768ced27ed8bf515a Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 25 Apr 2019 10:09:44 -0400 Subject: [PATCH 1/2] change sorting_settings to sort_by --- .../components/ControlledTable/index.tsx | 4 +- src/dash-table/components/HeaderFactory.tsx | 8 +-- src/dash-table/components/Table/index.tsx | 10 ++-- src/dash-table/components/Table/props.ts | 4 +- src/dash-table/dash/DataTable.js | 8 +-- src/dash-table/derived/data/virtual.ts | 4 +- src/dash-table/derived/header/content.tsx | 2 +- tests/cypress/dash/v_be_page.py | 14 ++--- tests/dash/app_dataframe_backend_paging.py | 52 +++++++++---------- .../percy-storybook/DashTable.percy.tsx | 10 ++-- 10 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/dash-table/components/ControlledTable/index.tsx b/src/dash-table/components/ControlledTable/index.tsx index a9d8dc57e..685ea9e7e 100644 --- a/src/dash-table/components/ControlledTable/index.tsx +++ b/src/dash-table/components/ControlledTable/index.tsx @@ -537,7 +537,7 @@ export default class ControlledTable extends PureComponent editable, filter, setProps, - sorting_settings, + sort_by, viewport } = this.props; @@ -552,7 +552,7 @@ export default class ControlledTable extends PureComponent columns, data, true, - !sorting_settings.length || !filter.length + !sort_by.length || !filter.length ); if (result) { diff --git a/src/dash-table/components/HeaderFactory.tsx b/src/dash-table/components/HeaderFactory.tsx index f87a3b932..185b0ab1c 100644 --- a/src/dash-table/components/HeaderFactory.tsx +++ b/src/dash-table/components/HeaderFactory.tsx @@ -32,7 +32,7 @@ export default class HeaderFactory { public createHeaders() { const props = this.props; - let { + const { columns, merge_duplicate_headers, pagination_mode, @@ -40,7 +40,7 @@ export default class HeaderFactory { row_selectable, setProps, sorting, - sorting_settings, + sort_by, sorting_type, style_cell, style_cell_conditional, @@ -85,7 +85,7 @@ export default class HeaderFactory { labelsAndIndices, sorting, sorting_type, - sorting_settings, + sort_by, pagination_mode, setProps, props @@ -99,4 +99,4 @@ export default class HeaderFactory { return arrayMap(operations, headers, (o, h) => Array.prototype.concat(o, h)); } -} \ No newline at end of file +} diff --git a/src/dash-table/components/Table/index.tsx b/src/dash-table/components/Table/index.tsx index 1ce9b95a2..2ebd9d603 100644 --- a/src/dash-table/components/Table/index.tsx +++ b/src/dash-table/components/Table/index.tsx @@ -76,7 +76,7 @@ export default class Table extends Component new QuerySyntaxTree(query).toStructure() ); -} \ No newline at end of file +} diff --git a/src/dash-table/components/Table/props.ts b/src/dash-table/components/Table/props.ts index 1a8f1e64d..698d16aec 100644 --- a/src/dash-table/components/Table/props.ts +++ b/src/dash-table/components/Table/props.ts @@ -281,7 +281,7 @@ interface IProps { selected_rows?: Indices; setProps?: SetProps; sorting?: Sorting; - sorting_settings?: SortSettings; + sort_by?: SortSettings; sorting_type?: SortingType; sorting_treat_empty_string_as_none?: boolean; style_as_list_view?: boolean; @@ -322,7 +322,7 @@ interface IDefaultProps { selected_cells: SelectedCells; selected_rows: number[]; sorting: Sorting; - sorting_settings: SortSettings; + sort_by: SortSettings; sorting_type: SortingType; sorting_treat_empty_string_as_none: boolean; style_as_list_view: boolean; diff --git a/src/dash-table/dash/DataTable.js b/src/dash-table/dash/DataTable.js index b0ab6b87b..52119b881 100644 --- a/src/dash-table/dash/DataTable.js +++ b/src/dash-table/dash/DataTable.js @@ -46,7 +46,7 @@ export const defaultProps = { filtering_types: ['basic'], sorting: false, sorting_type: 'single', - sorting_settings: [], + sort_by: [], style_as_list_view: false, derived_viewport_data: [], @@ -831,7 +831,7 @@ export const propTypes = { * with the `fe` (or True) setting or via a callback in your * python "back-end" with the `be` setting. * Clicking on the sort arrows will update the - * `sorting_settings` property. + * `sort_by` property. */ sorting: PropTypes.oneOf(['fe', 'be', true, false]), @@ -848,7 +848,7 @@ export const propTypes = { sorting_type: PropTypes.oneOf(['single', 'multi']), /** - * `sorting_settings` describes the current state + * `sort_by` describes the current state * of the sorting UI. * That is, if the user clicked on the sort arrow * of a column, then this property will be updated @@ -858,7 +858,7 @@ export const propTypes = { * sorting parameters, in the order in which they were * clicked. */ - sorting_settings: PropTypes.arrayOf( + sort_by: PropTypes.arrayOf( // .exact PropTypes.shape({ column_id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, diff --git a/src/dash-table/derived/data/virtual.ts b/src/dash-table/derived/data/virtual.ts index f46b597f1..ca14879d0 100644 --- a/src/dash-table/derived/data/virtual.ts +++ b/src/dash-table/derived/data/virtual.ts @@ -16,7 +16,7 @@ const getter = ( filtering: Filtering, filter: string, sorting: Sorting, - sorting_settings: SortSettings = [], + sort_by: SortSettings = [], sorting_treat_empty_string_as_none: boolean ): IDerivedData => { const map = new Map(); @@ -37,7 +37,7 @@ const getter = ( undefined; if (sorting === 'fe' || sorting === true) { - data = sort(data, sorting_settings, isNully); + data = sort(data, sort_by, isNully); } // virtual_indices diff --git a/src/dash-table/derived/header/content.tsx b/src/dash-table/derived/header/content.tsx index 3840d849d..003ebe27b 100644 --- a/src/dash-table/derived/header/content.tsx +++ b/src/dash-table/derived/header/content.tsx @@ -47,7 +47,7 @@ function doSort(columnId: ColumnId, sortSettings: SortSettings, sortType: Sortin multiUpdateSettings; setProps({ - sorting_settings: sortingStrategy( + sort_by: sortingStrategy( sortSettings, { column_id: columnId, direction } ) diff --git a/tests/cypress/dash/v_be_page.py b/tests/cypress/dash/v_be_page.py index 293083347..c5296d929 100644 --- a/tests/cypress/dash/v_be_page.py +++ b/tests/cypress/dash/v_be_page.py @@ -64,9 +64,9 @@ @app.callback(Output("table", "data"), [ Input("table", "pagination_settings"), - Input("table", "sorting_settings") + Input("table", "sort_by") ]) -def updateData(pagination_settings, sorting_settings): +def updateData(pagination_settings, sort_by): print(pagination_settings) current_page = pagination_settings["current_page"] @@ -75,14 +75,14 @@ def updateData(pagination_settings, sorting_settings): start_index = current_page * page_size end_index = start_index + page_size print(str(start_index) + "," + str(end_index)) - print(sorting_settings) + print(sort_by) - if (sorting_settings is None or len(sorting_settings) == 0): + if (sort_by is None or len(sort_by) == 0): sorted_df = df.values else: sorted_df = df.sort_index( - axis=sorting_settings[0]['column_id'], - ascending=(sorting_settings[0]['direction'] == 'asc') + axis=sort_by[0]['column_id'], + ascending=(sort_by[0]['direction'] == 'asc') ).values return sorted_df[start_index:end_index] @@ -109,4 +109,4 @@ def findModifiedValue(data, previous): if __name__ == "__main__": - app.run_server(port=8081, debug=False) \ No newline at end of file + app.run_server(port=8081, debug=False) diff --git a/tests/dash/app_dataframe_backend_paging.py b/tests/dash/app_dataframe_backend_paging.py index 93fb53bc2..6fe7dcc28 100644 --- a/tests/dash/app_dataframe_backend_paging.py +++ b/tests/dash/app_dataframe_backend_paging.py @@ -77,7 +77,7 @@ def layout(): sorting='be', sorting_type='single', - sorting_settings=[] + sort_by=[] ), section_title('Backend Paging with Multi Column Sorting'), @@ -104,7 +104,7 @@ def layout(): sorting='be', sorting_type='multi', - sorting_settings=[] + sort_by=[] ), section_title('Backend Paging with Filtering'), @@ -162,7 +162,7 @@ def layout(): sorting='be', sorting_type='multi', - sorting_settings=[] + sort_by=[] ), section_title('Connecting Backend Paging with a Graph'), @@ -192,7 +192,7 @@ def layout(): sorting='be', sorting_type='multi', - sorting_settings=[] + sort_by=[] ), style={'height': 750, 'overflowY': 'scroll'}, className='six columns' @@ -221,13 +221,13 @@ def update_graph(pagination_settings): @app.callback( Output(IDS["table-sorting"], "data"), [Input(IDS["table-sorting"], "pagination_settings"), - Input(IDS["table-sorting"], "sorting_settings")]) -def update_graph(pagination_settings, sorting_settings): - print(sorting_settings) - if len(sorting_settings): + Input(IDS["table-sorting"], "sort_by")]) +def update_graph(pagination_settings, sort_by): + print(sort_by) + if len(sort_by): dff = df.sort_values( - sorting_settings[0]['columnId'], - ascending=sorting_settings[0]['direction'] == 'asc', + sort_by[0]['columnId'], + ascending=sort_by[0]['direction'] == 'asc', inplace=False ) else: @@ -244,15 +244,15 @@ def update_graph(pagination_settings, sorting_settings): @app.callback( Output(IDS["table-multi-sorting"], "data"), [Input(IDS["table-multi-sorting"], "pagination_settings"), - Input(IDS["table-multi-sorting"], "sorting_settings")]) -def update_graph(pagination_settings, sorting_settings): - print(sorting_settings) - if len(sorting_settings): + Input(IDS["table-multi-sorting"], "sort_by")]) +def update_graph(pagination_settings, sort_by): + print(sort_by) + if len(sort_by): dff = df.sort_values( - [col['columnId'] for col in sorting_settings], + [col['columnId'] for col in sort_by], ascending=[ col['direction'] == 'asc' - for col in sorting_settings + for col in sort_by ], inplace=False ) @@ -297,9 +297,9 @@ def update_graph(pagination_settings, filter): @app.callback( Output(IDS["table-sorting-filtering"], "data"), [Input(IDS["table-sorting-filtering"], "pagination_settings"), - Input(IDS["table-sorting-filtering"], "sorting_settings"), + Input(IDS["table-sorting-filtering"], "sort_by"), Input(IDS["table-sorting-filtering"], "filter")]) -def update_graph(pagination_settings, sorting_settings, filter): +def update_graph(pagination_settings, sort_by, filter): filtering_expressions = filter.split(' && ') dff = df for filter in filtering_expressions: @@ -316,12 +316,12 @@ def update_graph(pagination_settings, sorting_settings, filter): filter_value = float(filter.split(' < ')[1]) dff = dff.loc[dff[col_name] < filter_value] - if len(sorting_settings): + if len(sort_by): dff = dff.sort_values( - [col['columnId'] for col in sorting_settings], + [col['columnId'] for col in sort_by], ascending=[ col['direction'] == 'asc' - for col in sorting_settings + for col in sort_by ], inplace=False ) @@ -335,9 +335,9 @@ def update_graph(pagination_settings, sorting_settings, filter): @app.callback( Output(IDS["table-paging-with-graph"], "data"), [Input(IDS["table-paging-with-graph"], "pagination_settings"), - Input(IDS["table-paging-with-graph"], "sorting_settings"), + Input(IDS["table-paging-with-graph"], "sort_by"), Input(IDS["table-paging-with-graph"], "filter")]) -def update_table(pagination_settings, sorting_settings, filter): +def update_table(pagination_settings, sort_by, filter): filtering_expressions = filter.split(' && ') dff = df for filter in filtering_expressions: @@ -354,12 +354,12 @@ def update_table(pagination_settings, sorting_settings, filter): filter_value = float(filter.split(' < ')[1]) dff = dff.loc[dff[col_name] < filter_value] - if len(sorting_settings): + if len(sort_by): dff = dff.sort_values( - [col['columnId'] for col in sorting_settings], + [col['columnId'] for col in sort_by], ascending=[ col['direction'] == 'asc' - for col in sorting_settings + for col in sort_by ], inplace=False ) diff --git a/tests/visual/percy-storybook/DashTable.percy.tsx b/tests/visual/percy-storybook/DashTable.percy.tsx index a2ac626c1..dd681b1c3 100644 --- a/tests/visual/percy-storybook/DashTable.percy.tsx +++ b/tests/visual/percy-storybook/DashTable.percy.tsx @@ -208,7 +208,7 @@ storiesOf('DashTable/Sorting', module) data={sparseData} columns={mergedColumns} sorting={true} - sorting_settings={[{ column_id: 'a', direction: 'asc' }]} + sort_by={[{ column_id: 'a', direction: 'asc' }]} style_data_conditional={style_data_conditional} />)) .add('"a" descending', () => ()) .add('"a" ascending -- empty string override', () => ()) @@ -236,7 +236,7 @@ storiesOf('DashTable/Sorting', module) data={sparseData} columns={mergedColumns} sorting={true} - sorting_settings={[{ column_id: 'a', direction: 'desc' }]} + sort_by={[{ column_id: 'a', direction: 'desc' }]} sorting_treat_empty_string_as_none={true} style_data_conditional={style_data_conditional} />)); @@ -305,4 +305,4 @@ storiesOf('DashTable/Without id', module) rule: 'border: 4px solid cyan' }]} /> - )); \ No newline at end of file + )); From 5410f924eaaf0a604b6f12989cc62ce0f7dd157d Mon Sep 17 00:00:00 2001 From: alexcjohnson Date: Thu, 25 Apr 2019 10:12:57 -0400 Subject: [PATCH 2/2] changelog for sort_by --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf9c7646..fd4b5b81f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). [#397](https://github.com/plotly/dash-table/pull/397) - Rename `filtering_settings` to `filter` +[#412](https://github.com/plotly/dash-table/pull/412) +- Rename `sorting_settings` to `sort_by` + ## [3.6.0] - 2019-03-04 ### Fixed [#189](https://github.com/plotly/dash-table/issues/189)