diff --git a/frontend/__tests__/context/metricsSlice.test.ts b/frontend/__tests__/context/metricsSlice.test.ts index 02b9e5d28..23a8ccab6 100644 --- a/frontend/__tests__/context/metricsSlice.test.ts +++ b/frontend/__tests__/context/metricsSlice.test.ts @@ -1638,11 +1638,8 @@ describe('saveMetricsSetting reducer', () => { expect(savedMetricsSetting.sourceControlConfigurationSettings).toEqual(expectedSourceControlConfigurationSettings); }); - it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and isProjectCreated is true and setting is empty', () => { - const expectedSourceControlConfigurationSettings = [ - { id: 0, organization: '', repo: '', branches: [] }, - { id: 1, organization: '', repo: '', branches: [] }, - ]; + it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and setting is empty', () => { + const expectedSourceControlConfigurationSettings = [{ id: 0, organization: '', repo: '', branches: [] }]; const savedMetricsSetting = saveMetricsSettingReducer( initState, updateSourceControlConfigurationSettingsFirstInto({ @@ -1655,31 +1652,7 @@ describe('saveMetricsSetting reducer', () => { expect(savedMetricsSetting.sourceControlConfigurationSettings).toEqual(expectedSourceControlConfigurationSettings); }); - it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and isProjectCreated is true and setting is not empty', () => { - const existedSourceControlConfigurationSettings = [ - { id: 1, organization: 'test-org1', repo: 'test-repo1', branches: ['test-branch1'] }, - ]; - const expectedSourceControlConfigurationSettings = [ - { id: 1, organization: 'test-org1', repo: 'test-repo1', branches: ['test-branch1'] }, - ]; - const state = { - ...initState, - sourceControlConfigurationSettings: existedSourceControlConfigurationSettings, - }; - - const savedMetricsSetting = saveMetricsSettingReducer( - state, - updateSourceControlConfigurationSettingsFirstInto({ - name: ['test1', 'test2'], - isProjectCreated: true, - type: 'organization', - }), - ); - - expect(savedMetricsSetting.sourceControlConfigurationSettings).toEqual(expectedSourceControlConfigurationSettings); - }); - - it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and isProjectCreated is false and setting is empty', () => { + it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and setting is empty', () => { const existedImportedSourceControlSettings = [ { id: 1, organization: 'test-org1', repo: 'test-repo1', branches: ['test-branch1'] }, { id: 2, organization: 'test-org2', repo: 'test-repo2', branches: ['test-branch2'] }, @@ -1698,7 +1671,6 @@ describe('saveMetricsSetting reducer', () => { state, updateSourceControlConfigurationSettingsFirstInto({ name: ['test-org1', 'test2'], - isProjectCreated: false, type: 'organization', }), ); diff --git a/frontend/src/containers/MetricsStep/SouceControlConfiguration/index.tsx b/frontend/src/containers/MetricsStep/SouceControlConfiguration/index.tsx index c6c873a49..6aa22b101 100644 --- a/frontend/src/containers/MetricsStep/SouceControlConfiguration/index.tsx +++ b/frontend/src/containers/MetricsStep/SouceControlConfiguration/index.tsx @@ -94,7 +94,7 @@ export const SourceControlConfiguration = () => { setLoadingCompletedNumber={setLoadingCompletedNumber} /> ))} - + {shouldShowCrews && ( { - const { name, isProjectCreated, type } = action.payload; + const { name, type } = action.payload; const sourceControlConfigurationSettings = state.sourceControlConfigurationSettings; - if (isProjectCreated) { - state.sourceControlConfigurationSettings = - sourceControlConfigurationSettings.length > 0 - ? sourceControlConfigurationSettings - : name.map((it: string, index: number) => ({ - id: index, + + let validSourceControlConfigurationSettings = + sourceControlConfigurationSettings.length > 0 + ? sourceControlConfigurationSettings + : state.importedData.importedSourceControlSettings + .filter((it) => it.id !== undefined) + .map((it) => ({ + id: it.id, + organization: it.organization, + repo: it.repo, + branches: it.branches, + })); + validSourceControlConfigurationSettings = + validSourceControlConfigurationSettings.length > 0 + ? validSourceControlConfigurationSettings + : [ + { + id: 0, organization: '', repo: '', branches: [], - })); - } else { - let validSourceControlConfigurationSettings = - sourceControlConfigurationSettings.length > 0 - ? sourceControlConfigurationSettings - : state.importedData.importedSourceControlSettings - .filter((it) => it.id !== undefined) - .map((it) => ({ - id: it.id, - organization: it.organization, - repo: it.repo, - branches: it.branches, - })); - - if (type === 'organization') { - validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter( - (it) => it['organization'] === '' || name.includes(it['organization']), - ); - } else if (type === 'repo') { - validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter( - (it) => it['repo'] === '' || name.includes(it['repo']), - ); - } else { - validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter( - (it) => it['branches'].length === 0 || it['branches'].filter((branch) => name.includes(branch)), - ); - } + }, + ]; - state.sourceControlConfigurationSettings = validSourceControlConfigurationSettings; + if (type === 'organization') { + validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter( + (it) => it['organization'] === '' || name.includes(it['organization']), + ); + } else if (type === 'repo') { + validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter( + (it) => it['repo'] === '' || name.includes(it['repo']), + ); + } else { + validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter( + (it) => it['branches'].length === 0 || it['branches'].filter((branch) => name.includes(branch)), + ); } + + state.sourceControlConfigurationSettings = validSourceControlConfigurationSettings; }, updateShouldGetBoardConfig: (state, action) => { diff --git a/frontend/src/context/config/configSlice.ts b/frontend/src/context/config/configSlice.ts index 6a87a198b..42c4476fd 100644 --- a/frontend/src/context/config/configSlice.ts +++ b/frontend/src/context/config/configSlice.ts @@ -220,6 +220,9 @@ export const configSlice = createSlice({ updateSourceControl: (state, action) => { state.sourceControl.config = action.payload; }, + clearSourceControlVerifiedResponse: (state) => { + state.sourceControl.verifiedResponse.repoList = { name: 'root', value: '-1', children: [] }; + }, updateSourceControlVerifiedResponse: (state, action) => { const namesList = ['organization', 'repo', 'branch', 'time', 'crew']; const matchedRepoList = state.sourceControl.verifiedResponse.repoList; @@ -249,6 +252,7 @@ export const { updatePipelineTool, updatePipelineToolVerifyResponse, updateSourceControl, + clearSourceControlVerifiedResponse, updateSourceControlVerifiedResponse, updatePipelineToolVerifyResponseSteps, resetImportedData, diff --git a/frontend/src/hooks/useGetSourceControlConfigurationBranchEffect.tsx b/frontend/src/hooks/useGetSourceControlConfigurationBranchEffect.tsx index edb46de62..5f81e68c5 100644 --- a/frontend/src/hooks/useGetSourceControlConfigurationBranchEffect.tsx +++ b/frontend/src/hooks/useGetSourceControlConfigurationBranchEffect.tsx @@ -1,8 +1,4 @@ -import { - selectIsProjectCreated, - selectSourceControl, - updateSourceControlVerifiedResponse, -} from '@src/context/config/configSlice'; +import { selectSourceControl, updateSourceControlVerifiedResponse } from '@src/context/config/configSlice'; import { updateSourceControlConfigurationSettingsFirstInto } from '@src/context/Metrics/metricsSlice'; import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient'; import { useAppDispatch, useAppSelector } from '@src/hooks/index'; @@ -20,7 +16,6 @@ export const useGetSourceControlConfigurationBranchEffect = (): IUseGetSourceCon const [isLoading, setIsLoading] = useState(false); const [isGetBranch, setIsGetBranch] = useState(false); const restoredSourceControlInfo = useAppSelector(selectSourceControl); - const isProjectCreated = useAppSelector(selectIsProjectCreated); function getEnumKeyByEnumValue(enumValue: string): SourceControlTypes { return Object.entries(SourceControlTypes) @@ -57,7 +52,6 @@ export const useGetSourceControlConfigurationBranchEffect = (): IUseGetSourceCon dispatch( updateSourceControlConfigurationSettingsFirstInto({ ...response.data, - isProjectCreated, type: 'branch', }), ); diff --git a/frontend/src/hooks/useGetSourceControlConfigurationOrganizationEffect.tsx b/frontend/src/hooks/useGetSourceControlConfigurationOrganizationEffect.tsx index 5fb71c04d..41ba36313 100644 --- a/frontend/src/hooks/useGetSourceControlConfigurationOrganizationEffect.tsx +++ b/frontend/src/hooks/useGetSourceControlConfigurationOrganizationEffect.tsx @@ -1,12 +1,12 @@ import { - selectShouldGetSourceControlConfig, - updateSourceControlConfigurationSettingsFirstInto, -} from '@src/context/Metrics/metricsSlice'; -import { - selectIsProjectCreated, + clearSourceControlVerifiedResponse, selectSourceControl, updateSourceControlVerifiedResponse, } from '@src/context/config/configSlice'; +import { + selectShouldGetSourceControlConfig, + updateSourceControlConfigurationSettingsFirstInto, +} from '@src/context/Metrics/metricsSlice'; import { ISourceControlGetOrganizationResponseDTO } from '@src/clients/sourceControl/dto/response'; import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient'; import { useAppDispatch, useAppSelector } from '@src/hooks/index'; @@ -20,6 +20,7 @@ export interface IUseGetSourceControlConfigurationStateInterface { readonly info: ISourceControlGetOrganizationResponseDTO; readonly isFirstFetch: boolean; } + export const useGetSourceControlConfigurationOrganizationEffect = (): IUseGetSourceControlConfigurationStateInterface => { const defaultInfoStructure = { @@ -34,7 +35,6 @@ export const useGetSourceControlConfigurationOrganizationEffect = const restoredSourceControlInfo = useAppSelector(selectSourceControl); const shouldGetSourceControlConfig = useAppSelector(selectShouldGetSourceControlConfig); const [isFirstFetch, setIsFirstFetch] = useState(shouldGetSourceControlConfig); - const isProjectCreated = useAppSelector(selectIsProjectCreated); function getEnumKeyByEnumValue(enumValue: string): SourceControlTypes { return Object.entries(SourceControlTypes) @@ -61,7 +61,6 @@ export const useGetSourceControlConfigurationOrganizationEffect = dispatch( updateSourceControlConfigurationSettingsFirstInto({ ...response.data, - isProjectCreated, type: 'organization', }), ); @@ -70,7 +69,7 @@ export const useGetSourceControlConfigurationOrganizationEffect = setIsLoading(false); setIsFirstFetch(false); } - }, [dispatch, restoredSourceControlInfo.token, restoredSourceControlInfo.type, isProjectCreated]); + }, [dispatch, restoredSourceControlInfo.token, restoredSourceControlInfo.type]); useEffect(() => { if (!apiTouchedRef.current && !isLoading) { @@ -78,6 +77,11 @@ export const useGetSourceControlConfigurationOrganizationEffect = getSourceControlInfo(); } }, [getSourceControlInfo, isLoading]); + + useEffect(() => { + dispatch(clearSourceControlVerifiedResponse()); + }, [dispatch, restoredSourceControlInfo.token]); + return { isLoading, getSourceControlInfo, diff --git a/frontend/src/hooks/useGetSourceControlConfigurationRepoEffect.tsx b/frontend/src/hooks/useGetSourceControlConfigurationRepoEffect.tsx index 61c947a0a..9f38920bf 100644 --- a/frontend/src/hooks/useGetSourceControlConfigurationRepoEffect.tsx +++ b/frontend/src/hooks/useGetSourceControlConfigurationRepoEffect.tsx @@ -1,9 +1,4 @@ -import { - DateRange, - selectIsProjectCreated, - selectSourceControl, - updateSourceControlVerifiedResponse, -} from '@src/context/config/configSlice'; +import { DateRange, selectSourceControl, updateSourceControlVerifiedResponse } from '@src/context/config/configSlice'; import { updateSourceControlConfigurationSettingsFirstInto } from '@src/context/Metrics/metricsSlice'; import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient'; import { FULFILLED, SourceControlTypes } from '@src/constants/resources'; @@ -21,7 +16,6 @@ export const useGetSourceControlConfigurationRepoEffect = (): IUseGetSourceContr const [isLoading, setIsLoading] = useState(false); const [isGetRepo, setIsGetRepo] = useState(false); const restoredSourceControlInfo = useAppSelector(selectSourceControl); - const isProjectCreated = useAppSelector(selectIsProjectCreated); function getEnumKeyByEnumValue(enumValue: string): SourceControlTypes { return Object.entries(SourceControlTypes) @@ -58,7 +52,6 @@ export const useGetSourceControlConfigurationRepoEffect = (): IUseGetSourceContr dispatch( updateSourceControlConfigurationSettingsFirstInto({ ...response.value.data, - isProjectCreated, type: 'repo', }), );