Skip to content

Commit 068bb10

Browse files
Show interim JSON provision flow even when nothing provisioned (#633) (#636)
(cherry picked from commit a66f7e2) Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 192a9d1 commit 068bb10

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

public/pages/workflow_detail/workspace/workspace.tsx

+19-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55

66
import React, { useRef, useCallback, useEffect, useState } from 'react';
7+
import { useFormikContext } from 'formik';
8+
import { isEmpty } from 'lodash';
79
import ReactFlow, {
810
Controls,
911
useNodesState,
@@ -24,6 +26,7 @@ import {
2426
WORKFLOW_TUTORIAL_LINK,
2527
Workflow,
2628
WorkflowConfig,
29+
WorkflowFormValues,
2730
customStringify,
2831
} from '../../../../common';
2932
import {
@@ -32,7 +35,11 @@ import {
3235
WorkspaceComponent,
3336
} from './workspace_components';
3437
import { DeletableEdge } from './workspace_edge';
35-
import { uiConfigToWorkspaceFlow } from '../../../utils';
38+
import {
39+
configToTemplateFlows,
40+
formikToUiConfig,
41+
uiConfigToWorkspaceFlow,
42+
} from '../../../utils';
3643

3744
// styling
3845
import 'reactflow/dist/style.css';
@@ -60,6 +67,7 @@ enum TOGGLE_BUTTON_ID {
6067
}
6168

6269
export function Workspace(props: WorkspaceProps) {
70+
const { values } = useFormikContext<WorkflowFormValues>();
6371
// Visual/JSON toggle states
6472
const [toggleButtonSelected, setToggleButtonSelected] = useState<
6573
TOGGLE_BUTTON_ID
@@ -78,12 +86,17 @@ export function Workspace(props: WorkspaceProps) {
7886
// JSON state
7987
const [provisionTemplate, setProvisionTemplate] = useState<string>('');
8088
useEffect(() => {
81-
if (props.workflow?.workflows?.provision) {
82-
const templateAsObj = props.workflow?.workflows.provision as {};
83-
const templateAsStr = customStringify(templateAsObj);
84-
setProvisionTemplate(templateAsStr);
89+
if (!isEmpty(props.uiConfig) && !isEmpty(values)) {
90+
const templateFlows = configToTemplateFlows(
91+
formikToUiConfig(values, props.uiConfig as WorkflowConfig),
92+
true,
93+
true
94+
);
95+
if (!isEmpty(templateFlows.provision)) {
96+
setProvisionTemplate(customStringify(templateFlows.provision));
97+
}
8598
}
86-
}, [props.workflow]);
99+
}, [props.uiConfig, values]);
87100

88101
// ReactFlow state
89102
const reactFlowWrapper = useRef(null);

0 commit comments

Comments
 (0)