From b505bf8a3c7541b305c64ce3efa5e326e0eb2c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 7 Apr 2020 15:59:44 -0400 Subject: [PATCH 1/5] `data` and `columns` are required props --- src/dash-table/dash/DataTable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dash-table/dash/DataTable.js b/src/dash-table/dash/DataTable.js index 6c53e4685..78526b1ed 100644 --- a/src/dash-table/dash/DataTable.js +++ b/src/dash-table/dash/DataTable.js @@ -390,7 +390,7 @@ export const propTypes = { * Stay tuned by following [https://github.com/plotly/dash-table/issues/166](https://github.com/plotly/dash-table/issues/166) */ type: PropTypes.oneOf(['any', 'numeric', 'text', 'datetime']) - })), + })).isRequired, /** * If true, headers are included when copying from the table to different @@ -450,7 +450,7 @@ export const propTypes = { * {'column-1': 8, 'column-2': 'boston', 'column-3': 'america'} * ] */ - data: PropTypes.arrayOf(PropTypes.object), + data: PropTypes.arrayOf(PropTypes.object).isRequired, /** * The previous state of `data`. `data_previous` From 299c2c07423cd7df89a8dd6337c0b4e4c5b76f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 7 Apr 2020 16:05:09 -0400 Subject: [PATCH 2/5] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b311679b7..1f8a61535 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [Unreleased] +### Fixed +- [#731](https://github.com/plotly/dash-table/pull/731) Flag `data` and `columns` as required props + ## [4.6.2] - 2020-04-01 ### Changed - [#713](https://github.com/plotly/dash-table/pull/713) Update from React 16.8.6 to 16.13.0 From c2d870c9e35c39237ad96327308eedc56c18f093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 7 Apr 2020 18:12:50 -0400 Subject: [PATCH 3/5] - undo data and columns `isRequired` - remove default value for data and columns - sanitize data and columns props - update columns prop validation - update TypeScript types --- CHANGELOG.md | 2 +- src/dash-table/components/Table/props.ts | 4 ++-- src/dash-table/dash/DataTable.js | 6 ++---- src/dash-table/dash/Sanitizer.ts | 8 ++++++-- src/dash-table/dash/validate.ts | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8a61535..dece70075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Fixed -- [#731](https://github.com/plotly/dash-table/pull/731) Flag `data` and `columns` as required props +- [#731](https://github.com/plotly/dash-table/pull/731) Fix a bug where `data=None` and `columns=None` caused the table to throw an error ## [4.6.2] - 2020-04-01 ### Changed diff --git a/src/dash-table/components/Table/props.ts b/src/dash-table/components/Table/props.ts index 9fc5771d6..67fa48335 100644 --- a/src/dash-table/components/Table/props.ts +++ b/src/dash-table/components/Table/props.ts @@ -341,12 +341,10 @@ export interface IProps { interface IDefaultProps { active_cell: ICellCoordinates; column_selectable: Selection; - columns: Columns; dropdown: StaticDropdowns; dropdown_conditional: ConditionalDropdowns; dropdown_data: DataDropdowns; css: IStylesheetRule[]; - data: Data; editable: boolean; export_columns: ExportColumns; export_format: ExportFormat; @@ -410,6 +408,8 @@ export type PropsWithDefaults = IProps & IDefaultProps; export type SanitizedProps = Omit + return R.isNil(columns) || !R.any((column: any) => column.format && ( ( column.format.symbol && From 0c27fd3337869f6dbd464fcadbf2a61910713214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 7 Apr 2020 18:32:51 -0400 Subject: [PATCH 4/5] add empty and valid when data=None, columns=None --- tests/selenium/test_empty.py | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/selenium/test_empty.py diff --git a/tests/selenium/test_empty.py b/tests/selenium/test_empty.py new file mode 100644 index 000000000..e9fa01986 --- /dev/null +++ b/tests/selenium/test_empty.py @@ -0,0 +1,45 @@ +import dash +from dash.dependencies import Input, Output +from dash.exceptions import PreventUpdate + +from dash_table import DataTable +from dash_html_components import Button, Div + + +def get_app(): + app = dash.Dash(__name__) + + columns = [{"name": i, "id": i} for i in ["a", "b"]] + data = [dict(a=1, b=2), dict(a=11, b=22)] + + app.layout = Div( + [ + Button(id="clear-table", children=["Clear table"]), + DataTable(id="table", columns=columns, data=data), + ] + ) + + @app.callback( + [Output("table", "data"), Output("table", "columns")], + [Input("clear-table", "n_clicks")], + ) + def clear_table(n_clicks): + if n_clicks is None: + raise PreventUpdate + + nonlocal columns, data + + return (data, columns) if n_clicks % 2 == 0 else (None, None) + + return app + + +def test_empt001_clear_(test): + test.start_server(get_app()) + + target = test.table("table") + + assert target.is_ready() + test.driver.find_element_by_css_selector("#clear-table").click() + assert target.is_ready() + assert len(test.driver.find_elements_by_css_selector("tr")) == 0 From d93331d05c05bf009636eef30901f1e21ba2ab23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andre=CC=81=20Rivet?= Date: Tue, 14 Apr 2020 14:38:26 -0400 Subject: [PATCH 5/5] - make test more specific - add pytest.ini with `testpaths` --- pytest.ini | 5 +++++ tests/selenium/test_empty.py | 1 + 2 files changed, 6 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..b6302a609 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +testpaths = tests/ +addopts = -rsxX -vv +log_format = %(asctime)s | %(levelname)s | %(name)s:%(lineno)d | %(message)s +log_cli_level = ERROR diff --git a/tests/selenium/test_empty.py b/tests/selenium/test_empty.py index e9fa01986..6c62b9e22 100644 --- a/tests/selenium/test_empty.py +++ b/tests/selenium/test_empty.py @@ -40,6 +40,7 @@ def test_empt001_clear_(test): target = test.table("table") assert target.is_ready() + assert len(test.driver.find_elements_by_css_selector("tr")) == 3 test.driver.find_element_by_css_selector("#clear-table").click() assert target.is_ready() assert len(test.driver.find_elements_by_css_selector("tr")) == 0