Skip to content

Commit

Permalink
[Visualize] Remove visualization:colorMapping advanced setting (#19…
Browse files Browse the repository at this point in the history
…7802)

## Summary

Fixes #193682 Removes the deprecated `visualization:colorMapping` advanced setting.
  • Loading branch information
mbondyra authored Nov 21, 2024
1 parent c842db5 commit 407f6be
Show file tree
Hide file tree
Showing 25 changed files with 128 additions and 864 deletions.
86 changes: 31 additions & 55 deletions dev_docs/tutorials/advanced_settings.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,23 @@ On the client, the `uiSettings` service is accessible directly from `core` and t
The following is a basic example for using the `uiSettings` service:

**src/plugins/charts/public/plugin.ts**

```ts
import { Plugin, CoreSetup } from '@kbn/core/public';
import { ExpressionsSetup } from '../../expressions/public';
import { ExpressionsSetup } from '@kbn/expressions-plugin/public';
import { palette, systemPalette } from '../common';

import { ThemeService, LegacyColorsService } from './services';
import { ThemeService } from './services';
import { PaletteService } from './services/palettes/service';
import { ActiveCursor } from './services/active_cursor';

export type Theme = Omit<ThemeService, 'init'>;
export type Color = Omit<LegacyColorsService, 'init'>;

interface SetupDependencies {
expressions: ExpressionsSetup;
}

/** @public */
export interface ChartsPluginSetup {
legacyColors: Color;
theme: Theme;
theme: Omit<ThemeService, 'init'>;
palettes: ReturnType<PaletteService['setup']>;
}

Expand All @@ -84,7 +81,6 @@ export type ChartsPluginStart = ChartsPluginSetup & {
/** @public */
export class ChartsPlugin implements Plugin<ChartsPluginSetup, ChartsPluginStart> {
private readonly themeService = new ThemeService();
private readonly legacyColorsService = new LegacyColorsService();
private readonly paletteService = new PaletteService();
private readonly activeCursor = new ActiveCursor();

Expand All @@ -93,29 +89,25 @@ export class ChartsPlugin implements Plugin<ChartsPluginSetup, ChartsPluginStart
public setup(core: CoreSetup, dependencies: SetupDependencies): ChartsPluginSetup {
dependencies.expressions.registerFunction(palette);
dependencies.expressions.registerFunction(systemPalette);
this.themeService.init(core.uiSettings);
this.legacyColorsService.init(core.uiSettings);
this.palettes = this.paletteService.setup(this.legacyColorsService);
this.themeService.init(core.theme);
this.palettes = this.paletteService.setup();

this.activeCursor.setup();

return {
legacyColors: this.legacyColorsService,
theme: this.themeService,
palettes: this.palettes,
};
}

public start(): ChartsPluginStart {
return {
legacyColors: this.legacyColorsService,
theme: this.themeService,
palettes: this.palettes!,
activeCursor: this.activeCursor,
};
}
}

```

### Server side usage
Expand All @@ -124,66 +116,50 @@ On the server side, `uiSettings` are accessible directly from `core`. The follow
The example also shows how plugins can leverage the optional deprecation parameter on registration for handling deprecation notices and renames. The deprecation warnings are rendered in the Advanced Settings UI and should also be added to the Configure Kibana guide.

