-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Stack Monitoring] Add setup mode to react app #110670
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e88232b
Show setup mode button and setup bottom bar
estermv 1f57167
Adapt setup mode in react components to work without angular
estermv 7a64971
Add setup mode data update to react app
estermv e50ac54
Add missing functions from setup mode
estermv aa4fcbb
Revert setup mode changes from react components
estermv 1759c25
remove some empty lines
estermv 15e9184
Merge branch 'master' into add-setup-mode
kibanamachine 3ed7ab9
Merge branch 'master' into add-setup-mode
kibanamachine 3961c51
Add setup button to monitoring toolbar
estermv eb02b51
Fix types
estermv File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
200 changes: 200 additions & 0 deletions
200
x-pack/plugins/monitoring/public/application/setup_mode/setup_mode.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 |
---|---|---|
@@ -0,0 +1,200 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from 'react-dom'; | ||
import { get, includes } from 'lodash'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { HttpStart } from 'kibana/public'; | ||
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public'; | ||
import { Legacy } from '../../legacy_shims'; | ||
import { SetupModeEnterButton } from '../../components/setup_mode/enter_button'; | ||
import { SetupModeFeature } from '../../../common/enums'; | ||
import { ISetupModeContext } from '../../components/setup_mode/setup_mode_context'; | ||
import { State as GlobalState } from '../../application/global_state_context'; | ||
|
||
function isOnPage(hash: string) { | ||
return includes(window.location.hash, hash); | ||
} | ||
|
||
let globalState: GlobalState; | ||
let httpService: HttpStart; | ||
|
||
interface ISetupModeState { | ||
enabled: boolean; | ||
data: any; | ||
callback?: (() => void) | null; | ||
hideBottomBar: boolean; | ||
} | ||
const setupModeState: ISetupModeState = { | ||
enabled: false, | ||
data: null, | ||
callback: null, | ||
hideBottomBar: false, | ||
}; | ||
|
||
export const getSetupModeState = () => setupModeState; | ||
|
||
export const setNewlyDiscoveredClusterUuid = (clusterUuid: string) => { | ||
globalState.cluster_uuid = clusterUuid; | ||
globalState.save?.(); | ||
}; | ||
|
||
export const fetchCollectionData = async (uuid?: string, fetchWithoutClusterUuid = false) => { | ||
const clusterUuid = globalState.cluster_uuid; | ||
const ccs = globalState.ccs; | ||
|
||
let url = '../api/monitoring/v1/setup/collection'; | ||
if (uuid) { | ||
url += `/node/${uuid}`; | ||
} else if (!fetchWithoutClusterUuid && clusterUuid) { | ||
url += `/cluster/${clusterUuid}`; | ||
} else { | ||
url += '/cluster'; | ||
} | ||
|
||
try { | ||
const response = await httpService.post(url, { | ||
body: JSON.stringify({ | ||
ccs, | ||
}), | ||
}); | ||
return response; | ||
} catch (err) { | ||
// TODO: handle errors | ||
throw new Error(err); | ||
} | ||
}; | ||
|
||
const notifySetupModeDataChange = () => setupModeState.callback && setupModeState.callback(); | ||
|
||
export const updateSetupModeData = async (uuid?: string, fetchWithoutClusterUuid = false) => { | ||
const data = await fetchCollectionData(uuid, fetchWithoutClusterUuid); | ||
setupModeState.data = data; | ||
const hasPermissions = get(data, '_meta.hasPermissions', false); | ||
if (!hasPermissions) { | ||
let text: string = ''; | ||
if (!hasPermissions) { | ||
text = i18n.translate('xpack.monitoring.setupMode.notAvailablePermissions', { | ||
defaultMessage: 'You do not have the necessary permissions to do this.', | ||
}); | ||
} | ||
|
||
Legacy.shims.toastNotifications.addDanger({ | ||
title: i18n.translate('xpack.monitoring.setupMode.notAvailableTitle', { | ||
defaultMessage: 'Setup mode is not available', | ||
}), | ||
text, | ||
}); | ||
return toggleSetupMode(false); | ||
} | ||
notifySetupModeDataChange(); | ||
|
||
const clusterUuid = globalState.cluster_uuid; | ||
if (!clusterUuid) { | ||
const liveClusterUuid: string = get(data, '_meta.liveClusterUuid'); | ||
const migratedEsNodes = Object.values(get(data, 'elasticsearch.byUuid', {})).filter( | ||
(node: any) => node.isPartiallyMigrated || node.isFullyMigrated | ||
); | ||
if (liveClusterUuid && migratedEsNodes.length > 0) { | ||
setNewlyDiscoveredClusterUuid(liveClusterUuid); | ||
} | ||
} | ||
}; | ||
|
||
export const hideBottomBar = () => { | ||
setupModeState.hideBottomBar = true; | ||
notifySetupModeDataChange(); | ||
}; | ||
export const showBottomBar = () => { | ||
setupModeState.hideBottomBar = false; | ||
notifySetupModeDataChange(); | ||
}; | ||
|
||
export const disableElasticsearchInternalCollection = async () => { | ||
const clusterUuid = globalState.cluster_uuid; | ||
const url = `../api/monitoring/v1/setup/collection/${clusterUuid}/disable_internal_collection`; | ||
try { | ||
const response = await httpService.post(url); | ||
return response; | ||
} catch (err) { | ||
// TODO: handle errors | ||
throw new Error(err); | ||
} | ||
}; | ||
|
||
export const toggleSetupMode = (inSetupMode: boolean) => { | ||
setupModeState.enabled = inSetupMode; | ||
globalState.inSetupMode = inSetupMode; | ||
globalState.save?.(); | ||
setSetupModeMenuItem(); | ||
notifySetupModeDataChange(); | ||
|
||
if (inSetupMode) { | ||
// Intentionally do not await this so we don't block UI operations | ||
updateSetupModeData(); | ||
} | ||
}; | ||
|
||
export const setSetupModeMenuItem = () => { | ||
if (isOnPage('no-data')) { | ||
return; | ||
} | ||
|
||
const enabled = !globalState.inSetupMode; | ||
const I18nContext = Legacy.shims.I18nContext; | ||
|
||
render( | ||
<KibanaContextProvider services={Legacy.shims.kibanaServices}> | ||
<I18nContext> | ||
<SetupModeEnterButton enabled={enabled} toggleSetupMode={toggleSetupMode} /> | ||
</I18nContext> | ||
</KibanaContextProvider>, | ||
document.getElementById('setupModeNav') | ||
); | ||
}; | ||
|
||
export const initSetupModeState = async ( | ||
state: GlobalState, | ||
http: HttpStart, | ||
callback?: () => void | ||
) => { | ||
globalState = state; | ||
httpService = http; | ||
if (callback) { | ||
setupModeState.callback = callback; | ||
} | ||
|
||
if (globalState.inSetupMode) { | ||
toggleSetupMode(true); | ||
} | ||
}; | ||
|
||
export const isInSetupMode = (context?: ISetupModeContext) => { | ||
if (context?.setupModeSupported === false) { | ||
return false; | ||
} | ||
if (setupModeState.enabled) { | ||
return true; | ||
} | ||
|
||
return globalState.inSetupMode; | ||
}; | ||
|
||
export const isSetupModeFeatureEnabled = (feature: SetupModeFeature) => { | ||
if (!setupModeState.enabled) { | ||
return false; | ||
} | ||
|
||
if (feature === SetupModeFeature.MetricbeatMigration) { | ||
if (Legacy.shims.isCloud) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
}; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/monitoring/public/application/setup_mode/setup_mode_renderer.d.ts
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 |
---|---|---|
@@ -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 const SetupModeRenderer: FunctionComponent<Props>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we renter into the div here rather than put a conditional component into the PageTemplate?
Also I noticed we now have two "setup" things, so guessing we should maybe move the
setupModeNav
intoMonitoringToolbar
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how it was done before and I don't know exactly why they did it that way.
When I added it, it just worked so I thought that changing it will take more time and it could introduce some bugs. I also think that everything related to setup mode needs to be refactored, both from a UX perspective (I'm not sure how intuitive it is for users...) and technically so we could improve everything together.