-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: UI Resubmit [archived] workflows with parameter (#4662)
Signed-off-by: [email protected] <[email protected]>
- Loading branch information
1 parent
5a45dff
commit 9b26bd8
Showing
10 changed files
with
229 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ui/src/app/shared/components/parameters-input/parameters-input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import {Select, Tooltip} from 'argo-ui'; | ||
import * as React from 'react'; | ||
import {Parameter} from '../../../../models'; | ||
import {Utils} from '../../utils'; | ||
|
||
interface ParametersInputProps { | ||
parameters: Parameter[]; | ||
onChange?: (parameters: Parameter[]) => void; | ||
} | ||
|
||
export class ParametersInput extends React.Component<ParametersInputProps, {parameters: Parameter[]}> { | ||
constructor(props: ParametersInputProps) { | ||
super(props); | ||
this.state = {parameters: props.parameters || []}; | ||
} | ||
|
||
public render() { | ||
return ( | ||
<> | ||
{this.props.parameters.map((parameter, index) => ( | ||
<div key={parameter.name + '_' + index} style={{marginBottom: 14}}> | ||
<label>{parameter.name}</label> | ||
{parameter.description && ( | ||
<Tooltip content={parameter.description}> | ||
<i className='fa fa-question-circle' style={{marginLeft: 4}} /> | ||
</Tooltip> | ||
)} | ||
{(parameter.enum && this.displaySelectFieldForEnumValues(parameter)) || this.displayInputFieldForSingleValue(parameter)} | ||
</div> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
private displaySelectFieldForEnumValues(parameter: Parameter) { | ||
return ( | ||
<Select | ||
key={parameter.name} | ||
value={Utils.getValueFromParameter(parameter)} | ||
options={parameter.enum.map(value => ({ | ||
value, | ||
title: value | ||
}))} | ||
onChange={e => { | ||
const newParameters: Parameter[] = this.state.parameters.map(p => ({ | ||
name: p.name, | ||
value: p.name === parameter.name ? e.value : Utils.getValueFromParameter(p), | ||
enum: p.enum | ||
})); | ||
this.setState({parameters: newParameters}); | ||
this.onParametersChange(newParameters); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
private displayInputFieldForSingleValue(parameter: Parameter) { | ||
return ( | ||
<textarea | ||
className='argo-field' | ||
value={Utils.getValueFromParameter(parameter)} | ||
onChange={e => { | ||
const newParameters: Parameter[] = this.state.parameters.map(p => ({ | ||
name: p.name, | ||
value: p.name === parameter.name ? e.target.value : Utils.getValueFromParameter(p), | ||
enum: p.enum | ||
})); | ||
this.setState({parameters: newParameters}); | ||
this.onParametersChange(newParameters); | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
private onParametersChange(parameters: Parameter[]) { | ||
if (this.props.onChange) { | ||
this.props.onChange(parameters); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
ui/src/app/workflows/components/resubmit-workflow-panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import {Checkbox} from 'argo-ui'; | ||
import * as React from 'react'; | ||
import {Parameter, Workflow} from '../../../models'; | ||
import {uiUrl} from '../../shared/base'; | ||
import {ErrorNotice} from '../../shared/components/error-notice'; | ||
import {ParametersInput} from '../../shared/components/parameters-input/parameters-input'; | ||
import {services} from '../../shared/services'; | ||
import {Utils} from '../../shared/utils'; | ||
|
||
interface Props { | ||
workflow: Workflow; | ||
workflowParameters: Parameter[]; | ||
isArchived?: boolean; | ||
} | ||
|
||
interface State { | ||
workflowParameters: Parameter[]; | ||
memoized: boolean; | ||
error?: Error; | ||
isSubmitting: boolean; | ||
} | ||
|
||
export class ResubmitWorkflowPanel extends React.Component<Props, State> { | ||
constructor(props: any) { | ||
super(props); | ||
const state: State = { | ||
workflowParameters: JSON.parse(JSON.stringify(this.props.workflowParameters)), | ||
memoized: false, | ||
isSubmitting: false | ||
}; | ||
this.state = state; | ||
} | ||
|
||
public render() { | ||
return ( | ||
<> | ||
<h4>Submit Workflow</h4> | ||
<h5> | ||
{this.props.workflow.metadata.namespace}/{this.props.workflow.metadata.name} | ||
</h5> | ||
{this.state.error && <ErrorNotice error={this.state.error} />} | ||
<div className='white-box'> | ||
<div key='parameters' style={{marginBottom: 25}}> | ||
<label>Parameters</label> | ||
{this.state.workflowParameters.length > 0 && ( | ||
<ParametersInput parameters={this.state.workflowParameters} onChange={workflowParameters => this.setState({workflowParameters})} /> | ||
)} | ||
{this.state.workflowParameters.length === 0 ? ( | ||
<> | ||
<br /> | ||
<label>No parameters</label> | ||
</> | ||
) : ( | ||
<></> | ||
)} | ||
</div> | ||
|
||
<div key='memorized' style={{marginBottom: 25}}> | ||
<label>Memorized</label> | ||
<div className='columns small-9'> | ||
<Checkbox checked={this.state.memoized} onChange={memoized => this.setState({memoized})} /> | ||
</div> | ||
</div> | ||
|
||
<div key='resubmit'> | ||
<button onClick={() => this.submit()} className='argo-button argo-button--base' disabled={this.state.isSubmitting}> | ||
<i className='fa fa-plus' /> {this.state.isSubmitting ? 'Loading...' : 'Resubmit'} | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
|
||
private submit() { | ||
this.setState({isSubmitting: true}); | ||
if (!this.props.isArchived) { | ||
services.workflows | ||
.resubmit(this.props.workflow.metadata.name, this.props.workflow.metadata.namespace, { | ||
parameters: [ | ||
...this.state.workflowParameters.filter(p => Utils.getValueFromParameter(p) !== undefined).map(p => p.name + '=' + Utils.getValueFromParameter(p)) | ||
], | ||
memoized: this.state.memoized | ||
}) | ||
.then((submitted: Workflow) => (document.location.href = uiUrl(`workflows/${submitted.metadata.namespace}/${submitted.metadata.name}`))) | ||
.catch(error => this.setState({error, isSubmitting: false})); | ||
} else { | ||
services.archivedWorkflows | ||
.resubmit(this.props.workflow.metadata.uid, this.props.workflow.metadata.namespace) | ||
.then(newWorkflow => (document.location.href = uiUrl(`workflows/${newWorkflow.metadata.namespace}/${newWorkflow.metadata.name}`))) | ||
.catch(error => this.setState({error, isSubmitting: false})); | ||
} | ||
} | ||
} |
Oops, something went wrong.