Skip to content

Commit b8d8c73

Browse files
[Console Monaco Migration] Fix issue with different themes (#180321)
Fixes #180218 ## Summary This PR fixes the highlighting issue in the Monaco editor that is caused when using a theme in the output panel that is different from the theme in the editor. This fix is implemented by unifying the themes for both editors into one. The PR also fixes the issue with Console theme overwriting theme in other code editors (e.g. embeddable Console in the index detail tabs) by reusing the `euiTheme`. Note: This solution changes some of the original highlighting colors in Console (e.g. comments were green and now they are grey, background color is also different now). We might be able to fix the text colors by specifying unique token names in the Console language (e.g. using `consoleComment` instead of `comment` token name). cc: @yuliacech https://github.com/elastic/kibana/assets/59341489/d77d4ea3-61b5-43fa-81ef-7e4ac239aadd https://github.com/elastic/kibana/assets/59341489/1dab2eca-08e5-421b-acd4-38e0b3d91a3e <img width="1494" alt="Screenshot 2024-04-22 at 15 34 45" src="https://github.com/elastic/kibana/assets/59341489/a4241574-77ad-42db-8707-ae38761d52d0"> <!-- ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes&mdash;Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --> --------- Co-authored-by: Kibana Machine <[email protected]>
1 parent 5ea747c commit b8d8c73

File tree

12 files changed

+52
-129
lines changed

12 files changed

+52
-129
lines changed

packages/kbn-monaco/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export {
3636
CONSOLE_LANG_ID,
3737
CONSOLE_OUTPUT_LANG_ID,
3838
CONSOLE_THEME_ID,
39-
CONSOLE_OUTPUT_THEME_ID,
4039
getParsedRequestsProvider,
4140
ConsoleParsedRequestsProvider,
4241
} from './src/console';

packages/kbn-monaco/src/console/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@
99
export const CONSOLE_LANG_ID = 'console';
1010
export const CONSOLE_THEME_ID = 'consoleTheme';
1111
export const CONSOLE_OUTPUT_LANG_ID = 'consoleOutput';
12-
export const CONSOLE_OUTPUT_THEME_ID = 'consoleOutputTheme';
1312
export const CONSOLE_POSTFIX = '.console';

packages/kbn-monaco/src/console/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,9 @@ import {
2020
consoleOutputLanguageConfiguration,
2121
} from './lexer_rules';
2222

23-
export {
24-
CONSOLE_LANG_ID,
25-
CONSOLE_OUTPUT_LANG_ID,
26-
CONSOLE_THEME_ID,
27-
CONSOLE_OUTPUT_THEME_ID,
28-
} from './constants';
23+
export { CONSOLE_LANG_ID, CONSOLE_OUTPUT_LANG_ID, CONSOLE_THEME_ID } from './constants';
2924

30-
export { buildConsoleTheme, buildConsoleOutputTheme } from './theme';
25+
export { buildConsoleTheme } from './theme';
3126

3227
export const ConsoleLang: LangModuleType = {
3328
ID: CONSOLE_LANG_ID,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { makeHighContrastColor } from '@elastic/eui';
10+
import { euiThemeVars } from '@kbn/ui-theme';
11+
import { darkMode } from '@kbn/ui-theme';
12+
import { buildLightTheme, buildDarkTheme } from '../code_editor';
13+
import { themeRuleGroupBuilderFactory } from '../common/theme';
14+
import { monaco } from '../monaco_imports';
15+
16+
const buildRuleGroup = themeRuleGroupBuilderFactory();
17+
18+
const background = euiThemeVars.euiFormBackgroundColor;
19+
const booleanTextColor = '#585CF6';
20+
const methodTextColor = '#DD0A73';
21+
const urlTextColor = '#00A69B';
22+
export const buildConsoleTheme = (): monaco.editor.IStandaloneThemeData => {
23+
const euiTheme = darkMode ? buildDarkTheme() : buildLightTheme();
24+
return {
25+
...euiTheme,
26+
rules: [
27+
...euiTheme.rules,
28+
...buildRuleGroup(
29+
['string-literal', 'multi-string', 'punctuation.end-triple-quote'],
30+
makeHighContrastColor(euiThemeVars.euiColorDangerText)(background)
31+
),
32+
...buildRuleGroup(
33+
['constant.language.boolean'],
34+
makeHighContrastColor(booleanTextColor)(background)
35+
),
36+
...buildRuleGroup(
37+
['constant.numeric'],
38+
makeHighContrastColor(euiThemeVars.euiColorAccentText)(background)
39+
),
40+
...buildRuleGroup(['method'], makeHighContrastColor(methodTextColor)(background)),
41+
...buildRuleGroup(['url'], makeHighContrastColor(urlTextColor)(background)),
42+
],
43+
};
44+
};

packages/kbn-monaco/src/console/theme/editor_theme.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/kbn-monaco/src/console/theme/index.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/kbn-monaco/src/console/theme/output_theme.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/kbn-monaco/src/console/theme/shared.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/kbn-monaco/src/register_globals.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@ import { monaco } from './monaco_imports';
1313
import { ESQL_THEME_ID, ESQLLang, buildESQlTheme } from './esql';
1414
import { YAML_LANG_ID } from './yaml';
1515
import { registerLanguage, registerTheme } from './helpers';
16-
import {
17-
ConsoleLang,
18-
ConsoleOutputLang,
19-
CONSOLE_THEME_ID,
20-
CONSOLE_OUTPUT_THEME_ID,
21-
buildConsoleTheme,
22-
buildConsoleOutputTheme,
23-
} from './console';
16+
import { ConsoleLang, ConsoleOutputLang, CONSOLE_THEME_ID, buildConsoleTheme } from './console';
2417
import {
2518
CODE_EDITOR_LIGHT_THEME_ID,
2619
CODE_EDITOR_DARK_THEME_ID,
@@ -58,7 +51,6 @@ registerLanguage(ConsoleOutputLang);
5851
*/
5952
registerTheme(ESQL_THEME_ID, buildESQlTheme());
6053
registerTheme(CONSOLE_THEME_ID, buildConsoleTheme());
61-
registerTheme(CONSOLE_OUTPUT_THEME_ID, buildConsoleOutputTheme());
6254
registerTheme(CODE_EDITOR_LIGHT_THEME_ID, buildLightTheme());
6355
registerTheme(CODE_EDITOR_DARK_THEME_ID, buildDarkTheme());
6456
registerTheme(CODE_EDITOR_LIGHT_THEME_TRANSPARENT_ID, buildLightTransparentTheme());

packages/kbn-monaco/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@kbn/repo-info",
2727
"@kbn/ui-theme",
2828
"@kbn/esql-ast",
29-
"@kbn/esql-validation-autocomplete"
29+
"@kbn/esql-validation-autocomplete",
3030
],
3131
"exclude": [
3232
"target/**/*",

0 commit comments

Comments
 (0)