From 71ecf5a02ed22011cd9b0aa7db293de8a566984b Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Fri, 24 Nov 2023 13:15:13 +0000 Subject: [PATCH 1/8] Add persistence_type="session" --- vizro-core/docs/pages/user_guides/custom_components.md | 6 +++--- vizro-core/src/vizro/models/_components/form/_user_input.py | 1 + vizro-core/src/vizro/models/_components/form/checklist.py | 1 + vizro-core/src/vizro/models/_components/form/dropdown.py | 1 + vizro-core/src/vizro/models/_components/form/radio_items.py | 1 + .../src/vizro/models/_components/form/range_slider.py | 3 +++ vizro-core/src/vizro/models/_components/form/slider.py | 2 ++ .../unit/vizro/models/_components/form/test_checklist.py | 1 + .../unit/vizro/models/_components/form/test_dropdown.py | 2 ++ .../unit/vizro/models/_components/form/test_radioitems.py | 1 + .../unit/vizro/models/_components/form/test_range_slider.py | 6 ++++++ .../tests/unit/vizro/models/_components/form/test_slider.py | 2 ++ 12 files changed, 24 insertions(+), 3 deletions(-) diff --git a/vizro-core/docs/pages/user_guides/custom_components.md b/vizro-core/docs/pages/user_guides/custom_components.md index f3872edfd..6d7644972 100644 --- a/vizro-core/docs/pages/user_guides/custom_components.md +++ b/vizro-core/docs/pages/user_guides/custom_components.md @@ -136,7 +136,7 @@ vm.Parameter.add_type("selector", TooltipNonCrossRangeSlider) marks=self.marks, className="range_slider_control" if self.step else "range_slider_control_no_space", value=value, - persistence=True, + persistence=True, persistence_type="session", allowCross=False, # (3)! tooltip={"placement": "bottom", "always_visible": True}, # (4)! ), @@ -153,7 +153,7 @@ vm.Parameter.add_type("selector", TooltipNonCrossRangeSlider) else "slider_input_field_no_space_left", value=value[0], size="24px", - persistence=True, + persistence=True, persistence_type="session", ), dcc.Input( id=f"{self.id}_end_value", @@ -165,7 +165,7 @@ vm.Parameter.add_type("selector", TooltipNonCrossRangeSlider) if self.step else "slider_input_field_no_space_right", value=value[1], - persistence=True, + persistence=True, persistence_type="session", ), dcc.Store(id=f"temp-store-range_slider-{self.id}", storage_type="local"), ], diff --git a/vizro-core/src/vizro/models/_components/form/_user_input.py b/vizro-core/src/vizro/models/_components/form/_user_input.py index cfe29a275..53821ed98 100644 --- a/vizro-core/src/vizro/models/_components/form/_user_input.py +++ b/vizro-core/src/vizro/models/_components/form/_user_input.py @@ -42,6 +42,7 @@ def build(self): placeholder=self.placeholder, type=self.input_type, persistence=True, + persistence_type="session", debounce=True, className="user_input", ), diff --git a/vizro-core/src/vizro/models/_components/form/checklist.py b/vizro-core/src/vizro/models/_components/form/checklist.py index b8f0daea6..83d07aa06 100644 --- a/vizro-core/src/vizro/models/_components/form/checklist.py +++ b/vizro-core/src/vizro/models/_components/form/checklist.py @@ -47,6 +47,7 @@ def build(self): options=full_options, value=self.value if self.value is not None else [default_value], persistence=True, + persistence_type="session", className="selector_body_checklist", ), ], diff --git a/vizro-core/src/vizro/models/_components/form/dropdown.py b/vizro-core/src/vizro/models/_components/form/dropdown.py index 9d01c79a5..cf5626954 100755 --- a/vizro-core/src/vizro/models/_components/form/dropdown.py +++ b/vizro-core/src/vizro/models/_components/form/dropdown.py @@ -60,6 +60,7 @@ def build(self): value=self.value if self.value is not None else default_value, multi=self.multi, persistence=True, + persistence_type="session", className="selector_body_dropdown", ), ], diff --git a/vizro-core/src/vizro/models/_components/form/radio_items.py b/vizro-core/src/vizro/models/_components/form/radio_items.py index 782f15d21..2d69efa6c 100644 --- a/vizro-core/src/vizro/models/_components/form/radio_items.py +++ b/vizro-core/src/vizro/models/_components/form/radio_items.py @@ -48,6 +48,7 @@ def build(self): options=full_options, value=self.value if self.value is not None else default_value, persistence=True, + persistence_type="session", className="selector_body_radio_items", ), ], diff --git a/vizro-core/src/vizro/models/_components/form/range_slider.py b/vizro-core/src/vizro/models/_components/form/range_slider.py index 4ee181c8d..25b558520 100644 --- a/vizro-core/src/vizro/models/_components/form/range_slider.py +++ b/vizro-core/src/vizro/models/_components/form/range_slider.py @@ -98,6 +98,7 @@ def build(self): marks=self.marks, value=value, persistence=True, + persistence_type="session", className="range_slider_control" if self.step else "range_slider_control_no_space", ), html.Div( @@ -112,6 +113,7 @@ def build(self): value=value[0], size="24px", persistence=True, + persistence_type="session", className="slider_input_field_left" if self.step else "slider_input_field_no_space_left", @@ -125,6 +127,7 @@ def build(self): step=self.step, value=value[1], persistence=True, + persistence_type="session", className="slider_input_field_right" if self.step else "slider_input_field_no_space_right", diff --git a/vizro-core/src/vizro/models/_components/form/slider.py b/vizro-core/src/vizro/models/_components/form/slider.py index 4a44e898f..1e234443f 100644 --- a/vizro-core/src/vizro/models/_components/form/slider.py +++ b/vizro-core/src/vizro/models/_components/form/slider.py @@ -93,6 +93,7 @@ def build(self): value=self.value or self.min, included=False, persistence=True, + persistence_type="session", className="slider_control" if self.step else "slider_control_no_space", ), dcc.Input( @@ -104,6 +105,7 @@ def build(self): step=self.step, value=self.value or self.min, persistence=True, + persistence_type="session", className="slider_input_field_right" if self.step else "slider_input_field_no_space_right", ), dcc.Store(id=f"{self.id}_temp_store", storage_type="local"), diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py b/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py index c73dd0c06..be1275a13 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_checklist.py @@ -21,6 +21,7 @@ def expected_checklist(): value=["ALL"], className="selector_body_checklist", persistence=True, + persistence_type="session", ), ], className="selector_container", diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py b/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py index 64b94f0e2..76b496162 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_dropdown.py @@ -21,6 +21,7 @@ def expected_dropdown_with_all(): value="ALL", multi=True, persistence=True, + persistence_type="session", className="selector_body_dropdown", ), ], @@ -40,6 +41,7 @@ def expected_dropdown_without_all(): value="A", multi=False, persistence=True, + persistence_type="session", className="selector_body_dropdown", ), ], diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py b/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py index 83c2053bd..05f935895 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_radioitems.py @@ -21,6 +21,7 @@ def expected_radio_items(): value="A", className="selector_body_radio_items", persistence=True, + persistence_type="session", ), ], className="selector_container", diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py b/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py index dba28f7b6..c356004f5 100644 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py @@ -28,6 +28,7 @@ def expected_range_slider_default(): id="range_slider", className="range_slider_control_no_space", persistence=True, + persistence_type="session", min=None, max=None, marks=None, @@ -44,6 +45,7 @@ def expected_range_slider_default(): size="24px", step=None, persistence=True, + persistence_type="session", min=None, max=None, value=None, @@ -54,6 +56,7 @@ def expected_range_slider_default(): placeholder="end", className="slider_input_field_no_space_right", persistence=True, + persistence_type="session", step=None, min=None, max=None, @@ -96,6 +99,7 @@ def expected_range_slider_with_optional(): className="range_slider_control", value=[0, 10], persistence=True, + persistence_type="session", ), html.Div( [ @@ -110,6 +114,7 @@ def expected_range_slider_with_optional(): value=0, size="24px", persistence=True, + persistence_type="session", ), dcc.Input( id="range_slider_with_all_end_value", @@ -121,6 +126,7 @@ def expected_range_slider_with_optional(): className="slider_input_field_right", value=10, persistence=True, + persistence_type="session", ), dcc.Store(id="temp-store-range_slider-range_slider_with_all", storage_type="local"), ], diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py b/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py index a8cd4a6ab..2657de882 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py @@ -33,6 +33,7 @@ def expected_slider(): value=5, included=False, persistence=True, + persistence_type="session", className="slider_control", ), dcc.Input( @@ -44,6 +45,7 @@ def expected_slider(): max=10, value=5, persistence=True, + persistence_type="session", className="slider_input_field_right", ), dcc.Store(id="slider_id_temp_store", storage_type="local"), From 8b8ee2dc61c1476e8bfc085df016b1eda95c7123 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Fri, 24 Nov 2023 13:16:56 +0000 Subject: [PATCH 2/8] Add storage_type="session" --- vizro-core/docs/pages/user_guides/custom_components.md | 2 +- vizro-core/src/vizro/models/_components/form/range_slider.py | 2 +- vizro-core/src/vizro/models/_components/form/slider.py | 2 +- .../unit/vizro/models/_components/form/test_range_slider.py | 4 ++-- .../tests/unit/vizro/models/_components/form/test_slider.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/vizro-core/docs/pages/user_guides/custom_components.md b/vizro-core/docs/pages/user_guides/custom_components.md index 6d7644972..666cb977c 100644 --- a/vizro-core/docs/pages/user_guides/custom_components.md +++ b/vizro-core/docs/pages/user_guides/custom_components.md @@ -167,7 +167,7 @@ vm.Parameter.add_type("selector", TooltipNonCrossRangeSlider) value=value[1], persistence=True, persistence_type="session", ), - dcc.Store(id=f"temp-store-range_slider-{self.id}", storage_type="local"), + dcc.Store(id=f"temp-store-range_slider-{self.id}", storage_type="session"), ], className="slider_input_container", ), diff --git a/vizro-core/src/vizro/models/_components/form/range_slider.py b/vizro-core/src/vizro/models/_components/form/range_slider.py index 25b558520..9bd94e52b 100644 --- a/vizro-core/src/vizro/models/_components/form/range_slider.py +++ b/vizro-core/src/vizro/models/_components/form/range_slider.py @@ -132,7 +132,7 @@ def build(self): if self.step else "slider_input_field_no_space_right", ), - dcc.Store(id=f"temp-store-range_slider-{self.id}", storage_type="local"), + dcc.Store(id=f"temp-store-range_slider-{self.id}", storage_type="session"), ], className="slider_input_container", ), diff --git a/vizro-core/src/vizro/models/_components/form/slider.py b/vizro-core/src/vizro/models/_components/form/slider.py index 1e234443f..28be60714 100644 --- a/vizro-core/src/vizro/models/_components/form/slider.py +++ b/vizro-core/src/vizro/models/_components/form/slider.py @@ -108,7 +108,7 @@ def build(self): persistence_type="session", className="slider_input_field_right" if self.step else "slider_input_field_no_space_right", ), - dcc.Store(id=f"{self.id}_temp_store", storage_type="local"), + dcc.Store(id=f"{self.id}_temp_store", storage_type="session"), ], className="slider_inner_container", ), diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py b/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py index c356004f5..5e74b86df 100644 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_range_slider.py @@ -62,7 +62,7 @@ def expected_range_slider_default(): max=None, value=None, ), - dcc.Store(id="temp-store-range_slider-range_slider", storage_type="local"), + dcc.Store(id="temp-store-range_slider-range_slider", storage_type="session"), ], className="slider_input_container", ), @@ -128,7 +128,7 @@ def expected_range_slider_with_optional(): persistence=True, persistence_type="session", ), - dcc.Store(id="temp-store-range_slider-range_slider_with_all", storage_type="local"), + dcc.Store(id="temp-store-range_slider-range_slider_with_all", storage_type="session"), ], className="slider_input_container", ), diff --git a/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py b/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py index 2657de882..6a2747010 100755 --- a/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py +++ b/vizro-core/tests/unit/vizro/models/_components/form/test_slider.py @@ -48,7 +48,7 @@ def expected_slider(): persistence_type="session", className="slider_input_field_right", ), - dcc.Store(id="slider_id_temp_store", storage_type="local"), + dcc.Store(id="slider_id_temp_store", storage_type="session"), ], className="slider_inner_container", ), From a36236ff50b811ec69bc90c89edf85fc7008d0c6 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Mon, 27 Nov 2023 13:37:32 +0000 Subject: [PATCH 3/8] Add changelog --- ...124_130803_antony.milne_session_storage.md | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md diff --git a/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md b/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md new file mode 100644 index 000000000..ab6e76f6b --- /dev/null +++ b/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md @@ -0,0 +1,46 @@ + + + + + +### Changed + +- Change the persistence of clientside data to `session` rather than `local` ([#182](https://github.com/mckinsey/vizro/pull/182)) + + + + From 5a56bdb878808a73a78785c674d9102086b89ca2 Mon Sep 17 00:00:00 2001 From: Antony Milne Date: Tue, 28 Nov 2023 15:58:03 +0000 Subject: [PATCH 4/8] Update docs --- .../20231124_130803_antony.milne_session_storage.md | 1 + vizro-core/docs/pages/user_guides/custom_charts.md | 7 ------- vizro-core/docs/pages/user_guides/custom_components.md | 2 ++ vizro-core/docs/pages/user_guides/integration.md | 7 ------- 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md b/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md index ab6e76f6b..cea5d1301 100644 --- a/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md +++ b/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md @@ -22,6 +22,7 @@ Uncomment the section that is right (remove the HTML comment wrapper). - A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX ([#1](https://github.com/mckinsey/vizro/pull/1)) --> + ### Changed - Change the persistence of clientside data to `session` rather than `local` ([#182](https://github.com/mckinsey/vizro/pull/182)) diff --git a/vizro-core/docs/pages/user_guides/custom_charts.md b/vizro-core/docs/pages/user_guides/custom_charts.md index 3dda3f720..7325b16d2 100644 --- a/vizro-core/docs/pages/user_guides/custom_charts.md +++ b/vizro-core/docs/pages/user_guides/custom_charts.md @@ -151,10 +151,3 @@ The below examples shows a more involved use-case. We create and style a waterfa [![Graph3]][Graph3] [Graph3]: ../../assets/user_guides/custom_charts/custom_chart_waterfall.png - - -???+ warning - - Please note that users of this package are responsible for the content of any custom-created component, - function or integration they write - especially with regard to leaking any sensitive information or exposing to - any security threat during implementation. diff --git a/vizro-core/docs/pages/user_guides/custom_components.md b/vizro-core/docs/pages/user_guides/custom_components.md index 666cb977c..8bbbf93ee 100644 --- a/vizro-core/docs/pages/user_guides/custom_components.md +++ b/vizro-core/docs/pages/user_guides/custom_components.md @@ -355,3 +355,5 @@ vm.Page.add_type("components", Jumbotron) Please note that users of this package are responsible for the content of any custom-created component, function or integration they write - especially with regard to leaking any sensitive information or exposing to any security threat during implementation. + + By default, all Dash components in Vizro that persist client-side data set [`persistence_type="session"` to use `window.SessionStorage`](https://dash.plotly.com/persistence), which is cleared upon closing the browser. Be careful when using any custom components that persist data beyond this scope: it is your responsibility to ensure compliance with any legal requirements affecting jurisdictions in which your app operates. diff --git a/vizro-core/docs/pages/user_guides/integration.md b/vizro-core/docs/pages/user_guides/integration.md index c4c6e1253..faa0f4961 100644 --- a/vizro-core/docs/pages/user_guides/integration.md +++ b/vizro-core/docs/pages/user_guides/integration.md @@ -70,10 +70,3 @@ The full code for these different cases is given below. for dataset_name, dataset in kedro_integration.datasets_from_catalog(catalog).items(): data_manager[dataset_name] = dataset ``` - - -???+ warning - - Please note that users of this package are responsible for the content of any custom-created component, - function or integration they write - especially with regard to leaking any sensitive information or exposing to - any security threat during implementation. From 21ca9b6035b11d630e2f6c6e0e7509aef5d35cbf Mon Sep 17 00:00:00 2001 From: Antony Milne <49395058+antonymilne@users.noreply.github.com> Date: Tue, 28 Nov 2023 15:58:44 +0000 Subject: [PATCH 5/8] Update vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md Signed-off-by: Antony Milne <49395058+antonymilne@users.noreply.github.com> --- .../changelog.d/20231124_130803_antony.milne_session_storage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md b/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md index cea5d1301..9231939f6 100644 --- a/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md +++ b/vizro-core/changelog.d/20231124_130803_antony.milne_session_storage.md @@ -25,7 +25,7 @@ Uncomment the section that is right (remove the HTML comment wrapper). ### Changed -- Change the persistence of clientside data to `session` rather than `local` ([#182](https://github.com/mckinsey/vizro/pull/182)) +- Change the persistence of client-side data to `session` rather than `local` ([#182](https://github.com/mckinsey/vizro/pull/182))