Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(CanvasForm): Search field not showing correct fields in case of nested fields #1906

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions packages/ui/src/components/Form/CustomAutoFields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { useForm } from 'uniforms';
import { CatalogKind, KaotoSchemaDefinition } from '../../models';
import { CanvasFormTabsContext, FilteredFieldContext } from '../../providers';
import { getFieldGroups } from '../../utils';
import { getFieldGroups, getFilteredProperties, isDefined } from '../../utils';
import './CustomAutoFields.scss';
import { CustomExpandableSection } from './customField/CustomExpandableSection';
import { NoFieldFound } from './NoFieldFound';
Expand All @@ -29,16 +29,20 @@
const { filteredFieldText, isGroupExpanded } = useContext(FilteredFieldContext);
const canvasFormTabsContext = useContext(CanvasFormTabsContext);
const oneOf = (rootField as KaotoSchemaDefinition['schema']).oneOf;

const cleanQueryTerm = filteredFieldText.replace(/\s/g, '').toLowerCase();
const actualFields = (fields ?? schema.getSubfields()).filter(
(field) => !omitFields!.includes(field) && (field === 'parameters' || field.toLowerCase().includes(cleanQueryTerm)),
const schemaObject = isDefined(fields)
? fields.reduce((acc: { [name: string]: unknown }, name) => {
acc[name] = schema.getField(name);
return acc;

Check warning on line 36 in packages/ui/src/components/Form/CustomAutoFields.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Form/CustomAutoFields.tsx#L34-L36

Added lines #L34 - L36 were not covered by tests
}, {})
: (rootField as KaotoSchemaDefinition['schema']).properties;

const filteredProperties = getFilteredProperties(
schemaObject as KaotoSchemaDefinition['schema']['properties'],
cleanQueryTerm,
omitFields,
);
const actualFieldsSchema = actualFields.reduce((acc: { [name: string]: unknown }, name) => {
acc[name] = schema.getField(name);
return acc;
}, {});
const propertiesArray = getFieldGroups(actualFieldsSchema);
const propertiesArray = getFieldGroups(filteredProperties);

if (
canvasFormTabsContext?.selectedTab !== 'All' &&
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/components/Form/customField/CustomNestField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import { Card, CardBody, CardHeader, CardTitle } from '@patternfly/react-core';
import { useContext } from 'react';
import { HTMLFieldProps, connectField, filterDOMProps } from 'uniforms';
import { FilteredFieldContext } from '../../../providers';
import { getFieldGroups } from '../../../utils';
import { getFieldGroups, getFilteredProperties } from '../../../utils';
import { CustomAutoField } from '../CustomAutoField';
import { CustomExpandableSection } from './CustomExpandableSection';
import './CustomNestField.scss';
import { KaotoSchemaDefinition } from '../../../models';

export type CustomNestFieldProps = HTMLFieldProps<
object,
Expand All @@ -51,12 +52,11 @@ export const CustomNestField = connectField(
}: CustomNestFieldProps) => {
const { filteredFieldText, isGroupExpanded } = useContext(FilteredFieldContext);
const cleanQueryTerm = filteredFieldText.replace(/\s/g, '').toLowerCase();
const filteredProperties = Object.entries(props.properties ?? {}).filter((field) =>
field[0].toLowerCase().includes(cleanQueryTerm),
const filteredProperties = getFilteredProperties(
props.properties as KaotoSchemaDefinition['schema']['properties'],
cleanQueryTerm,
);
const actualProperties = Object.fromEntries(filteredProperties);
const propertiesArray = getFieldGroups(actualProperties);

const propertiesArray = getFieldGroups(filteredProperties);
if (propertiesArray.common.length === 0 && Object.keys(propertiesArray.groups).length === 0) return null;

return (
Expand Down
11 changes: 3 additions & 8 deletions packages/ui/src/components/Form/dataFormat/DataFormatEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import { CanvasNode } from '../../Visualization/Canvas/canvas.models';
import './DataFormatEditor.scss';
import { DataFormatService } from './dataformat.service';
import { TypeaheadEditor } from '../customField/TypeaheadEditor';
import {
getRequiredPropertiesSchema,
getSerializedModel,
getUserUpdatedPropertiesSchema,
isDefined,
} from '../../../utils';
import { getRequiredPropertiesSchema, getSerializedModel, getUserUpdatedProperties, isDefined } from '../../../utils';
import { FormTabsModes } from '../../Visualization/Canvas/Form/canvasformtabs.modes';

interface DataFormatEditorProps {
Expand Down Expand Up @@ -67,13 +62,13 @@ export const DataFormatEditor: FunctionComponent<DataFormatEditorProps> = (props

const processedSchema = useMemo(() => {
if (props.formMode === 'Required') {
return getRequiredPropertiesSchema(dataFormatSchema ?? {});
return getRequiredPropertiesSchema(dataFormatSchema, dataFormatSchema);
} else if (props.formMode === 'All') {
return dataFormatSchema;
} else if (props.formMode === 'Modified') {
return {
...dataFormatSchema,
properties: getUserUpdatedPropertiesSchema(dataFormatSchema?.properties ?? {}, dataFormatModel ?? {}),
properties: getUserUpdatedProperties(dataFormatSchema?.properties, dataFormatModel, dataFormatSchema),
};
}
}, [props.formMode, dataFormat]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@ import { CanvasNode } from '../../Visualization/Canvas/canvas.models';
import { LoadBalancerService } from './loadbalancer.service';
import './LoadBalancerEditor.scss';
import { TypeaheadEditor } from '../customField/TypeaheadEditor';
import {
getRequiredPropertiesSchema,
getSerializedModel,
getUserUpdatedPropertiesSchema,
isDefined,
} from '../../../utils';
import { getRequiredPropertiesSchema, getSerializedModel, getUserUpdatedProperties, isDefined } from '../../../utils';
import { FormTabsModes } from '../../Visualization/Canvas/Form/canvasformtabs.modes';

interface LoadBalancerEditorProps {
Expand Down Expand Up @@ -68,13 +63,13 @@ export const LoadBalancerEditor: FunctionComponent<LoadBalancerEditorProps> = (p

const processedSchema = useMemo(() => {
if (props.formMode === 'Required') {
return getRequiredPropertiesSchema(loadBalancerSchema ?? {});
return getRequiredPropertiesSchema(loadBalancerSchema, loadBalancerSchema);
} else if (props.formMode === 'All') {
return loadBalancerSchema;
} else if (props.formMode === 'Modified') {
return {
...loadBalancerSchema,
properties: getUserUpdatedPropertiesSchema(loadBalancerSchema?.properties ?? {}, loadBalancerModel ?? {}),
properties: getUserUpdatedProperties(loadBalancerSchema?.properties, loadBalancerModel, loadBalancerSchema),
};
}
}, [props.formMode, loadBalancer]);
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/components/Form/schema-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class SchemaBridge extends JSONSchemaBridge {
} else if (definition.$ref) {
/** Resolve $ref if needed */
Object.assign(definition, resolveRefIfNeeded(definition, this.schema));
delete definition['$ref'];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import {
} from '@patternfly/react-core';
import { FunctionComponent, useCallback, useContext, useMemo, useState } from 'react';
import { EntitiesContext } from '../../../providers';
import {
getRequiredPropertiesSchema,
getSerializedModel,
getUserUpdatedPropertiesSchema,
isDefined,
} from '../../../utils';
import { getRequiredPropertiesSchema, getSerializedModel, getUserUpdatedProperties, isDefined } from '../../../utils';
import { CanvasNode } from '../../Visualization/Canvas/canvas.models';
import { TypeaheadEditor } from '../customField/TypeaheadEditor';
import { ExpressionService } from '../expression/expression.service';
Expand Down Expand Up @@ -71,13 +66,13 @@ export const StepExpressionEditor: FunctionComponent<StepExpressionEditorProps>

const processedSchema = useMemo(() => {
if (props.formMode === 'Required') {
return getRequiredPropertiesSchema(languageSchema ?? {});
return getRequiredPropertiesSchema(languageSchema, languageSchema);
} else if (props.formMode === 'All') {
return languageSchema;
} else if (props.formMode === 'Modified') {
return {
...languageSchema,
properties: getUserUpdatedPropertiesSchema(languageSchema?.properties ?? {}, languageModel ?? {}),
properties: getUserUpdatedProperties(languageSchema?.properties, languageModel, languageSchema),
};
}
}, [props.formMode, language]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FunctionComponent, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
import { EntitiesContext } from '../../../../providers/entities.provider';
import { SchemaBridgeProvider } from '../../../../providers/schema-bridge.provider';
import { getUserUpdatedPropertiesSchema, getRequiredPropertiesSchema, isDefined, setValue } from '../../../../utils';
import { getUserUpdatedProperties, getRequiredPropertiesSchema, isDefined, setValue } from '../../../../utils';
import { CustomAutoForm, CustomAutoFormRef } from '../../../Form/CustomAutoForm';
import { DataFormatEditor } from '../../../Form/dataFormat/DataFormatEditor';
import { LoadBalancerEditor } from '../../../Form/loadBalancer/LoadBalancerEditor';
Expand Down Expand Up @@ -32,11 +32,15 @@ export const CanvasFormBody: FunctionComponent<CanvasFormTabsProps> = (props) =>
const model = visualComponentSchema?.definition;
let processedSchema = visualComponentSchema?.schema;
if (selectedTab === 'Required') {
processedSchema = getRequiredPropertiesSchema(visualComponentSchema?.schema ?? {});
processedSchema = getRequiredPropertiesSchema(visualComponentSchema?.schema, visualComponentSchema?.schema);
} else if (selectedTab === 'Modified') {
processedSchema = {
...visualComponentSchema?.schema,
properties: getUserUpdatedPropertiesSchema(visualComponentSchema?.schema.properties ?? {}, model),
properties: getUserUpdatedProperties(
visualComponentSchema?.schema.properties,
model,
visualComponentSchema?.schema,
),
};
}

Expand Down
Loading
Loading