Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Add namespace input to ClusterWorkflowTemplate submit. Fixes #10398 #13596

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions ui/src/app/workflows/components/submit-workflow-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Select} from 'argo-ui/src/components/select/select';
import {TextInput} from '../../shared/components/text-input';
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
import React, {useContext, useMemo, useState} from 'react';

import {Parameter, Template} from '../../../models';
Expand All @@ -10,8 +11,10 @@ import {TagsInput} from '../../shared/components/tags-input/tags-input';
import {services} from '../../shared/services';
import {Utils} from '../../shared/utils';

type WorkflowTemplateType = 'ClusterWorkflowTemplate' | 'WorkflowTemplate';

interface Props {
kind: string;
kind: WorkflowTemplateType;
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
namespace: string;
name: string;
entrypoint: string;
Expand All @@ -31,6 +34,7 @@ export function SubmitWorkflowPanel(props: Props) {
const {navigation} = useContext(Context);
const [entrypoint, setEntrypoint] = useState(workflowEntrypoint);
const [parameters, setParameters] = useState<Parameter[]>([]);
const [namespace, setNamespace] = useState(props.namespace);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is not entirely correct to have props.namespace be the initial state. For a WorkflowTemplate, it will always be props.namespace, and for a ClusterWorkflowTemplate, it will always be the namespace state.

This would be particularly relevant in cases where this panel is off-screen but still rendered; the next time it's on-screen, the prop would not be used.
That's normally not how this component is used, but that is why the correctness matters if it were to be used that way.

Also this should be ordered after the useContext instead of in between the two parameter state variables for better organization

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I pushed 59dbea3 to lift the state up to <ClusterWorkflowTemplateDetails>, which is simpler than handling it here

const [workflowParameters, setWorkflowParameters] = useState<Parameter[]>(JSON.parse(JSON.stringify(props.workflowParameters)));
const [labels, setLabels] = useState(['submit-from-ui=true']);
const [error, setError] = useState<Error>();
Expand All @@ -50,7 +54,7 @@ export function SubmitWorkflowPanel(props: Props) {
async function submit() {
setIsSubmitting(true);
try {
const submitted = await services.workflows.submit(props.kind, props.name, props.namespace, {
const submitted = await services.workflows.submit(props.kind, props.name, namespace, {
entryPoint: entrypoint === workflowEntrypoint ? null : entrypoint,
parameters: [
...workflowParameters.filter(p => Utils.getValueFromParameter(p) !== undefined).map(p => p.name + '=' + Utils.getValueFromParameter(p)),
Expand All @@ -69,7 +73,7 @@ export function SubmitWorkflowPanel(props: Props) {
<>
<h4>Submit Workflow</h4>
<h5>
{props.namespace}/{props.name}
{namespace}/{props.name}
</h5>
{error && <ErrorNotice error={error} />}
<div className='white-box'>
Expand All @@ -85,6 +89,12 @@ export function SubmitWorkflowPanel(props: Props) {
}}
/>
</div>
{props.kind === 'ClusterWorkflowTemplate' && (
<div key='namespace' style={{marginBottom: 25}}>
<label>Namespace</label>
<TextInput value={namespace} onChange={setNamespace} />
</div>
)}
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
<div key='parameters' style={{marginBottom: 25}}>
<label>Parameters</label>
{workflowParameters.length > 0 && <ParametersInput parameters={workflowParameters} onChange={setWorkflowParameters} />}
Expand Down
Loading