Skip to content

Commit

Permalink
[Proposal] Other misc cleanup
Browse files Browse the repository at this point in the history
- Rename engineNameParam to engineNameFromUrl to make reading flow a little bit more nicely + hopefully make the var source a bit clearer

- Change other references back to engineName for simplicity (they should really only be running after engineName has already been set, so there shouldn't be any race conditions there - moving engineBreadcrumb to after Loading should also solve that)
  • Loading branch information
cee-chen committed Jan 4, 2021
1 parent 32f34dd commit 382a378
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ describe('EngineRouter', () => {
});

it('redirects to engines list and flashes an error if the engine param was not found', () => {
(useParams as jest.Mock).mockReturnValue({ engineName: '404-engine' });
setMockValues({ ...values, engineNotFound: true });
setMockValues({ ...values, engineNotFound: true, engineName: '404-engine' });
const wrapper = shallow(<EngineRouter />);

expect(wrapper.find(Redirect).prop('to')).toEqual('/engines');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,31 @@ export const EngineRouter: React.FC = () => {
},
} = useValues(AppLogic);

const { engineName: engineNameFromUrl } = useParams() as { engineName: string };
const { engineName, dataLoading, engineNotFound } = useValues(EngineLogic);
const { setEngineName, initializeEngine, clearEngine } = useActions(EngineLogic);

const { engineName: engineNameParam } = useParams() as { engineName: string };
const engineBreadcrumb = [ENGINES_TITLE, engineNameParam];

useEffect(() => {
setEngineName(engineNameParam);
setEngineName(engineNameFromUrl);
initializeEngine();
return clearEngine;
}, [engineNameParam]);
}, [engineNameFromUrl]);

if (engineNotFound) {
setQueuedErrorMessage(
i18n.translate('xpack.enterpriseSearch.appSearch.engine.notFound', {
defaultMessage: "No engine with name '{engineNameParam}' could be found.",
values: { engineNameParam },
defaultMessage: "No engine with name '{engineName}' could be found.",
values: { engineName },
})
);
return <Redirect to={ENGINES_PATH} />;
}

const isLoadingNewEngine = engineName !== engineNameParam;
const isLoadingNewEngine = engineName !== engineNameFromUrl;
if (isLoadingNewEngine || dataLoading) return <Loading />;

const engineBreadcrumb = [ENGINES_TITLE, engineName];

return (
<Switch>
{canViewEngineAnalytics && (
Expand Down

0 comments on commit 382a378

Please sign in to comment.