diff --git a/ui/src/app/workflows/components/resubmit-workflow-panel.tsx b/ui/src/app/workflows/components/resubmit-workflow-panel.tsx index e6604f467bb6..a23476de06b1 100644 --- a/ui/src/app/workflows/components/resubmit-workflow-panel.tsx +++ b/ui/src/app/workflows/components/resubmit-workflow-panel.tsx @@ -1,5 +1,5 @@ import {Checkbox} from 'argo-ui'; -import * as React from 'react'; +import React, {useState} from 'react'; import {Parameter, ResubmitOpts, Workflow} from '../../../models'; import {uiUrl} from '../../shared/base'; import {ErrorNotice} from '../../shared/components/error-notice'; @@ -12,103 +12,82 @@ interface Props { isArchived: boolean; } -interface State { - overrideParameters: boolean; - workflowParameters: Parameter[]; - memoized: boolean; - error?: Error; - isSubmitting: boolean; -} +export function ResubmitWorkflowPanel(props: Props) { + const [overrideParameters, setOverrideParameters] = useState(false); + const [workflowParameters, setWorkflowParameters] = useState(JSON.parse(JSON.stringify(props.workflow.spec.arguments.parameters || []))); + const [memoized, setMemoized] = useState(false); + const [error, setError] = useState(); + const [isSubmitting, setIsSubmitting] = useState(false); -export class ResubmitWorkflowPanel extends React.Component { - constructor(props: any) { - super(props); - const state: State = { - workflowParameters: JSON.parse(JSON.stringify(this.props.workflow.spec.arguments.parameters || [])), - memoized: false, - isSubmitting: false, - overrideParameters: false + async function submit() { + setIsSubmitting(true); + const parameters: ResubmitOpts['parameters'] = overrideParameters + ? [...workflowParameters.filter(p => Utils.getValueFromParameter(p) !== undefined).map(p => p.name + '=' + Utils.getValueFromParameter(p))] + : []; + const opts: ResubmitOpts = { + parameters, + memoized }; - this.state = state; + + try { + const submitted = props.isArchived + ? await services.workflows.resubmitArchived(props.workflow.metadata.uid, props.workflow.metadata.namespace, opts) + : await services.workflows.resubmit(props.workflow.metadata.name, props.workflow.metadata.namespace, opts); + document.location.href = uiUrl(`workflows/${submitted.metadata.namespace}/${submitted.metadata.name}`); + } catch (err) { + setError(err); + setIsSubmitting(false); + } } - public render() { - return ( - <> -

Resubmit Workflow

-
- {this.props.workflow.metadata.namespace}/{this.props.workflow.metadata.name} -
- {this.state.error && } -
-
- -
- this.setState({overrideParameters})} /> -
+ return ( + <> +

Resubmit Workflow

+
+ {props.workflow.metadata.namespace}/{props.workflow.metadata.name} +
+ {error && } +
+
+ +
+
+
- {this.state.overrideParameters && ( -
- - {this.state.workflowParameters.length > 0 && ( - this.setState({workflowParameters})} /> - )} - {this.state.workflowParameters.length === 0 ? ( - <> -
- - - ) : ( - <> - )} -
- )} - -
- -
- this.setState({memoized})} /> -
+ {overrideParameters && ( +
+ + {workflowParameters.length > 0 && } + {workflowParameters.length === 0 && ( + <> +
+ + + )}
+ )} - {this.state.overrideParameters && this.state.memoized && ( -
- - Overriding parameters on memoized submitted workflows may have unexpected results. -
- )} - -
- +
+ +
+
- - ); - } - private submit() { - this.setState({isSubmitting: true}); - const parameters: ResubmitOpts['parameters'] = this.state.overrideParameters - ? [...this.state.workflowParameters.filter(p => Utils.getValueFromParameter(p) !== undefined).map(p => p.name + '=' + Utils.getValueFromParameter(p))] - : []; - const opts: ResubmitOpts = { - parameters, - memoized: this.state.memoized - }; + {overrideParameters && memoized && ( +
+ + Overriding parameters on memoized submitted workflows may have unexpected results. +
+ )} - if (!this.props.isArchived) { - services.workflows - .resubmit(this.props.workflow.metadata.name, this.props.workflow.metadata.namespace, opts) - .then((submitted: Workflow) => (document.location.href = uiUrl(`workflows/${submitted.metadata.namespace}/${submitted.metadata.name}`))) - .catch(error => this.setState({error, isSubmitting: false})); - } else { - services.workflows - .resubmitArchived(this.props.workflow.metadata.uid, this.props.workflow.metadata.namespace, opts) - .then((submitted: Workflow) => (document.location.href = uiUrl(`workflows/${submitted.metadata.namespace}/${submitted.metadata.name}`))) - .catch(error => this.setState({error, isSubmitting: false})); - } - } +
+ +
+
+ + ); } diff --git a/ui/src/app/workflows/components/retry-workflow-panel.tsx b/ui/src/app/workflows/components/retry-workflow-panel.tsx index 678088075a74..fe71c59bf3bc 100644 --- a/ui/src/app/workflows/components/retry-workflow-panel.tsx +++ b/ui/src/app/workflows/components/retry-workflow-panel.tsx @@ -1,5 +1,5 @@ import {Checkbox} from 'argo-ui'; -import * as React from 'react'; +import React, {useState} from 'react'; import {Parameter, RetryOpts, Workflow} from '../../../models'; import {uiUrl} from '../../shared/base'; import {ErrorNotice} from '../../shared/components/error-notice'; @@ -12,112 +12,94 @@ interface Props { isArchived: boolean; } -interface State { - overrideParameters: boolean; - restartSuccessful: boolean; - workflowParameters: Parameter[]; - nodeFieldSelector: string; - error?: Error; - isSubmitting: boolean; -} +export function RetryWorkflowPanel(props: Props) { + const [overrideParameters, setOverrideParameters] = useState(false); + const [restartSuccessful, setRestartSuccessful] = useState(false); + const [workflowParameters, setWorkflowParameters] = useState(JSON.parse(JSON.stringify(props.workflow.spec.arguments.parameters || []))); + const [nodeFieldSelector, setNodeFieldSelector] = useState(''); + const [error, setError] = useState(); + const [isSubmitting, setIsSubmitting] = useState(false); -export class RetryWorkflowPanel extends React.Component { - constructor(props: any) { - super(props); - const state: State = { - workflowParameters: JSON.parse(JSON.stringify(this.props.workflow.spec.arguments.parameters || [])), - isSubmitting: false, - overrideParameters: false, - nodeFieldSelector: '', - restartSuccessful: false + async function submit() { + setIsSubmitting(true); + const parameters: RetryOpts['parameters'] = overrideParameters + ? [...workflowParameters.filter(p => Utils.getValueFromParameter(p) !== undefined).map(p => p.name + '=' + Utils.getValueFromParameter(p))] + : []; + const opts: RetryOpts = { + parameters, + restartSuccessful, + nodeFieldSelector }; - this.state = state; + + try { + const submitted = props.isArchived + ? await services.workflows.retryArchived(props.workflow.metadata.uid, props.workflow.metadata.namespace, opts) + : await services.workflows.retry(props.workflow.metadata.name, props.workflow.metadata.namespace, opts); + document.location.href = uiUrl(`workflows/${submitted.metadata.namespace}/${submitted.metadata.name}`); + } catch (err) { + setError(err); + setIsSubmitting(false); + } } - public render() { - return ( - <> -

Retry Workflow

-
- {this.props.workflow.metadata.namespace}/{this.props.workflow.metadata.name} -
+ return ( + <> +

Retry Workflow

+
+ {props.workflow.metadata.namespace}/{props.workflow.metadata.name} +
- {this.state.error && } -
-
- -
- this.setState({overrideParameters})} /> -
+ {error && } +
+ {/* Override Parameters */} +
+ +
+
+
- {this.state.overrideParameters && ( -
- - {this.state.workflowParameters.length > 0 && ( - this.setState({workflowParameters})} /> - )} - {this.state.workflowParameters.length === 0 ? ( - <> -
- - - ) : ( - <> - )} -
- )} + {overrideParameters && ( +
+ + {workflowParameters.length > 0 ? ( + + ) : ( + <> +
+ + + )} +
+ )} -
- -
- this.setState({restartSuccessful})} /> -
+ {/* Restart Successful */} +
+ +
+
+
- {this.state.restartSuccessful && ( -
- + {restartSuccessful && ( +
+ -
-