Skip to content

Commit

Permalink
feat(ui): Submit resources without namespace to current namespace. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec authored Oct 16, 2020
1 parent 240cd79 commit db20b4f
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@ export class CronWorkflowList extends BasePage<RouteComponentProps<any>, State>
<SlidingPanel isShown={this.sidePanel !== null} onClose={() => (this.sidePanel = null)}>
<ResourceEditor
title={'New Cron Workflow'}
value={exampleCronWorkflow(this.namespace)}
namespace={this.namespace}
value={exampleCronWorkflow()}
onSubmit={cronWf =>
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require('./resource.scss');
interface Props<T> {
kind: string;
upload?: boolean;
namespace?: string;
title?: string;
value: T;
readonly?: boolean;
Expand Down Expand Up @@ -158,8 +159,12 @@ export class ResourceEditor<T> extends React.Component<Props<T>, 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) {
Expand Down
9 changes: 3 additions & 6 deletions ui/src/app/shared/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -60,10 +59,9 @@ export const exampleClusterWorkflowTemplate = (): ClusterWorkflowTemplate => ({
}
});

export const exampleWorkflowTemplate = (namespace: string): WorkflowTemplate => ({
export const exampleWorkflowTemplate = (): WorkflowTemplate => ({
metadata: {
name: randomSillyName(),
namespace,
labels
},
spec: {
Expand All @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class WorkflowTemplateList extends BasePage<RouteComponentProps<any>, 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ export class WorkflowsList extends BasePage<RouteComponentProps<any>, 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)
Expand Down

0 comments on commit db20b4f

Please sign in to comment.