Skip to content

Commit

Permalink
Revert "ADM-777:[frontend]feat: add should call api ability"
Browse files Browse the repository at this point in the history
This reverts commit e98fc2f.
  • Loading branch information
weiraneve committed Feb 1, 2024
1 parent 350b592 commit 2013e5d
Show file tree
Hide file tree
Showing 11 changed files with 7 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
4 changes: 0 additions & 4 deletions frontend/__tests__/context/pipelineToolSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ describe('pipelineTool reducer', () => {
token: '',
},
isVerified: false,
shouldCallInfoApi: true,
shouldCallStepApi: true,
isShow: false,
verifiedResponse: {
pipelineList: [
Expand Down Expand Up @@ -131,8 +129,6 @@ describe('pipelineTool reducer', () => {
token: '',
},
isVerified: false,
shouldCallInfoApi: true,
shouldCallStepApi: true,
isShow: false,
verifiedResponse: {
pipelineList: [
Expand Down
20 changes: 3 additions & 17 deletions frontend/__tests__/hooks/useGetMetricsStepsEffect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<Provider store={store}>
<ContextProvider>{children}</ContextProvider>
</Provider>
);
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);
});
Expand All @@ -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);

Expand All @@ -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);
Expand Down
23 changes: 0 additions & 23 deletions frontend/__tests__/hooks/useGetPipelineToolInfoEffect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({
Expand Down Expand Up @@ -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 <Provider store={store}>{children}</Provider>;
};

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 });

Expand Down
2 changes: 0 additions & 2 deletions frontend/__tests__/initialConfigState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ const initialConfigState: BasicConfigState = {
},
isVerified: false,
isShow: false,
shouldCallInfoApi: true,
shouldCallStepApi: true,
verifiedResponse: {
pipelineList: [],
pipelineCrews: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
selectPipelineOrganizations,
selectSteps,
selectStepsParams,
shouldCallStepApi,
updatePipelineToolVerifyResponseSteps,
} from '@src/context/config/configSlice';
import {
Expand All @@ -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';

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -97,7 +95,7 @@ export const PipelineMetricSelection = ({
{pipelineNameWarningMessage && <WarningNotification message={pipelineNameWarningMessage} />}
{stepWarningMessage && <WarningNotification message={stepWarningMessage} />}
{isShowNoStepWarning && <WarningNotification message={MESSAGE.NO_STEP_WARNING} />}
{shouldCallApi && isLoading && <Loading />}
{isLoading && <Loading />}
{isDuplicated && <WarningMessage>This pipeline is the same as another one!</WarningMessage>}
{errorMessage && <ErrorNotification message={errorMessage} />}
<SingleSelection
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/containers/MetricsStepper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import {
updateBoard,
updateBoardVerifyState,
updatePipelineTool,
updatePipelineToolShouldCallInfoApi,
updatePipelineToolShouldCallStepApi,
updatePipelineToolVerifyState,
updateSourceControl,
updateSourceControlVerifyState,
Expand Down Expand Up @@ -233,8 +231,6 @@ const MetricsStepper = () => {
};

const handleBack = () => {
dispatch(updatePipelineToolShouldCallInfoApi(true));
dispatch(updatePipelineToolShouldCallStepApi(true));
setIsDialogShowing(!activeStep);
dispatch(backStep());
};
Expand Down
10 changes: 0 additions & 10 deletions frontend/src/context/config/configSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -185,8 +179,6 @@ export const {
updateSourceControlVerifiedResponse,
updatePipelineToolVerifyResponseSteps,
resetImportedData,
updatePipelineToolShouldCallInfoApi,
updatePipelineToolShouldCallStepApi,
} = configSlice.actions;

export const selectProjectName = (state: RootState) => state.config.basic.projectName;
Expand All @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions frontend/src/context/config/pipelineTool/pipelineToolSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -16,8 +14,6 @@ export const initialPipelineToolState: IPipelineToolState = {
token: '',
},
isVerified: false,
shouldCallInfoApi: true,
shouldCallStepApi: true,
isShow: false,
verifiedResponse: initialPipelineToolVerifiedResponseState,
};
5 changes: 0 additions & 5 deletions frontend/src/hooks/useGetMetricsStepsEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: (
Expand All @@ -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,
Expand All @@ -48,7 +44,6 @@ export const useGetMetricsStepsEffect = (): useGetMetricsStepsEffectInterface =>
setErrorMessage('');
}, DURATION.ERROR_MESSAGE_TIME);
} finally {
shouldCallApi && dispatch(updatePipelineToolShouldCallStepApi(false));
setIsLoading(false);
}
};
Expand Down
10 changes: 2 additions & 8 deletions frontend/src/hooks/useGetPipelineToolInfoEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 = {
Expand All @@ -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);
Expand All @@ -53,19 +48,18 @@ export const useGetPipelineToolInfoEffect = (): IUseVerifyPipeLineToolStateInter
dispatch,
isProjectCreated,
pipelineToolVerified,
shouldCallApi,
dateRange.startDate,
dateRange.endDate,
restoredPipelineTool.type,
restoredPipelineTool.token,
]);

useEffect(() => {
if (!apiTouchedRef.current && !isLoading && shouldCallApi) {
if (!apiTouchedRef.current && !isLoading) {
apiTouchedRef.current = true;
getPipelineToolInfo();
}
}, [getPipelineToolInfo, isLoading, shouldCallApi]);
}, [getPipelineToolInfo, isLoading]);

return {
result: info,
Expand Down

0 comments on commit 2013e5d

Please sign in to comment.