Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport main] Show interim JSON provision flow even if provisioned #636

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions public/pages/workflow_detail/workspace/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/

import React, { useRef, useCallback, useEffect, useState } from 'react';
import { useFormikContext } from 'formik';
import { isEmpty } from 'lodash';
import ReactFlow, {
Controls,
useNodesState,
Expand All @@ -24,6 +26,7 @@ import {
WORKFLOW_TUTORIAL_LINK,
Workflow,
WorkflowConfig,
WorkflowFormValues,
customStringify,
} from '../../../../common';
import {
Expand All @@ -32,7 +35,11 @@ import {
WorkspaceComponent,
} from './workspace_components';
import { DeletableEdge } from './workspace_edge';
import { uiConfigToWorkspaceFlow } from '../../../utils';
import {
configToTemplateFlows,
formikToUiConfig,
uiConfigToWorkspaceFlow,
} from '../../../utils';

// styling
import 'reactflow/dist/style.css';
Expand Down Expand Up @@ -60,6 +67,7 @@ enum TOGGLE_BUTTON_ID {
}

export function Workspace(props: WorkspaceProps) {
const { values } = useFormikContext<WorkflowFormValues>();
// Visual/JSON toggle states
const [toggleButtonSelected, setToggleButtonSelected] = useState<
TOGGLE_BUTTON_ID
Expand All @@ -78,12 +86,17 @@ export function Workspace(props: WorkspaceProps) {
// JSON state
const [provisionTemplate, setProvisionTemplate] = useState<string>('');
useEffect(() => {
if (props.workflow?.workflows?.provision) {
const templateAsObj = props.workflow?.workflows.provision as {};
const templateAsStr = customStringify(templateAsObj);
setProvisionTemplate(templateAsStr);
if (!isEmpty(props.uiConfig) && !isEmpty(values)) {
const templateFlows = configToTemplateFlows(
formikToUiConfig(values, props.uiConfig as WorkflowConfig),
true,
true
);
if (!isEmpty(templateFlows.provision)) {
setProvisionTemplate(customStringify(templateFlows.provision));
}
}
}, [props.workflow]);
}, [props.uiConfig, values]);

// ReactFlow state
const reactFlowWrapper = useRef(null);
Expand Down
Loading