From 799ea492dded2c02578a72784c4f23cc0a4d1165 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 30 Jan 2023 11:53:35 -0500 Subject: [PATCH 1/7] new mechanism to handle help more in line with how carbon works --- .../carbon/BaseInputTemplate/BaseInputTemplate.tsx | 6 ++++++ .../carbon/FieldHelpTemplate/FieldHelpTemplate.tsx | 10 ++++------ .../src/themes/carbon/SelectWidget/SelectWidget.tsx | 9 ++++++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx index 7954a0ac..c6f677d2 100644 --- a/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx @@ -85,6 +85,11 @@ export default function BaseInputTemplate< labelToUse = `${labelToUse}*`; } + let helperText = null; + if (uiSchema && uiSchema['ui:help']) { + helperText = uiSchema['ui:help']; + } + let invalid = false; let errorMessageForField = null; if (rawErrors && rawErrors.length > 0) { @@ -103,6 +108,7 @@ export default function BaseInputTemplate< name={id} className="input" labelText={labelToUse} + helperText={helperText} invalid={invalid} invalidText={errorMessageForField} autoFocus={autofocus} diff --git a/spiffworkflow-frontend/src/themes/carbon/FieldHelpTemplate/FieldHelpTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/FieldHelpTemplate/FieldHelpTemplate.tsx index 08a61aeb..da4543f2 100644 --- a/spiffworkflow-frontend/src/themes/carbon/FieldHelpTemplate/FieldHelpTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/FieldHelpTemplate/FieldHelpTemplate.tsx @@ -7,10 +7,8 @@ import FormHelperText from '@mui/material/FormHelperText'; * @param props - The `FieldHelpProps` to be rendered */ export default function FieldHelpTemplate(props: FieldHelpProps) { - const { idSchema, help } = props; - if (!help) { - return null; - } - const id = `${idSchema.$id}__help`; - return {help}; + // ui:help is handled by helperText in all carbon widgets. + // see BaseInputTemplate/BaseInputTemplate.tsx and + // SelectWidget/SelectWidget.tsx + return null; } diff --git a/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx b/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx index 616b11a7..d74b9b7b 100644 --- a/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/SelectWidget/SelectWidget.tsx @@ -41,6 +41,10 @@ function SelectWidget({ } else if (schema && schema.title) { labelToUse = schema.title; } + let helperText = null; + if (uiSchema && uiSchema['ui:help']) { + helperText = uiSchema['ui:help']; + } if (required) { labelToUse = `${labelToUse}*`; } @@ -52,13 +56,16 @@ function SelectWidget({ errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`; } + // maybe use placeholder somehow. it was previously jammed into the helperText field, + // but allowing ui:help to grab that spot seems much more appropriate. + return ( 0) { invalid = true; - errorMessageForField = `${labelToUse.replace(/\*$/, '')} ${rawErrors[0]}`; + errorMessageForField = rawErrors[0]; } return ( From de607ded0f10c02b295ff5226faa7a242a54f822 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 30 Jan 2023 14:21:02 -0500 Subject: [PATCH 4/7] even textareas need to have blank labels since labels are in FieldTemplate --- .../src/themes/carbon/TextareaWidget/TextareaWidget.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spiffworkflow-frontend/src/themes/carbon/TextareaWidget/TextareaWidget.tsx b/spiffworkflow-frontend/src/themes/carbon/TextareaWidget/TextareaWidget.tsx index beb1934e..d6c8dd72 100644 --- a/spiffworkflow-frontend/src/themes/carbon/TextareaWidget/TextareaWidget.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/TextareaWidget/TextareaWidget.tsx @@ -74,7 +74,7 @@ function TextareaWidget< name={id} className="form-control" value={value || ''} - labelText={labelToUse} + labelText="" placeholder={placeholder} required={required} disabled={disabled} From b43f7b6cf5a73ae91c20a9320f5f3069adae0d06 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 30 Jan 2023 15:51:48 -0500 Subject: [PATCH 5/7] make task show wide, and make repeating form icons match site styles. w/ dfunk --- .../src/routes/TaskShow.tsx | 2 +- .../src/themes/carbon/AddButton/AddButton.tsx | 45 +++++--- .../ArrayFieldItemTemplate.tsx | 105 ++++++++++------- .../themes/carbon/IconButton/IconButton.tsx | 107 ++++++++++++------ .../src/themes/carbon/index.css | 4 + 5 files changed, 173 insertions(+), 90 deletions(-) diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index f08bf904..de7141a1 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -217,7 +217,7 @@ export default function TaskShow() { return ( - +
= ({ - uiSchema, - ...props -}) => { +// @ts-ignore +import { AddAlt } from '@carbon/icons-react'; + +import IconButton from '../IconButton/IconButton'; + +/** The `AddButton` renders a button that represent the `Add` action on a form + */ +export default function AddButton< + T = any, + S extends StrictRJSFSchema = RJSFSchema, + F extends FormContextType = any +>({ className, onClick, disabled, registry }: IconButtonProps) { return ( - - - +
+

+ +

+
); -}; - -export default AddButton; +} diff --git a/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx index cf596f98..df8896bf 100644 --- a/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx @@ -5,6 +5,11 @@ import { RJSFSchema, StrictRJSFSchema, } from '@rjsf/utils'; +import { + Grid, + Column, + // @ts-ignore +} from '@carbon/react'; /** The `ArrayFieldItemTemplate` component is the template used to render an items of an array. * @@ -33,53 +38,67 @@ export default function ArrayFieldItemTemplate< const { MoveDownButton, MoveUpButton, RemoveButton } = registry.templates.ButtonTemplates; const btnStyle: CSSProperties = { - flex: 1, - paddingLeft: 6, - paddingRight: 6, - fontWeight: 'bold', + marginBottom: '0.5em', }; + const mainColumnWidthSmall = hasToolbar ? 3 : 4; + const mainColumnWidthMedium = hasToolbar ? 6 : 8; + const mainColumnWidthLarge = hasToolbar ? 12 : 16; return (
-
{children}
- {hasToolbar && ( -
-
+ + {children} + + {hasToolbar && ( + - {(hasMoveUp || hasMoveDown) && ( - - )} - {(hasMoveUp || hasMoveDown) && ( - - )} - {hasRemove && ( - - )} -
-
- )} +
+
+
+ {(hasMoveUp || hasMoveDown) && ( + + )} +
+
+ {(hasMoveUp || hasMoveDown) && ( + + )} +
+
+ {hasRemove && ( + + )} +
+
+
+ + )} +
); } diff --git a/spiffworkflow-frontend/src/themes/carbon/IconButton/IconButton.tsx b/spiffworkflow-frontend/src/themes/carbon/IconButton/IconButton.tsx index 82559106..64eb883d 100644 --- a/spiffworkflow-frontend/src/themes/carbon/IconButton/IconButton.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/IconButton/IconButton.tsx @@ -1,55 +1,96 @@ import React from 'react'; -import IconButton, { - IconButtonProps as MuiIconButtonProps, -} from '@mui/material/IconButton'; -import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward'; -import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward'; -import RemoveIcon from '@mui/icons-material/Remove'; -import { IconButtonProps } from '@rjsf/utils'; +import { + FormContextType, + IconButtonProps, + RJSFSchema, + StrictRJSFSchema, +} from '@rjsf/utils'; -export default function MuiIconButton(props: IconButtonProps) { - const { icon, color, uiSchema, ...otherProps } = props; +// @ts-ignore +import { Add, TrashCan, ArrowUp, ArrowDown } from '@carbon/icons-react'; + +export default function IconButton< + T = any, + S extends StrictRJSFSchema = RJSFSchema, + F extends FormContextType = any +>(props: IconButtonProps) { + const { + iconType = 'default', + icon, + className, + uiSchema, + registry, + ...otherProps + } = props; + // icon string optios: plus, remove, arrow-up, arrow-down + let carbonIcon = ( +

+ Add new +

+ ); + if (icon === 'remove') { + carbonIcon = ; + } + if (icon === 'arrow-up') { + carbonIcon = ; + } + if (icon === 'arrow-down') { + carbonIcon = ; + } + + return ( + + ); +} + +export function MoveDownButton< + T = any, + S extends StrictRJSFSchema = RJSFSchema, + F extends FormContextType = any +>(props: IconButtonProps) { return ( - {icon} - - ); -} - -export function MoveDownButton(props: IconButtonProps) { - return ( - } + icon="arrow-down" /> ); } -export function MoveUpButton(props: IconButtonProps) { +export function MoveUpButton< + T = any, + S extends StrictRJSFSchema = RJSFSchema, + F extends FormContextType = any +>(props: IconButtonProps) { return ( - } + icon="arrow-up" /> ); } -export function RemoveButton(props: IconButtonProps) { - const { iconType, ...otherProps } = props; +export function RemoveButton< + T = any, + S extends StrictRJSFSchema = RJSFSchema, + F extends FormContextType = any +>(props: IconButtonProps) { return ( - - } + className="array-item-remove" + {...props} + iconType="danger" + icon="remove" /> ); } diff --git a/spiffworkflow-frontend/src/themes/carbon/index.css b/spiffworkflow-frontend/src/themes/carbon/index.css index 72cdbb84..b536e7d2 100644 --- a/spiffworkflow-frontend/src/themes/carbon/index.css +++ b/spiffworkflow-frontend/src/themes/carbon/index.css @@ -17,3 +17,7 @@ .rjsf .rjsf-field .rjsf-field { margin-bottom: 2em; } + +.array-item-toolbox { + margin-left: 2em; +} From a4e4fdbd44e614df4bd01d3731c940466ccacf2a Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 30 Jan 2023 16:43:47 -0500 Subject: [PATCH 6/7] IBM says you can't have more columns than your parents, even if you try to start another grid, with kburnett --- spiffworkflow-frontend/src/routes/TaskShow.tsx | 2 +- .../ArrayFieldItemTemplate.tsx | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index de7141a1..83e5df3f 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -217,7 +217,7 @@ export default function TaskShow() { return ( - + @@ -55,9 +55,9 @@ export default function ArrayFieldItemTemplate< {hasToolbar && (
From 797ccbad5f656efdc9ff2d3dddcf47f8d554a985 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 30 Jan 2023 16:47:20 -0500 Subject: [PATCH 7/7] remove unneeded divs --- .../ArrayFieldItemTemplate.tsx | 66 ++++++++----------- 1 file changed, 28 insertions(+), 38 deletions(-) diff --git a/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx index 1a732a1c..cf1d2e35 100644 --- a/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/ArrayFieldItemTemplate/ArrayFieldItemTemplate.tsx @@ -54,46 +54,36 @@ export default function ArrayFieldItemTemplate< {children} {hasToolbar && ( - +
-
- {(hasMoveUp || hasMoveDown) && ( - - )} -
-
- {(hasMoveUp || hasMoveDown) && ( - - )} -
-
- {hasRemove && ( - - )} -
+ {(hasMoveUp || hasMoveDown) && ( + + )} + {(hasMoveUp || hasMoveDown) && ( + + )} + {hasRemove && ( + + )}