From 2013e5d013d7facacd99fe1d809751547006485d Mon Sep 17 00:00:00 2001
From: "weiran.sun" <907221539@qq.com>
Date: Thu, 1 Feb 2024 10:00:27 +0800
Subject: [PATCH] Revert "ADM-777:[frontend]feat: add should call api ability"
This reverts commit e98fc2f0ad7791764c1d5d6f3dc39997d1d7ae52.
---
.../DeploymentFrequencySettings.test.tsx | 2 --
.../context/pipelineToolSlice.test.ts | 4 ----
.../hooks/useGetMetricsStepsEffect.test.tsx | 20 +++-------------
.../useGetPipelineToolInfoEffect.test.tsx | 23 -------------------
frontend/__tests__/initialConfigState.ts | 2 --
.../PipelineMetricSelection/index.tsx | 6 ++---
.../src/containers/MetricsStepper/index.tsx | 4 ----
frontend/src/context/config/configSlice.ts | 10 --------
.../config/pipelineTool/pipelineToolSlice.ts | 4 ----
.../src/hooks/useGetMetricsStepsEffect.ts | 5 ----
.../src/hooks/useGetPipelineToolInfoEffect.ts | 10 ++------
11 files changed, 7 insertions(+), 83 deletions(-)
diff --git a/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/DeploymentFrequencySettings.test.tsx b/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/DeploymentFrequencySettings.test.tsx
index 71a751ff4a..b4bef8f3ee 100644
--- a/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/DeploymentFrequencySettings.test.tsx
+++ b/frontend/__tests__/containers/MetricsStep/DeploymentFrequencySettings/DeploymentFrequencySettings.test.tsx
@@ -38,8 +38,6 @@ jest.mock('@src/context/config/configSlice', () => ({
selectSteps: jest.fn().mockReturnValue(['']),
selectBranches: jest.fn().mockReturnValue(['']),
selectPipelineCrews: jest.fn().mockReturnValue(['']),
- shouldCallInfoApi: jest.fn().mockReturnValue([true]),
- shouldCallStepApi: jest.fn().mockReturnValue([true]),
}));
const mockValidationCheckContext = {
diff --git a/frontend/__tests__/context/pipelineToolSlice.test.ts b/frontend/__tests__/context/pipelineToolSlice.test.ts
index 4861a344bf..2dad4b5e66 100644
--- a/frontend/__tests__/context/pipelineToolSlice.test.ts
+++ b/frontend/__tests__/context/pipelineToolSlice.test.ts
@@ -81,8 +81,6 @@ describe('pipelineTool reducer', () => {
token: '',
},
isVerified: false,
- shouldCallInfoApi: true,
- shouldCallStepApi: true,
isShow: false,
verifiedResponse: {
pipelineList: [
@@ -131,8 +129,6 @@ describe('pipelineTool reducer', () => {
token: '',
},
isVerified: false,
- shouldCallInfoApi: true,
- shouldCallStepApi: true,
isShow: false,
verifiedResponse: {
pipelineList: [
diff --git a/frontend/__tests__/hooks/useGetMetricsStepsEffect.test.tsx b/frontend/__tests__/hooks/useGetMetricsStepsEffect.test.tsx
index e6ae47b14b..400d442cdc 100644
--- a/frontend/__tests__/hooks/useGetMetricsStepsEffect.test.tsx
+++ b/frontend/__tests__/hooks/useGetMetricsStepsEffect.test.tsx
@@ -4,25 +4,11 @@ import { useGetMetricsStepsEffect } from '@src/hooks/useGetMetricsStepsEffect';
import { metricsClient } from '@src/clients/MetricsClient';
import { act, renderHook } from '@testing-library/react';
import { HttpStatusCode } from 'axios';
-import {setupStore} from "@test/utils/setupStoreUtil";
-import {Provider} from "react-redux";
-import {ContextProvider} from "@src/hooks/useMetricsStepValidationCheckContext";
-import React from "react";
-
-const setup = () => {
- const store = setupStore();
- const wrapper = ({children}: { children: React.ReactNode }) => (
-
- {children}
-
- );
- return renderHook(() => useGetMetricsStepsEffect(), {wrapper});
-};
describe('use get steps effect', () => {
const { params, buildId, organizationId, pipelineType, token } = MOCK_GET_STEPS_PARAMS;
it('should init data state when render hook', async () => {
- const { result } = setup();
+ const { result } = renderHook(() => useGetMetricsStepsEffect());
expect(result.current.isLoading).toEqual(false);
});
@@ -32,7 +18,7 @@ describe('use get steps effect', () => {
metricsClient.getSteps = jest.fn().mockImplementation(() => {
throw new Error('error');
});
- const { result } = setup();
+ const { result } = renderHook(() => useGetMetricsStepsEffect());
expect(result.current.isLoading).toEqual(false);
@@ -48,7 +34,7 @@ describe('use get steps effect', () => {
metricsClient.getSteps = jest.fn().mockImplementation(() => {
throw new InternalServerException('error message', HttpStatusCode.InternalServerError);
});
- const { result } = setup();
+ const { result } = renderHook(() => useGetMetricsStepsEffect());
act(() => {
result.current.getSteps(params, buildId, organizationId, pipelineType, token);
diff --git a/frontend/__tests__/hooks/useGetPipelineToolInfoEffect.test.tsx b/frontend/__tests__/hooks/useGetPipelineToolInfoEffect.test.tsx
index 2a85e82e95..011f075413 100644
--- a/frontend/__tests__/hooks/useGetPipelineToolInfoEffect.test.tsx
+++ b/frontend/__tests__/hooks/useGetPipelineToolInfoEffect.test.tsx
@@ -7,8 +7,6 @@ import { Provider } from 'react-redux';
import { HttpStatusCode } from 'axios';
import { ReactNode } from 'react';
import React from 'react';
-import {act} from "react-dom/test-utils";
-import { updatePipelineToolShouldCallInfoApi } from "@src/context/config/configSlice";
const mockDispatch = jest.fn();
jest.mock('react-redux', () => ({
@@ -48,27 +46,6 @@ beforeEach(() => {
});
describe('use get pipelineTool info side effect', () => {
- it('should return immediately if shouldCallApi is false', async () => {
- const store = setupStore();
- const Wrapper = ({children}: { children: ReactNode }) => {
- return {children};
- };
-
- act(() => {
- store.dispatch(updatePipelineToolShouldCallInfoApi(false));
- });
-
- const {result} = renderHook(() => useGetPipelineToolInfoEffect(), {wrapper: Wrapper});
-
- act(() => {
- result.current.apiCallFunc();
- });
-
- await waitFor(() => {
- expect(pipelineToolClient.getInfo).not.toHaveBeenCalled();
- });
- });
-
it('should return success data and loading state when client goes happy path', async () => {
const { result } = renderHook(() => useGetPipelineToolInfoEffect(), { wrapper: Wrapper });
diff --git a/frontend/__tests__/initialConfigState.ts b/frontend/__tests__/initialConfigState.ts
index 33268e55c3..694ea57cec 100644
--- a/frontend/__tests__/initialConfigState.ts
+++ b/frontend/__tests__/initialConfigState.ts
@@ -37,8 +37,6 @@ const initialConfigState: BasicConfigState = {
},
isVerified: false,
isShow: false,
- shouldCallInfoApi: true,
- shouldCallStepApi: true,
verifiedResponse: {
pipelineList: [],
pipelineCrews: [],
diff --git a/frontend/src/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection/index.tsx b/frontend/src/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection/index.tsx
index 87b2ed57fb..63369fef73 100644
--- a/frontend/src/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection/index.tsx
+++ b/frontend/src/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection/index.tsx
@@ -3,7 +3,6 @@ import {
selectPipelineOrganizations,
selectSteps,
selectStepsParams,
- shouldCallStepApi,
updatePipelineToolVerifyResponseSteps,
} from '@src/context/config/configSlice';
import {
@@ -20,7 +19,7 @@ import { useGetMetricsStepsEffect } from '@src/hooks/useGetMetricsStepsEffect';
import { ErrorNotification } from '@src/components/ErrorNotification';
import { MESSAGE } from '@src/constants/resources';
import { Loading } from '@src/components/Loading';
-import { useAppDispatch, useAppSelector} from '@src/hooks';
+import { useAppDispatch } from '@src/hooks';
import { store } from '@src/store';
import { useState } from 'react';
@@ -57,7 +56,6 @@ export const PipelineMetricSelection = ({
const pipelineNameWarningMessage = selectPipelineNameWarningMessage(store.getState(), id);
const stepWarningMessage = selectStepWarningMessage(store.getState(), id);
const [isShowNoStepWarning, setIsShowNoStepWarning] = useState(false);
- const shouldCallApi = useAppSelector(shouldCallStepApi);
const handleRemoveClick = () => {
onRemovePipeline(id);
@@ -97,7 +95,7 @@ export const PipelineMetricSelection = ({
{pipelineNameWarningMessage && }
{stepWarningMessage && }
{isShowNoStepWarning && }
- {shouldCallApi && isLoading && }
+ {isLoading && }
{isDuplicated && This pipeline is the same as another one!}
{errorMessage && }
{
};
const handleBack = () => {
- dispatch(updatePipelineToolShouldCallInfoApi(true));
- dispatch(updatePipelineToolShouldCallStepApi(true));
setIsDialogShowing(!activeStep);
dispatch(backStep());
};
diff --git a/frontend/src/context/config/configSlice.ts b/frontend/src/context/config/configSlice.ts
index c26a2cfeb1..8f6827f00f 100644
--- a/frontend/src/context/config/configSlice.ts
+++ b/frontend/src/context/config/configSlice.ts
@@ -120,12 +120,6 @@ export const configSlice = createSlice({
updatePipelineToolVerifyState: (state, action) => {
state.pipelineTool.isVerified = action.payload;
},
- updatePipelineToolShouldCallInfoApi: (state, action) => {
- state.pipelineTool.shouldCallInfoApi = action.payload;
- },
- updatePipelineToolShouldCallStepApi: (state, action) => {
- state.pipelineTool.shouldCallStepApi = action.payload;
- },
updatePipelineTool: (state, action) => {
state.pipelineTool.config = action.payload;
},
@@ -185,8 +179,6 @@ export const {
updateSourceControlVerifiedResponse,
updatePipelineToolVerifyResponseSteps,
resetImportedData,
- updatePipelineToolShouldCallInfoApi,
- updatePipelineToolShouldCallStepApi,
} = configSlice.actions;
export const selectProjectName = (state: RootState) => state.config.basic.projectName;
@@ -199,8 +191,6 @@ export const isSelectDoraMetrics = (state: RootState) =>
state.config.basic.metrics.some((metric) => DORA_METRICS.includes(metric));
export const selectBoard = (state: RootState) => state.config.board.config;
export const isPipelineToolVerified = (state: RootState) => state.config.pipelineTool.isVerified;
-export const shouldCallInfoApi = (state: RootState) => state.config.pipelineTool.shouldCallInfoApi;
-export const shouldCallStepApi = (state: RootState) => state.config.pipelineTool.shouldCallStepApi;
export const selectPipelineTool = (state: RootState) => state.config.pipelineTool.config;
export const isSourceControlVerified = (state: RootState) => state.config.sourceControl.isVerified;
export const selectSourceControl = (state: RootState) => state.config.sourceControl.config;
diff --git a/frontend/src/context/config/pipelineTool/pipelineToolSlice.ts b/frontend/src/context/config/pipelineTool/pipelineToolSlice.ts
index a607866eba..2179ae7994 100644
--- a/frontend/src/context/config/pipelineTool/pipelineToolSlice.ts
+++ b/frontend/src/context/config/pipelineTool/pipelineToolSlice.ts
@@ -4,8 +4,6 @@ import { PIPELINE_TOOL_TYPES } from '@src/constants/resources';
export interface IPipelineToolState {
config: { type: string; token: string };
isVerified: boolean;
- shouldCallInfoApi: boolean;
- shouldCallStepApi: boolean;
isShow: boolean;
verifiedResponse: IPipelineToolVerifyResponse;
}
@@ -16,8 +14,6 @@ export const initialPipelineToolState: IPipelineToolState = {
token: '',
},
isVerified: false,
- shouldCallInfoApi: true,
- shouldCallStepApi: true,
isShow: false,
verifiedResponse: initialPipelineToolVerifiedResponseState,
};
diff --git a/frontend/src/hooks/useGetMetricsStepsEffect.ts b/frontend/src/hooks/useGetMetricsStepsEffect.ts
index ab6fd541a5..f73f7a0120 100644
--- a/frontend/src/hooks/useGetMetricsStepsEffect.ts
+++ b/frontend/src/hooks/useGetMetricsStepsEffect.ts
@@ -2,8 +2,6 @@ import { getStepsParams, metricsClient } from '@src/clients/MetricsClient';
import { MESSAGE } from '@src/constants/resources';
import { DURATION } from '@src/constants/commons';
import { useState } from 'react';
-import { shouldCallStepApi, updatePipelineToolShouldCallStepApi } from "@src/context/config/configSlice";
-import { useAppDispatch, useAppSelector } from "@src/hooks/index";
export interface useGetMetricsStepsEffectInterface {
getSteps: (
@@ -28,8 +26,6 @@ export interface useGetMetricsStepsEffectInterface {
export const useGetMetricsStepsEffect = (): useGetMetricsStepsEffectInterface => {
const [isLoading, setIsLoading] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
- const shouldCallApi = useAppSelector(shouldCallStepApi);
- const dispatch = useAppDispatch();
const getSteps = async (
params: getStepsParams,
@@ -48,7 +44,6 @@ export const useGetMetricsStepsEffect = (): useGetMetricsStepsEffectInterface =>
setErrorMessage('');
}, DURATION.ERROR_MESSAGE_TIME);
} finally {
- shouldCallApi && dispatch(updatePipelineToolShouldCallStepApi(false));
setIsLoading(false);
}
};
diff --git a/frontend/src/hooks/useGetPipelineToolInfoEffect.ts b/frontend/src/hooks/useGetPipelineToolInfoEffect.ts
index 0653df025f..2a49103c5f 100644
--- a/frontend/src/hooks/useGetPipelineToolInfoEffect.ts
+++ b/frontend/src/hooks/useGetPipelineToolInfoEffect.ts
@@ -4,8 +4,6 @@ import {
selectIsProjectCreated,
selectPipelineTool,
selectDateRange,
- shouldCallInfoApi,
- updatePipelineToolShouldCallInfoApi,
} from '@src/context/config/configSlice';
import { pipelineToolClient, IGetPipelineToolInfoResult } from '@src/clients/pipeline/PipelineToolClient';
import { updatePipelineSettings } from '@src/context/Metrics/metricsSlice';
@@ -32,7 +30,6 @@ export const useGetPipelineToolInfoEffect = (): IUseVerifyPipeLineToolStateInter
const isProjectCreated = useAppSelector(selectIsProjectCreated);
const restoredPipelineTool = useAppSelector(selectPipelineTool);
const dateRange = useAppSelector(selectDateRange);
- const shouldCallApi = useAppSelector(shouldCallInfoApi);
const getPipelineToolInfo = useCallback(async () => {
const params = {
@@ -41,8 +38,6 @@ export const useGetPipelineToolInfoEffect = (): IUseVerifyPipeLineToolStateInter
startTime: dateRange.startDate,
endTime: dateRange.endDate,
};
- if (!shouldCallApi) return;
- dispatch(updatePipelineToolShouldCallInfoApi(false));
setIsLoading(true);
const response = await pipelineToolClient.getInfo(params);
setInfo(response);
@@ -53,7 +48,6 @@ export const useGetPipelineToolInfoEffect = (): IUseVerifyPipeLineToolStateInter
dispatch,
isProjectCreated,
pipelineToolVerified,
- shouldCallApi,
dateRange.startDate,
dateRange.endDate,
restoredPipelineTool.type,
@@ -61,11 +55,11 @@ export const useGetPipelineToolInfoEffect = (): IUseVerifyPipeLineToolStateInter
]);
useEffect(() => {
- if (!apiTouchedRef.current && !isLoading && shouldCallApi) {
+ if (!apiTouchedRef.current && !isLoading) {
apiTouchedRef.current = true;
getPipelineToolInfo();
}
- }, [getPipelineToolInfo, isLoading, shouldCallApi]);
+ }, [getPipelineToolInfo, isLoading]);
return {
result: info,