Skip to content

Commit 2125cee

Browse files
authored
Show 'Start task' instead of 'Start workflow' for tasks + custom colors (#2332)
* Show 'Start task' button instead of 'Start workflow' for tasks + custom button texts and colors * Adds changeset * Update pydantic-forms ui to 0.10.1
1 parent bb89d24 commit 2125cee

File tree

5 files changed

+155
-51
lines changed

5 files changed

+155
-51
lines changed

.changeset/calm-dancers-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': patch
3+
---
4+
5+
2246 Show 'Start task' button instead of 'Start workflow' for tasks + custom button texts and colors

package-lock.json

Lines changed: 85 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/orchestrator-ui-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"next-query-params": "^5.0.0",
5555
"object-hash": "^3.0.0",
5656
"prism-themes": "^1.9.0",
57-
"pydantic-forms": "^0.10.0",
57+
"pydantic-forms": "^0.10.1",
5858
"react-diff-view": "^3.2.0",
5959
"react-draggable": "^4.4.6",
6060
"react-redux": "^9.1.2",

packages/orchestrator-ui-components/src/components/WfoPydanticForm/Footer.tsx

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ import { EuiButton, EuiFlexGroup, EuiHorizontalRule } from '@elastic/eui';
1212

1313
import { ConfirmationDialogContext } from '@/contexts';
1414
import { useOrchestratorTheme } from '@/hooks';
15+
import { WfoPlayCircle } from '@/icons';
16+
import { WfoThemeExtraColors } from '@/theme';
1517

1618
import { RenderFormErrors } from './RenderFormErrors';
1719

20+
type FooterProps = PydanticFormFooterProps & {
21+
isTask?: boolean;
22+
};
23+
1824
export const Footer = ({
1925
onCancel,
2026
onPrevious,
2127
hasNext,
2228
hasPrevious,
23-
}: PydanticFormFooterProps) => {
29+
isTask = false,
30+
buttons,
31+
}: FooterProps) => {
2432
const { theme } = useOrchestratorTheme();
2533
const t = useTranslations('pydanticForms.userInputForm');
2634
const { showConfirmDialog } = useContext(ConfirmationDialogContext);
@@ -34,24 +42,37 @@ export const Footer = ({
3442
}
3543
};
3644

37-
const PreviousButton = () => (
38-
<EuiButton
39-
data-testid="button-submit-form-previous"
40-
id="button-submit-form-submit"
41-
tabIndex={0}
42-
fill
43-
onClick={() => {
44-
if (onPrevious) {
45-
onPrevious();
46-
}
47-
}}
48-
color={'primary'}
49-
iconSide="right"
50-
aria-label={t('previous')}
51-
>
52-
{t('previous')}
53-
</EuiButton>
54-
);
45+
const { next, previous } = buttons || {};
46+
47+
const PreviousButton = () => {
48+
const previousButtonColor =
49+
theme.colors[
50+
(previous?.color as keyof WfoThemeExtraColors['colors']) ??
51+
'primary'
52+
];
53+
54+
return (
55+
<EuiButton
56+
data-testid="button-submit-form-previous"
57+
id="button-submit-form-submit"
58+
tabIndex={0}
59+
fill
60+
onClick={() => {
61+
if (onPrevious) {
62+
onPrevious();
63+
}
64+
}}
65+
css={{
66+
backgroundColor: previousButtonColor,
67+
padding: '12px',
68+
}}
69+
iconSide="right"
70+
aria-label={t('previous')}
71+
>
72+
{previous?.text ?? t('previous')}
73+
</EuiButton>
74+
);
75+
};
5576

5677
const CancelButton = () => (
5778
<div
@@ -71,26 +92,45 @@ export const Footer = ({
7192
);
7293

7394
const SubmitButton = () => {
74-
const submitButtonLabel = hasNext ? t('next') : t('startWorkflow');
75-
7695
/*
7796
* The submit button is used to submit the form data.
7897
* If there is a next step, it will be labeled as "Next".
7998
* If there is no next step, it will be labeled as "Start Workflow".
99+
* If there is a label provided in the buttonNextProps, it will be used instead.
80100
* The button is styled with primary color and has an icon on the right side.
81101
* We don't use the disable property based on the form valid state here. When calculating the form valid state
82102
* react-hook-form might return a false negative - marking the form invalid - when not all fields have a defaultValue
83103
* which is a valid use case. https://chatgpt.com/share/6874ce66-35e8-800c-9434-725ff895ac44
84104
*/
105+
106+
const submitButtonTranslated = hasNext
107+
? t('next')
108+
: isTask
109+
? t('startTask')
110+
: t('startWorkflow');
111+
112+
const submitButtonLabel = next?.text ?? submitButtonTranslated;
113+
const submitIconType =
114+
!hasNext && !next?.text
115+
? () => <WfoPlayCircle color="currentColor" />
116+
: undefined;
117+
const submitButtonColor = next?.color
118+
? (next?.color as keyof WfoThemeExtraColors['colors'])
119+
: 'primary';
120+
85121
return (
86122
<EuiButton
87123
data-testid="button-submit-form-submit"
88124
id="button-submit-form-submit"
89125
tabIndex={0}
90126
fill
91-
color={'primary'}
127+
css={{
128+
backgroundColor: submitButtonColor,
129+
padding: '12px',
130+
}}
92131
type="submit"
93132
iconSide="right"
133+
iconType={submitIconType}
94134
aria-label={submitButtonLabel}
95135
>
96136
{submitButtonLabel}

packages/orchestrator-ui-components/src/components/WfoPydanticForm/WfoPydanticForm.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ export const WfoPydanticForm = ({
368368

369369
return {
370370
apiProvider: getPydanticFormProvider(),
371-
footerRenderer: Footer,
371+
footerRenderer: (props) => <Footer {...props} isTask={isTask} />,
372372
headerRenderer: Header,
373373
componentMatcherExtender: wfoComponentMatcherExtender,
374374
labelProvider: pydanticLabelProvider,
@@ -380,6 +380,7 @@ export const WfoPydanticForm = ({
380380
}, [
381381
customTranslations,
382382
getPydanticFormProvider,
383+
isTask,
383384
pydanticLabelProvider,
384385
router.locale,
385386
wfoComponentMatcherExtender,

0 commit comments

Comments
 (0)