diff --git a/packages/ui/src/models/camel/kamelet-resource.ts b/packages/ui/src/models/camel/kamelet-resource.ts index 62299d808..93989136e 100644 --- a/packages/ui/src/models/camel/kamelet-resource.ts +++ b/packages/ui/src/models/camel/kamelet-resource.ts @@ -1,5 +1,5 @@ -import { set } from 'lodash'; import { TileFilter } from '../../components/Catalog/Catalog.models'; +import { setValue } from '../../utils'; import { IKameletDefinition } from '../kamelets-catalog'; import { AddStepMode } from '../visualization/base-visual-entity'; import { CamelComponentFilterService } from '../visualization/flows/support/camel-component-filter.service'; @@ -61,9 +61,9 @@ export class KameletResource extends CamelKResource implements RouteTemplateBean * and this way the kamelet definition is updated when the user interacts with * the CamelRouteVisualEntity. */ - set(this.resource, 'metadata.name', this.flow.getId()); - set(this.resource, 'spec.template.from', this.flow.entityDef.template.from); - set(this.resource, 'spec.template.beans', this.beans?.parent.beans); + setValue(this.resource, 'metadata.name', this.flow.getId()); + setValue(this.resource, 'spec.template.from', this.flow.entityDef.template.from); + setValue(this.resource, 'spec.template.beans', this.beans?.parent.beans); return this.resource as IKameletDefinition; } diff --git a/packages/ui/src/models/visualization/flows/pipe-visual-entity.test.ts b/packages/ui/src/models/visualization/flows/pipe-visual-entity.test.ts index 7b0bcfab0..0f0c4fca3 100644 --- a/packages/ui/src/models/visualization/flows/pipe-visual-entity.test.ts +++ b/packages/ui/src/models/visualization/flows/pipe-visual-entity.test.ts @@ -108,14 +108,14 @@ describe('Pipe', () => { pipeVisualEntity.removeStep('source'); expect(pipeVisualEntity.toJSON()).not.toEqual(pipeJson.spec); - expect(pipeVisualEntity.pipe.spec?.source).toEqual({}); + expect(pipeVisualEntity.pipe.spec?.source).toBeUndefined(); }); it('should remove the `sink` step', () => { pipeVisualEntity.removeStep('sink'); expect(pipeVisualEntity.toJSON()).not.toEqual(pipeJson.spec); - expect(pipeVisualEntity.pipe.spec?.sink).toEqual({}); + expect(pipeVisualEntity.pipe.spec?.sink).toBeUndefined(); }); it('should remove the `steps.0` step', () => { diff --git a/packages/ui/src/models/visualization/flows/pipe-visual-entity.ts b/packages/ui/src/models/visualization/flows/pipe-visual-entity.ts index 26b6ed311..e45a40910 100644 --- a/packages/ui/src/models/visualization/flows/pipe-visual-entity.ts +++ b/packages/ui/src/models/visualization/flows/pipe-visual-entity.ts @@ -1,5 +1,4 @@ import { Pipe } from '@kaoto/camel-catalog/types'; -import { set } from 'lodash'; import { getCamelRandomId } from '../../../camel-utils/camel-random-id'; import { SchemaService } from '../../../components/Form/schema.service'; import { @@ -152,12 +151,7 @@ export class PipeVisualEntity implements BaseVisualCamelEntity { /** Replace an existing Kamelet */ if (options.mode === AddStepMode.ReplaceStep) { - if (path === 'source' || path === 'sink') { - set(this.pipe.spec!, path, step); - } else { - set(this.pipe.spec!, path, step); - } - + setValue(this.pipe.spec, path, step); return; } @@ -180,7 +174,7 @@ export class PipeVisualEntity implements BaseVisualCamelEntity { * If the path is `source` or `sink`, we can remove it directly */ if (path === 'source' || path === 'sink') { - set(this.pipe.spec!, path, {}); + setValue(this.pipe.spec, path, {}); return; } const pathArray = path.split('.'); diff --git a/packages/ui/src/utils/get-array-property.ts b/packages/ui/src/utils/get-array-property.ts index 10dd4eba5..7249b3e34 100644 --- a/packages/ui/src/utils/get-array-property.ts +++ b/packages/ui/src/utils/get-array-property.ts @@ -1,11 +1,12 @@ -import { get, set } from 'lodash'; +import { getValue } from './get-value'; +import { setValue } from './set-value'; export const getArrayProperty = (model: object, path: string): T[] => { - let stepsArray: T[] | undefined = get(model, path); + let stepsArray: T[] | undefined = getValue(model, path); if (!Array.isArray(stepsArray)) { - set(model, path, []); - stepsArray = get(model, path) as T[]; + setValue(model, path, []); + stepsArray = getValue(model, path) as T[]; } return stepsArray; diff --git a/packages/ui/src/utils/pipe-custom-schema.ts b/packages/ui/src/utils/pipe-custom-schema.ts index 8a6ada495..d9c60e2c1 100644 --- a/packages/ui/src/utils/pipe-custom-schema.ts +++ b/packages/ui/src/utils/pipe-custom-schema.ts @@ -1,7 +1,6 @@ import { Pipe } from '@kaoto/camel-catalog/types'; import { getValue } from './get-value'; import { setValue } from './set-value'; -import { set } from 'lodash'; export const getCustomSchemaFromPipe = (pipe: Pipe) => { const name: string = getValue(pipe, 'metadata.name', ''); @@ -19,11 +18,11 @@ export const getCustomSchemaFromPipe = (pipe: Pipe) => { export const updatePipeFromCustomSchema = (pipe: Pipe, value: Record): void => { // Ensure 'labels' and 'annotations' are defined in 'value' - if (getValue(value, 'labels') === undefined) { - set(value, 'labels', {}); + if (value && getValue(value, 'labels') === undefined) { + value.labels = {}; } - if (getValue(value, 'annotations') === undefined) { - set(value, 'annotations', {}); + if (value && getValue(value, 'annotations') === undefined) { + value.annotations = {}; } const previousName: string = getValue(pipe, 'metadata.name'); const newName: string = getValue(value, 'name');