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

Initial refactoring of workflow editor page #149

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
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
13 changes: 3 additions & 10 deletions public/pages/workflow_detail/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
} from '../../../../common';

interface WorkflowDetailHeaderProps {
tabs: any[];
isNewWorkflow: boolean;
workflow?: Workflow;
}
Expand Down Expand Up @@ -51,17 +50,11 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
</EuiFlexGroup>
}
rightSideItems={[
// TODO: finalize if this is needed
<EuiButton
fill={false}
color="danger"
style={{ marginTop: '8px' }}
onClick={() => {}}
>
Delete
// TODO: implement export functionality
<EuiButton fill={false} style={{ marginTop: '8px' }} onClick={() => {}}>
Export
</EuiButton>,
]}
tabs={props.tabs}
bottomBorder={true}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import { Form, Formik, FormikProps } from 'formik';
import * as yup from 'yup';
import { cloneDeep } from 'lodash';
import {
EuiButton,
EuiCallOut,
EuiFlexGroup,
EuiFlexItem,
EuiPageHeader,
EuiResizableContainer,
} from '@elastic/eui';
import { getCore } from '../../../services';
import { getCore } from '../../services';

import {
Workflow,
Expand All @@ -29,39 +27,28 @@ import {
WorkspaceFlowState,
WORKFLOW_STATE,
ReactFlowEdge,
} from '../../../../common';
} from '../../../common';
import {
componentDataToFormik,
getComponentSchema,
processNodes,
reduceToTemplate,
APP_PATH,
} from '../../../utils';
import { validateWorkspaceFlow, toTemplateFlows } from '../utils';
import {
AppState,
createWorkflow,
deprovisionWorkflow,
getWorkflowState,
provisionWorkflow,
removeDirty,
setDirty,
updateWorkflow,
useAppDispatch,
} from '../../../store';
import { Workspace } from './workspace';
import { ComponentDetails } from '../component_details';
} from '../../utils';
import { validateWorkspaceFlow, toTemplateFlows } from './utils';
import { AppState, setDirty, useAppDispatch } from '../../store';
import { Workspace } from './workspace/workspace';

// styling
import './workspace-styles.scss';
import '../../../global-styles.scss';
import './workspace/workspace-styles.scss';
import '../../global-styles.scss';
import { WorkflowInputs } from './workflow_inputs';

interface ResizableWorkspaceProps {
isNewWorkflow: boolean;
workflow?: Workflow;
}

const COMPONENT_DETAILS_PANEL_ID = 'component_details_panel_id';
const WORKFLOW_INPUTS_PANEL_ID = 'workflow_inputs_panel_id';

/**
* The overall workspace component that maintains state related to the 2 resizable
Expand Down Expand Up @@ -337,114 +324,6 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
deprovisioned.
</EuiCallOut>
)}
<EuiPageHeader
style={{ marginBottom: '8px' }}
rightSideItems={[
<EuiButton
fill={false}
disabled={!isDeprovisionable || isLoadingGlobal}
isLoading={isDeprovisioning}
onClick={() => {
if (workflow?.id) {
setIsDeprovisioning(true);
dispatch(deprovisionWorkflow(workflow.id))
.unwrap()
.then(async (result) => {
await new Promise((f) => setTimeout(f, 3000));
dispatch(getWorkflowState(workflow.id as string));
setIsDeprovisioning(false);
})
.catch((error: any) => {
setIsDeprovisioning(false);
});
} else {
// This case should not happen
console.debug(
'Deprovisioning triggered on an invalid workflow. Ignoring.'
);
}
}}
>
Deprovision
</EuiButton>,
<EuiButton
fill={false}
disabled={!isProvisionable || isLoadingGlobal}
isLoading={isProvisioning}
onClick={() => {
if (workflow?.id) {
setIsProvisioning(true);
dispatch(provisionWorkflow(workflow.id))
.unwrap()
.then(async (result) => {
await new Promise((f) => setTimeout(f, 3000));
dispatch(getWorkflowState(workflow.id as string));
setIsProvisioning(false);
})
.catch((error: any) => {
setIsProvisioning(false);
});
} else {
// This case should not happen
console.debug(
'Provisioning triggered on an invalid workflow. Ignoring.'
);
}
}}
>
Provision
</EuiButton>,
<EuiButton
fill={false}
disabled={!isSaveable || isLoadingGlobal || isDeprovisionable}
isLoading={isSaving}
onClick={() => {
setIsSaving(true);
dispatch(removeDirty());
if (isFirstSave) {
setIsFirstSave(false);
}
validateFormAndFlow(
formikProps,
// The callback fn to run if everything is valid.
(updatedWorkflow) => {
if (updatedWorkflow.id) {
dispatch(
updateWorkflow({
workflowId: updatedWorkflow.id,
workflowTemplate: reduceToTemplate(updatedWorkflow),
})
)
.unwrap()
.then((result) => {
setIsSaving(false);
})
.catch((error: any) => {
setIsSaving(false);
});
} else {
dispatch(createWorkflow(updatedWorkflow))
.unwrap()
.then((result) => {
const { workflow } = result;
history.replace(
`${APP_PATH.WORKFLOWS}/${workflow.id}`
);
history.go(0);
})
.catch((error: any) => {
setIsSaving(false);
});
}
}
);
}}
>
{props.isNewWorkflow || isCreating ? 'Create' : 'Save'}
</EuiButton>,
]}
bottomBorder={false}
/>
<EuiResizableContainer
direction="horizontal"
className="stretch-absolute"
Expand All @@ -461,48 +340,43 @@ export function ResizableWorkspace(props: ResizableWorkspaceProps) {
return (
<>
<EuiResizablePanel
mode="main"
initialSize={80}
minSize="50%"
id={WORKFLOW_INPUTS_PANEL_ID}
mode="collapsible"
initialSize={50}
minSize="25%"
paddingSize="s"
onToggleCollapsedInternal={() => onToggleChange()}
>
<EuiFlexGroup
direction="column"
gutterSize="s"
className="workspace-panel"
>
<EuiFlexItem>
<Workspace
id="ingest"
workflow={workflow}
readonly={false}
onNodesChange={onNodesChange}
onSelectionChange={onSelectionChange}
/>
<WorkflowInputs workflow={props.workflow} />
</EuiFlexItem>
</EuiFlexGroup>
</EuiResizablePanel>
<EuiResizableButton />
<EuiResizablePanel
style={{ marginRight: '-16px' }}
id={COMPONENT_DETAILS_PANEL_ID}
mode="collapsible"
initialSize={25}
minSize="10%"
mode="main"
initialSize={60}
minSize="25%"
paddingSize="s"
onToggleCollapsedInternal={() => onToggleChange()}
>
<EuiFlexGroup
direction="column"
gutterSize="s"
className="workspace-panel"
>
<EuiFlexItem>
<ComponentDetails
workflow={props.workflow}
selectedComponent={selectedComponent}
isDeprovisionable={isDeprovisionable}
onFormChange={onFormChange}
<Workspace
id="ingest"
workflow={workflow}
readonly={false}
onNodesChange={onNodesChange}
onSelectionChange={onSelectionChange}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Loading
Loading