Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: David Kwon <dakwon@redhat.com>
  • Loading branch information
dkwon17 committed Jun 14, 2022
1 parent 588cb87 commit e8973de
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { TextContent, Text, TextVariants } from '@patternfly/react-core';
import { WarningTriangleIcon } from '@patternfly/react-icons';
import React from 'react';
import { BrandingData } from '../../../services/bootstrap/branding.constant';
import { Issue } from '../../../services/bootstrap/issuesReporter';
import { Issue, WorkspaceRoutes } from '../../../services/bootstrap/issuesReporter';

import * as styles from './index.module.css';

Expand All @@ -33,7 +33,10 @@ export class IssueComponent extends React.PureComponent<Props> {
case 'sso':
return this.renderSsoError(issue.error);
case 'workspaceStopped':
return this.renderWorkspaceStoppedError(issue.error);
return this.renderWorkspaceStoppedError(
issue.error,
(issue as Issue<WorkspaceRoutes>).data,
);
default:
return this.renderUnknownError(issue.error);
}
Expand Down Expand Up @@ -94,23 +97,35 @@ export class IssueComponent extends React.PureComponent<Props> {
);
}

private renderWorkspaceStoppedError(error: Error): React.ReactNode {
const reload = () => {
window.location.hash = '#/workspaces';
window.location.reload();
private renderWorkspaceStoppedError(
error: Error,
workspaceRoutes: WorkspaceRoutes | undefined,
): React.ReactNode {
const linkOnClick = (hash: string) => {
return () => {
window.location.hash = hash;
window.location.reload();
};
};

const dashboardLink = (
<Text component={TextVariants.p}>
Click <a onClick={reload}>here</a> to go back to the dashboard.
</Text>
);
let ideLoader;
let workspaceDetails;

const restartLink = (
<Text component={TextVariants.p}>
Click <a href="#">here</a> to restart your workspace.
</Text>
);
if (workspaceRoutes) {
ideLoader = (
<Text component={TextVariants.p}>
Click <a onClick={linkOnClick(workspaceRoutes.ideLoader)}>here</a> to restart your
workspace.
</Text>
);

workspaceDetails = (
<Text component={TextVariants.p}>
Click <a onClick={linkOnClick(workspaceRoutes.workspaceDetails)}>here</a> to return to the
dashboard.
</Text>
);
}

const warningTextbox = !error ? undefined : (
<Text component={TextVariants.pre} className={styles.errorMessage}>
Expand All @@ -125,8 +140,8 @@ export class IssueComponent extends React.PureComponent<Props> {
Warning
</Text>
{warningTextbox}
{restartLink}
{dashboardLink}
{ideLoader}
{workspaceDetails}
</TextContent>
);
}
Expand Down
31 changes: 23 additions & 8 deletions packages/dashboard-frontend/src/services/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import * as WorkspacesStore from '../../store/Workspaces';
import * as DevWorkspacesStore from '../../store/Workspaces/devWorkspaces';
import * as WorkspacesSettingsStore from '../../store/Workspaces/Settings';
import { ResourceFetcherService } from '../resource-fetcher';
import { IssuesReporterService } from './issuesReporter';
import { IssuesReporterService, WorkspaceRoutes } from './issuesReporter';
import { CheWorkspaceClient } from '../workspace-client/cheworkspace/cheWorkspaceClient';
import { DevWorkspaceClient } from '../workspace-client/devworkspace/devWorkspaceClient';
import { isDevworkspacesEnabled } from '../helpers/devworkspace';
Expand All @@ -39,6 +39,7 @@ import { selectDevWorkspacesResourceVersion } from '../../store/Workspaces/devWo
import { AppAlerts } from '../alerts/appAlerts';
import { AlertVariant } from '@patternfly/react-core';
import SessionStorageService, { SessionStorageKey } from '../session-storage';
import { ROUTE } from '../../route.enum';

/**
* This class executes a few initial instructions
Expand Down Expand Up @@ -277,13 +278,27 @@ export default class Bootstrap {
}

const state = this.store.getState();
if (state.devWorkspaces.workspaces.some(w => w.status?.mainUrl?.includes(path))) {
this.issuesReporterService.registerIssue(
'workspaceStopped',
new Error(
'Your workspace has stopped. This could happen if your workspace shuts down due to inactivity.',
),
);
const workspace = state.devWorkspaces.workspaces.find(w => w.status?.mainUrl?.includes(path));
if (!workspace) {
return;
}

const ideLoader = ROUTE.IDE_LOADER.replace(':namespace', workspace.metadata.namespace).replace(
':workspaceName',
workspace.metadata.name,
);

const workspaceDetails = ROUTE.WORKSPACE_DETAILS.replace(
':namespace',
workspace.metadata.namespace,
).replace(':workspaceName', workspace.metadata.name);

this.issuesReporterService.registerIssue<WorkspaceRoutes>(
'workspaceStopped',
new Error(
'Your workspace has stopped. This could happen if your workspace shuts down due to inactivity.',
),
{ ideLoader, workspaceDetails },
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
import { injectable } from 'inversify';

export type IssueType = 'cert' | 'sso' | 'workspaceStopped' | 'unknown';
export type Issue = {
export type Issue<T = unknown> = {
type: IssueType;
error: Error;
data?: T;
};

export type WorkspaceRoutes = { ideLoader: string; workspaceDetails: string };

@injectable()
export class IssuesReporterService {
private issues: Issue[] = [];
Expand All @@ -26,8 +29,8 @@ export class IssuesReporterService {
return this.issues.length !== 0;
}

public registerIssue(type: IssueType, error: Error): void {
this.issues.push({ type, error });
public registerIssue<T>(type: IssueType, error: Error, data?: T): void {
this.issues.push({ type, error, data });
}

public reportIssue(): Issue | undefined {
Expand Down

0 comments on commit e8973de

Please sign in to comment.