-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): Enable 'Required' field feature in the canvas form
- Loading branch information
1 parent
410e10e
commit 2c3ddb3
Showing
7 changed files
with
72 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
packages/ui/src/components/Visualization/Canvas/canvasformtabs.modes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum FormTabsModes { | ||
ALL_FIELDS = 'All Fields', | ||
USER_MODIFIED = 'User Modified', | ||
REQUIRED_FIELDS = 'Required', | ||
ALL_FIELDS = 'All', | ||
USER_MODIFIED = 'Modified', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { KaotoSchemaDefinition } from '../models'; | ||
import { isDefined } from './is-defined'; | ||
|
||
export function getRequiredPropertiesSchema(schema: KaotoSchemaDefinition['schema']): KaotoSchemaDefinition['schema'] { | ||
const schemaProperties = schema.properties ?? {}; | ||
const requiredProperties = schema.required as string[]; | ||
|
||
if (!isDefined(schema)) return {}; | ||
|
||
if ('required' in schema) { | ||
const requiredFormSchema = Object.entries(schemaProperties).reduce( | ||
(acc, [property, definition]) => { | ||
if (definition['type'] === 'object' && 'properties' in definition) { | ||
const subSchema = getRequiredPropertiesSchema(definition); | ||
acc[property] = subSchema; | ||
} else { | ||
if (requiredProperties.indexOf(property) > -1) acc[property] = definition; | ||
} | ||
|
||
return acc; | ||
}, | ||
{} as KaotoSchemaDefinition['schema'], | ||
); | ||
return { ...schema, properties: requiredFormSchema }; | ||
} | ||
|
||
return {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters