Skip to content

Commit

Permalink
feat(ui): Add parameter value enum support to the UI. Fixes #4192 (#4365
Browse files Browse the repository at this point in the history
)

Signed-off-by: basanthjenuhb <basanthjenuhb@gmail.com>
  • Loading branch information
basanthjenuhb authored Dec 7, 2020
1 parent 7d0f113 commit 5614700
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
63 changes: 45 additions & 18 deletions ui/src/app/workflows/components/submit-workflow-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,11 @@ export class SubmitWorkflowPanel extends React.Component<Props, State> {
<label>Parameters</label>
{this.state.parameters.length > 0 ? (
<>
{this.state.parameters.map(parameter => (
<p key={parameter.name}>
<label>
{parameter.name}
<input
className='argo-field'
value={parameter.value}
onChange={event => {
this.setState({
parameters: this.state.parameters.map(p => ({
name: p.name,
value: p.name === parameter.name ? event.target.value : p.value
}))
});
}}
/>
</label>
</p>
{this.state.parameters.map((parameter, index) => (
<div key={parameter.name + '_' + index}>
<label>{parameter.name}</label>
{(parameter.enum && this.displaySelectFieldForEnumValues(parameter)) || this.displayInputFieldForSingleValue(parameter)}
</div>
))}
</>
) : (
Expand All @@ -98,6 +85,46 @@ export class SubmitWorkflowPanel extends React.Component<Props, State> {
);
}

private displaySelectFieldForEnumValues(parameter: Parameter) {
return (
<Select
key={parameter.name}
value={parameter.value}
options={parameter.enum.map(value => ({
value,
title: value
}))}
onChange={event => {
this.setState({
parameters: this.state.parameters.map(p => ({
name: p.name,
value: p.name === parameter.name ? event.value : p.value,
enum: p.enum
}))
});
}}
/>
);
}

private displayInputFieldForSingleValue(parameter: Parameter) {
return (
<input
className='argo-field'
value={parameter.value}
onChange={event => {
this.setState({
parameters: this.state.parameters.map(p => ({
name: p.name,
value: p.name === parameter.name ? event.target.value : p.value,
enum: p.enum
}))
});
}}
/>
);
}

private submit() {
services.workflows
.submit(this.props.kind, this.props.name, this.props.namespace, {
Expand Down
4 changes: 4 additions & 0 deletions ui/src/models/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export interface Parameter {
* ValueFrom is the source for the output parameter's value
*/
valueFrom?: ValueFrom;
/**
* Enum holds a list of string values to choose from, for the actual value of the parameter
*/
enum?: Array<string>;
}

/**
Expand Down

0 comments on commit 5614700

Please sign in to comment.