Skip to content

Commit

Permalink
feat: add override checkbox and some minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
toyamagu-2021 committed May 20, 2023
1 parent 170328f commit 2177c0a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const ArchivedWorkflowDetails = ({history, location, match}: RouteCompone
<SlidingPanel isShown={!!sidePanel} onClose={() => setSidePanel(null)}>
{sidePanel === 'yaml' && <WorkflowYamlViewer workflow={workflow} selectedNode={node} />}
{sidePanel === 'logs' && <WorkflowLogsViewer workflow={workflow} initialPodName={podName()} nodeId={nodeId} container={container} archived={true} />}
{sidePanel === 'resubmit' && <ResubmitWorkflowPanel workflow={workflow} workflowParameters={workflow.spec.arguments.parameters || []} />}
{sidePanel === 'resubmit' && <ResubmitWorkflowPanel workflow={workflow} archived={true} />}
</SlidingPanel>
</>
);
Expand Down
72 changes: 47 additions & 25 deletions ui/src/app/workflows/components/resubmit-workflow-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Checkbox} from 'argo-ui';
import * as React from 'react';
import {Parameter, Workflow} from '../../../models';
import {Parameter, ResubmitOpts, Workflow} from '../../../models';
import {uiUrl} from '../../shared/base';
import {ErrorNotice} from '../../shared/components/error-notice';
import {ParametersInput} from '../../shared/components/parameters-input/parameters-input';
Expand All @@ -9,11 +9,11 @@ import {Utils} from '../../shared/utils';

interface Props {
workflow: Workflow;
workflowParameters: Parameter[];
isArchived?: boolean;
archived?: boolean;
}

interface State {
overrideParameters: boolean;
workflowParameters: Parameter[];
memoized: boolean;
error?: Error;
Expand All @@ -24,44 +24,61 @@ export class ResubmitWorkflowPanel extends React.Component<Props, State> {
constructor(props: any) {
super(props);
const state: State = {
workflowParameters: JSON.parse(JSON.stringify(this.props.workflowParameters)),
workflowParameters: JSON.parse(JSON.stringify(this.props.workflow.spec.arguments.parameters || [])),
memoized: false,
isSubmitting: false
isSubmitting: false,
overrideParameters: false
};
this.state = state;
}

public render() {
return (
<>
<h4>Submit Workflow</h4>
<h4>Resubmit 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 key='override-parameters' style={{marginBottom: 25}}>
<label>Override Parameters</label>
<div className='columns small-9'>
<Checkbox checked={this.state.overrideParameters} onChange={overrideParameters => this.setState({overrideParameters})} />
</div>
</div>

{this.state.overrideParameters && (
<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='memoized' style={{marginBottom: 25}}>
<label>Memorized</label>
<label>Memoized</label>
<div className='columns small-9'>
<Checkbox checked={this.state.memoized} onChange={memoized => this.setState({memoized})} />
</div>
</div>

{this.state.overrideParameters && this.state.memoized && (
<div key='warning-override-with-memoized'>
<i className='fa fa-exclamation-triangle' style={{color: '#f4c030'}} />
Overriding parameters on memoized submitted workflows may have unexpected results.
</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'}
Expand All @@ -74,19 +91,24 @@ export class ResubmitWorkflowPanel extends React.Component<Props, State> {

private submit() {
this.setState({isSubmitting: true});
if (!this.props.isArchived) {
const parameters: ResubmitOpts['parameters'] = this.state.overrideParameters
? [...this.state.workflowParameters.filter(p => Utils.getValueFromParameter(p) !== undefined).map(p => p.name + '=' + Utils.getValueFromParameter(p))]
: [];

if (!this.props.archived) {
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))
],
parameters,
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)
.resubmit(this.props.workflow.metadata.uid, this.props.workflow.metadata.namespace, {
parameters,
memoized: this.state.memoized
})
.then(newWorkflow => (document.location.href = uiUrl(`workflows/${newWorkflow.metadata.namespace}/${newWorkflow.metadata.name}`)))
.catch(error => this.setState({error, isSubmitting: false}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export const WorkflowDetails = ({history, location, match}: RouteComponentProps<
{parsedSidePanel.type === 'events' && <EventsPanel namespace={namespace} kind='Pod' name={podName} />}
{parsedSidePanel.type === 'share' && <WidgetGallery namespace={namespace} name={name} />}
{parsedSidePanel.type === 'yaml' && <WorkflowYamlViewer workflow={workflow} selectedNode={selectedNode} />}
{parsedSidePanel.type === 'resubmit' && <ResubmitWorkflowPanel workflow={workflow} workflowParameters={workflow.spec.arguments.parameters || []} />}
{parsedSidePanel.type === 'resubmit' && <ResubmitWorkflowPanel workflow={workflow} />}
{!parsedSidePanel}
</SlidingPanel>
)}
Expand Down
1 change: 1 addition & 0 deletions ui/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './workflows';
export * from './workflow-templates';
export * from './cron-workflows';
export * from './cluster-workflow-templates';
export * from './resubmit-opts';
export {EventSource} from './event-source';
export {Sensor, SensorList} from './sensor';
export {models as kubernetes} from 'argo-ui';

0 comments on commit 2177c0a

Please sign in to comment.