-
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
298 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
56 changes: 56 additions & 0 deletions
56
.../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,56 @@ | ||
import { FormFieldGroupExpandable, FormFieldGroupHeader } from '@patternfly/react-core'; | ||
import { FunctionComponent, useContext } from 'react'; | ||
import { FilteredFieldContext } from '../../../../../../providers'; | ||
import { getFieldGroupsV2, getFilteredProperties, isDefined } from '../../../../../../utils'; | ||
import { SchemaContext, SchemaProvider } from '../../providers/SchemaProvider'; | ||
import { FieldProps } from '../../typings'; | ||
import { AnyOfField } from '../AnyOfField'; | ||
import { ObjectFieldInner } from './ObjectFieldInner'; | ||
import { capitalizeString } from '../../../../../../utils/capitalize-string'; | ||
|
||
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 cleanQueryTerm = filteredFieldText.replace(SPACE_REGEX, '').toLowerCase(); | ||
const filteredProperties = getFilteredProperties(schema.properties, cleanQueryTerm); | ||
const groupedProperties = getFieldGroupsV2(filteredProperties); | ||
|
||
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 */} | ||
{Object.entries(groupedProperties.groups) | ||
.sort((a, b) => (a[0] === 'advanced' ? 1 : b[0] === 'advanced' ? -1 : 0)) | ||
.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.