Skip to content

Commit

Permalink
feat(BaseEntity): Allow individual entities to omit fields
Browse files Browse the repository at this point in the history
Currently, there's a single array to omit form fields, and while this
works, in some cases, we could be omitting unintended fields.

The solution is to allow for individual Entities to provide their own
omit fields list.

relates to: #492
  • Loading branch information
lordrip committed Apr 15, 2024
1 parent dc611f8 commit 9010c88
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { EntitiesContext } from '../../../providers/entities.provider';
import { SchemaBridgeProvider } from '../../../providers/schema-bridge.provider';
import { isDefined, setValue } from '../../../utils';
import { ErrorBoundary } from '../../ErrorBoundary';
import { SchemaService } from '../../Form';
import { CustomAutoForm, CustomAutoFormRef } from '../../Form/CustomAutoForm';
import { DataFormatEditor } from '../../Form/dataFormat/DataFormatEditor';
import { LoadBalancerEditor } from '../../Form/loadBalancer/LoadBalancerEditor';
Expand All @@ -26,6 +25,7 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
const formRef = useRef<CustomAutoFormRef>(null);
const divRef = useRef<HTMLDivElement>(null);
const flowIdRef = useRef<string | undefined>(undefined);
const omitFields = useRef(props.selectedNode.data?.vizNode?.getBaseEntity()?.getOmitFormFields() || []);

const visualComponentSchema = useMemo(() => {
const answer = props.selectedNode.data?.vizNode?.getComponentSchema();
Expand Down Expand Up @@ -107,7 +107,7 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
model={model}
onChange={handleOnChangeIndividualProp}
sortFields={false}
omitFields={SchemaService.OMIT_FORM_FIELDS}
omitFields={omitFields.current}
data-testid="autoform"
/>
<div data-testid="root-form-placeholder" ref={divRef} />
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/models/visualization/base-visual-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export interface BaseVisualCamelEntity extends BaseCamelEntity {
/** Given a path, get the component type and definition */
getComponentSchema: (path?: string) => VisualComponentSchema | undefined;

/** Returnt fields that should be omitted when configuring this entity */
getOmitFormFields: () => string[];

/** Given a path, update the model */
updateModel(path: string | undefined, value: unknown): void;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-case-declarations */
import { ProcessorDefinition, RouteDefinition } from '@kaoto-next/camel-catalog/types';
import { SchemaService } from '../../../components/Form/schema.service';
import { ROOT_PATH, getArrayProperty, getValue, isDefined, setValue } from '../../../utils';
import { NodeIconResolver } from '../../../utils/node-icon-resolver';
import { DefinedComponent } from '../../camel-catalog-index';
Expand Down Expand Up @@ -63,6 +64,10 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity
return visualComponentSchema;
}

getOmitFormFields(): string[] {
return SchemaService.OMIT_FORM_FIELDS;
}

toJSON() {
return { route: this.route };
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ErrorHandler, ProcessorDefinition } from '@kaoto-next/camel-catalog/types';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { SchemaService } from '../../../components/Form/schema.service';
import { useSchemasStore } from '../../../store';
import { isDefined, setValue } from '../../../utils';
import { EntityType } from '../../camel/entities/base-entity';
Expand Down Expand Up @@ -67,6 +68,10 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
};
}

getOmitFormFields(): string[] {
return SchemaService.OMIT_FORM_FIELDS;
}

updateModel(path: string | undefined, value: unknown): void {
if (!path) return;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OnException, ProcessorDefinition } from '@kaoto-next/camel-catalog/types';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { SchemaService } from '../../../components/Form/schema.service';
import { getArrayProperty, getValue, isDefined, setValue } from '../../../utils';
import { DefinedComponent } from '../../camel-catalog-index';
import { EntityType } from '../../camel/entities/base-entity';
Expand All @@ -11,12 +12,12 @@ import {
NodeInteraction,
VisualComponentSchema,
} from '../base-visual-entity';
import { AbstractCamelVisualEntity } from './abstract-camel-visual-entity';
import { CamelComponentDefaultService } from './support/camel-component-default.service';
import { CamelComponentSchemaService } from './support/camel-component-schema.service';
import { CamelProcessorStepsProperties, CamelRouteVisualEntityData } from './support/camel-component-types';
import { CamelStepsService } from './support/camel-steps.service';
import { ModelValidationService } from './support/validators/model-validation.service';
import { CamelProcessorStepsProperties, CamelRouteVisualEntityData } from './support/camel-component-types';
import { AbstractCamelVisualEntity } from './abstract-camel-visual-entity';
import { CamelComponentDefaultService } from './support/camel-component-default.service';

export class CamelOnExceptionVisualEntity implements BaseVisualCamelEntity {
id: string;
Expand Down Expand Up @@ -81,6 +82,10 @@ export class CamelOnExceptionVisualEntity implements BaseVisualCamelEntity {
return visualComponentSchema;
}

getOmitFormFields(): string[] {
return SchemaService.OMIT_FORM_FIELDS;
}

updateModel(path: string | undefined, value: unknown): void {
if (!path) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ProcessorDefinition, RestConfiguration } from '@kaoto-next/camel-catalo
import Ajv, { ValidateFunction } from 'ajv-draft-04';
import addFormats from 'ajv-formats';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { SchemaService } from '../../../components/Form/schema.service';
import { isDefined, setValue } from '../../../utils';
import { EntityType } from '../../camel/entities/base-entity';
import { CatalogKind } from '../../catalog-kind';
Expand Down Expand Up @@ -77,6 +78,10 @@ export class CamelRestConfigurationVisualEntity implements BaseVisualCamelEntity
};
}

getOmitFormFields(): string[] {
return SchemaService.OMIT_FORM_FIELDS;
}

updateModel(path: string | undefined, value: unknown): void {
if (!path) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Pipe } from '@kaoto-next/camel-catalog/types';
import get from 'lodash/get';
import set from 'lodash/set';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { SchemaService } from '../../../components/Form/schema.service';
import { getArrayProperty, NodeIconResolver } from '../../../utils';
import { DefinedComponent } from '../../camel-catalog-index';
import { EntityType } from '../../camel/entities';
Expand Down Expand Up @@ -64,6 +65,10 @@ export class PipeVisualEntity implements BaseVisualCamelEntity {
return KameletSchemaService.getVisualComponentSchema(stepModel);
}

getOmitFormFields(): string[] {
return SchemaService.OMIT_FORM_FIELDS;
}

toJSON() {
return this.spec;
}
Expand Down

0 comments on commit 9010c88

Please sign in to comment.