import { ApolloProvider } from '@apollo/client'; import { UIView } from '@uirouter/react'; import React from 'react'; import { ApplicationContextProvider } from './ApplicationContext'; import type { Application } from './application.model'; import { RecentHistoryService } from '../history'; import { createApolloClient } from '../managed/graphql/client'; import { ApplicationNavigation } from './nav/ApplicationNavigation'; import { DebugWindow } from '../utils/consoleDebug'; import './application.less'; export interface IApplicationComponentProps { app: Application; } export class ApplicationComponent extends React.Component { private apolloClient = createApolloClient(); private unsubscribeAppRefresh?: () => void; constructor(props: IApplicationComponentProps) { super(props); this.mountApplication(props.app); } public componentWillUnmount(): void { this.unmountApplication(this.props.app); } public componentWillReceiveProps(nextProps: IApplicationComponentProps): void { this.unmountApplication(this.props.app); this.mountApplication(nextProps.app); } private mountApplication(app: Application) { if (app.notFound || app.hasError) { RecentHistoryService.removeLastItem('applications'); return; } DebugWindow.application = app; // KLUDGE: warning, do not use, this is temporarily and will be removed very soon. if (!app.attributes?.disableAutoRefresh) { this.unsubscribeAppRefresh = this.props.app.subscribeToRefresh(this.apolloClient.onRefresh); app.enableAutoRefresh(); } } private unmountApplication(app: Application) { if (app.notFound || app.hasError) { return; } DebugWindow.application = undefined; this.unsubscribeAppRefresh?.(); this.unsubscribeAppRefresh = undefined; app.disableAutoRefresh(); } public render() { const { app } = this.props; return (
{!app.notFound && !app.hasError && } {app.notFound && (

Application Not Found

Please check your URL - we can't find any data for {app.name}.

)} {app.hasError && (

Something went wrong

There was a problem loading {app.name}. Try checking your browser console for errors.

)}
); } }