Skip to content

Commit 4522d8c

Browse files
fix(bulk-import): UI improvements and bug fixes (#2975)
Signed-off-by: its-mitesh-kumar <itsmiteshkumar98@gmail.com>
1 parent 4a08308 commit 4522d8c

6 files changed

Lines changed: 36 additions & 26 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-bulk-import': patch
3+
---
4+
5+
- Fixed duplicate header in NFS app by adding `noHeader: true` to the PageBlueprint configuration
6+
- Persist selected approval tool (GitHub/GitLab) in URL parameter to survive page refresh
7+
- Fixed large empty space between table rows and pagination on the last page when rows is less than rows-per-page

workspaces/bulk-import/plugins/bulk-import/src/alpha.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const bulkImportPage = PageBlueprint.make({
7373
params: {
7474
path: '/bulk-import',
7575
routeRef: rootRouteRef,
76+
noHeader: true,
7677
loader: () => import('./components').then(({ Router }) => <Router />),
7778
},
7879
});

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { useEffect } from 'react';
17+
import { useEffect, useMemo } from 'react';
18+
import { useSearchParams } from 'react-router-dom';
1819

1920
import { useApi } from '@backstage/core-plugin-api';
2021

@@ -44,22 +45,34 @@ export const AddRepositoriesForm = ({
4445
}) => {
4546
const bulkImportApi = useApi(bulkImportApiRef);
4647
const queryClient = useQueryClient();
47-
const { numberOfApprovalTools, gitlabConfigured } =
48+
const [searchParams] = useSearchParams();
49+
const { numberOfApprovalTools, gitlabConfigured, githubConfigured } =
4850
useNumberOfApprovalTools();
4951

50-
// Set default approval tool based on configuration
51-
const getDefaultApprovalTool = () => {
52+
// Get approval tool from URL or fallback to default based on configuration
53+
const getInitialApprovalTool = useMemo(() => {
54+
const urlApprovalTool = searchParams.get('approvalTool');
55+
56+
// Validate URL param against configured integrations
57+
if (urlApprovalTool === ApprovalTool.Git && githubConfigured) {
58+
return ApprovalTool.Git;
59+
}
60+
if (urlApprovalTool === ApprovalTool.Gitlab && gitlabConfigured) {
61+
return ApprovalTool.Gitlab;
62+
}
63+
64+
// Fallback to default based on configuration
5265
if (numberOfApprovalTools === 1) {
5366
return gitlabConfigured ? ApprovalTool.Gitlab : ApprovalTool.Git;
5467
}
5568
return ApprovalTool.Git; // Default to GitHub when both are configured
56-
};
69+
}, [searchParams, numberOfApprovalTools, gitlabConfigured, githubConfigured]);
5770

5871
const initialValues: AddRepositoriesFormValues = {
5972
repositoryType: RepositorySelection.Repository,
6073
repositories: {},
6174
excludedRepositories: {},
62-
approvalTool: getDefaultApprovalTool(),
75+
approvalTool: getInitialApprovalTool,
6376
};
6477

6578
const createImportJobs = (importOptions: {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import type { ChangeEvent, FC } from 'react';
18+
import { useSearchParams } from 'react-router-dom';
1819

1920
import HelpIcon from '@mui/icons-material/HelpOutline';
2021
import Box from '@mui/material/Box';
@@ -38,11 +39,18 @@ const ApprovalTool: FC<ApprovalToolProps> = ({
3839
}) => {
3940
const { t } = useTranslation();
4041
const theme = useTheme();
42+
const [searchParams, setSearchParams] = useSearchParams();
43+
4144
const handleApprovalToolChange = (
4245
_event: ChangeEvent<{}>,
4346
newValue: string,
4447
) => {
4548
setFieldValue('approvalTool', newValue);
49+
50+
// Persist approval tool selection in URL
51+
const newSearchParams = new URLSearchParams(searchParams);
52+
newSearchParams.set('approvalTool', newValue);
53+
setSearchParams(newSearchParams, { replace: true });
4654
};
4755
return (
4856
<Box

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ export const RepositoriesTable = ({
165165
return filteredData?.slice(startIndex, startIndex + rowsPerPage) || [];
166166
}, [filteredData, effectivePage, rowsPerPage]);
167167

168-
// Avoid a layout jump when reaching the last page with empty rows.
169-
const emptyRows =
170-
effectivePage > 0 ? Math.max(0, rowsPerPage - paginatedData.length) : 0;
171-
172168
const handleClickAllForRepositoriesTable = (drawer?: boolean) => {
173169
let newSelectedRows: AddedRepositories = { ...selected };
174170

@@ -321,7 +317,7 @@ export const RepositoriesTable = ({
321317
</div>
322318
)}
323319
<Table
324-
style={{ minWidth: 750, height: '70%' }}
320+
style={{ minWidth: 750 }}
325321
size="small"
326322
data-testid={ariaLabel()}
327323
className={classes.repositoriesTableFixedColumns}
@@ -343,7 +339,6 @@ export const RepositoriesTable = ({
343339
loading={loading}
344340
ariaLabel={ariaLabel()}
345341
rows={paginatedData}
346-
emptyRows={emptyRows}
347342
onOrgRowSelected={handleOrgRowSelected}
348343
onClick={handleClick}
349344
selectedRepos={selected}
@@ -354,7 +349,6 @@ export const RepositoriesTable = ({
354349
</Table>
355350
{!isOpen && tableData?.length > 0 && (
356351
<TablePagination
357-
style={{ height: '30%' }}
358352
rowsPerPageOptions={[
359353
{ value: 5, label: t('table.pagination.rows5') },
360354
{ value: 10, label: t('table.pagination.rows10') },

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import type { MouseEvent } from 'react';
1919
import Box from '@mui/material/Box';
2020
import CircularProgress from '@mui/material/CircularProgress';
2121
import TableBody from '@mui/material/TableBody';
22-
import TableCell from '@mui/material/TableCell';
23-
import TableRow from '@mui/material/TableRow';
2422

2523
import { useTranslation } from '../../hooks/useTranslation';
2624
import { AddedRepositories, AddRepositoryData } from '../../types';
@@ -33,7 +31,6 @@ export const RepositoriesTableBody = ({
3331
ariaLabel,
3432
showOrganizations,
3533
rows,
36-
emptyRows,
3734
onOrgRowSelected,
3835
onClick,
3936
selectedRepos,
@@ -42,7 +39,6 @@ export const RepositoriesTableBody = ({
4239
}: {
4340
loading: boolean;
4441
ariaLabel: string;
45-
emptyRows: number;
4642
rows: AddRepositoryData[];
4743
onOrgRowSelected: (org: AddRepositoryData) => void;
4844
onClick: (_event: MouseEvent, repo: AddRepositoryData) => void;
@@ -100,15 +96,6 @@ export const RepositoriesTableBody = ({
10096
/>
10197
);
10298
})}
103-
{emptyRows > 0 && (
104-
<TableRow
105-
style={{
106-
height: 55 * emptyRows,
107-
}}
108-
>
109-
<TableCell />
110-
</TableRow>
111-
)}
11299
</TableBody>
113100
);
114101
}

0 commit comments

Comments
 (0)