Skip to content

Commit 69d27cd

Browse files
authored
Merge pull request #220 from vbihun/PATH-210-filter-by-unique-projects-for-import-and-filer-out-archive-projects
PATH-210: Filter by unique projects to import and filter out archive projects
2 parents 4d74729 + 76d1ca2 commit 69d27cd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/client/gitlab.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ export const getProjects = async (
296296
): Promise<{ data: GitlabAPIProject[]; headers: Headers }> => {
297297
const params = {
298298
include_subgroups: 'true',
299+
archived: 'false',
299300
page: page.toString(),
300301
per_page: perPage.toString(),
301302
...(orderBy ? { order_by: orderBy } : {}),

ui/src/hooks/useImportAll.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { showFlag } from '@forge/bridge';
33
import { useAppContext } from './useAppContext';
44
import { createMRWithCompassYML, createSingleComponent, getGroupProjects } from '../services/invokes';
55
import { getComponentTypeOptionForBuiltInType, sleep } from '../components/utils';
6-
import { ImportableProject } from '../types';
6+
import { ImportableProject, ProjectReadyForImport } from '../types';
77
import { DEFAULT_COMPONENT_TYPE_ID } from '../constants';
88
import { useComponentTypes } from './useComponentTypes';
99
import { useImportAllCaCContext } from './useImportAllCaCContext';
@@ -121,7 +121,18 @@ export const useImportAll = (): {
121121
const { data, errors } = await getGroupProjects(groupId, page, locationGroupId, undefined, MAX_PER_PAGE);
122122

123123
if (data && data.projects.length) {
124-
const projectsToImport = data.projects.map((project) => {
124+
const uniqueProjectsForImport = data.projects.reduce<ProjectReadyForImport[]>(
125+
(uniqueProjects, currentProject) => {
126+
const isUniqueProject = !uniqueProjects.some((uniqueProject) => uniqueProject.id === currentProject.id);
127+
if (isUniqueProject) {
128+
uniqueProjects.push(currentProject);
129+
}
130+
return uniqueProjects;
131+
},
132+
[],
133+
);
134+
135+
const projectsToImport = uniqueProjectsForImport.map((project) => {
125136
const componentType = componentTypes.find((t) => t.id === project.typeId);
126137
const typeOption = componentType
127138
? { label: componentType.name, value: componentType.id }

0 commit comments

Comments
 (0)