Skip to content

Commit

Permalink
[EPMDEDP-12007]: fix: Fix stage component sonar cognitive complexity …
Browse files Browse the repository at this point in the history
…critical

Change-Id: I46f7a3031b69add29547970bb6d816be5d722638
  • Loading branch information
callmevladik committed May 16, 2023
1 parent 266bb74 commit bd4cf0a
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { jest } from '@jest/globals';
import { EDPCDPipelineKubeObjectInterface } from '../../../../k8s/EDPCDPipeline/types';
import { EDPCDPipelineStageKubeObjectInterface } from '../../../../k8s/EDPCDPipelineStage/types';
import { EnrichedApplicationWithImageStreams } from '../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EDPCodebaseImageStreamKubeObjectInterface } from '../../../../k8s/EDPCodebaseImageStream/types';
import { EDPGitServerKubeObjectInterface } from '../../../../k8s/EDPGitServer/types';
import { createApplicationInstance } from './index';
Expand Down Expand Up @@ -33,8 +33,8 @@ describe('testing createApplicationInstance', () => {
CDPipeline: CDPipelineMock as EDPCDPipelineKubeObjectInterface,
currentCDPipelineStage:
CDPipelineStageMock as unknown as EDPCDPipelineStageKubeObjectInterface,
enrichedApplication:
enrichedApplicationMock as unknown as EnrichedApplicationWithImageStreams,
enrichedApplicationWithItsImageStreams:
enrichedApplicationMock as unknown as EnrichedApplicationWithItsImageStreams,
imageStream: imageStreamMock as EDPCodebaseImageStreamKubeObjectInterface,
imageTag: 'test-image-tag',
gitServer: gitServerMock as EDPGitServerKubeObjectInterface,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { kind, group, version } = ApplicationKubeObjectConfig;
export const createApplicationInstance = ({
CDPipeline,
currentCDPipelineStage,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageStream,
imageTag,
gitServer,
Expand All @@ -40,7 +40,7 @@ export const createApplicationInstance = ({
buildTool,
},
},
} = enrichedApplication;
} = enrichedApplicationWithItsImageStreams;

const {
spec: { imageName },
Expand Down Expand Up @@ -126,7 +126,7 @@ export const createApplicationInstance = ({

export const editApplicationInstance = ({
argoApplication,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageTag,
}: editApplicationInstanceProps): ApplicationKubeObjectInterface => {
const {
Expand All @@ -135,7 +135,7 @@ export const editApplicationInstance = ({
versioning: { type: versioningType },
},
},
} = enrichedApplication;
} = enrichedApplicationWithItsImageStreams;
const isEDPVersioning = versioningType === CODEBASE_VERSIONING_TYPES['EDP'];
const base = { ...argoApplication };

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { ApplicationKubeObjectInterface } from '../../../../k8s/Application/types';
import { EDPCDPipelineKubeObjectInterface } from '../../../../k8s/EDPCDPipeline/types';
import { EDPCDPipelineStageKubeObjectInterface } from '../../../../k8s/EDPCDPipelineStage/types';
import { EnrichedApplicationWithImageStreams } from '../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EDPCodebaseImageStreamKubeObjectInterface } from '../../../../k8s/EDPCodebaseImageStream/types';
import { EDPGitServerKubeObjectInterface } from '../../../../k8s/EDPGitServer/types';

export interface createApplicationInstanceProps {
CDPipeline: EDPCDPipelineKubeObjectInterface;
currentCDPipelineStage: EDPCDPipelineStageKubeObjectInterface;
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
imageStream: EDPCodebaseImageStreamKubeObjectInterface;
imageTag: string;
gitServer: EDPGitServerKubeObjectInterface;
}

export interface editApplicationInstanceProps {
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
argoApplication: ApplicationKubeObjectInterface;
imageTag: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EDPCodebaseImageStreamKubeObjectInterface } from '../../EDPCodebaseImag
import { EDPCodebaseKubeObjectInterface } from '../types';
import { useCodebasesByTypeLabelQuery } from './useCodebasesByTypeLabelQuery';

export interface EnrichedApplicationWithImageStreams {
export interface EnrichedApplicationWithItsImageStreams {
application: EDPCodebaseKubeObjectInterface;
applicationImageStream: string;
applicationImageStreams: EDPCodebaseImageStreamKubeObjectInterface[];
Expand All @@ -21,7 +21,7 @@ interface UseEnrichedApplicationsWithImageStreamsQueryProps {
options?: UseQueryOptions<
KubeObjectListInterface<EDPCodebaseKubeObjectInterface>,
Error,
EnrichedApplicationWithImageStreams[]
EnrichedApplicationWithItsImageStreams[]
>;
}

Expand All @@ -47,7 +47,7 @@ export const useEnrichedApplicationsWithImageStreamsQuery = ({

console.log(codebaseImageStreams);

return useCodebasesByTypeLabelQuery<EnrichedApplicationWithImageStreams[]>({
return useCodebasesByTypeLabelQuery<EnrichedApplicationWithItsImageStreams[]>({
props: {
namespace: CDPipelineData?.metadata.namespace,
codebaseType: CODEBASE_TYPES.APPLICATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { HeadlampSimpleTableGetterColumn } from '../../../../../components/Headl
import { StatusIcon } from '../../../../../components/StatusIcon';
import { ICONS } from '../../../../../constants/icons';
import { CUSTOM_RESOURCE_STATUSES } from '../../../../../constants/statuses';
import { EnrichedApplicationWithImageStreams } from '../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { Iconify, pluginLib, React } from '../../../../../plugin.globals';
import { COMPONENTS_ROUTE_NAME } from '../../../../../routes/names';
import { DeepPartial } from '../../../../../types/global';
Expand All @@ -14,7 +14,7 @@ const {
const { Icon } = Iconify;

export const useColumns = (): HeadlampSimpleTableGetterColumn<
DeepPartial<EnrichedApplicationWithImageStreams>
DeepPartial<EnrichedApplicationWithItsImageStreams>
>[] =>
React.useMemo(
() => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ApplicationKubeObject } from '../../../../../../../../../../../../k8s/A
import { ApplicationKubeObjectInterface } from '../../../../../../../../../../../../k8s/Application/types';
import { EDPCDPipelineKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCDPipeline/types';
import { EDPCDPipelineStageKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCDPipelineStage/types';
import { EnrichedApplicationWithImageStreams } from '../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EDPCodebaseImageStreamKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCodebaseImageStream/types';
import { EDPGitServerKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPGitServer/types';
import { React } from '../../../../../../../../../../../../plugin.globals';
Expand All @@ -17,14 +17,14 @@ interface CreateArgoApplicationProps {
gitServers: EDPGitServerKubeObjectInterface[];
CDPipeline: EDPCDPipelineKubeObjectInterface;
currentCDPipelineStage: EDPCDPipelineStageKubeObjectInterface;
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
imageStream: EDPCodebaseImageStreamKubeObjectInterface;
imageTag: string;
}

interface EditArgoApplicationProps {
argoApplication: ApplicationKubeObjectInterface;
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
imageTag: string;
}

Expand Down Expand Up @@ -53,18 +53,20 @@ export const useCreateArgoApplication = () => {
gitServers,
CDPipeline,
currentCDPipelineStage,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageStream,
imageTag,
}: CreateArgoApplicationProps): Promise<void> => {
const [gitServer] = gitServers.filter(
el => el.metadata.name === enrichedApplication.application.spec.gitServer
el =>
el.metadata.name ===
enrichedApplicationWithItsImageStreams.application.spec.gitServer
);

const argoApplicationData = createApplicationInstance({
CDPipeline,
currentCDPipelineStage,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageStream,
imageTag,
gitServer,
Expand All @@ -78,12 +80,12 @@ export const useCreateArgoApplication = () => {
const editArgoApplication = React.useCallback(
async ({
argoApplication,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageTag,
}: EditArgoApplicationProps): Promise<void> => {
const argoApplicationData: ApplicationKubeObjectInterface = editApplicationInstance({
argoApplication,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageTag,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import { renderHook } from '@testing-library/react-hooks';
import { EDPCDPipelineKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCDPipeline/types';
import { EDPCDPipelineStageKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCDPipelineStage/types';
import { EnrichedApplicationWithImageStreams } from '../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { useImageStreamBasedOnResources } from './index';
import { applicationMock } from './mocks/application.mock';
import { cdpipelineMock } from './mocks/cdpipeline.mock';
Expand All @@ -20,7 +20,8 @@ describe('testing useImageStreamBasedOnResources hook', () => {
},
} = renderHook(() =>
useImageStreamBasedOnResources({
enrichedApplication: applicationMock as EnrichedApplicationWithImageStreams,
enrichedApplicationWithItsImageStreams:
applicationMock as EnrichedApplicationWithItsImageStreams,
CDPipeline: cdpipelineMock as EDPCDPipelineKubeObjectInterface,
currentCDPipelineStage: stageMock as EDPCDPipelineStageKubeObjectInterface,
CDPipelineStages: stagesMock as EDPCDPipelineStageKubeObjectInterface[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { EDPCDPipelineKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCDPipeline/types';
import { EDPCDPipelineStageKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCDPipelineStage/types';
import { EnrichedApplicationWithImageStreams } from '../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EDPCodebaseImageStreamKubeObjectInterface } from '../../../../../../../../../../../../k8s/EDPCodebaseImageStream/types';

interface useImageStreamBasedOnResourcesInterface {
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
CDPipeline: EDPCDPipelineKubeObjectInterface;
currentCDPipelineStage: EDPCDPipelineStageKubeObjectInterface;
CDPipelineStages: EDPCDPipelineStageKubeObjectInterface[];
}
export const useImageStreamBasedOnResources = ({
enrichedApplication,
enrichedApplicationWithItsImageStreams,
CDPipeline,
currentCDPipelineStage,
CDPipelineStages,
Expand All @@ -30,7 +30,7 @@ export const useImageStreamBasedOnResources = ({

const CDPipelineInputDockerStreamsSet = new Set<string>(normalizedInputDockerStreamNames);

const { applicationImageStreams } = enrichedApplication;
const { applicationImageStreams } = enrichedApplicationWithItsImageStreams;

const findPreviousStage = (
stages: EDPCDPipelineStageKubeObjectInterface[],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EnrichedApplicationWithImageStreams } from '../../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { KubeObjectInterface } from '../../../../../../../../../../../../../plugin.types';
import { DeepPartial } from '../../../../../../../../../../../../../types/global';
export const applicationMock: DeepPartial<EnrichedApplicationWithImageStreams> = {
export const applicationMock: DeepPartial<EnrichedApplicationWithItsImageStreams> = {
application: {
apiVersion: 'v2.edp.epam.com/v1',
kind: 'Codebase',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormSelect } from '../../../../../../../../../../components/FormCompone
import { Render } from '../../../../../../../../../../components/Render';
import { ICONS } from '../../../../../../../../../../constants/icons';
import { ApplicationKubeObjectInterface } from '../../../../../../../../../../k8s/Application/types';
import { EnrichedApplicationWithImageStreams } from '../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { useGitServerListQuery } from '../../../../../../../../../../k8s/EDPGitServer/hooks/useGitServerListQuery';
import { Iconify, MuiCore, React } from '../../../../../../../../../../plugin.globals';
import { rem } from '../../../../../../../../../../utils/styling/rem';
Expand All @@ -19,11 +19,11 @@ const { Grid, Tooltip, IconButton } = MuiCore;
const { Icon } = Iconify;

export const ImageStreamTagsSelect = ({
enrichedApplication,
enrichedApplicationWithItsImageStreams,
argoApplication,
qualityGatePipelineIsRunning,
}: {
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
argoApplication: ApplicationKubeObjectInterface;
qualityGatePipelineIsRunning: boolean;
jaegerLink: string;
Expand All @@ -43,7 +43,7 @@ export const ImageStreamTagsSelect = ({
const { data: gitServers } = useGitServerListQuery({});

const { imageStream } = useImageStreamBasedOnResources({
enrichedApplication,
enrichedApplicationWithItsImageStreams,
CDPipeline,
currentCDPipelineStage,
CDPipelineStages,
Expand Down Expand Up @@ -73,15 +73,15 @@ export const ImageStreamTagsSelect = ({
gitServers: gitServers?.items,
CDPipeline,
currentCDPipelineStage,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageStream,
imageTag: streamTagFieldValue,
});
}, [
CDPipeline,
createArgoApplication,
currentCDPipelineStage,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
gitServers,
imageStream,
streamTagFieldValue,
Expand All @@ -90,10 +90,15 @@ export const ImageStreamTagsSelect = ({
const handleEditRequest = React.useCallback(async () => {
await editArgoApplication({
argoApplication,
enrichedApplication,
enrichedApplicationWithItsImageStreams,
imageTag: streamTagFieldValue,
});
}, [argoApplication, editArgoApplication, enrichedApplication, streamTagFieldValue]);
}, [
argoApplication,
editArgoApplication,
enrichedApplicationWithItsImageStreams,
streamTagFieldValue,
]);

const handleDeleteRequest = React.useCallback(async () => {
await deleteArgoApplication({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from '../../../../../../../../../configs/codebase-mappings';
import { CUSTOM_RESOURCE_STATUSES } from '../../../../../../../../../constants/statuses';
import { ApplicationKubeObjectInterface } from '../../../../../../../../../k8s/Application/types';
import { EnrichedApplicationWithImageStreams } from '../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { EnrichedApplicationWithItsImageStreams } from '../../../../../../../../../k8s/EDPCodebase/hooks/useEnrichedApplicationsWithImageStreamsQuery';
import { useEDPComponentsURLsQuery } from '../../../../../../../../../k8s/EDPComponent/hooks/useEDPComponentsURLsQuery';
import { MuiCore, pluginLib, React } from '../../../../../../../../../plugin.globals';
import { COMPONENTS_ROUTE_NAME } from '../../../../../../../../../routes/names';
Expand All @@ -25,7 +25,7 @@ const { Link: MuiLink } = MuiCore;
export const useColumns = (
qualityGatePipelineIsRunning: boolean
): HeadlampSimpleTableGetterColumn<{
enrichedApplication: EnrichedApplicationWithImageStreams;
enrichedApplicationWithItsImageStreams: EnrichedApplicationWithItsImageStreams;
argoApplication: ApplicationKubeObjectInterface;
}>[] => {
const { data: EDPComponentsURLS } = useEDPComponentsURLsQuery();
Expand Down Expand Up @@ -81,7 +81,7 @@ export const useColumns = (
{
label: 'Application',
getter: ({
enrichedApplication: {
enrichedApplicationWithItsImageStreams: {
application: {
metadata: { name, namespace },
},
Expand All @@ -106,7 +106,7 @@ export const useColumns = (
label: 'Deployed version',
getter: ({
argoApplication,
enrichedApplication: {
enrichedApplicationWithItsImageStreams: {
application: {
spec: { lang, framework, buildTool },
},
Expand Down Expand Up @@ -139,12 +139,14 @@ export const useColumns = (
},
{
label: 'Image stream version',
getter: ({ enrichedApplication, argoApplication }) => {
getter: ({ enrichedApplicationWithItsImageStreams, argoApplication }) => {
const jaegerLink = _createJaegerLink(argoApplication);

return (
<ImageStreamTagsSelect
enrichedApplication={enrichedApplication}
enrichedApplicationWithItsImageStreams={
enrichedApplicationWithItsImageStreams
}
argoApplication={argoApplication}
qualityGatePipelineIsRunning={qualityGatePipelineIsRunning}
jaegerLink={jaegerLink}
Expand Down
Loading

0 comments on commit bd4cf0a

Please sign in to comment.