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
[release-4.5] Bug 1861433: Show descriptions for all dynamic form fields #6136
[release-4.5] Bug 1861433: Show descriptions for all dynamic form fields #6136
Conversation
Manual cherry pick of openshift#6054
@TheRealJon: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh |
@TheRealJon: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@TheRealJon Were there just a few small merge conflicts or did you have to rewrite this for 4.5? Can you point me to where the changes from 4.6 are? |
There were not many conflicts. The high line count for changes came from moving some components around mainly. I'll leave some comments where the main changes were made. |
import * as _ from 'lodash'; | ||
import * as classnames from 'classnames'; | ||
import * as React from 'react'; | ||
import { FieldProps } from 'react-jsonschema-form'; | ||
import { JSONSchema6 } from 'json-schema'; | ||
import { getUiOptions } from 'react-jsonschema-form/lib/utils'; | ||
import { FieldProps, UiSchema } from 'react-jsonschema-form'; | ||
import SchemaField, { | ||
SchemaFieldProps, | ||
} from 'react-jsonschema-form/lib/components/fields/SchemaField'; | ||
import { LinkifyExternal, SelectorInput, Dropdown } from '@console/internal/components/utils'; | ||
import { AccordionContent, AccordionItem, AccordionToggle, Switch } from '@patternfly/react-core'; | ||
import { MatchExpressions } from '@console/operator-lifecycle-manager/src/components/descriptors/spec/match-expressions'; | ||
import { ResourceRequirements } from '@console/operator-lifecycle-manager/src/components/descriptors/spec/resource-requirements'; | ||
import { FieldSet, FormField } from './templates'; | ||
import { ConfigureUpdateStrategy } from '@console/internal/components/modals/configure-update-strategy-modal'; | ||
import { | ||
ConfigureUpdateStrategy, | ||
UPDATE_STRATEGY_DESCRIPTION, | ||
} from '@console/internal/components/modals/configure-update-strategy-modal'; | ||
import { | ||
NodeAffinity, | ||
PodAffinity, | ||
} from '@console/operator-lifecycle-manager/src/components/descriptors/spec/affinity'; | ||
import { MatchExpressions } from '@console/operator-lifecycle-manager/src/components/descriptors/spec/match-expressions'; | ||
import { getUiOptions } from 'react-jsonschema-form/lib/utils'; | ||
import { Switch } from '@patternfly/react-core'; | ||
import SchemaField, { | ||
SchemaFieldProps, | ||
} from 'react-jsonschema-form/lib/components/fields/SchemaField'; | ||
import { getSchemaErrors } from './utils'; | ||
import { getSchemaErrors, useSchemaDescription, useSchemaLabel } from './utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost all of this was from moving components around and adjusting types.
|
||
export const DescriptionField: React.FC<FieldProps> = ({ id, description }) => | ||
const Description = ({ id, description }) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulled this out so that it can be used in components that don't have all FieldProps
.
<Description id={id} description={description} /> | ||
); | ||
|
||
export const FormField: React.FC<FormFieldProps> = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved FormField
component from templates file and use instead of FieldWrapper
component since these two were very similar components. Moving it here was mostly to prevent dependency cycles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also refined the props for this component so that it's more easily reused between field and template components.
</dd> | ||
</dl> | ||
</FieldSet> | ||
export const FieldSet: React.FC<FieldSetProps> = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move FieldSet
component from templates file to prevent dependency cycle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as FormField
component. Refined props so that they are more easily reused or calculated in field or template components.
); | ||
}; | ||
|
||
export const UpdateStrategyField: React.FC<FieldProps> = (props) => { | ||
const { formData = {}, idSchema, onChange } = props; | ||
export const ResourceRequirementsField: React.FC<FieldProps> = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just got pushed down because of the other components that were added at the top of the file. The rest of the changes in this file were mostly just getting rid of the spread operator where FieldSet
is used and making better use of the null coalescence operator.
<FieldSet | ||
defaultLabel={title} | ||
idSchema={idSchema} | ||
required={required} | ||
schema={schema} | ||
uiSchema={uiSchema} | ||
> | ||
<div className="co-dynamic-form__field-group-content"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New props for FieldSet
and getting rid of spread operator
return ( | ||
<FieldSet {...props}> | ||
{_.map(items, (item) => { | ||
<FieldSet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New props for FieldSet
import * as classnames from 'classnames'; | ||
import * as React from 'react'; | ||
import { | ||
ArrayFieldTemplateProps, | ||
FieldTemplateProps, | ||
ObjectFieldTemplateProps, | ||
FieldProps, | ||
} from 'react-jsonschema-form'; | ||
import { | ||
AccordionItem, | ||
AccordionToggle, | ||
AccordionContent, | ||
Button, | ||
Alert, | ||
} from '@patternfly/react-core'; | ||
import { Button, Alert, FormHelperText } from '@patternfly/react-core'; | ||
import { MinusCircleIcon, PlusCircleIcon } from '@patternfly/react-icons'; | ||
import { JSON_SCHEMA_GROUP_TYPES } from './const'; | ||
import { getUiOptions, getSchemaType } from 'react-jsonschema-form/lib/utils'; | ||
import { ExpandCollapse } from '@console/internal/components/utils'; | ||
|
||
export const FieldLabel: React.FC<FieldLabelProps> = ({ htmlFor, label, required }) => ( | ||
<label className={classnames('form-label', { 'co-required': required })} htmlFor={htmlFor}> | ||
{label} | ||
</label> | ||
); | ||
|
||
export const FormField: React.FC<FormFieldProps> = ({ | ||
children, | ||
displayTitle = true, | ||
id, | ||
required, | ||
title, | ||
}) => { | ||
return ( | ||
<div id={`${id}_field`} className="form-group"> | ||
{displayTitle && <FieldLabel label={title || 'Value'} required={required} htmlFor={id} />} | ||
{children} | ||
</div> | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just from moving FieldSet
and FormField
components to the fields.tsx
file.
export const FieldSet: React.FC<FieldSetProps> = ({ | ||
children, | ||
idSchema, | ||
name, | ||
required = false, | ||
schema, | ||
title, | ||
uiSchema = {}, | ||
}) => { | ||
const [expanded, setExpanded] = React.useState(false); | ||
const options = getUiOptions(uiSchema); | ||
const { label: showLabel = true } = options; | ||
const displayName = (options?.title as string) ?? schema?.title ?? title ?? name; | ||
const onToggle = (e) => { | ||
e.preventDefault(); | ||
setExpanded((current) => !current); | ||
}; | ||
return showLabel && displayName ? ( | ||
<div id={`${idSchema.$id}_field-group`} className="co-dynamic-form__field-group"> | ||
<AccordionItem> | ||
<AccordionToggle | ||
id={`${idSchema.$id}_accordion-toggle`} | ||
onClick={onToggle} | ||
isExpanded={expanded} | ||
> | ||
<label | ||
className={classnames({ 'co-required': required })} | ||
htmlFor={`${idSchema.$id}_accordion-content`} | ||
> | ||
{_.startCase(displayName)} | ||
</label> | ||
</AccordionToggle> | ||
<AccordionContent id={`${idSchema.$id}_accordion-content`} isHidden={!expanded}> | ||
{children} | ||
</AccordionContent> | ||
</AccordionItem> | ||
</div> | ||
) : ( | ||
<>{children}</> | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to fields.tsx
const { showDescription = true } = props; | ||
return ( | ||
<> | ||
<div className="co-m-form-row"> | ||
<p>How should the pods be replaced when a new revision is created?</p> | ||
</div> | ||
|
||
{showDescription && ( | ||
<div className="co-m-form-row"> | ||
<p>{UPDATE_STRATEGY_DESCRIPTION}</p> | ||
</div> | ||
)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed to override default description when one is provided through a descriptor or schema property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: spadgett, TheRealJon The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/bugzilla refresh Recalculating validity in case the underlying Bugzilla bug has changed. |
@openshift-bot: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh Recalculating validity in case the underlying Bugzilla bug has changed. |
@openshift-bot: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh |
@TheRealJon: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh Recalculating validity in case the underlying Bugzilla bug has changed. |
@openshift-bot: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh Recalculating validity in case the underlying Bugzilla bug has changed. |
@openshift-bot: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh Recalculating validity in case the underlying Bugzilla bug has changed. |
@openshift-bot: This pull request references Bugzilla bug 1861433, which is invalid:
Comment In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/bugzilla refresh |
@TheRealJon: This pull request references Bugzilla bug 1861433, which is valid. The bug has been moved to the POST state. 6 validation(s) were run on this bug
In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
@TheRealJon: All pull requests linked via external trackers have merged: openshift/console#6136. Bugzilla bug 1861433 has been moved to the MODIFIED state. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Manual cherry pick of #6054