-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(MaintenancePage): rework maintenance activation
- Loading branch information
1 parent
9ef193c
commit c7ed6e4
Showing
8 changed files
with
112 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 9 additions & 8 deletions
17
packages/ui/src/ui/containers/ClusterPageHeader/ClusterPageHeader.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
81
packages/ui/src/ui/containers/MaintenancePage/HandleMaintenance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.