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

[App Search] Minor var names follow-up #87258

Merged
merged 2 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,30 @@ export const EngineRouter: React.FC = () => {
},
} = useValues(AppLogic);

const { engineName: engineNameFromUrl } = useParams() as { engineName: string };
Copy link
Contributor Author

@cee-chen cee-chen Jan 4, 2021

Choose a reason for hiding this comment

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

Feel free to push back if you disagree, but I was thinking FromUrl flowed a little better reading-wise and also made it a little clearer where we're setting engineName from. I also played with engineNameFromParam but ended up likeing FromUrl a little better

const { engineName, dataLoading, engineNotFound } = useValues(EngineLogic);
const { setEngineName, initializeEngine, clearEngine } = useActions(EngineLogic);

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

const isEngineInStateStale = () => engineName !== 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 },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There isn't really a realistic scenario where engineName would get set after engineNotFound gets set so I think it's safe to simplify this

})
);
return <Redirect to={ENGINES_PATH} />;
}

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

const engineBreadcrumb = [ENGINES_TITLE, engineName];
Copy link
Contributor Author

@cee-chen cee-chen Jan 4, 2021

Choose a reason for hiding this comment

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

Similarly, I wanted to simplify engineBreadcrumb to just use engineName (and also to think of engineName as a source of truth once an engine is initialized from url), so I moved this to after the Loading component to reduce confusion & keep the logic together.


return (
<Switch>
Expand Down