Skip to content

Commit

Permalink
[Visualizations] Get dark mode from core theme service (elastic#173715)
Browse files Browse the repository at this point in the history
## Summary

Part of elastic#173529

Correctly get the darkmode from the core theme
  • Loading branch information
stratoula authored Dec 21, 2023
1 parent b40b566 commit 34a3381
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/

import color from 'color';
import { getUISettings } from '../../services';

const isDarkTheme = () => getUISettings().get('theme:darkMode');
import { getCoreStart } from '../../services';

/**
* Returns true if the color that is passed has low luminosity
Expand All @@ -23,7 +21,7 @@ const isColorDark = (c) => {
* Defaults to checking `theme:darkMode`.
*/
export const isThemeDark = (currentTheme) => {
let themeIsDark = currentTheme || isDarkTheme();
let themeIsDark = currentTheme || getCoreStart().theme.getTheme().darkMode;

// If passing a string, check the luminosity
if (typeof currentTheme === 'string') {
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/vis_types/vega/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
setData,
setDataViews,
setInjectedVars,
setUISettings,
setThemeService,
setDocLinks,
setMapsEms,
setUsageCollectionStart,
Expand Down Expand Up @@ -77,8 +77,6 @@ export class VegaPlugin implements Plugin<void, void> {
enableExternalUrls: this.initializerContext.config.get().enableExternalUrls,
});

setUISettings(core.uiSettings);

const visualizationDependencies: Readonly<VegaVisualizationDependencies> = {
core,
plugins: {
Expand All @@ -104,6 +102,7 @@ export class VegaPlugin implements Plugin<void, void> {
setDataViews(dataViews);
setDocLinks(core.docLinks);
setMapsEms(mapsEms);
setThemeService(core.theme);
setUsageCollectionStart(usageCollection);
}
}
6 changes: 4 additions & 2 deletions src/plugins/vis_types/vega/public/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { NotificationsStart, IUiSettingsClient, DocLinksStart } from '@kbn/core/public';
import type { NotificationsStart, DocLinksStart, ThemeServiceStart } from '@kbn/core/public';

import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
Expand All @@ -22,7 +22,6 @@ export const [getDataViews, setDataViews] =
export const [getNotifications, setNotifications] =
createGetterSetter<NotificationsStart>('Notifications');

export const [getUISettings, setUISettings] = createGetterSetter<IUiSettingsClient>('UISettings');
export const [getMapsEms, setMapsEms] = createGetterSetter<MapsEmsPluginPublicStart>('mapsEms');

export const [getInjectedVars, setInjectedVars] = createGetterSetter<{
Expand All @@ -35,3 +34,6 @@ export const [getDocLinks, setDocLinks] = createGetterSetter<DocLinksStart>('doc

export const [getUsageCollectionStart, setUsageCollectionStart] =
createGetterSetter<UsageCollectionStart>('UsageCollection');

export const [getThemeService, setThemeService] =
createGetterSetter<ThemeServiceStart>('ThemeServiceStart');
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
setInjectedVars,
setData,
setNotifications,
setUISettings,
setThemeService,
setDataViews,
} from '../../services';
import { initVegaLayer, initTmsRasterLayer } from './layers';
Expand Down Expand Up @@ -121,7 +121,7 @@ describe('vega_map_view/view', () => {
setData(dataPluginStart);
setDataViews(dataViewsStart);
setNotifications(coreStart.notifications);
setUISettings(coreStart.uiSettings);
setThemeService(coreStart.theme);

async function createVegaMapView() {
await vegaParser.parseAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { maplibregl } from '@kbn/mapbox-gl';

import { initTmsRasterLayer, initVegaLayer } from './layers';
import { VegaBaseView } from '../vega_base_view';
import { getUISettings } from '../../services';
import { getThemeService } from '../../services';

import { defaultMapConfig, defaultMabBoxStyle, vegaLayerId } from './constants';
import { validateZoomSettings, injectMapPropsIntoSpec } from './utils';
Expand Down Expand Up @@ -98,7 +98,7 @@ export class VegaMapView extends VegaBaseView {
const { mapStyle, emsTileServiceId } = this._parser.mapConfig;
//
if (mapStyle) {
const isDarkMode: boolean = getUISettings().get('theme:darkMode');
const isDarkMode: boolean = getThemeService().getTheme().darkMode;
return emsTileServiceId
? emsTileServiceId
: await this._serviceSettings.getDefaultTmsLayer(isDarkMode);
Expand Down

0 comments on commit 34a3381

Please sign in to comment.