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

CHI-1994: Modal routing #1737

Merged
merged 4 commits into from
Oct 24, 2023
Merged

CHI-1994: Modal routing #1737

merged 4 commits into from
Oct 24, 2023

Conversation

stephenhand
Copy link
Collaborator

@stephenhand stephenhand commented Oct 18, 2023

Review after #1732 is merged

Description

  • Significantly enhances the capabilities of the routing system. Now every task has a 'stack' of routes which gets added to with forward navigation, and removed from when the user 'goes back'
  • Added first class support for modal navigation - now a route can have an 'activeModal' property, which is another stack of routes. Routes in activeModalStacks can have their own activeModals, thus allowing us to stack modal navigation
  • changeRoute now automatically adds routes to the top level active modal. going back pops from the current top modal routes
  • closing a modal drops the whole stack of routes, removing the parent route's 'activeModal' property
  • Components base their rendering on the latest route of the top modal, a helper function is included for this
  • Case navigation is reworked as a modal to demonstrate

Checklist

  • Corresponding issue has been opened
  • New tests added
  • N/A Feature flags added
  • N/A Strings are localized
  • Tested for chat contacts
  • Tested for call contacts

Related Issues

CHI-1994

Verification steps

Regression test navigation around the application

Copy link
Contributor

@murilovmachado murilovmachado left a comment

Choose a reason for hiding this comment

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

The code looks great, Steve.

I haven't tried it locally yet, but I don't want you to be blocked by it. Feel free to merge.

Comment on lines +139 to +158
const closeTopModal = (routeStack: AppRoutes[], parent?: AppRoutes): AppRoutes[] => {
if (routeStack?.length) {
const currentRoute = routeStack[routeStack.length - 1];

if (!isRouteWithModalSupport(currentRoute) || !currentRoute.activeModal) {
// This is the top of the modal stack - if it has a parent, return undefined so the caller removes it
// Otherwise it's the base route, so just return it as is
return parent ? undefined : routeStack;
}
const nextStack = closeTopModal(currentRoute.activeModal, currentRoute);
if (nextStack) {
return [...routeStack.slice(0, -1), { ...currentRoute, activeModal: nextStack }];
}
// closeTopModal returned undefined, currentRoute's activeModal is the top of the stack and should be removed
const { activeModal, ...currentRouteWithoutModal } = currentRoute;
return [...routeStack.slice(0, -1), currentRouteWithoutModal];
}
// Empty activeModalStack should be removed, empty base route should be left alone (probably in a bad state though...
return parent ? undefined : routeStack;
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I was a bit confused trying to understand the parent parameter, but it seems it's only being used internally for the recursion, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, basically there are some parts of the behaviour that vary based on whether this is the base route or not - but it should only be used internally, external callers should always use the base route as the parameter and not set the parent

I am absolutely going to write unit tests for these routing reducer helpers in a follow on PR ASAP!

Comment on lines +35 to +39
export type TabbedFormRoute = {
route: 'tabbed-forms';
subroute?: TabbedFormSubroutes;
autoFocus?: boolean;
} & RouteWithModalSupport;
Copy link
Contributor

Choose a reason for hiding this comment

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

Written like this, the route gets overwritten from tabbed-forms to tabbed-forms' | 'case' | 'case-list' | 'search.

If that's intentional, then I would suggest removing line 36 route: 'tabbed-forms';
If not, this type would have to be defined like:

export type TabbedFormRoute = RouteWithModalSupport & {
  route: 'tabbed-forms';
  subroute?: TabbedFormSubroutes;
  autoFocus?: boolean;
};

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The '&' means that the type has to satisfy both sides of the operator, meaning that it should only allow tabbed-forms but still add support for activeModal shouldn't it?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right! I didn't know that

@stephenhand
Copy link
Collaborator Author

FYI - since #1745 will be merged very soon after this I wouldn't bother testing it, better to test it all together

@stephenhand stephenhand merged commit e6c576b into master Oct 24, 2023
8 checks passed
@stephenhand stephenhand deleted the CHI-1994-modal_routing branch October 24, 2023 09:02
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.

2 participants