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

[BUGFIX] fix NavDrawer to force href update of menu items #32

Merged
merged 7 commits into from
Aug 11, 2021

Conversation

romanwozniak
Copy link
Contributor

@romanwozniak romanwozniak commented Aug 10, 2021

In #30, NavDrawer component was updated to use EuiTreeView instead of EuiListGroup. EuiTreeView doesn't support href property, so menu navigation was implemented with onClick property and then navigate to the desired destination.

However, this doesn't work properly, because mlp applications are deployed as separate single page apps, so the destination utl could be outside of the application's state (i.e. if user clicks on Merlin menu item from the Turing app, then this page doesn't exist in Turing's router). To solve this, the page should be forcefully refreshed and this is achieved with update of window.location.href.

On top of this, I've updated dependencies and fixed some of rollup warnings (such as circular dependency).

@@ -53,7 +58,9 @@ export const NavDrawer = ({ homeUrl = "/", docLinks }) => {

callback: () =>
!children || !projectId
? navigate(projectId ? `${a.href}/projects/${projectId}` : a.href)
? window.location.href = !!projectId
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about this line. At first, I thought it should be a condition expression for the ternary operator, but it seems you are assigning value to window.location.href by using one =. Is it another JS magic that I don't know? Please enlighten me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which part is magical here? :) yeah, I'm assigning a value (conditional) to window.location.href and with that you can sort of programatically trigger a click on a link with assigned href value.
Trick is that navigate comes from @reach/router and it navigates inside a single page app (SPA) (without triggering a full refresh of the page), so I need to emulate a click on a link to completely refresh the page (so another SPA can be downloaded)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants