diff --git a/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection.test.tsx b/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection.test.tsx index 9a8bd5202e..712b3bdd92 100644 --- a/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection.test.tsx +++ b/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection.test.tsx @@ -11,9 +11,9 @@ import { } from '@test/fixtures'; import { PipelineMetricSelection } from '@src/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection'; import { updatePipelineToolVerifyResponseSteps } from '@src/context/config/configSlice'; -import { act, render, waitFor, within, screen } from '@testing-library/react'; +import { act, render, screen, waitFor, within } from '@testing-library/react'; +import { IPipelineConfig } from '@src/context/Metrics/metricsSlice'; import { metricsClient } from '@src/clients/MetricsClient'; -import { PipelineSetting } from '@src/context/interface'; import { setupStore } from '@test/utils/setupStoreUtil'; import userEvent from '@testing-library/user-event'; import { Provider } from 'react-redux'; @@ -70,7 +70,7 @@ describe('PipelineMetricSelection', () => { const mockUpdatePipeline = jest.fn(); const setup = async ( - deploymentFrequencySetting: PipelineSetting, + deploymentFrequencySetting: IPipelineConfig, isShowRemoveButton: boolean, isDuplicated: boolean, ) => { diff --git a/frontend/__tests__/containers/ReportStep/ReportStep.test.tsx b/frontend/__tests__/containers/ReportStep/ReportStep.test.tsx index d120d12c54..a3a305bbd4 100644 --- a/frontend/__tests__/containers/ReportStep/ReportStep.test.tsx +++ b/frontend/__tests__/containers/ReportStep/ReportStep.test.tsx @@ -101,12 +101,12 @@ describe('Report Step', () => { store.dispatch(updateMetrics(params)); store.dispatch(addADeploymentFrequencySetting()); store.dispatch( - updateDeploymentFrequencySettings({ updateId: 0, label: 'organization', value: 'mock organization' }), + updateDeploymentFrequencySettings({ updateId: 1, label: 'organization', value: 'mock organization' }), ); store.dispatch( - updateDeploymentFrequencySettings({ updateId: 0, label: 'pipelineName', value: 'mock pipeline name' }), + updateDeploymentFrequencySettings({ updateId: 1, label: 'pipelineName', value: 'mock pipeline name' }), ); - store.dispatch(updateDeploymentFrequencySettings({ updateId: 0, label: 'step', value: 'mock step1' })); + store.dispatch(updateDeploymentFrequencySettings({ updateId: 1, label: 'step', value: 'mock step1' })); store.dispatch( updatePipelineToolVerifyResponse({ pipelineList: [ diff --git a/frontend/__tests__/context/metricsSlice.test.ts b/frontend/__tests__/context/metricsSlice.test.ts index 29b009a564..50e4f77dcb 100644 --- a/frontend/__tests__/context/metricsSlice.test.ts +++ b/frontend/__tests__/context/metricsSlice.test.ts @@ -341,7 +341,7 @@ describe('saveMetricsSetting reducer', () => { }); it('should add a deploymentFrequencySetting when handle addADeploymentFrequencySettings given initial state', () => { - const addedDeploymentFrequencySettings = [{ id: 0, organization: '', pipelineName: '', step: '', branches: [] }]; + const addedDeploymentFrequencySettings = [{ id: 1, organization: '', pipelineName: '', step: '', branches: [] }]; const savedMetricsSetting = saveMetricsSettingReducer(initState, addADeploymentFrequencySetting()); @@ -349,7 +349,7 @@ describe('saveMetricsSetting reducer', () => { }); it('should add a deploymentFrequencySetting when handle addADeploymentFrequencySettings but initState dont have DeploymentFrequencySettings', () => { - const addedDeploymentFrequencySettings = [{ id: 0, organization: '', pipelineName: '', step: '', branches: [] }]; + const addedDeploymentFrequencySettings = [{ id: 1, organization: '', pipelineName: '', step: '', branches: [] }]; const initStateWithoutDeploymentFrequencySettings = { ...initState, diff --git a/frontend/src/context/Metrics/metricsSlice.ts b/frontend/src/context/Metrics/metricsSlice.ts index 582d457947..4d8451a42e 100644 --- a/frontend/src/context/Metrics/metricsSlice.ts +++ b/frontend/src/context/Metrics/metricsSlice.ts @@ -7,7 +7,6 @@ import { METRICS_CONSTANTS, } from '@src/constants/resources'; import { pipeline } from '@src/context/config/pipelineTool/verifyResponseSlice'; -import { initialBasicConfigState } from '@src/context/config/configSlice'; import { createSlice } from '@reduxjs/toolkit'; import camelCase from 'lodash.camelcase'; import { RootState } from '@src/store'; @@ -212,12 +211,14 @@ export const metricsSlice = createSlice({ state.cycleTimeSettingsType = action.payload; }, addADeploymentFrequencySetting: (state) => { + const { deploymentFrequencySettings, importedData } = state; const newId = - state.deploymentFrequencySettings.length >= 1 - ? state.deploymentFrequencySettings[state.deploymentFrequencySettings.length - 1].id + 1 - : 0; + Math.max( + deploymentFrequencySettings[deploymentFrequencySettings.length - 1]?.id ?? 0, + importedData.importedDeployment[importedData.importedDeployment.length - 1]?.id ?? 0, + ) + 1; state.deploymentFrequencySettings = [ - ...state.deploymentFrequencySettings, + ...deploymentFrequencySettings, { id: newId, organization: '', pipelineName: '', step: '', branches: [] }, ]; }, @@ -488,8 +489,7 @@ export const selectOrganizationWarningMessage = (state: RootState, id: number) = export const selectPipelineNameWarningMessage = (state: RootState, id: number) => { const { deploymentWarningMessage } = state.metrics; - const warningMessage = deploymentWarningMessage; - return warningMessage.find((item) => item.id === id)?.pipelineName; + return deploymentWarningMessage.find((item) => item.id === id)?.pipelineName; }; export const selectStepWarningMessage = (state: RootState, id: number) => { diff --git a/frontend/src/context/interface/index.tsx b/frontend/src/context/interface/index.tsx deleted file mode 100644 index 4c9e832e23..0000000000 --- a/frontend/src/context/interface/index.tsx +++ /dev/null @@ -1,7 +0,0 @@ -export interface PipelineSetting { - id: number; - organization: string; - pipelineName: string; - step: string; - branches: string[]; -} diff --git a/frontend/src/hooks/useMetricsStepValidationCheckContext.tsx b/frontend/src/hooks/useMetricsStepValidationCheckContext.tsx index 6e92394581..1fdcd3ad6d 100644 --- a/frontend/src/hooks/useMetricsStepValidationCheckContext.tsx +++ b/frontend/src/hooks/useMetricsStepValidationCheckContext.tsx @@ -1,8 +1,8 @@ -import { PipelineSetting } from '@src/context/interface'; +import { IPipelineConfig } from '@src/context/Metrics/metricsSlice'; import React, { createContext, useContext } from 'react'; interface ProviderContextType { - getDuplicatedPipeLineIds: (pipelineSettings: PipelineSetting[]) => number[]; + getDuplicatedPipeLineIds: (pipelineSettings: IPipelineConfig[]) => number[]; } interface ContextProviderProps { @@ -13,7 +13,7 @@ export const ValidationContext = createContext({ getDuplicatedPipeLineIds: () => [], }); -const getDuplicatedPipeLineIds = (pipelineSettings: PipelineSetting[]) => { +const getDuplicatedPipeLineIds = (pipelineSettings: IPipelineConfig[]) => { const errors: { [key: string]: number[] } = {}; pipelineSettings.forEach(({ id, organization, pipelineName, step }) => { if (organization && pipelineName && step) {