-
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): Add property filtering and grouping
- Loading branch information
Showing
10 changed files
with
312 additions
and
44 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
1 change: 0 additions & 1 deletion
1
packages/ui/src/components/Visualization/Canvas/FormV2/fields/EnumField.tsx
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
57 changes: 57 additions & 0 deletions
57
.../ui/src/components/Visualization/Canvas/FormV2/fields/ObjectField/ObjectFieldGrouping.tsx
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,57 @@ | ||
import { FormFieldGroupExpandable, FormFieldGroupHeader } from '@patternfly/react-core'; | ||
import { FunctionComponent, useContext, useMemo } from 'react'; | ||
import { FilteredFieldContext } from '../../../../../../providers'; | ||
import { getFieldGroupsV2, getFilteredProperties, isDefined } from '../../../../../../utils'; | ||
import { capitalizeString } from '../../../../../../utils/capitalize-string'; | ||
import { SchemaContext, SchemaProvider } from '../../providers/SchemaProvider'; | ||
import { FieldProps } from '../../typings'; | ||
import { AnyOfField } from '../AnyOfField'; | ||
import { ObjectFieldInner } from './ObjectFieldInner'; | ||
|
||
const SPACE_REGEX = /\s/g; | ||
|
||
export const ObjectFieldGrouping: FunctionComponent<FieldProps> = ({ propName }) => { | ||
const { schema } = useContext(SchemaContext); | ||
if (!isDefined(schema)) { | ||
throw new Error(`ObjectFieldGrouping: schema is not defined for ${propName}`); | ||
} | ||
|
||
const { filteredFieldText } = useContext(FilteredFieldContext); | ||
|
||
const groupedProperties = useMemo(() => { | ||
const cleanQueryTerm = filteredFieldText.replace(SPACE_REGEX, '').toLowerCase(); | ||
const filteredProperties = getFilteredProperties(schema.properties, cleanQueryTerm); | ||
return getFieldGroupsV2(filteredProperties); | ||
}, [filteredFieldText, schema.properties]); | ||
|
||
const requiredProperties = Array.isArray(schema.required) ? schema.required : []; | ||
|
||
return ( | ||
<> | ||
{/* Common properties */} | ||
<SchemaProvider schema={{ properties: groupedProperties.common }}> | ||
<ObjectFieldInner propName={propName} requiredProperties={requiredProperties} /> | ||
</SchemaProvider> | ||
|
||
{/* AnyOf field */} | ||
{Array.isArray(schema.anyOf) && <AnyOfField propName={propName} anyOf={schema.anyOf} />} | ||
|
||
{/* Grouped properties */} | ||
{groupedProperties.groups.map(([groupName, groupProperties]) => { | ||
const name = capitalizeString(groupName); | ||
|
||
return ( | ||
<FormFieldGroupExpandable | ||
key={`${name}-section-toggle`} | ||
toggleAriaLabel={`Toggle ${name} group`} | ||
header={<FormFieldGroupHeader titleText={{ text: name, id: `${propName}-${name}` }} />} | ||
> | ||
<SchemaProvider schema={{ properties: groupProperties }}> | ||
<ObjectFieldInner propName={propName} requiredProperties={requiredProperties} /> | ||
</SchemaProvider> | ||
</FormFieldGroupExpandable> | ||
); | ||
})} | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.