From 223c8765934cab5d801ff8f3fc7ed5bad3b239fd Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 17 Mar 2020 10:58:36 -0600 Subject: [PATCH] Add NP dark mode and toast handling. Some fixes --- x-pack/legacy/plugins/maps/public/kibana_services.js | 4 ++++ .../layers/sources/es_search_source/load_index_settings.js | 6 +++--- .../vector/components/symbol/vector_style_icon_editor.js | 6 +++--- .../public/layers/styles/vector/vector_style_defaults.js | 4 ++-- x-pack/legacy/plugins/maps/public/plugin.ts | 2 ++ 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 9a53f187b4e1be..e59bbeebd02f4b 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -52,6 +52,10 @@ let dataTimeFilter; export const setTimeFilter = timeFilter => (dataTimeFilter = timeFilter); export const getTimeFilter = () => dataTimeFilter; +let toast; +export const setToasts = notificationToast => (toast = notificationToast); +export const getToasts = () => toast; + export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js index 5723e52beacd0e..811291de26d351 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/load_index_settings.js @@ -9,8 +9,7 @@ import { DEFAULT_MAX_INNER_RESULT_WINDOW, INDEX_SETTINGS_API_PATH, } from '../../../../common/constants'; -import { getHttp } from '../../../kibana_services'; -import { toastNotifications } from 'ui/notify'; +import { getHttp, getToasts } from '../../../kibana_services'; import { i18n } from '@kbn/i18n'; let toastDisplayed = false; @@ -28,6 +27,7 @@ export async function loadIndexSettings(indexPatternTitle) { async function fetchIndexSettings(indexPatternTitle) { const http = getHttp(); + const toasts = getToasts(); try { const indexSettings = await http.fetch(`../${INDEX_SETTINGS_API_PATH}`, { method: 'GET', @@ -49,7 +49,7 @@ async function fetchIndexSettings(indexPatternTitle) { if (!toastDisplayed) { // Only show toast for first failure to avoid flooding user with warnings toastDisplayed = true; - toastNotifications.addWarning(warningMsg); + toasts.addWarning(warningMsg); } console.warn(warningMsg); return { diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js index d5ec09f5159540..36b6c1a76470ca 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/symbol/vector_style_icon_editor.js @@ -6,7 +6,7 @@ import React from 'react'; -import chrome from 'ui/chrome'; +import { getUiSettings } from '../../../../../kibana_services'; import { StylePropEditor } from '../style_prop_editor'; import { DynamicIconForm } from './dynamic_icon_form'; import { StaticIconForm } from './static_icon_form'; @@ -16,13 +16,13 @@ export function VectorStyleIconEditor(props) { const iconForm = props.styleProperty.isDynamic() ? ( ) : ( ); diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js index 8bc397dd98b56a..956390e051b82f 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/vector_style_defaults.js @@ -12,7 +12,7 @@ import { DEFAULT_FILL_COLORS, DEFAULT_LINE_COLORS, } from '../color_utils'; -import chrome from 'ui/chrome'; +import { getUiSettings } from '../../../kibana_services'; export const MIN_SIZE = 1; export const MAX_SIZE = 64; @@ -67,7 +67,7 @@ export function getDefaultStaticProperties(mapColors = []) { const nextFillColor = DEFAULT_FILL_COLORS[nextColorIndex]; const nextLineColor = DEFAULT_LINE_COLORS[nextColorIndex]; - const isDarkMode = chrome.getUiSettingsClient().get('theme:darkMode', false); + const isDarkMode = getUiSettings().get('theme:darkMode', false); return { [VECTOR_STYLES.ICON]: { diff --git a/x-pack/legacy/plugins/maps/public/plugin.ts b/x-pack/legacy/plugins/maps/public/plugin.ts index 3ed0e4a48ca7cd..a33136753a994c 100644 --- a/x-pack/legacy/plugins/maps/public/plugin.ts +++ b/x-pack/legacy/plugins/maps/public/plugin.ts @@ -19,6 +19,7 @@ import { setTimeFilter, setUiSettings, setInjectedVarFunc, + setToasts, } from './kibana_services'; import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public'; import { LicensingPluginSetup } from '../../../../plugins/licensing/public'; @@ -61,6 +62,7 @@ export const bindSetupCoreAndPlugins = (core: CoreSetup, plugins: any) => { setHttp(http); setUiSettings(core.uiSettings); setInjectedVarFunc(core.injectedMetadata.getInjectedVar); + setToasts(core.notifications.toasts); }; export const bindStartCoreAndPlugins = (core: CoreStart, plugins: any) => {