Skip to content

Commit 1535c78

Browse files
committed
feat: Migrate EDPComponent to QuickLink (#157)
Jira: EPMDEDP-13245 Related: #157 Change-Id: I4df3b65229d9ccc732343c243c01fe374c221b73
1 parent cf8291b commit 1535c78

File tree

181 files changed

+1012
-1056
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+1012
-1056
lines changed

src/components/EDPComponentLink/index.tsx src/components/QuickLink/index.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Link } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
22
import { Grid } from '@mui/material';
33
import React from 'react';
44
import { ResourceIconLink } from '../ResourceIconLink';
5-
import { EDPComponentExternalLinkProps } from './types';
5+
import { QuickLinkExternalLinkProps } from './types';
66

7-
export const EDPComponentLink = ({
7+
export const QuickLink = ({
88
name,
99
icon,
1010
externalLink,
1111
enabledText = `Open in ${name.label}`,
1212
configurationLink,
13-
}: EDPComponentExternalLinkProps) => {
13+
}: QuickLinkExternalLinkProps) => {
1414
return externalLink ? (
1515
<ResourceIconLink icon={icon} tooltipTitle={enabledText} link={externalLink} />
1616
) : (

src/components/EDPComponentLink/types.ts src/components/QuickLink/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface EDPComponentExternalLinkProps {
1+
export interface QuickLinkExternalLinkProps {
22
icon: string;
33
externalLink: string;
44
name?: {

src/hooks/useResourceCRUDMutation/data.mock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const mutationDataMock = {
22
apiVersion: 'v1.edp.epam.com/v1',
3-
kind: 'EDPComponent',
3+
kind: 'QuickLink',
44
metadata: {
55
creationTimestamp: '2023-05-16T13:17:33Z',
66
name: 'tekton',

src/hooks/useResourceCRUDMutation/index.test.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { act, renderHook } from '@testing-library/react-hooks';
77
import React, { ReactNode } from 'react';
88
import { QueryClient, QueryClientProvider } from 'react-query';
99
import { CRUD_TYPES } from '../../constants/crudTypes';
10-
import { EDPComponentKubeObject } from '../../k8s/EDPComponent';
10+
import { QuickLinkKubeObject } from '../../k8s/QuickLink';
1111
import { mutationDataMock } from './data.mock';
1212
import { useResourceCRUDMutation } from './index';
1313

@@ -44,12 +44,12 @@ const wrapper = ({ children }: { children: ReactNode }) => (
4444

4545
describe('testing useResourceCRUDMutation hook', () => {
4646
it('Request resolve scenario: the hook renders successfully, useMutation.mutate fn works correctly, notification callbacks are firing', async () => {
47-
jest.spyOn(EDPComponentKubeObject.apiEndpoint, 'post').mockResolvedValue(mutationDataMock);
47+
jest.spyOn(QuickLinkKubeObject.apiEndpoint, 'post').mockResolvedValue(mutationDataMock);
4848

4949
await act(async () => {
5050
console.log('Before renderHook');
5151
const { result } = renderHook(
52-
() => useResourceCRUDMutation('test', EDPComponentKubeObject, CRUD_TYPES.CREATE),
52+
() => useResourceCRUDMutation('test', QuickLinkKubeObject, CRUD_TYPES.CREATE),
5353
{
5454
wrapper: wrapper,
5555
}
@@ -77,12 +77,12 @@ describe('testing useResourceCRUDMutation hook', () => {
7777
});
7878
});
7979
it('Request reject scenario: the hook renders successfully, useMutation.mutate fn works correctly, notification callbacks are firing', async () => {
80-
jest.spyOn(EDPComponentKubeObject.apiEndpoint, 'put').mockRejectedValue({ error: 'error' });
80+
jest.spyOn(QuickLinkKubeObject.apiEndpoint, 'put').mockRejectedValue({ error: 'error' });
8181

8282
await act(async () => {
8383
console.log('Before renderHook');
8484
const { result } = renderHook(
85-
() => useResourceCRUDMutation('test', EDPComponentKubeObject, CRUD_TYPES.EDIT),
85+
() => useResourceCRUDMutation('test', QuickLinkKubeObject, CRUD_TYPES.EDIT),
8686
{
8787
wrapper: wrapper,
8888
}

src/k8s/EDPComponent/config.ts

-11
This file was deleted.

src/k8s/EDPComponent/constants.ts

-39
This file was deleted.

src/k8s/EDPComponent/hooks/useEDPComponentCRUD.ts

-69
This file was deleted.

src/k8s/EDPComponent/hooks/useEDPComponentsQuery.ts

-31
This file was deleted.

src/k8s/EDPComponent/requestKeys.ts

-1
This file was deleted.

src/k8s/EDPComponent/types.ts

-15
This file was deleted.

src/k8s/EDPComponent/utils/isSystemEDPComponent/index.ts

-10
This file was deleted.

src/k8s/QuickLink/config.ts

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { KubeObjectConfig } from '../../types/configs/k8s';
2+
3+
export const QuickLinkKubeObjectConfig: KubeObjectConfig = {
4+
kind: 'QuickLink',
5+
name: {
6+
singularForm: 'quicklink',
7+
pluralForm: 'quicklinks',
8+
},
9+
group: 'v2.edp.epam.com',
10+
version: 'v1',
11+
};

src/k8s/QuickLink/constants.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
export const SYSTEM_QUICK_LINKS = {
2+
// must be equal to QuickLink.metadata.name
3+
4+
GERRIT: 'gerrit',
5+
GITLAB: 'gitlab',
6+
GITHUB: 'github',
7+
TEKTON: 'tekton',
8+
ARGOCD: 'argocd',
9+
DEFECT_DOJO: 'defectdojo',
10+
DEPENDENCY_TRACK: 'dependency-track',
11+
DOCKER_REGISTRY: 'docker-registry',
12+
GRAFANA: 'grafana',
13+
KIBANA: 'kibana',
14+
NEXUS: 'nexus',
15+
SONAR: 'sonar',
16+
} as const;
17+
18+
export const SYSTEM_QUICK_LINKS_WITH_CONFIGURATION = [
19+
SYSTEM_QUICK_LINKS.NEXUS,
20+
SYSTEM_QUICK_LINKS.ARGOCD,
21+
SYSTEM_QUICK_LINKS.SONAR,
22+
SYSTEM_QUICK_LINKS.DEFECT_DOJO,
23+
SYSTEM_QUICK_LINKS.DEPENDENCY_TRACK,
24+
] as const;
25+
26+
export const SYSTEM_QUICK_LINKS_LABELS = {
27+
[SYSTEM_QUICK_LINKS.GERRIT]: 'Gerrit',
28+
[SYSTEM_QUICK_LINKS.GITLAB]: 'GitLab',
29+
[SYSTEM_QUICK_LINKS.GITHUB]: 'GitHub',
30+
[SYSTEM_QUICK_LINKS.TEKTON]: 'Tekton',
31+
[SYSTEM_QUICK_LINKS.ARGOCD]: 'Argo CD',
32+
[SYSTEM_QUICK_LINKS.DEFECT_DOJO]: 'DefectDojo',
33+
[SYSTEM_QUICK_LINKS.DEPENDENCY_TRACK]: 'DependencyTrack',
34+
[SYSTEM_QUICK_LINKS.DOCKER_REGISTRY]: 'DockerRegistry',
35+
[SYSTEM_QUICK_LINKS.GRAFANA]: 'Grafana',
36+
[SYSTEM_QUICK_LINKS.KIBANA]: 'Kibana',
37+
[SYSTEM_QUICK_LINKS.NEXUS]: 'Nexus',
38+
[SYSTEM_QUICK_LINKS.SONAR]: 'Sonar',
39+
} as const;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
import { CRUD_TYPES } from '../../../constants/crudTypes';
3+
import { useResourceCRUDMutation } from '../../../hooks/useResourceCRUDMutation';
4+
import { QuickLinkKubeObject } from '../index';
5+
import { QuickLinkKubeObjectInterface } from '../types';
6+
7+
interface CreateQuickLinkProps {
8+
QuickLinkData: QuickLinkKubeObjectInterface;
9+
}
10+
11+
interface EditQuickLinkProps {
12+
QuickLinkData: QuickLinkKubeObjectInterface;
13+
}
14+
15+
export const useQuickLinkCRUD = ({
16+
onSuccess,
17+
onError,
18+
}: {
19+
onSuccess?: () => void;
20+
onError?: () => void;
21+
}) => {
22+
const invokeOnSuccessCallback = React.useCallback(() => onSuccess && onSuccess(), [onSuccess]);
23+
const invokeOnErrorCallback = React.useCallback(() => onError && onError(), [onError]);
24+
25+
const QuickLinkCreateMutation = useResourceCRUDMutation<
26+
QuickLinkKubeObjectInterface,
27+
CRUD_TYPES.CREATE
28+
>('QuickLinkCreateMutation', QuickLinkKubeObject, CRUD_TYPES.CREATE);
29+
30+
const QuickLinkEditMutation = useResourceCRUDMutation<
31+
QuickLinkKubeObjectInterface,
32+
CRUD_TYPES.EDIT
33+
>('QuickLinkEditMutation', QuickLinkKubeObject, CRUD_TYPES.EDIT);
34+
35+
const createQuickLink = React.useCallback(
36+
async ({ QuickLinkData }: CreateQuickLinkProps) => {
37+
QuickLinkCreateMutation.mutate(QuickLinkData, {
38+
onSuccess: () => {
39+
invokeOnSuccessCallback();
40+
},
41+
onError: () => {
42+
invokeOnErrorCallback();
43+
},
44+
});
45+
},
46+
[QuickLinkCreateMutation, invokeOnErrorCallback, invokeOnSuccessCallback]
47+
);
48+
49+
const editQuickLink = React.useCallback(
50+
async ({ QuickLinkData }: EditQuickLinkProps) => {
51+
QuickLinkEditMutation.mutate(QuickLinkData, {
52+
onSuccess: () => {
53+
invokeOnSuccessCallback();
54+
},
55+
onError: () => {
56+
invokeOnErrorCallback();
57+
},
58+
});
59+
},
60+
[QuickLinkEditMutation, invokeOnErrorCallback, invokeOnSuccessCallback]
61+
);
62+
63+
const mutations = {
64+
QuickLinkCreateMutation,
65+
QuickLinkEditMutation,
66+
};
67+
68+
return { createQuickLink, editQuickLink, mutations };
69+
};

0 commit comments

Comments
 (0)