Skip to content

Commit 172d39f

Browse files
fix(bulk-import): prevent approval tool resetting to GitHub on link clicks (#3364)
Add e.preventDefault() to Link onClick handlers that use to="" to stop React Router from navigating and stripping the approvalTool query parameter from the URL, which caused the form to reinitialize with GitHub as the default. Fixes: https://redhat.atlassian.net/browse/RHDHBUGS-3345 Signed-off-by: its-mitesh-kumar <itsmiteshkumar98@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 27b0488 commit 172d39f

4 files changed

Lines changed: 44 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-bulk-import': patch
3+
---
4+
5+
Fixed approval tool selection resetting to GitHub when clicking Preview file by preventing unintended router navigation that stripped the approvalTool query parameter from the URL.

workspaces/bulk-import/plugins/bulk-import/src/components/AddRepositories/SelectRepositories.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ export const SelectRepositories = ({
5252
data-testid="no-repositories"
5353
>
5454
{t('addRepositories.allRepositoriesAdded')}{' '}
55-
<Link to="" onClick={() => onOrgRowSelected(orgData)}>
55+
<Link
56+
to=""
57+
onClick={e => {
58+
e.preventDefault();
59+
onOrgRowSelected(orgData);
60+
}}
61+
>
5662
{t('common.view')}
5763
</Link>
5864
</Typography>
@@ -66,7 +72,13 @@ export const SelectRepositories = ({
6672
return (
6773
<Typography component="span" data-testid="select-repositories">
6874
{t('addRepositories.noSelection')}{' '}
69-
<Link to="" onClick={() => onOrgRowSelected(orgData)}>
75+
<Link
76+
to=""
77+
onClick={e => {
78+
e.preventDefault();
79+
onOrgRowSelected(orgData);
80+
}}
81+
>
7082
{t('common.select')}
7183
</Link>
7284
</Typography>
@@ -76,7 +88,13 @@ export const SelectRepositories = ({
7688
<Typography component="span" data-testid="edit-repositories">
7789
{Object.keys(orgData.selectedRepositories || [])?.length}/
7890
{(orgData?.totalReposInOrg || 0) - addedRepositoriesCount}{' '}
79-
<Link onClick={() => onOrgRowSelected(orgData)} to="">
91+
<Link
92+
to=""
93+
onClick={e => {
94+
e.preventDefault();
95+
onOrgRowSelected(orgData);
96+
}}
97+
>
8098
{t('common.edit')}
8199
</Link>
82100
</Typography>

workspaces/bulk-import/plugins/bulk-import/src/components/PreviewFile/PreviewFile.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,12 @@ export const PreviewFile = ({ data }: { data: AddRepositoryData }) => {
8080

8181
<Link
8282
to={errorMessage.showRepositoryLink ? data.repoUrl || '' : ''}
83-
onClick={() =>
84-
errorMessage.showRepositoryLink ? null : openDrawer(data)
85-
}
83+
onClick={e => {
84+
if (!errorMessage.showRepositoryLink) {
85+
e.preventDefault();
86+
openDrawer(data);
87+
}
88+
}}
8689
data-testid="edit-pull-request"
8790
>
8891
{errorMessage.showRepositoryLink ? (
@@ -107,7 +110,10 @@ export const PreviewFile = ({ data }: { data: AddRepositoryData }) => {
107110
<Link
108111
to=""
109112
style={{ marginLeft: '4px' }}
110-
onClick={() => openDrawer(data)}
113+
onClick={e => {
114+
e.preventDefault();
115+
openDrawer(data);
116+
}}
111117
data-testid={
112118
Object.keys(data?.selectedRepositories || []).length > 1
113119
? 'preview-files'

workspaces/bulk-import/plugins/bulk-import/src/components/PreviewFile/PreviewFileSidebarDrawerContent.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,14 @@ export const PreviewFileSidebarDrawerContent = ({
201201
>
202202
{t('common.save')}
203203
</Button>
204-
<Link to="" variant="button" onClick={onCancel}>
204+
<Link
205+
to=""
206+
variant="button"
207+
onClick={e => {
208+
e.preventDefault();
209+
onCancel();
210+
}}
211+
>
205212
<Button variant="outlined">{t('common.cancel')}</Button>
206213
</Link>
207214
</Box>

0 commit comments

Comments
 (0)