Skip to content

Commit

Permalink
Remove Optional in favour of proper default values
Browse files Browse the repository at this point in the history
  • Loading branch information
antonymilne committed Nov 15, 2023
1 parent 26c88f5 commit 99acc01
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 2 additions & 0 deletions vizro-core/examples/default/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,14 @@ def create_home_page():
selector=vm.NavBar(
items=[
vm.NavItem(
text="asdf",
pages={
"Analysis": ["Homepage", "Variable Analysis"],
"Summary": ["Relationship Analysis", "Continent Summary"],
},
),
vm.NavItem(
text="ASDF",
pages=["Country Analysis"],
icon="summarize",
),
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_navigation/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Accordion(VizroBaseModel):
"""

type: Literal["accordion"] = "accordion"
pages: Optional[Dict[str, List[str]]] = Field(
pages: Dict[str, List[str]] = Field(
{}, description="A dictionary with a page group title as key and a list of page IDs as values."
)

Expand Down
4 changes: 2 additions & 2 deletions vizro-core/src/vizro/models/_navigation/nav_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ class NavBar(VizroBaseModel):
"""

type: Literal["navbar"] = "navbar" # AM: nav_bar?
pages: Optional[Dict[str, List[str]]] = Field(
pages: Dict[str, List[str]] = Field(
{}, description="A dictionary with a page group title as key and a list of page IDs as values."
)
items: Optional[List[NavItem]] = [] # AM: think about name
items: List[NavItem] = [] # AM: think about name

# validators
_validate_pages = validator("pages", allow_reuse=True)(_validate_pages)
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_navigation/nav_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class NavItem(VizroBaseModel):
"""

type: Literal["navitem"] = "navitem" # AM: nav_item?
pages: Optional[NavPagesType] = []
pages: NavPagesType = []
text: str = Field(
..., description="Text to be displayed below the icon."
) # AM: Maybe call label. This just does tooltip for now.
Expand Down
5 changes: 2 additions & 3 deletions vizro-core/src/vizro/models/_navigation/navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class Navigation(VizroBaseModel):
Defaults to `None`.
"""

pages: Optional[NavPagesType] = None # AM: yes but NavPagesType: note breaking change, maybe put whole type hint in
selector: Optional[NavSelectorType] = None
pages: NavPagesType = [] # AM: yes but NavPagesType: note breaking change, maybe put whole type hint in
selector: NavSelectorType = Accordion()

# validators
_validate_pages = validator("pages", allow_reuse=True)(_validate_pages)
Expand All @@ -33,7 +33,6 @@ class Navigation(VizroBaseModel):
def pre_build(self):
# Since models instantiated in pre_build do not themselves have pre_build called on them, we call it manually
# here. Note that not all selectors have pre_build (Accordion does not).
self.selector = self.selector or Accordion()
self.selector.pages = self.selector.pages or self.pages
if hasattr(self.selector, "pre_build"):
self.selector.pre_build()
Expand Down

0 comments on commit 99acc01

Please sign in to comment.