From 035588120b2b90403fcaffe4f107d3833af5d79c Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 30 Jan 2023 14:06:41 -0500 Subject: [PATCH] replace fieldTemplate with unthemed core version and remove labels since that is handled in there --- .../BaseInputTemplate/BaseInputTemplate.tsx | 1 - .../carbon/FieldTemplate/FieldTemplate.tsx | 101 ++++++++---------- .../carbon/SelectWidget/SelectWidget.tsx | 5 +- .../carbon/TextareaWidget/TextareaWidget.tsx | 2 +- 4 files changed, 50 insertions(+), 59 deletions(-) diff --git a/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx index c6f677d29..699ffeb90 100644 --- a/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx @@ -107,7 +107,6 @@ export default function BaseInputTemplate< id={id} name={id} className="input" - labelText={labelToUse} helperText={helperText} invalid={invalid} invalidText={errorMessageForField} diff --git a/spiffworkflow-frontend/src/themes/carbon/FieldTemplate/FieldTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/FieldTemplate/FieldTemplate.tsx index b105e3edf..a1cccb06b 100644 --- a/spiffworkflow-frontend/src/themes/carbon/FieldTemplate/FieldTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/FieldTemplate/FieldTemplate.tsx @@ -1,66 +1,57 @@ import React from 'react'; -import FormControl from '@mui/material/FormControl'; -import Typography from '@mui/material/Typography'; -import { FieldTemplateProps, getTemplate, getUiOptions } from '@rjsf/utils'; +import { + FieldTemplateProps, + FormContextType, + RJSFSchema, + StrictRJSFSchema, + getTemplate, + getUiOptions, +} from '@rjsf/utils'; -function FieldTemplate({ - id, - children, - classNames, - disabled, - displayLabel, - hidden, - label, - onDropPropertyClick, - onKeyChange, - readonly, - required, - rawErrors = [], - errors, - help, - rawDescription, - schema, - uiSchema, - registry, -}: FieldTemplateProps) { - const uiOptions = getUiOptions(uiSchema); - const WrapIfAdditionalTemplate = getTemplate<'WrapIfAdditionalTemplate'>( - 'WrapIfAdditionalTemplate', +import Label from './Label'; + +/** The `FieldTemplate` component is the template used by `SchemaField` to render any field. It renders the field + * content, (label, description, children, errors and help) inside of a `WrapIfAdditional` component. + * + * @param props - The `FieldTemplateProps` for this component + */ +export default function FieldTemplate< + T = any, + S extends StrictRJSFSchema = RJSFSchema, + F extends FormContextType = any +>(props: FieldTemplateProps) { + const { + id, + label, + children, + errors, + help, + description, + hidden, + required, + displayLabel, registry, - uiOptions - ); - + uiSchema, + } = props; + const uiOptions = getUiOptions(uiSchema); + const WrapIfAdditionalTemplate = getTemplate< + 'WrapIfAdditionalTemplate', + T, + S, + F + >('WrapIfAdditionalTemplate', registry, uiOptions); if (hidden) { - return
{children}
; + return
{children}
; } return (
- - - {children} - {displayLabel && rawDescription ? ( - - {rawDescription} - - ) : null} - {errors} - {help} - + + {displayLabel &&
); } - -export default FieldTemplate; diff --git a/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx b/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx index d74b9b7b2..eaae4eb61 100644 --- a/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx @@ -53,7 +53,8 @@ function SelectWidget({ let errorMessageForField = null; if (rawErrors && rawErrors.length > 0) { invalid = true; - errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`; + // errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`; + errorMessageForField = rawErrors[0]; } // maybe use placeholder somehow. it was previously jammed into the helperText field, @@ -63,7 +64,7 @@ function SelectWidget({