Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UIFactory): introduce renderCustomPreloaderError method which allows to render custom error page #815

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/ui/src/shared/ui-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface UISettings {

announcesMailListUrl?: string;

sslCertFixUrl?: string;
queryTrackerStage?: string;
queryTrackerCluster?: string;

Expand Down
3 changes: 3 additions & 0 deletions packages/ui/src/ui/UIFactory/default-ui-factory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,7 @@ export const defaultUIFactory: UIFactory = {
getNavigationMapNodeSettings() {
return undefined;
},
renderCustomPreloaderError() {
return null;
},
};
17 changes: 8 additions & 9 deletions packages/ui/src/ui/UIFactory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import type {Reducer} from 'redux';
import forEach_ from 'lodash/forEach';

import type {DropdownMenuItem} from '@gravity-ui/uikit';
import type {SVGIconData} from '@gravity-ui/uikit/build/esm/components/Icon/types';
Expand All @@ -27,6 +26,7 @@ import type {UISettingsMonitoring} from '../../shared/ui-settings';
import type {SubjectCardProps} from '../components/SubjectLink/SubjectLink';
import type {QueryItem} from '../pages/query-tracker/module/api';
import type {Node} from '../utils/navigation/content/map-nodes/node';
import type {PreloadErrorType} from '../constants';

type HeaderItemOrPage =
| {
Expand Down Expand Up @@ -428,20 +428,19 @@ export interface UIFactory {
additionalAttributes: Array<string>;
renderNodeIcon: (item: Node) => React.ReactNode;
};

renderCustomPreloaderError: (params: {
cluster: string;
errorType: PreloadErrorType;
error: Error;
}) => React.ReactNode;
}

// All methods comes from `configureUIFactory` method
const uiFactory: UIFactory = {} as any;

function configureUIFactoryItem<K extends keyof UIFactory>(k: K, redefinition: UIFactory[K]) {
uiFactory[k] = redefinition;
}

export function configureUIFactory(overrides: UIFactory) {
forEach_(overrides, (_v, k) => {
const key = k as keyof UIFactory;
configureUIFactoryItem(key, overrides[key]!);
});
Object.assign(uiFactory, overrides);
}

export default new Proxy(uiFactory, {
Expand Down

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions packages/ui/src/ui/components/Support/Support.scss

This file was deleted.

60 changes: 0 additions & 60 deletions packages/ui/src/ui/components/Support/Support.tsx

This file was deleted.

7 changes: 5 additions & 2 deletions packages/ui/src/ui/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {ValueOf} from '../types/index';
import createActionTypes, {createPrefix} from './utils';
export {Page} from '../../shared/constants/settings';

Expand All @@ -22,11 +23,13 @@ export const LOADING_STATUS = {
CANCELLED: 'cancelled',
} as const;

export const LOAD_ERROR = {
export const PRELOAD_ERROR = {
GENERAL: 'general',
CONNECTION: 'connection',
AUTHENTICATION: 'authentication',
};
} as const;

export type PreloadErrorType = ValueOf<typeof PRELOAD_ERROR>;

export const TYPED_OUTPUT_FORMAT = {
$value: 'json' as const,
Expand Down
34 changes: 5 additions & 29 deletions packages/ui/src/ui/containers/ClusterPage/ClusterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import ClusterPageHeader from '../ClusterPageHeader/ClusterPageHeader';
import PageTracker from './PageTracker';

import {PageHeadByCluster} from '../../components/PageHead/PageHead';
import ConnectionErrorRegion from '../../components/PreloaderErrors/ConnectionErrorRegion';
import GeneralErrorRegion from '../../components/PreloaderErrors/GeneralErrorRegion';

import FlexSplitPane from '../../components/FlexSplitPane/FlexSplitPane';
import ErrorBlock from '../../components/Error/Error';
import HandleMaintenance from '../../containers/MaintenancePage/HandleMaintenance';
import PreloadError from '../../containers/PreloadError/PreloadError';

import {LOADING_STATUS, LOAD_ERROR, Page, SPLIT_PANE_ID} from '../../constants/index';
import {LOADING_STATUS, Page, SPLIT_PANE_ID} from '../../constants/index';
import {joinMenuItemsAction, splitMenuItemsAction, trackVisit} from '../../store/actions/menu';
import {setSetting} from '../../store/actions/settings';
import {unmountCluster, updateCluster} from '../../store/actions/cluster-params';
Expand Down Expand Up @@ -178,30 +178,6 @@ class ClusterPage extends Component {
return this.props.clusterPagePaneSizes;
};

renderError(clusterConfig) {
const {errorType} = this.props.error || {};

switch (errorType) {
case LOAD_ERROR.CONNECTION:
return <ConnectionErrorRegion cluster={clusterConfig.id} />;
case LOAD_ERROR.AUTHENTICATION:
return (
<GeneralErrorRegion
cluster={clusterConfig.id}
message={
'Could not fetch the XSRF token, therefore preventing further operations. Sometimes ' +
'token fetching fails due to the network issues. If the problem persists, please report it ' +
'via Bug Reporter.'
}
/>
);
case LOAD_ERROR.GENERAL:
return (
<GeneralErrorRegion message="Unexpected error occurred. If problem persists please report it via Bug Reporter." />
);
}
}

isParamsLoading() {
const {cluster, paramsCluster} = this.props;
return cluster !== paramsCluster;
Expand Down Expand Up @@ -268,9 +244,9 @@ class ClusterPage extends Component {
</Fragment>
) : (
<React.Fragment>
<div className="preloader">
<div className={b('preloader')}>
{hasError ? (
this.renderError(clusterConfig)
<PreloadError />
) : (
<p className="preloader__loading">Loading {clusterConfig?.id}...</p>
)}
Expand Down
Loading
Loading