From 3777219215e02250984f9057f5405174aa9ea1a8 Mon Sep 17 00:00:00 2001 From: Tyler Ohlsen Date: Tue, 9 Jul 2024 09:22:29 -0700 Subject: [PATCH] Add name confirmation modal Signed-off-by: Tyler Ohlsen --- .../pages/workflows/new_workflow/use_case.tsx | 108 +++++++++++++----- 1 file changed, 81 insertions(+), 27 deletions(-) diff --git a/public/pages/workflows/new_workflow/use_case.tsx b/public/pages/workflows/new_workflow/use_case.tsx index 687cf9b8..fe8b6a61 100644 --- a/public/pages/workflows/new_workflow/use_case.tsx +++ b/public/pages/workflows/new_workflow/use_case.tsx @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import React from 'react'; +import React, { useState } from 'react'; import { useHistory } from 'react-router-dom'; import { EuiText, @@ -13,6 +13,14 @@ import { EuiCard, EuiHorizontalRule, EuiButton, + EuiModal, + EuiModalHeader, + EuiModalHeaderTitle, + EuiModalBody, + EuiModalFooter, + EuiButtonEmpty, + EuiFieldText, + EuiFormRow, } from '@elastic/eui'; import { Workflow } from '../../../../common'; import { APP_PATH } from '../../../utils'; @@ -20,7 +28,6 @@ import { processWorkflowName } from './utils'; import { createWorkflow, useAppDispatch } from '../../../store'; interface UseCaseProps { - // onClick: () => {}; workflow: Workflow; } @@ -28,35 +35,50 @@ export function UseCase(props: UseCaseProps) { const dispatch = useAppDispatch(); const history = useHistory(); + // name modal state + const [isNameModalOpen, setIsNameModalOpen] = useState(false); + + // workflow name state + const [workflowName, setWorkflowName] = useState( + processWorkflowName(props.workflow.name) + ); + return ( - -

{props.workflow.name}

- - } - titleSize="s" - paddingSize="l" - layout="horizontal" - > - - - - {props.workflow.description} - - - + <> + {isNameModalOpen && ( + setIsNameModalOpen(false)}> + + +

{`Set a unique name for your workflow`}

+
+
+ + + { + setWorkflowName(e.target.value); + }} + /> + + + + setIsNameModalOpen(false)}> + Cancel + { const workflowToCreate = { ...props.workflow, - // TODO: handle duplicate name gracefully. it won't slash or produce errors, but nice-to-have - // as long as not too expensive to fetch duplicate names - name: processWorkflowName(props.workflow.name), + name: workflowName, }; - dispatch(createWorkflow(workflowToCreate)) .unwrap() .then((result) => { @@ -68,12 +90,44 @@ export function UseCase(props: UseCaseProps) { console.error(err); }); }} + fill={true} + color="primary" > Create + +
+ )} + +

{props.workflow.name}

+ + } + titleSize="s" + paddingSize="l" + layout="horizontal" + > + + + + {props.workflow.description} + + + { + setIsNameModalOpen(true); + }} + > + Go + + + -
-
+ + ); }