Skip to content

Commit

Permalink
chore: refactor app.tsx. Fixes argoproj#9810 (argoproj#10867)
Browse files Browse the repository at this point in the history
Signed-off-by: Tianchu Zhao <[email protected]>
  • Loading branch information
tczhao authored and JPZ13 committed Jul 4, 2023
1 parent f3f08ec commit c59db06
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 53 deletions.
56 changes: 16 additions & 40 deletions ui/src/app/app.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,27 @@
import {NavigationManager, NotificationsManager, PopupManager} from 'argo-ui';

import {createBrowserHistory} from 'history';
import * as PropTypes from 'prop-types';
import * as React from 'react';
import {AppRouter} from './app-router';
import {ContextApis, Provider} from './shared/context';

const history = createBrowserHistory();

export class App extends React.Component<{}> {
public static childContextTypes = {
history: PropTypes.object,
apis: PropTypes.object
};

private readonly popupManager: PopupManager;
private readonly notificationsManager: NotificationsManager;
private readonly navigationManager: NavigationManager;
export const App = () => {
const popupManager: PopupManager = new PopupManager();
const notificationsManager: NotificationsManager = new NotificationsManager();
const navigationManager: NavigationManager = new NavigationManager(history);

constructor(props: {}) {
super(props);
this.popupManager = new PopupManager();
this.notificationsManager = new NotificationsManager();
this.navigationManager = new NavigationManager(history);
}

public render() {
const providerContext: ContextApis = {
notifications: this.notificationsManager,
popup: this.popupManager,
navigation: this.navigationManager,
history
};
return (
<Provider value={providerContext}>
<AppRouter history={history} notificationsManager={this.notificationsManager} popupManager={this.popupManager} />
</Provider>
);
}
const providerContext: ContextApis = {
notifications: notificationsManager,
popup: popupManager,
navigation: navigationManager,
history
};

public getChildContext() {
return {
history,
apis: {
popup: this.popupManager,
notifications: this.notificationsManager
}
};
}
}
return (
<Provider value={providerContext}>
<AppRouter history={history} notificationsManager={notificationsManager} popupManager={popupManager} />
</Provider>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {NotificationType} from 'argo-ui';
import * as PropTypes from 'prop-types';
import * as React from 'react';
import {Workflow} from '../../../../models';
import {AppContext, Consumer} from '../../../shared/context';
import {Consumer} from '../../../shared/context';
import * as Actions from '../../../shared/workflow-operations-map';
import {WorkflowOperation, WorkflowOperationAction} from '../../../shared/workflow-operations-map';

Expand All @@ -22,11 +21,6 @@ interface WorkflowGroupAction extends WorkflowOperation {
}

export class WorkflowsToolbar extends React.Component<WorkflowsToolbarProps, {}> {
public static contextTypes = {
router: PropTypes.object,
apis: PropTypes.object
};

constructor(props: WorkflowsToolbarProps) {
super(props);
}
Expand Down Expand Up @@ -60,7 +54,7 @@ export class WorkflowsToolbar extends React.Component<WorkflowsToolbarProps, {}>
promises.push(
action(wf).catch(() => {
this.props.loadWorkflows();
this.appContext.apis.notifications.show({
ctx.notifications.show({
content: `Unable to ${title} workflow`,
type: NotificationType.Error
});
Expand All @@ -85,7 +79,7 @@ export class WorkflowsToolbar extends React.Component<WorkflowsToolbarProps, {}>
return this.performActionOnSelectedWorkflows(ctx, action.title, action.action).then(confirmed => {
if (confirmed) {
this.props.clearSelection();
this.appContext.apis.notifications.show({
ctx.notifications.show({
content: `Performed '${action.title}' on selected workflows.`,
type: NotificationType.Success
});
Expand Down Expand Up @@ -113,8 +107,4 @@ export class WorkflowsToolbar extends React.Component<WorkflowsToolbarProps, {}>
}
return actionButtons;
}

private get appContext(): AppContext {
return this.context as AppContext;
}
}

0 comments on commit c59db06

Please sign in to comment.