diff --git a/vizro-core/changelog.d/20230927_163719_huong_li_nguyen_button_as_control.md b/vizro-core/changelog.d/20230927_163719_huong_li_nguyen_button_as_control.md new file mode 100644 index 000000000..b01f2fc93 --- /dev/null +++ b/vizro-core/changelog.d/20230927_163719_huong_li_nguyen_button_as_control.md @@ -0,0 +1,41 @@ + + + + + +### Changed + +- Add `Button` to `ControlType` ([#88](https://github.com/mckinsey/vizro/pull/88)) + + + +### Fixed + +- Fix bug of horizontal rulers not being visible in `Card` ([#88](https://github.com/mckinsey/vizro/pull/88)) + + diff --git a/vizro-core/docs/pages/development/authors.md b/vizro-core/docs/pages/development/authors.md index 132016b74..b930aa1d2 100644 --- a/vizro-core/docs/pages/development/authors.md +++ b/vizro-core/docs/pages/development/authors.md @@ -10,7 +10,7 @@ [Maximilian Schulz](https://github.com/maxschulz-COL), [Huong Li Nguyen](https://github.com/huong-li-nguyen), [Dan Dumitriu](https://github.com/dandumitriu1), -[Joseph Perkins](https://github.com/Joseph-Perkins), +[Joseph Perkins](https://github.com/Joseph-Perkins) ## Previous team members and code contributors diff --git a/vizro-core/docs/pages/user_guides/buttons.md b/vizro-core/docs/pages/user_guides/buttons.md new file mode 100755 index 000000000..d30664bc9 --- /dev/null +++ b/vizro-core/docs/pages/user_guides/buttons.md @@ -0,0 +1,5 @@ +# How to use buttons + +For further details on how to use the [`Button`][vizro.models.Button], see our user guide on [Buttons](components.md#button). +Configuration instructions remain the same, but to add a [`Button`][vizro.models.Button] to the control panel, +simply insert it into the `controls` argument of the [`Page`][vizro.models.Page]. diff --git a/vizro-core/docs/pages/user_guides/components.md b/vizro-core/docs/pages/user_guides/components.md index a08484b00..e7d602d34 100755 --- a/vizro-core/docs/pages/user_guides/components.md +++ b/vizro-core/docs/pages/user_guides/components.md @@ -674,7 +674,7 @@ To enhance dashboard interactions, you can use the [`Button`][vizro.models.Butto action functions such as e.g. exporting chart data. Please refer to the [user guide][vizro.actions] on [`Actions`][vizro.models.Action] for currently available options. -To add a [`Button`][vizro.models.Button], simply insert it into the `components` argument of the +To add a [`Button`][vizro.models.Button] as a component, simply insert it into the `components` argument of the [`Page`][vizro.models.Page]. You can configure the `text` argument to alter the display text of the [`Button`][vizro.models.Button] and the diff --git a/vizro-core/mkdocs.yml b/vizro-core/mkdocs.yml index 5f925659f..7a468a18c 100644 --- a/vizro-core/mkdocs.yml +++ b/vizro-core/mkdocs.yml @@ -17,6 +17,7 @@ nav: - Filters: pages/user_guides/filters.md - Parameters: pages/user_guides/parameters.md - Selectors: pages/user_guides/selectors.md + - Buttons: pages/user_guides/buttons.md - Navigation: - Accordion: pages/user_guides/navigation.md - Visual Formatting: diff --git a/vizro-core/schemas/0.1.4.dev0.json b/vizro-core/schemas/0.1.4.dev0.json index ad89ca9e6..29b1d1516 100644 --- a/vizro-core/schemas/0.1.4.dev0.json +++ b/vizro-core/schemas/0.1.4.dev0.json @@ -826,11 +826,15 @@ "discriminator": { "propertyName": "type", "mapping": { + "button": "#/definitions/Button", "filter": "#/definitions/Filter", "parameter": "#/definitions/Parameter" } }, "oneOf": [ + { + "$ref": "#/definitions/Button" + }, { "$ref": "#/definitions/Filter" }, diff --git a/vizro-core/src/vizro/models/types.py b/vizro-core/src/vizro/models/types.py index 6ba038e05..257c9a6bb 100644 --- a/vizro-core/src/vizro/models/types.py +++ b/vizro-core/src/vizro/models/types.py @@ -255,7 +255,7 @@ class OptionsDictType(TypedDict): ] ControlType = Annotated[ - Union["Filter", "Parameter"], + Union["Button", "Filter", "Parameter"], Field( discriminator="type", description="Control that affects components on the page.", diff --git a/vizro-core/tests/unit/vizro/models/test_page.py b/vizro-core/tests/unit/vizro/models/test_page.py index 6505eff57..975795b96 100644 --- a/vizro-core/tests/unit/vizro/models/test_page.py +++ b/vizro-core/tests/unit/vizro/models/test_page.py @@ -87,6 +87,23 @@ def test_set_layout_invalid(self): with pytest.raises(ValidationError, match="Number of page and grid components need to be the same."): vm.Page(title="Page 4", components=[vm.Button()], layout=vm.Layout(grid=[[0, 1]])) + def test_valid_component_types(self, standard_px_chart): + vm.Page( + title="Page Title", + components=[vm.Graph(figure=standard_px_chart), vm.Card(text="""# Header 1"""), vm.Button()], + ) + + def test_valid_control_types(self, standard_px_chart): + vm.Page( + title="Page Title", + components=[vm.Graph(id="scatter", figure=standard_px_chart)], + controls=[ + vm.Filter(column="continent"), + vm.Parameter(targets=["scatter.x"], selector=vm.RadioItems(options=["lifeExp", "pop", "gdpPercap"])), + vm.Button(), + ], + ) + # TODO: Remove this if we can get rid of on-page-load action class TestPagePreBuildMethod: