Skip to content

Commit

Permalink
[Monitoring] Fix Set Up Monitoring redirect to setup mode (elastic#11…
Browse files Browse the repository at this point in the history
…4354) (elastic#114707)

* [Monitoring] Fix Set Up Monitoring redirect to setup mode

* Fix initt setup mode from route init
  • Loading branch information
Zacqary authored Oct 12, 2021
1 parent 8bd946e commit 5707a2b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { TabMenuItem, PageTemplateProps } from '../page_template';
import { ML_SUPPORTED_LICENSES } from '../../../../common/constants';

interface ElasticsearchTemplateProps extends PageTemplateProps {
cluster: any;
cluster?: any;
}

export const ElasticsearchTemplate: React.FC<ElasticsearchTemplateProps> = ({
Expand Down Expand Up @@ -43,7 +43,7 @@ export const ElasticsearchTemplate: React.FC<ElasticsearchTemplateProps> = ({
},
];

if (mlIsSupported(cluster.license)) {
if (cluster && mlIsSupported(cluster.license)) {
tabs.push({
id: 'ml',
label: i18n.translate('xpack.monitoring.esNavigation.jobsLinkText', {
Expand All @@ -53,7 +53,7 @@ export const ElasticsearchTemplate: React.FC<ElasticsearchTemplateProps> = ({
});
}

if (cluster.isCcrEnabled) {
if (cluster?.isCcrEnabled) {
tabs.push({
id: 'ccr',
label: i18n.translate('xpack.monitoring.esNavigation.ccrLinkText', {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/monitoring/public/application/route_init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Route, Redirect, useLocation } from 'react-router-dom';
import { useClusters } from './hooks/use_clusters';
import { GlobalStateContext } from './contexts/global_state_context';
import { getClusterFromClusters } from '../lib/get_cluster_from_clusters';
import { isInSetupMode } from './setup_mode';
import { LoadingPage } from './pages/loading_page';

export interface ComponentProps {
Expand All @@ -35,13 +36,12 @@ export const RouteInit: React.FC<RouteInitProps> = ({

const { clusters, loaded } = useClusters(clusterUuid, undefined, codePaths);

// TODO: we will need this when setup mode is migrated
// const inSetupMode = isInSetupMode();
const inSetupMode = isInSetupMode(undefined, globalState);

const cluster = getClusterFromClusters(clusters, globalState, unsetGlobalState);

// TODO: check for setupMode too when the setup mode is migrated
if (loaded && !cluster) {
if (loaded && !cluster && !inSetupMode) {
return <Redirect to="/no-data" />;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export * from './setup_mode';
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ export const initSetupModeState = async (
}
};

export const isInSetupMode = (context?: ISetupModeContext) => {
export const isInSetupMode = (context?: ISetupModeContext, gState: GlobalState = globalState) => {
if (context?.setupModeSupported === false) {
return false;
}
if (setupModeState.enabled) {
return true;
}

return globalState.inSetupMode;
return gState.inSetupMode;
};

export const isSetupModeFeatureEnabled = (feature: SetupModeFeature) => {
Expand Down

0 comments on commit 5707a2b

Please sign in to comment.