Skip to content

Commit

Permalink
fix(MaintenancePage): rework maintenance activation
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-efremoff committed Jul 24, 2024
1 parent 9ef193c commit c7ed6e4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 189 deletions.
8 changes: 0 additions & 8 deletions packages/ui/src/server/controllers/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ function isRootPage(page: string) {
return -1 !== rootPages.indexOf(page);
}

export function homeRedirect(req: Request, res: Response) {
const cluster = req.params.ytAuthCluster;
const {referrer} = req.query;
const url = referrer ? (referrer as string) : `/${cluster}`;

res.redirect(url);
}

export function homeIndexFactory(entryName = 'main') {
return async (req: Request, res: Response) => {
const isRoot = isRootPage(req.params.ytAuthCluster);
Expand Down
3 changes: 1 addition & 2 deletions packages/ui/src/server/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
settingsGetItem,
settingsSetItem,
} from './controllers/settings';
import {homeIndexFactory, homeRedirect} from './controllers/home';
import {homeIndexFactory} from './controllers/home';
import {handleClusterInfo} from './controllers/cluster-info';

import {clusterAuthStatus, clusterVersions} from './controllers/clusters';
Expand Down Expand Up @@ -89,7 +89,6 @@ const routes: AppRoutes = {
'POST /api/table-column-preset/:ytAuthCluster': {handler: tableColumnPresetSave},

'GET /:ytAuthCluster/': HOME_INDEX_TARGET,
'GET /:ytAuthCluster/maintenance': {handler: homeRedirect},
'GET /:ytAuthCluster/:page': HOME_INDEX_TARGET,
'GET /:ytAuthCluster/:page/:tab': HOME_INDEX_TARGET,
'GET /:ytAuthCluster/:page/:operation/:tab': HOME_INDEX_TARGET,
Expand Down
11 changes: 5 additions & 6 deletions packages/ui/src/ui/containers/ClusterPage/ClusterPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import PropTypes from 'prop-types';
import cn from 'bem-cn-lite';

import BanPage from '../BanPage/BanPage';
import MaintenancePage from '../MaintenancePage/MaintenancePage';
import HandleMaintenanceRedirect from '../MaintenancePage/HandleRedirect';
import Components from '../../pages/components/Components/Components';
import Operations from '../../pages/operations/Operations/Operations';
import Accounts from '../../pages/accounts/Accounts/Accounts';
Expand All @@ -31,6 +29,7 @@ import ConnectionErrorRegion from '../../components/PreloaderErrors/ConnectionEr
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 {LOADING_STATUS, LOAD_ERROR, Page, SPLIT_PANE_ID} from '../../constants/index';
import {joinMenuItemsAction, splitMenuItemsAction, trackVisit} from '../../store/actions/menu';
Expand Down Expand Up @@ -222,11 +221,9 @@ class ClusterPage extends Component {
return isLoaded && !this.isParamsLoading() ? (
<Fragment>
<SupportedFeaturesUpdater />
<HandleMaintenanceRedirect />
<RedirectToBanIfNeededMemo to={`/${cluster}/${Page.BAN}`} />
<Switch>
<Route path={`/:cluster/${Page.BAN}`} component={BanPage} />
<Route path={`/:cluster/${Page.MAINTENANCE}`} component={MaintenancePage} />
<Route path={`/:cluster/${Page.COMPONENTS}`} component={Components} />
<Route path={`/:cluster/${Page.OPERATIONS}`} component={Operations} />
<Route path={`/:cluster/${Page.JOB}`} component={Job} />
Expand Down Expand Up @@ -296,7 +293,7 @@ class ClusterPage extends Component {
<ClusterPageStopRumMeasure />
<PageHeadByCluster cluster={cluster} />

<ClusterPageHeader />
<ClusterPageHeader cluster={cluster} />

<FlexSplitPane
className={b('panes-wrapper', {
Expand All @@ -320,7 +317,9 @@ class ClusterPage extends Component {
width: this.state.width,
})}
>
{this.renderContent(clusterConfig)}
<HandleMaintenance cluster={cluster}>
{this.renderContent(clusterConfig)}
</HandleMaintenance>
</div>

{null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
import React, {FC} from 'react';
import React from 'react';
import cn from 'bem-cn-lite';
import TopRowContent from '../AppNavigation/TopRowContent/TopRowContent';
import {useSelector} from 'react-redux';
import './ClusterPageHeader.scss';
import {getCluster, getCurrentClusterConfig} from '../../store/selectors/global';
import {ClusterPicker} from './ClusterPicker';
import {HeadSpacer} from './HeadSpacer';
import {getClusterConfigByName} from '../../store/selectors/global';
import HandleMaintenance from '../../containers/MaintenancePage/HandleMaintenance';

const block = cn('cluster-page-header');

const ClusterPageHeader: FC = () => {
const cluster = useSelector(getCluster);
const clusterConfig = useSelector(getCurrentClusterConfig);
function ClusterPageHeader({cluster}: {cluster: string}) {
const clusterConfig = getClusterConfigByName(cluster);

return (
<div className={block()}>
<ClusterPicker cluster={cluster} clusterConfig={clusterConfig} />
<HeadSpacer />
<TopRowContent />
<HandleMaintenance cluster={cluster} maintenanceContent={null}>
<TopRowContent />
</HandleMaintenance>
</div>
);
};
}

export default React.memo(ClusterPageHeader);
81 changes: 35 additions & 46 deletions packages/ui/src/ui/containers/MaintenancePage/HandleMaintenance.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,51 @@
import {withRouter} from 'react-router-dom';
import React, {Component} from 'react';
import {Redirect} from 'react-router';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {compose} from 'redux';

import MaintenancePage from '../../containers/MaintenancePage/MaintenancePage';

import {Page} from '../../constants/index';

class HandleRedirect extends Component {
static propTypes = {
location: PropTypes.object.isRequired,
cluster: PropTypes.string,
eventsFirstUpdate: PropTypes.bool.isRequired,
maintenancePageEvent: PropTypes.object,
};

shouldComponentUpdate(nextProps) {
const {location} = this.props;
const {eventsFirstUpdate, location: nextLocation} = nextProps;
const isDifferentLocation = location !== nextLocation;

return isDifferentLocation || eventsFirstUpdate;
}
import React from 'react';
import {ConnectedProps, connect} from 'react-redux';

import {MaintenancePage} from '../../containers/MaintenancePage/MaintenancePage';
import {RootState} from '../../store/reducers';
import {isMaintenanceIgnored, setMaintenanceIgnored} from '../../utils/maintenance';

type Props = {
cluster: string;
children: React.ReactNode;
maintenanceContent?: React.ReactNode;
};

type ReduxProps = ConnectedProps<typeof connector>;

class HandleMaintenance extends React.Component<Props & ReduxProps> {
render() {
const {location, cluster, maintenancePageEvent} = this.props;
const {cluster, maintenancePageEvent, maintenanceContent, children} = this.props;

if (maintenancePageEvent) {
const isMaintenancePage = MaintenancePage.checkMaintenancePageUrl(location);
const isIgnored = MaintenancePage.getBypassCookie(cluster);
const makeRedirect = Boolean(!isMaintenancePage && !isIgnored);

if (makeRedirect) {
const referrer = location.pathname + location.search;

return (
<Redirect
to={{
pathname: `/${cluster}/${Page.MAINTENANCE}`,
state: {referrer},
const isIgnored = isMaintenanceIgnored(cluster);

if (!isIgnored) {
return maintenanceContent !== undefined ? (
maintenanceContent
) : (
<MaintenancePage
cluster={cluster}
maintenancePageEvent={maintenancePageEvent}
onProceed={() => {
setMaintenanceIgnored(cluster);
this.forceUpdate();
}}
/>
);
}

return null;
}

return null;
return children;
}
}

const mapStateToProps = ({global}) => {
const {maintenancePageEvent, eventsFirstUpdate, cluster} = global;
const mapStateToProps = (state: RootState) => {
const {maintenancePageEvent, eventsFirstUpdate} = state.global;

return {maintenancePageEvent, eventsFirstUpdate, cluster};
return {maintenancePageEvent, eventsFirstUpdate};
};

export default compose(withRouter, connect(mapStateToProps))(HandleRedirect);
const connector = connect(mapStateToProps);

export default connector(HandleMaintenance);
Loading

0 comments on commit c7ed6e4

Please sign in to comment.