Skip to content

Commit

Permalink
fix: Namespace redirects no longer error and are snappier (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
simster7 authored Jan 30, 2020
1 parent 16aed5c commit 516d05f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {Utils} from '../../../shared/utils';

interface State {
continue: string;
loading: boolean;
namespace: string;
workflows?: Workflow[];
error?: Error;
}
Expand All @@ -29,16 +31,17 @@ export class ArchivedWorkflowList extends BasePage<RouteComponentProps<any>, Sta
}

private get namespace() {
return this.props.match.params.namespace || '';
return this.state.namespace;
}

private set namespace(namespace: string) {
document.location.href = uiUrl('archived-workflows/' + namespace);
this.setState({namespace});
history.pushState(null, '', uiUrl('cron-workflows/' + namespace));
}

constructor(props: RouteComponentProps<any>, context: any) {
super(props, context);
this.state = {continue: ''};
this.state = {continue: '', loading: true, namespace: this.props.match.params.namespace || ''};
}

public componentDidMount(): void {
Expand All @@ -51,16 +54,18 @@ export class ArchivedWorkflowList extends BasePage<RouteComponentProps<any>, Sta
return services.archivedWorkflows.list(this.namespace, this.continue);
})
.then(list => {
this.setState({workflows: list.items || [], continue: list.metadata.continue || ''});
this.setState({workflows: list.items || [], continue: list.metadata.continue || '', loading: false});
})
.catch(error => this.setState({error}));
.catch(error => this.setState({error, loading: false}));
}

public render() {
if (this.state.loading) {
return <Loading />;
}
if (this.state.error) {
throw this.state.error;
}

return (
<Page
title='Archived Workflows'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@ import {ZeroState} from '../../../shared/components/zero-state';
import {Consumer} from '../../../shared/context';
import {exampleCronWorkflow} from '../../../shared/examples';
import {services} from '../../../shared/services';

require('./cron-workflow-list.scss');

interface State {
loading: boolean;
namespace: string;
cronWorkflows?: models.CronWorkflow[];
error?: Error;
}

export class CronWorkflowList extends BasePage<RouteComponentProps<any>, State> {
private get namespace() {
return this.props.match.params.namespace || '';
return this.state.namespace;
}

private set namespace(namespace: string) {
document.location.href = uiUrl('cron-workflows/' + namespace);
this.setState({namespace});
history.pushState(null, '', uiUrl('cron-workflows/' + namespace));
}

private get sidePanel() {
Expand All @@ -38,10 +42,10 @@ export class CronWorkflowList extends BasePage<RouteComponentProps<any>, State>
}
constructor(props: any) {
super(props);
this.state = {};
this.state = {loading: true, namespace: this.props.match.params.namespace || ''};
}

public componentDidMount(): void {
public componentWillMount(): void {
services.info
.get()
.then(info => {
Expand All @@ -50,11 +54,14 @@ export class CronWorkflowList extends BasePage<RouteComponentProps<any>, State>
}
return services.cronWorkflows.list(this.namespace);
})
.then(cronWorkflows => this.setState({cronWorkflows}))
.catch(error => this.setState({error}));
.then(cronWorkflows => this.setState({cronWorkflows, loading: false}))
.catch(error => this.setState({error, loading: false}));
}

public render() {
if (this.state.loading) {
return <Loading />;
}
if (this.state.error) {
throw this.state.error;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,20 @@ import {services} from '../../../shared/services';
require('./workflow-template-list.scss');

interface State {
loading: boolean;
namespace: string;
templates?: models.WorkflowTemplate[];
error?: Error;
}

export class WorkflowTemplateList extends BasePage<RouteComponentProps<any>, State> {
private get namespace() {
return this.props.match.params.namespace || '';
return this.state.namespace;
}

private set namespace(namespace: string) {
document.location.href = uiUrl('workflow-templates/' + namespace);
this.setState({namespace});
history.pushState(null, '', uiUrl('workflow-templates/' + namespace));
}

private get sidePanel() {
Expand All @@ -40,7 +43,7 @@ export class WorkflowTemplateList extends BasePage<RouteComponentProps<any>, Sta

constructor(props: RouteComponentProps<any>, context: any) {
super(props, context);
this.state = {};
this.state = {loading: true, namespace: this.props.match.params.namespace || ''};
}

public componentDidMount(): void {
Expand All @@ -52,11 +55,14 @@ export class WorkflowTemplateList extends BasePage<RouteComponentProps<any>, Sta
}
return services.workflowTemplate.list(this.namespace);
})
.then(templates => this.setState({templates}))
.catch(error => this.setState({error}));
.then(templates => this.setState({templates, loading: false}))
.catch(error => this.setState({error, loading: false}));
}

public render() {
if (this.state.loading) {
return <Loading />;
}
if (this.state.error) {
throw this.state.error;
}
Expand Down
17 changes: 12 additions & 5 deletions ui/src/app/workflows/components/workflows-list/workflows-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import {WorkflowSubmit} from '../workflow-submit';
require('./workflows-list.scss');

interface State {
loading: boolean;
namespace: string;
workflows?: Workflow[];
error?: Error;
}
Expand All @@ -30,11 +32,12 @@ export class WorkflowsList extends BasePage<RouteComponentProps<any>, State> {
private subscription: Subscription;

private get namespace() {
return this.props.match.params.namespace || '';
return this.state.namespace;
}

private set namespace(namespace: string) {
document.location.href = uiUrl('workflows/' + namespace);
this.setState({namespace});
history.pushState(null, '', uiUrl('workflows/' + namespace));
}

private get phases() {
Expand All @@ -51,10 +54,10 @@ export class WorkflowsList extends BasePage<RouteComponentProps<any>, State> {

constructor(props: RouteComponentProps<State>, context: any) {
super(props, context);
this.state = {};
this.state = {loading: true, namespace: this.props.match.params.namespace || ''};
}

public componentDidMount(): void {
public componentWillMount(): void {
services.info
.get()
.then(info => {
Expand Down Expand Up @@ -99,7 +102,8 @@ export class WorkflowsList extends BasePage<RouteComponentProps<any>, State> {
})
.subscribe(workflows => this.setState({workflows}));
})
.catch(error => this.setState({error}));
.then(_ => this.setState({loading: false}))
.catch(error => this.setState({error, loading: false}));
}

public componentWillUnmount(): void {
Expand All @@ -109,6 +113,9 @@ export class WorkflowsList extends BasePage<RouteComponentProps<any>, State> {
}

public render() {
if (this.state.loading) {
return <Loading />;
}
if (this.state.error) {
throw this.state.error;
}
Expand Down

0 comments on commit 516d05f

Please sign in to comment.