Skip to content

Commit bb0264e

Browse files
Georgi2704DutchBen
andauthored
WfoStepForm (#2145)
* Migrate WfoStepForm to pydantic forms, fix bug with summary field with accept field * add changeset * Fix for sumbit button * Update packages/orchestrator-ui-components/src/components/WfoWorkflowSteps/WfoStep/WfoStepFormFooter.tsx Co-authored-by: Ruben van Leeuwen <[email protected]> * Add temporary whitelist for corelink step form --------- Co-authored-by: Ruben van Leeuwen <[email protected]>
1 parent 516239f commit bb0264e

File tree

14 files changed

+281
-50
lines changed

14 files changed

+281
-50
lines changed

.changeset/twelve-times-care.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': minor
3+
---
4+
5+
Migrate WfoStepForm to pydantic forms

apps/wfo-ui

Submodule wfo-ui updated 1 file

packages/orchestrator-ui-components/src/components/WfoForms/UserInputForm.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,6 @@ export function WfoUserInputForm({
686686
</em>
687687
</section>
688688
)}
689-
690689
{renderButtons(buttons)}
691690
</AutoForm>
692691
</AutoFieldProvider>

packages/orchestrator-ui-components/src/components/WfoForms/formFields/AcceptFieldStyling.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ export const getAcceptFieldStyles = ({ theme }: WfoTheme) => {
2121
marginTop: 0,
2222
},
2323
},
24+
25+
'.labelTitle': {
26+
fontWeight: '600',
27+
color: theme.colors.text,
28+
},
2429
},
2530
});
2631

packages/orchestrator-ui-components/src/components/WfoForms/formFields/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ export * from './deprecated/FileUploadField';
2727
export * from './commonStyles';
2828
export * from './types';
2929
export * from './SummaryFieldStyling';
30+
export * from './AcceptFieldStyling';

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import type { PydanticFormElement } from 'pydantic-forms';
55

66
import { EuiFlexItem, EuiFormRow, EuiText } from '@elastic/eui';
77

8-
import { getCommonFormFieldStyles, summaryFieldStyles } from '@/components';
8+
import {
9+
getCommonFormFieldStyles,
10+
getNestedSummaryLabel,
11+
summaryFieldStyles,
12+
} from '@/components';
913
import { useWithOrchestratorTheme } from '@/hooks';
1014
import { snakeToHuman } from '@/utils';
1115

@@ -29,7 +33,11 @@ export const WfoSummary: PydanticFormElement = ({ pydanticFormField }) => {
2933

3034
const rows = columns[0].map((row, index) => (
3135
<tr key={index}>
32-
{labels && <td className={`label`}>{labels[index]}</td>}
36+
{labels && (
37+
<td className={`label`}>
38+
{getNestedSummaryLabel(labels, index)}
39+
</td>
40+
)}
3341
<td className={`value`}>
3442
{typeof row === 'string' && row.includes('<!doctype html>') ? (
3543
<div
@@ -43,7 +51,7 @@ export const WfoSummary: PydanticFormElement = ({ pydanticFormField }) => {
4351
{extraColumnsData &&
4452
extraColumnsData.map((_, idx) => (
4553
<td className={`value`} key={idx}>
46-
{extraColumnsData[idx][index]}
54+
{extraColumnsData[idx][index].toString()}
4755
</td>
4856
))}
4957
</tr>

packages/orchestrator-ui-components/src/components/WfoPydanticForm/fields/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './WfoInteger';
1111
export * from './WfoDropdown';
1212
export * from './WfoReactSelect';
1313
export * from './WfoMultiCheckboxField';
14+
export * from './wfoPydanticFormUtils';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { getNestedSummaryLabel } from '@/components';
2+
3+
describe('getNestedSummaryLabel', () => {
4+
it('returns string value as-is', () => {
5+
const labels = ['name', 'age', 'city'];
6+
expect(getNestedSummaryLabel(labels, 0)).toBe('name');
7+
expect(getNestedSummaryLabel(labels, 1)).toBe('age');
8+
expect(getNestedSummaryLabel(labels, 2)).toBe('city');
9+
});
10+
11+
it('returns capitalized first key when value is an object', () => {
12+
const labels = [{ first: 'John', last: 'Doe' }];
13+
expect(getNestedSummaryLabel(labels, 0)).toBe('First');
14+
});
15+
16+
it('handles object with multiple keys', () => {
17+
const labels = [{ last: 'Doe', first: 'John' }];
18+
// only the first key should matter
19+
expect(getNestedSummaryLabel(labels, 0)).toBe('Last');
20+
});
21+
22+
it('handles empty object', () => {
23+
const labels = [{}];
24+
expect(getNestedSummaryLabel(labels, 0)).toBe('');
25+
});
26+
27+
it('handles null and undefined values safely', () => {
28+
const labels = [null, undefined];
29+
expect(getNestedSummaryLabel(labels, 0)).toBe('null');
30+
expect(getNestedSummaryLabel(labels, 1)).toBe('undefined');
31+
});
32+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { capitalize } from 'lodash';
2+
3+
export type SummaryFormLabel =
4+
| string
5+
| null
6+
| undefined
7+
| Record<string, unknown>;
8+
9+
export const getNestedSummaryLabel = (
10+
labels: SummaryFormLabel[],
11+
index: number,
12+
): string => {
13+
const value = labels[index];
14+
if (typeof value === 'object' && value !== null) {
15+
const firstKey: string = Object.keys(value)[0] ?? '';
16+
return capitalize(firstKey);
17+
}
18+
return String(value);
19+
};

packages/orchestrator-ui-components/src/components/WfoWorkflowSteps/WfoStep/WfoStep.tsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '@elastic/eui';
1212

1313
import { WfoJsonCodeBlock, WfoTableCodeBlock } from '@/components';
14+
import { WfoStepFormOld } from '@/components/WfoWorkflowSteps/WfoStep/WfoStepFormOld';
1415
import { useOrchestratorTheme, useWithOrchestratorTheme } from '@/hooks';
1516
import { WfoChevronDown, WfoChevronUp } from '@/icons';
1617
import type { EmailState } from '@/types';
@@ -117,6 +118,11 @@ export const WfoStep = React.forwardRef(
117118
);
118119
};
119120

121+
const whitelist = ['confirm_corelink'];
122+
const isCorelinkForm = whitelist.includes(
123+
Object.keys(userInputForm?.properties ?? {})[0],
124+
);
125+
120126
return (
121127
<div ref={ref}>
122128
<EuiPanel>
@@ -209,14 +215,23 @@ export const WfoStep = React.forwardRef(
209215
)}
210216
</div>
211217
)}
212-
{step.status === StepStatus.SUSPEND && userInputForm && (
213-
<WfoStepForm
214-
userInputForm={userInputForm}
215-
isTask={isTask}
216-
processId={processId}
217-
userPermissions={userPermissions}
218-
/>
219-
)}
218+
{step.status === StepStatus.SUSPEND &&
219+
userInputForm &&
220+
(isCorelinkForm ? (
221+
<WfoStepForm
222+
userInputForm={userInputForm}
223+
isTask={isTask}
224+
processId={processId ?? ''}
225+
userPermissions={userPermissions}
226+
/>
227+
) : (
228+
<WfoStepFormOld
229+
userInputForm={userInputForm}
230+
isTask={isTask}
231+
processId={processId}
232+
userPermissions={userPermissions}
233+
/>
234+
))}
220235
</EuiPanel>
221236
</div>
222237
);

0 commit comments

Comments
 (0)