Skip to content

Commit 35977a1

Browse files
Fix Terminology "Translate" link dropping the string query (#4637)
The click handler navigated to the link's pathname only, losing `?string=<id>`, so the Terminology project opened on its first string instead of the selected term. Pass pathname + search, as Metadata.tsx already does.
1 parent 981ca93 commit 35977a1

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎translate/src/modules/terms/components/Term.test.jsx‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,19 @@ const TERM = {
2525
doNotTranslate: false,
2626
};
2727

28-
function MockTerm({ isAuthenticated, setEditorSelection, term }) {
28+
function MockTerm({
29+
isAuthenticated,
30+
setEditorSelection,
31+
navigateToPath,
32+
term,
33+
}) {
2934
const store = createReduxStore({ user: { isAuthenticated } });
3035
return (
3136
<MockStore store={store}>
3237
<Locale.Provider value={{ code: 'kg' }}>
3338
<EntityView.Provider value={{ entity: {} }}>
3439
<EditorActions.Provider value={{ setEditorSelection }}>
35-
<Term term={term ?? TERM} />
40+
<Term term={term ?? TERM} navigateToPath={navigateToPath} />
3641
</EditorActions.Provider>
3742
</EntityView.Provider>
3843
</Locale.Provider>
@@ -123,4 +128,19 @@ describe('<Term>', () => {
123128
await userEvent.click(container.querySelector('li'));
124129
expect(spy).not.toHaveBeenCalled();
125130
});
131+
132+
it('navigates to the term entity, including the string query', async () => {
133+
const navigateToPath = vi.fn();
134+
const { container } = render(
135+
<MockTerm
136+
isAuthenticated
137+
setEditorSelection={vi.fn()}
138+
navigateToPath={navigateToPath}
139+
/>,
140+
);
141+
await userEvent.click(container.querySelector('a.translate'));
142+
expect(navigateToPath).toHaveBeenCalledWith(
143+
'/kg/terminology/common/?string=1',
144+
);
145+
});
126146
});

‎translate/src/modules/terms/components/Term.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ export function Term({ navigateToPath, term }: Props): React.ReactElement {
3333
};
3434

3535
const handleLinkClick = (ev: React.MouseEvent<HTMLAnchorElement>) => {
36+
const { pathname, search } = ev.currentTarget;
37+
3638
ev.preventDefault();
3739
ev.stopPropagation();
38-
navigateToPath(ev.currentTarget.pathname);
40+
navigateToPath(pathname + search);
3941
};
4042

4143
const cn = classNames(

0 commit comments

Comments
 (0)