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

Bug fix on accordion active item #276

Merged
merged 17 commits into from
Jan 26, 2024
Merged

Conversation

nadijagraca
Copy link
Contributor

Description

Fixing bug on accordion active item:

What to test:
If relevant accordion item opens when navigating from homepage or by typing path in browser.

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

    • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.
    • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorized to submit this contribution on behalf of the original creator(s) or their licensees.
    • I certify that the use of this contribution as authorized by the Apache 2.0 license does not violate the intellectual property rights of anyone else.
    • I have not referenced individuals, products or companies in any commits, directly or indirectly.
    • I have not added data or restricted code in any commits, directly or indirectly.

nadijagraca and others added 7 commits January 22, 2024 18:28
Co-authored-by: petar-qb <petar_pejovic@external.mckinsey.com>
Co-authored-by: Antony Milne <49395058+antonymilne@users.noreply.github.com>
Signed-off-by: Anna Xiong <anna.xiong@quantumblack.com>
Co-authored-by: Maximilian Schulz <83698606+maxschulz-COL@users.noreply.github.com>
Co-authored-by: Antony Milne <49395058+antonymilne@users.noreply.github.com>
Copy link
Contributor

@huong-li-nguyen huong-li-nguyen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well - thanks for fixing! 👍

@nadijagraca - for the next time it would be great if you could add some example code snippet to see that the relevant changes work. I wasn't quite sure what I had to test first 😄

For the next reviewer - replace the navigation in the example demo with:

navigation=vm.Navigation(
        nav_selector=vm.NavBar(
            items=[
                vm.NavLink(label="Homepage", pages=["Homepage"], icon="Home"),
                vm.NavLink(
                    label="Analysis",
                    pages={"Title 1": ["Variable Analysis", "Benchmark Analysis"],
                           "Title 2": ["Continent Summary", "Relationship Analysis"]},
                    icon="Stacked Bar Chart",
                ),
            ]
        ),
    ),

Then navigate to relationship-analysis either via clicking on the card on the homepage or by directly changing the path in the URL. What you should see is that the accordion opens accordingly (opens where active page is)

@nadijagraca @l0uden - will we add screenshots to test this? or do the unit tests cover this use case sufficiently?

Copy link
Contributor

@antonymilne antonymilne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice fix! I didn't test it out but it looks great, thank you for doing it 👍

However, I think there might be a minor bug in it. In this code:

next(
    page_group for page_group, page_members in self.pages.items() if active_page_id in page_members
)

if active_page_id in page_members is always False then this will turn into next of an empty dictionary, which will raise StopIteration and crash. Try this out:

next(x for x, y in dict(a=1).items() if x == "b")

What I'm not sure about is whether this case can ever occur in practice? If I type the URL to a page that doesn't exist in the navigation then is it possible it would trigger this error?

vizro-core/src/vizro/models/_navigation/accordion.py Outdated Show resolved Hide resolved
huong-li-nguyen and others added 4 commits January 24, 2024 11:07
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Alexey Snigir <35569332+l0uden@users.noreply.github.com>
Co-authored-by: Li Nguyen <90609403+huong-li-nguyen@users.noreply.github.com>
@huong-li-nguyen huong-li-nguyen changed the base branch from main to bug/109 January 24, 2024 10:34
@huong-li-nguyen huong-li-nguyen changed the base branch from bug/109 to main January 24, 2024 10:35
@nadijagraca nadijagraca merged commit 8b40813 into main Jan 26, 2024
33 checks passed
@nadijagraca nadijagraca deleted the fix/accordion_active_item branch January 26, 2024 08:34
nadijagraca added a commit that referenced this pull request Jan 26, 2024
Signed-off-by: Anna Xiong <anna.xiong@quantumblack.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Anna Xiong <anna.xiong@quantumblack.com>
Co-authored-by: Li Nguyen <90609403+huong-li-nguyen@users.noreply.github.com>
Co-authored-by: petar-qb <petar_pejovic@external.mckinsey.com>
Co-authored-by: Antony Milne <49395058+antonymilne@users.noreply.github.com>
Co-authored-by: Maximilian Schulz <83698606+maxschulz-COL@users.noreply.github.com>
Co-authored-by: huong-li-nguyen <huong_li_nguyen@mckinsey.com>
Co-authored-by: Alexey Snigir <35569332+l0uden@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Report 🐛 Issue contains a bug report
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants