Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable highlighting of active page button and refactor accordion.build() #74

Merged
merged 24 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3033abd
fixing accordion item highlight bug
nadijagraca Sep 27, 2023
b4cbf9f
removing background color highlight from selected accordion, aligning…
nadijagraca Sep 28, 2023
f630b50
added changelog
nadijagraca Sep 28, 2023
d843b1d
minor linting fixes'
nadijagraca Sep 28, 2023
417ca3c
fixed tests
nadijagraca Sep 28, 2023
19983a8
Merge branch 'main' into vizro/bug/highlight_active_accordion_item
huong-li-nguyen Oct 2, 2023
e6307aa
Lint
huong-li-nguyen Oct 2, 2023
9fecf3c
Replace active class with active param
huong-li-nguyen Oct 2, 2023
8cd1bfc
Merge branch 'main' into vizro/bug/highlight_active_accordion_item
huong-li-nguyen Oct 2, 2023
5768665
Merge branch 'main' into vizro/bug/highlight_active_accordion_item
huong-li-nguyen Oct 3, 2023
901c7f2
Merge branch 'main' into vizro/bug/highlight_active_accordion_item
huong-li-nguyen Oct 3, 2023
4bdca79
Refactor code
huong-li-nguyen Oct 3, 2023
e320bb8
Fix tests
huong-li-nguyen Oct 3, 2023
ca5e675
Lint
huong-li-nguyen Oct 3, 2023
56ebe70
Merge branch 'main' into vizro/bug/highlight_active_accordion_item
huong-li-nguyen Oct 3, 2023
5081c89
Move page registering to Dashboard.pre_build
huong-li-nguyen Oct 3, 2023
6401a26
Update changelog
huong-li-nguyen Oct 3, 2023
a9dc868
Remove Accordion.build from page.build
huong-li-nguyen Oct 3, 2023
e3851c3
Remove navigation.pre_build from page and fix tests
huong-li-nguyen Oct 3, 2023
203975f
Update changelog
huong-li-nguyen Oct 4, 2023
2fa3429
PR comments
huong-li-nguyen Oct 4, 2023
947cdaf
Merge branch 'main' into vizro/bug/highlight_active_accordion_item
huong-li-nguyen Oct 4, 2023
a316e42
Fix access to dash.page_registry
huong-li-nguyen Oct 4, 2023
bb8d9f0
Update KeyError
huong-li-nguyen Oct 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Uncomment the section that is right (remove the HTML comment wrapper).

### Added

- Add validator for `dashboard.navigation` to default to `Navigation()` if not provided ([#74](https://github.com/mckinsey/vizro/pull/74))
- Add validator for `Dashboard.navigation` to default to `Navigation()` if not provided ([#74](https://github.com/mckinsey/vizro/pull/74))

### Changed

- Move creation of `dash.page_registry` to `Dashboard.pre_build` ([#74](https://github.com/mckinsey/vizro/pull/74))
- Change the collapsible default behavior and highlighting color of the selected accordion group ([#74](https://github.com/mckinsey/vizro/pull/74))
- Change the default collapsible behavior and highlighting color of the selected accordion group ([#74](https://github.com/mckinsey/vizro/pull/74))

<!--
### Deprecated
Expand Down
9 changes: 6 additions & 3 deletions vizro-core/src/vizro/models/_navigation/_accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ class Accordion(VizroBaseModel):
_validate_pages = validator("pages", allow_reuse=True, always=True)(_validate_pages)

@_log_call
def build(self, active_page_id):
def build(self, *, active_page_id=None):
return self._create_accordion(active_page_id=active_page_id)

def _create_accordion_buttons(self, pages, active_page_id):
"""Creates a button for each provided page that is registered."""
accordion_buttons = []
for page_id in pages:
page = dash.page_registry[page_id]
try:
page = dash.page_registry[page_id]
except KeyError:
raise KeyError(f"Page with ID {page_id} cannot be found. Please add the page to `Dashboard.pages`")
huong-li-nguyen marked this conversation as resolved.
Show resolved Hide resolved
accordion_buttons.append(
dbc.Button(
children=[page["name"]],
key=page["relative_path"],
className="accordion-item-button",
active=True if active_page_id == page["module"] else False,
active=page_id == active_page_id,
href=page["relative_path"],
)
)
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ def _set_selector(self):
self._selector = Accordion(pages=self.pages)

@_log_call
def build(self, active_page_id):
def build(self, *, active_page_id=None):
return self._selector.build(active_page_id=active_page_id)
6 changes: 3 additions & 3 deletions vizro-core/src/vizro/models/_page.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import List, Optional
from typing import List, Optional, cast

import dash_bootstrap_components as dbc
import dash_daq as daq
Expand All @@ -12,7 +12,7 @@
from vizro.actions import _on_page_load
from vizro.managers import model_manager
from vizro.managers._model_manager import DuplicateIDError
from vizro.models import Action, Dashboard, Graph, Layout, VizroBaseModel
from vizro.models import Action, Dashboard, Graph, Layout, Navigation, VizroBaseModel
from vizro.models._action._actions_chain import ActionsChain, Trigger
from vizro.models._models_utils import _log_call, get_unique_grid_component_ids

Expand Down Expand Up @@ -168,7 +168,7 @@ def _create_control_panel(controls_content):

def _create_nav_panel(self):
_, dashboard = next(model_manager._items_with_type(Dashboard))
return dashboard.navigation.build(active_page_id=self.id) # type: ignore[union-attr]
return cast(Navigation, dashboard.navigation).build(active_page_id=self.id)

def _create_component_container(self, components_content):
component_container = html.Div(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_accordion_build_pages_as_dict(self, pages_as_dict, accordion_from_pages
assert result == expected

def test_accordion_build_single_page_accordion(self):
accordion = Accordion(pages=["Page 1"], id="single_accordion").build(active_page_id="Page 1")
accordion = Accordion(pages=["Page 1"], id="single_accordion").build()
assert accordion is None

def test_navigation_not_all_pages_included(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ def test_navigation_build(self, pages):
accordion = Accordion(pages=pages)
navigation._selector.id = accordion.id

result = json.loads(json.dumps(navigation.build(active_page_id="Page 1"), cls=plotly.utils.PlotlyJSONEncoder))
expected = json.loads(json.dumps(accordion.build(active_page_id="Page 1"), cls=plotly.utils.PlotlyJSONEncoder))
result = json.loads(json.dumps(navigation.build(), cls=plotly.utils.PlotlyJSONEncoder))
expected = json.loads(json.dumps(accordion.build(), cls=plotly.utils.PlotlyJSONEncoder))
assert result == expected
2 changes: 1 addition & 1 deletion vizro-core/tests/unit/vizro/models/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,5 @@ def test_page_build_left_side_removed(standard_px_chart):
dashboard = vm.Dashboard(pages=[page])
dashboard.pre_build()
dashboard.navigation.pre_build()
assert ("className='left_side'" not in str(page.build())) is True
assert "className='left_side'" not in str(page.build())
del dash.page_registry["Single Page"]
Loading