diff --git a/workspaces/bulk-import/plugins/bulk-import-backend/src/helpers/utils.ts b/workspaces/bulk-import/plugins/bulk-import-backend/src/helpers/utils.ts index c630c996e..63ee32bd6 100644 --- a/workspaces/bulk-import/plugins/bulk-import-backend/src/helpers/utils.ts +++ b/workspaces/bulk-import/plugins/bulk-import-backend/src/helpers/utils.ts @@ -16,7 +16,13 @@ export function getNestedValue(obj: T, path: string): any { return path .split('.') - .reduce((acc, key) => (acc && acc[key] ? acc[key] : undefined), obj); + .reduce( + (acc, key) => + acc && (acc as Record)[key] + ? (acc as Record)[key] + : undefined, + obj, + ); } export enum SortingOrderEnum { ASC = 'asc', diff --git a/workspaces/bulk-import/plugins/bulk-import-backend/src/service/handlers/import/bulkImports.ts b/workspaces/bulk-import/plugins/bulk-import-backend/src/service/handlers/import/bulkImports.ts index cc33c6c52..3f934e66c 100644 --- a/workspaces/bulk-import/plugins/bulk-import-backend/src/service/handlers/import/bulkImports.ts +++ b/workspaces/bulk-import/plugins/bulk-import-backend/src/service/handlers/import/bulkImports.ts @@ -52,7 +52,7 @@ type FindAllImportsResponse = function sortImports( imports: Components.Schemas.Import[], - sortColumn: string, + sortColumn: string = 'repository.name', sortOrder: string = SortingOrderEnum.ASC, ) { imports.sort((a, b) => { diff --git a/workspaces/bulk-import/plugins/bulk-import/src/api/BulkImportBackendClient.test.ts b/workspaces/bulk-import/plugins/bulk-import/src/api/BulkImportBackendClient.test.ts index abc102fcf..78c15b2ba 100644 --- a/workspaces/bulk-import/plugins/bulk-import/src/api/BulkImportBackendClient.test.ts +++ b/workspaces/bulk-import/plugins/bulk-import/src/api/BulkImportBackendClient.test.ts @@ -24,7 +24,12 @@ import { mockGetRepositories, mockSelectedRepositories, } from '../mocks/mockData'; -import { ApprovalTool, RepositoryStatus } from '../types'; +import { + AddedRepositoryColumnNameEnum, + ApprovalTool, + RepositoryStatus, + SortingOrderEnum, +} from '../types'; import { prepareDataForSubmission } from '../utils/repository-utils'; import { BulkImportAPI, @@ -304,12 +309,24 @@ describe('BulkImportBackendClient', () => { describe('getImportJobs', () => { it('getImportJobs should retrieve the import jobs successfully', async () => { - const jobs = await bulkImportApi.getImportJobs(1, 2, ''); + const jobs = await bulkImportApi.getImportJobs( + 1, + 2, + '', + AddedRepositoryColumnNameEnum.repoName, + SortingOrderEnum.ASC, + ); expect(jobs).toEqual(mockGetImportJobs); }); it('getImportJobs should retrieve the import jobs based on search string', async () => { - const jobs = await bulkImportApi.getImportJobs(1, 2, 'cup'); + const jobs = await bulkImportApi.getImportJobs( + 1, + 2, + 'cup', + AddedRepositoryColumnNameEnum.repoName, + SortingOrderEnum.ASC, + ); expect(jobs).toEqual( mockGetImportJobs.imports.filter(r => r.repository.name?.includes('cup'), @@ -318,9 +335,15 @@ describe('BulkImportBackendClient', () => { }); it('getImportJobs should handle non-200/204 responses correctly', async () => { - await expect(bulkImportApi.getImportJobs(1, 2, '')).resolves.toEqual( - expect.objectContaining([]), - ); + await expect( + bulkImportApi.getImportJobs( + 1, + 2, + '', + AddedRepositoryColumnNameEnum.repoName, + SortingOrderEnum.ASC, + ), + ).resolves.toEqual(expect.objectContaining([])); }); }); diff --git a/workspaces/bulk-import/plugins/bulk-import/src/components/Repositories/RepositoriesList.tsx b/workspaces/bulk-import/plugins/bulk-import/src/components/Repositories/RepositoriesList.tsx index 3cc990700..7f7ae3fb3 100644 --- a/workspaces/bulk-import/plugins/bulk-import/src/components/Repositories/RepositoriesList.tsx +++ b/workspaces/bulk-import/plugins/bulk-import/src/components/Repositories/RepositoriesList.tsx @@ -28,7 +28,6 @@ import { AddRepositoryData, SortingOrderEnum, } from '../../types'; -import { getComparator } from '../../utils/repository-utils'; import { RepositoriesHeader } from '../AddRepositories/RepositoriesHeader'; import { AddedRepositoriesTableBody } from './AddedRepositoriesTableBody'; import DeleteRepositoryDialog from './DeleteRepositoryDialog'; diff --git a/workspaces/bulk-import/plugins/bulk-import/src/hooks/useAddedRepositories.test.ts b/workspaces/bulk-import/plugins/bulk-import/src/hooks/useAddedRepositories.test.ts index 1b1d1d4a4..b68f9d27f 100644 --- a/workspaces/bulk-import/plugins/bulk-import/src/hooks/useAddedRepositories.test.ts +++ b/workspaces/bulk-import/plugins/bulk-import/src/hooks/useAddedRepositories.test.ts @@ -16,6 +16,7 @@ import { renderHook, waitFor } from '@testing-library/react'; import { mockGetImportJobs, mockGetRepositories } from '../mocks/mockData'; +import { AddedRepositoryColumnNameEnum, SortingOrderEnum } from '../types'; import { useAddedRepositories } from './useAddedRepositories'; jest.mock('@backstage/core-plugin-api', () => ({ @@ -48,7 +49,15 @@ jest.mock('formik', () => ({ describe('useAddedRepositories', () => { it('should return import jobs', async () => { - const { result } = renderHook(() => useAddedRepositories(1, 5, '')); + const { result } = renderHook(() => + useAddedRepositories( + 1, + 5, + '', + AddedRepositoryColumnNameEnum.repoName, + SortingOrderEnum.ASC, + ), + ); await waitFor(() => { expect(result.current.loading).toBeFalsy(); expect(result.current.data.totalJobs).toBe(4);