From 314ea7f173dffc2564dd3214b99c45888b605900 Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Tue, 14 Jan 2025 15:44:54 +0530 Subject: [PATCH] Fix(CanvasForm): Fix commit --- .../ui/src/components/Form/CustomAutoFields.tsx | 2 +- .../Form/customField/CustomNestField.tsx | 2 +- packages/ui/src/utils/get-field-groups.ts | 5 ++++- packages/ui/src/utils/get-filtered-properties.ts | 14 +++++++------- .../ui/src/utils/get-required-properties-schema.ts | 4 ++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/ui/src/components/Form/CustomAutoFields.tsx b/packages/ui/src/components/Form/CustomAutoFields.tsx index 7165e6cc7..3559f9e7f 100644 --- a/packages/ui/src/components/Form/CustomAutoFields.tsx +++ b/packages/ui/src/components/Form/CustomAutoFields.tsx @@ -42,7 +42,7 @@ export function CustomAutoFields({ cleanQueryTerm, omitFields, ); - const propertiesArray = getFieldGroups(filteredProperties!); + const propertiesArray = getFieldGroups(filteredProperties); if ( canvasFormTabsContext?.selectedTab !== 'All' && diff --git a/packages/ui/src/components/Form/customField/CustomNestField.tsx b/packages/ui/src/components/Form/customField/CustomNestField.tsx index 3e2c30ad3..bafc16a31 100644 --- a/packages/ui/src/components/Form/customField/CustomNestField.tsx +++ b/packages/ui/src/components/Form/customField/CustomNestField.tsx @@ -56,7 +56,7 @@ export const CustomNestField = connectField( props.properties as KaotoSchemaDefinition['schema']['properties'], cleanQueryTerm, ); - const propertiesArray = getFieldGroups(filteredProperties!); + const propertiesArray = getFieldGroups(filteredProperties); if (propertiesArray.common.length === 0 && Object.keys(propertiesArray.groups).length === 0) return null; return ( diff --git a/packages/ui/src/utils/get-field-groups.ts b/packages/ui/src/utils/get-field-groups.ts index c4b2f470c..1e58d9001 100644 --- a/packages/ui/src/utils/get-field-groups.ts +++ b/packages/ui/src/utils/get-field-groups.ts @@ -1,6 +1,9 @@ import { getValue } from './get-value'; +import { isDefined } from './is-defined'; + +export const getFieldGroups = (fields?: { [name: string]: unknown }) => { + if (!isDefined(fields)) return { common: [], groups: {} }; -export const getFieldGroups = (fields: { [name: string]: unknown }) => { const propertiesArray = Object.entries(fields).reduce( (acc, [name, definition]) => { const group: string = getValue(definition, 'group', ''); diff --git a/packages/ui/src/utils/get-filtered-properties.ts b/packages/ui/src/utils/get-filtered-properties.ts index 327a61aec..43a9547e1 100644 --- a/packages/ui/src/utils/get-filtered-properties.ts +++ b/packages/ui/src/utils/get-filtered-properties.ts @@ -13,13 +13,13 @@ export function getFilteredProperties( const filteredFormSchema = Object.entries(properties).reduce( (acc, [property, definition]) => { - if (definition['type'] === 'object' && 'properties' in definition) { - const subFilteredSchema = getFilteredProperties(definition['properties'], filter); - if (Object.keys(subFilteredSchema!).length > 0) { - acc![property] = { ...definition, properties: subFilteredSchema }; - } - } else { - if ((!omitFields || !omitFields.includes(property)) && property.toLowerCase().includes(filter)) { + if (!omitFields?.includes(property)) { + if (definition['type'] === 'object' && 'properties' in definition) { + const subFilteredSchema = getFilteredProperties(definition['properties'], filter); + if (Object.keys(subFilteredSchema!).length > 0) { + acc![property] = { ...definition, properties: subFilteredSchema }; + } + } else if (property.toLowerCase().includes(filter)) { acc![property] = definition; } } diff --git a/packages/ui/src/utils/get-required-properties-schema.ts b/packages/ui/src/utils/get-required-properties-schema.ts index bf11233b5..1c61c839c 100644 --- a/packages/ui/src/utils/get-required-properties-schema.ts +++ b/packages/ui/src/utils/get-required-properties-schema.ts @@ -32,8 +32,8 @@ export function getRequiredPropertiesSchema( if (Object.keys(subSchema.properties as object).length > 0) { acc[property] = subSchema; } - } else { - if (isDefined(requiredProperties) && requiredProperties.indexOf(property) > -1) acc[property] = definition; + } else if (isDefined(requiredProperties) && requiredProperties.indexOf(property) > -1) { + acc[property] = definition; } return acc;