From db20b4f2c7ecf4388f70a5e422dc19fc78c4e753 Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Fri, 16 Oct 2020 12:22:57 -0700 Subject: [PATCH] feat(ui): Submit resources without namespace to current namespace. Fixes #4293 (#4298) --- .../components/cron-workflow-list/cron-workflow-list.tsx | 5 +++-- .../components/resource-editor/resource-editor.tsx | 7 ++++++- ui/src/app/shared/examples.ts | 9 +++------ .../workflow-template-list/workflow-template-list.tsx | 3 ++- .../components/workflows-list/workflows-list.tsx | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/ui/src/app/cron-workflows/components/cron-workflow-list/cron-workflow-list.tsx b/ui/src/app/cron-workflows/components/cron-workflow-list/cron-workflow-list.tsx index 93769037d317..838648f8080d 100644 --- a/ui/src/app/cron-workflows/components/cron-workflow-list/cron-workflow-list.tsx +++ b/ui/src/app/cron-workflows/components/cron-workflow-list/cron-workflow-list.tsx @@ -74,10 +74,11 @@ export class CronWorkflowList extends BasePage, State> (this.sidePanel = null)}> services.cronWorkflows - .create(cronWf, cronWf.metadata.namespace) + .create(cronWf, cronWf.metadata.namespace || this.namespace) .then(res => ctx.navigation.goto(uiUrl(`cron-workflows/${res.metadata.namespace}/${res.metadata.name}`))) } upload={true} diff --git a/ui/src/app/shared/components/resource-editor/resource-editor.tsx b/ui/src/app/shared/components/resource-editor/resource-editor.tsx index baac615b1f6b..e3d8ab27b665 100644 --- a/ui/src/app/shared/components/resource-editor/resource-editor.tsx +++ b/ui/src/app/shared/components/resource-editor/resource-editor.tsx @@ -12,6 +12,7 @@ require('./resource.scss'); interface Props { kind: string; upload?: boolean; + namespace?: string; title?: string; value: T; readonly?: boolean; @@ -158,8 +159,12 @@ export class ResourceEditor extends React.Component, State> { private submit() { try { + const value = parse(this.state.value); + if (!value.metadata.namespace && this.props.namespace) { + value.metadata.namespace = this.props.namespace; + } this.props - .onSubmit(parse(this.state.value)) + .onSubmit(value) .then(() => this.setState({error: null})) .catch(error => this.setState({error})); } catch (error) { diff --git a/ui/src/app/shared/examples.ts b/ui/src/app/shared/examples.ts index b833a7cd36ab..563e5a424ffc 100644 --- a/ui/src/app/shared/examples.ts +++ b/ui/src/app/shared/examples.ts @@ -29,11 +29,10 @@ const templates: Template[] = [ } ]; -export const exampleWorkflow = (namespace: string): Workflow => { +export const exampleWorkflow = (): Workflow => { return { metadata: { name: randomSillyName(), - namespace: namespace || 'default', labels }, spec: { @@ -60,10 +59,9 @@ export const exampleClusterWorkflowTemplate = (): ClusterWorkflowTemplate => ({ } }); -export const exampleWorkflowTemplate = (namespace: string): WorkflowTemplate => ({ +export const exampleWorkflowTemplate = (): WorkflowTemplate => ({ metadata: { name: randomSillyName(), - namespace, labels }, spec: { @@ -76,10 +74,9 @@ export const exampleWorkflowTemplate = (namespace: string): WorkflowTemplate => } }); -export const exampleCronWorkflow = (namespace: string): CronWorkflow => ({ +export const exampleCronWorkflow = (): CronWorkflow => ({ metadata: { name: randomSillyName(), - namespace: namespace || 'default', labels }, spec: { diff --git a/ui/src/app/workflow-templates/components/workflow-template-list/workflow-template-list.tsx b/ui/src/app/workflow-templates/components/workflow-template-list/workflow-template-list.tsx index d7fecf4cba8a..521eceaea36b 100644 --- a/ui/src/app/workflow-templates/components/workflow-template-list/workflow-template-list.tsx +++ b/ui/src/app/workflow-templates/components/workflow-template-list/workflow-template-list.tsx @@ -74,7 +74,8 @@ export class WorkflowTemplateList extends BasePage, Sta title='New Workflow Template' kind='WorkflowTemplate' upload={true} - value={exampleWorkflowTemplate(this.namespace || 'default')} + namespace={this.namespace || 'default'} + value={exampleWorkflowTemplate()} onSubmit={wfTmpl => services.workflowTemplate .create(wfTmpl, wfTmpl.metadata.namespace) diff --git a/ui/src/app/workflows/components/workflows-list/workflows-list.tsx b/ui/src/app/workflows/components/workflows-list/workflows-list.tsx index f7d0910d4302..3c33517c7d0a 100644 --- a/ui/src/app/workflows/components/workflows-list/workflows-list.tsx +++ b/ui/src/app/workflows/components/workflows-list/workflows-list.tsx @@ -184,7 +184,8 @@ export class WorkflowsList extends BasePage, State> { kind='Workflow' upload={true} editing={true} - value={exampleWorkflow(this.state.namespace)} + namespace={this.state.namespace || 'default'} + value={exampleWorkflow()} onSubmit={wfValue => services.workflows .create(wfValue, wfValue.metadata.namespace || this.state.namespace)