Skip to content

Commit 3fba476

Browse files
author
Constance
authored
[App Search] Minor var names follow-up (#87258)
* Var rename - so it doesn't sound negative or like a bug, but is instead an anticipated load/use case - remove unncessary function - move declaration down to right before it's used * [Proposal] Other misc cleanup - 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)
1 parent 0c41c2d commit 3fba476

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_router.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ describe('EngineRouter', () => {
5757
});
5858

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

6463
expect(wrapper.find(Redirect).prop('to')).toEqual('/engines');

x-pack/plugins/enterprise_search/public/applications/app_search/components/engine/engine_router.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,31 +69,30 @@ export const EngineRouter: React.FC = () => {
6969
},
7070
} = useValues(AppLogic);
7171

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

75-
const { engineName: engineNameParam } = useParams() as { engineName: string };
76-
const engineBreadcrumb = [ENGINES_TITLE, engineNameParam];
77-
78-
const isEngineInStateStale = () => engineName !== engineNameParam;
79-
8076
useEffect(() => {
81-
setEngineName(engineNameParam);
77+
setEngineName(engineNameFromUrl);
8278
initializeEngine();
8379
return clearEngine;
84-
}, [engineNameParam]);
80+
}, [engineNameFromUrl]);
8581

8682
if (engineNotFound) {
8783
setQueuedErrorMessage(
8884
i18n.translate('xpack.enterpriseSearch.appSearch.engine.notFound', {
89-
defaultMessage: "No engine with name '{engineNameParam}' could be found.",
90-
values: { engineNameParam },
85+
defaultMessage: "No engine with name '{engineName}' could be found.",
86+
values: { engineName },
9187
})
9288
);
9389
return <Redirect to={ENGINES_PATH} />;
9490
}
9591

96-
if (isEngineInStateStale() || dataLoading) return <Loading />;
92+
const isLoadingNewEngine = engineName !== engineNameFromUrl;
93+
if (isLoadingNewEngine || dataLoading) return <Loading />;
94+
95+
const engineBreadcrumb = [ENGINES_TITLE, engineName];
9796

9897
return (
9998
<Switch>

0 commit comments

Comments
 (0)