Skip to content

Commit

Permalink
fix: open search module based on the module you come from
Browse files Browse the repository at this point in the history
refs: SHELL-46 (#270)
  • Loading branch information
CataldoMazzilli authored Jul 4, 2023
1 parent 312b45d commit 2b12ec2
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/boot/bootstrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const StandaloneListener = (): null => {
return null;
};

const DefaultViewsRegister = (): null => {
export const DefaultViewsRegister = (): null => {
const [t] = useTranslation();
useEffect(() => {
registerDefaultViews(t);
Expand Down
7 changes: 1 addition & 6 deletions src/search/module-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ const ModuleSelectorComponent = ({ app }: ModuleSelectorProps): JSX.Element | nu
);

useEffect(() => {
// FIXME: this is part of the cause of SHELL-46
// When the user click on the search module directly, the app results to be the search one,
// and so the selected module, which is kept to the last one selected, does not match the module
// written inside the path (/search/<module>), causing a misalignment between what is rendered (which
// follow the path) and what is written inside the module selector (which updates its value based on the
// module where the user is coming from)
if (app !== SEARCH_APP_ID) {
if (!fullModule || fullModule?.app !== app) {
updateModule((modules.find((m) => m.app === app) ?? modules[0])?.route);
Expand All @@ -89,6 +83,7 @@ const ModuleSelectorComponent = ({ app }: ModuleSelectorProps): JSX.Element | nu
return (
<Dropdown items={dropdownItems} onOpen={openDropdown} onClose={closeDropdown}>
<SelectorContainer
data-testid="HeaderModuleSelector"
orientation="horizontal"
height="2.625rem"
width="fit"
Expand Down
13 changes: 5 additions & 8 deletions src/search/search-app-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ const ResultsHeader = ({

export const SearchAppView = (): JSX.Element => {
const searchViews = useAppStore((s) => s.views.search);
const { module } = useSearchStore();
const modules = useAppStore((s) => s.views.search);

const fullModule = useMemo(() => modules.find((m) => m.route === module), [module, modules]);

const routes = useMemo(
() =>
Expand All @@ -140,18 +144,11 @@ export const SearchAppView = (): JSX.Element => {
return (
<Switch>
{routes}
{/*
* FIXME: this is part of the cause of SHELL-46
* Every time the user clicks on the search module to navigate directly inside it,
* a redirect is made to go to the fixed path /search/<first module>. But first module
* does not match the module written inside the module selector, which is not updated
* accordingly.
*/}
<Redirect
exact
strict
from={`/${SEARCH_APP_ID}`}
to={`/${SEARCH_APP_ID}/${searchViews[0]?.route}`}
to={`/${SEARCH_APP_ID}/${fullModule ? fullModule.route : searchViews[0]?.route}`}
/>
</Switch>
);
Expand Down
Loading

0 comments on commit 2b12ec2

Please sign in to comment.