Skip to content

Commit

Permalink
refactor: Create generic editResource function (#94)
Browse files Browse the repository at this point in the history
Jira: EPMDPEDP-12902
Related: #94
Change-Id: I08ef5b6bf21bccf0c0b61c2b6cb6479806087be6
  • Loading branch information
callmevladik committed Nov 7, 2023
1 parent f165f7f commit f336859
Show file tree
Hide file tree
Showing 25 changed files with 35 additions and 273 deletions.

This file was deleted.

26 changes: 0 additions & 26 deletions src/k8s/EDPCDPipeline/utils/editCDPipelineInstance/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions src/k8s/EDPCodebase/utils/editCodebaseInstance/index.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/k8s/EDPCodebase/utils/editCodebaseInstance/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

26 changes: 0 additions & 26 deletions src/k8s/EDPComponent/utils/editEDPComponentInstance/index.ts

This file was deleted.

This file was deleted.

26 changes: 0 additions & 26 deletions src/k8s/EDPGitServer/utils/editGitServerInstance/index.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/k8s/Secret/utils/editGitServerSecretInstance/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/k8s/ServiceAccount/utils/editServiceAccount/index.test.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/k8s/ServiceAccount/utils/editServiceAccount/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { set } from 'lodash';
import { FormNameObject } from '../../../types/forms';
import { ConfigMapKubeObjectInterface } from '../types';
import { EDPKubeObjectInterface } from '../../../types/k8s';

export const editEDPConfigConfigMap = (
export const editResource = <T extends EDPKubeObjectInterface>(
names: {
[key: string]: FormNameObject;
},
currentConfigMap: ConfigMapKubeObjectInterface,
currentResource: T,
formValues: {
[key: string]: any;
}
): ConfigMapKubeObjectInterface => {
const base = { ...currentConfigMap };
): T => {
const base = { ...currentResource };

for (const [propKey, propValue] of Object.entries(formValues)) {
if (names[propKey]?.notUsedInFormData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { editResource } from '../../../../k8s/common/editResource';
import { useCreateCodebaseBranch } from '../../../../k8s/EDPCodebaseBranch/hooks/useCreateCodebaseBranch';
import { createCodebaseBranchInstance } from '../../../../k8s/EDPCodebaseBranch/utils/createCodebaseBranchInstance';
import { editCodebaseBranchInstance } from '../../../../k8s/EDPCodebaseBranch/utils/editCodebaseBranchInstance';
import { useSpecificDialogContext } from '../../../../providers/Dialog/hooks';
import { createVersioningString } from '../../../../utils/createVersioningString';
import { getUsedValues } from '../../../../utils/forms/getUsedValues';
Expand Down Expand Up @@ -70,7 +70,7 @@ export const FormActions = () => {
);

if (!!values.release) {
const newDefaultBranch = editCodebaseBranchInstance(
const newDefaultBranch = editResource(
{
version: {
name: 'version',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { editResource } from '../../../../../../k8s/common/editResource';
import { useEditCDPipeline } from '../../../../../../k8s/EDPCDPipeline/hooks/useEditCDPipeline';
import { editCDPipelineInstance } from '../../../../../../k8s/EDPCDPipeline/utils/editCDPipelineInstance';
import { useSpecificDialogContext } from '../../../../../../providers/Dialog/hooks';
import { getUsedValues } from '../../../../../../utils/forms/getUsedValues';
import { CREATE_EDIT_CD_PIPELINE_DIALOG_NAME } from '../../../../constants';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const FormActions = () => {
const onSubmit = React.useCallback(
async (values: CreateEditCDPipelineFormValues) => {
const usedValues = getUsedValues(values, CDPIPELINE_FORM_NAMES);
const newCDPipelineData = editCDPipelineInstance(
const newCDPipelineData = editResource(
CDPIPELINE_FORM_NAMES,
CDPipelineData,
usedValues
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { editResource } from '../../../../../../k8s/common/editResource';
import { useCodebaseCRUD } from '../../../../../../k8s/EDPCodebase/hooks/useCodebaseCRUD';
import { editCodebaseInstance } from '../../../../../../k8s/EDPCodebase/utils/editCodebaseInstance';
import { useSpecificDialogContext } from '../../../../../../providers/Dialog/hooks';
import { getUsedValues } from '../../../../../../utils/forms/getUsedValues';
import { CREATE_EDIT_CODEBASE_DIALOG_NAME } from '../../../../constants';
Expand Down Expand Up @@ -51,11 +51,7 @@ export const FormActions = () => {
jiraIssueMetadataPayload: null,
};

const updatedCodebaseData = editCodebaseInstance(
CODEBASE_FORM_NAMES,
codebaseData,
formValues
);
const updatedCodebaseData = editResource(CODEBASE_FORM_NAMES, codebaseData, formValues);

await editCodebase({
codebaseData: updatedCodebaseData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Button } from '@material-ui/core';
import React from 'react';
import { useFormContext } from 'react-hook-form';
import { editResource } from '../../../../../../k8s/common/editResource';
import { useEditCDPipelineStage } from '../../../../../../k8s/EDPCDPipelineStage/hooks/useEditCDPipelineStage';
import { editCDPipelineStageInstance } from '../../../../../../k8s/EDPCDPipelineStage/utils/editCDPipelineStageInstance';
import { useSpecificDialogContext } from '../../../../../../providers/Dialog/hooks';
import { getUsedValues } from '../../../../../../utils/forms/getUsedValues';
import { CREATE_EDIT_STAGE_DIALOG_NAME } from '../../../../constants';
Expand Down Expand Up @@ -46,11 +46,7 @@ export const FormActions = () => {
const onSubmit = React.useCallback(
async (values: CreateEditStageFormValues) => {
const usedValues = getUsedValues(values, STAGE_FORM_NAMES);
const newCDPipelineStageData = editCDPipelineStageInstance(
STAGE_FORM_NAMES,
stage,
usedValues
);
const newCDPipelineStageData = editResource(STAGE_FORM_NAMES, stage, usedValues);

await editCDPipelineStage({ CDPipelineStageData: newCDPipelineStageData });
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Button, Grid } from '@material-ui/core';
import React from 'react';
import { useFormContext as useReactHookFormContext } from 'react-hook-form';
import { Render } from '../../../../components/Render';
import { editResource } from '../../../../k8s/common/editResource';
import { useCreateEDPComponent } from '../../../../k8s/EDPComponent/hooks/useCreateEDPComponent';
import { EDPComponentKubeObjectInterface } from '../../../../k8s/EDPComponent/types';
import { createEDPComponentInstance } from '../../../../k8s/EDPComponent/utils/createEDPComponentInstance';
import { editEDPComponentInstance } from '../../../../k8s/EDPComponent/utils/editEDPComponentInstance';
import { useFormContext } from '../../../../providers/Form/hooks';
import { FORM_MODES } from '../../../../types/forms';
import { EDP_COMPONENT_FORM_NAMES } from '../../names';
Expand Down Expand Up @@ -49,7 +49,7 @@ export const FormActions = () => {
values
);

const EDPComponentEditedInstance = editEDPComponentInstance(
const EDPComponentEditedInstance = editResource(
EDP_COMPONENT_FORM_NAMES,
currentElement as EDPComponentKubeObjectInterface,
values
Expand Down
Loading

0 comments on commit f336859

Please sign in to comment.