<DocCallOut>
Refer to [the server-side uiSettings service API docs](https://github.com/elastic/kibana/blob/main/docs/development/core/server/kibana-plugin-core-server.iuisettingsclient.md)
Refer to [the server-side uiSettings service API
docs](https://github.com/elastic/kibana/blob/main/docs/development/core/server/kibana-plugin-core-server.iuisettingsclient.md)
</DocCallOut>

**src/plugins/charts/server/plugin.ts**
**src/plugins/dev_tools/server/plugin.ts**

```ts
import { i18n } from '@kbn/i18n';
import { schema } from '@kbn/config-schema';
import { CoreSetup, Plugin } from '@kbn/core/server';
import { COLOR_MAPPING_SETTING, LEGACY_TIME_AXIS, palette, systemPalette } from '../common';
import { ExpressionsServerSetup } from '../../expressions/server';
import { PluginInitializerContext, Plugin, CoreSetup } from '@kbn/core/server';

interface SetupDependencies {
expressions: ExpressionsServerSetup;
}
import { uiSettings } from './ui_settings';
export class DevToolsServerPlugin implements Plugin<object, object> {
constructor(initializerContext: PluginInitializerContext) {}

export class ChartsServerPlugin implements Plugin<object, object> {
public setup(core: CoreSetup, dependencies: SetupDependencies) {
dependencies.expressions.registerFunction(palette);
dependencies.expressions.registerFunction(systemPalette);
public setup(core: CoreSetup<object>) {
/**
* Register Dev Tools UI Settings
*/
core.uiSettings.register({
[COLOR_MAPPING_SETTING]: {
name: i18n.translate('charts.advancedSettings.visualization.colorMappingTitle', {
defaultMessage: 'Color mapping',
}),
value: JSON.stringify({
Count: '#00A69B',
}),
type: 'json',
description: i18n.translate('charts.advancedSettings.visualization.colorMappingText', {
[ENABLE_PERSISTENT_CONSOLE_UI_SETTING_ID]: {
category: [DEV_TOOLS_FEATURE_ID],
description: i18n.translate('devTools.uiSettings.persistentConsole.description', {
defaultMessage:
'Maps values to specific colors in charts using the <strong>Compatibility</strong> palette.',
'Enables a persistent console in the Kibana UI. This setting does not affect the standard Console in Dev Tools.',
}),
deprecation: {
message: i18n.translate(
'charts.advancedSettings.visualization.colorMappingTextDeprecation',
{
defaultMessage:
'This setting is deprecated and will not be supported in a future version.',
}
),
docLinksKey: 'visualizationSettings',
},
category: ['visualization'],
schema: schema.string(),
name: i18n.translate('devTools.uiSettings.persistentConsole.name', {
defaultMessage: 'Persistent Console',
}),
requiresPageReload: true,
schema: schema.boolean(),
value: true,
},
...
});

return {};
}

public start() {
return {};
}

public stop() {}
}
}
```
For optimal Kibana performance, `uiSettings` are cached. Any changes that require a cache refresh should use the `requiresPageReload` parameter on registration.

For optimal Kibana performance, `uiSettings` are cached. Any changes that require a cache refresh should use the `requiresPageReload` parameter on registration.

For example, changing the time filter refresh interval triggers a prompt in the UI that the page needs to be refreshed to save the new value:

Expand Down
7 changes: 2 additions & 5 deletions src/plugins/charts/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import { ChartsPlugin } from './plugin';
import { themeServiceMock } from './services/theme/mock';
import { activeCursorMock } from './services/active_cursor/mock';
import { colorsServiceMock } from './services/legacy_colors/mock';
import { getPaletteRegistry, paletteServiceMock } from './services/palettes/mock';

export { MOCK_SPARKLINE_THEME } from './services/theme/mock';
Expand All @@ -19,16 +18,14 @@ export type Setup = jest.Mocked<ReturnType<ChartsPlugin['setup']>>;
export type Start = jest.Mocked<ReturnType<ChartsPlugin['start']>>;

const createSetupContract = (): Setup => ({
legacyColors: colorsServiceMock,
theme: themeServiceMock,
palettes: paletteServiceMock.setup({} as any),
palettes: paletteServiceMock.setup(),
});

const createStartContract = (): Start => ({
legacyColors: colorsServiceMock,
theme: themeServiceMock,
activeCursor: activeCursorMock,
palettes: paletteServiceMock.setup({} as any),
palettes: paletteServiceMock.setup(),
});

export const chartPluginMock = {
Expand Down
9 changes: 2 additions & 7 deletions src/plugins/charts/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Plugin, CoreSetup } from '@kbn/core/public';
import { ExpressionsSetup } from '@kbn/expressions-plugin/public';
import { palette, systemPalette } from '../common';

import { ThemeService, LegacyColorsService } from './services';
import { ThemeService } from './services';
import { PaletteService } from './services/palettes/service';
import { ActiveCursor } from './services/active_cursor';

Expand All @@ -21,7 +21,6 @@ interface SetupDependencies {

/** @public */
export interface ChartsPluginSetup {
legacyColors: Omit<LegacyColorsService, 'init'>;
theme: Omit<ThemeService, 'init'>;
palettes: ReturnType<PaletteService['setup']>;
}
Expand All @@ -34,7 +33,6 @@ export type ChartsPluginStart = ChartsPluginSetup & {
/** @public */
export class ChartsPlugin implements Plugin<ChartsPluginSetup, ChartsPluginStart> {
private readonly themeService = new ThemeService();
private readonly legacyColorsService = new LegacyColorsService();
private readonly paletteService = new PaletteService();
private readonly activeCursor = new ActiveCursor();

Expand All @@ -44,21 +42,18 @@ export class ChartsPlugin implements Plugin<ChartsPluginSetup, ChartsPluginStart
dependencies.expressions.registerFunction(palette);
dependencies.expressions.registerFunction(systemPalette);
this.themeService.init(core.theme);
this.legacyColorsService.init(core.uiSettings);
this.palettes = this.paletteService.setup(this.legacyColorsService);
this.palettes = this.paletteService.setup();

this.activeCursor.setup();

return {
legacyColors: this.legacyColorsService,
theme: this.themeService,
palettes: this.palettes,
};
}

public start(): ChartsPluginStart {
return {
legacyColors: this.legacyColorsService,
theme: this.themeService,
palettes: this.palettes!,
activeCursor: this.activeCursor,
Expand Down
1 change: 0 additions & 1 deletion src/plugins/charts/public/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export { LegacyColorsService } from './legacy_colors';
export { ThemeService } from './theme';
export { ActiveCursor, useActiveCursor } from './active_cursor';
140 changes: 0 additions & 140 deletions src/plugins/charts/public/services/legacy_colors/colors.test.ts

This file was deleted.

Loading

0 comments on commit 407f6be

Please sign in to comment.