-
Notifications
You must be signed in to change notification settings - Fork 61
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
Implement Wazuh custom UI theme #417
Comments
Research 2024/12/23I have been researching to implement the Wazuh custom UI theme. I reviewed the PRs (#7757) (#7775) where the v9 theme of OpenSearch-Dashboards was added, and read the
diff --git a/packages/osd-ui-shared-deps/theme_config.d.ts b/packages/osd-ui-shared-deps/theme_config.d.ts
index 080611cddc..d01edddd8c 100644
--- a/packages/osd-ui-shared-deps/theme_config.d.ts
+++ b/packages/osd-ui-shared-deps/theme_config.d.ts
@@ -6,7 +6,7 @@
/**
* Types for valid theme versions
*/
-type ThemeVersion = 'v7' | 'v8' | 'v9';
+type ThemeVersion = 'v7' | 'v8' | 'v9' | 'wazuh';
/**
* Types for valid theme color-scheme modes
@@ -17,7 +17,15 @@ type ThemeMode = 'light' | 'dark';
* Types for valid theme tags (themeVersion + themeMode)
* Note: used by @osd/optimizer
*/
-export type ThemeTag = 'v7light' | 'v7dark' | 'v8light' | 'v8dark' | 'v9light' | 'v9dark';
+export type ThemeTag =
+ | 'v7light'
+ | 'v7dark'
+ | 'v8light'
+ | 'v8dark'
+ | 'v9light'
+ | 'v9dark'
+ | 'wazuhlight'
+ | 'wazuhdark';
export type ThemeTags = readonly ThemeTag[];
/**
diff --git a/packages/osd-ui-shared-deps/theme_config.js b/packages/osd-ui-shared-deps/theme_config.js
index ad782d98b2..0372766ddb 100644
--- a/packages/osd-ui-shared-deps/theme_config.js
+++ b/packages/osd-ui-shared-deps/theme_config.js
@@ -16,6 +16,7 @@ const THEME_VERSION_LABEL_MAP = {
v7: 'v7',
v8: 'Next (preview)',
v9: 'v9 (preview)',
+ wazuh: 'Wazuh',
};
const THEME_VERSION_VALUE_MAP = {
// allow version lookup by label ...
@@ -56,4 +57,5 @@ exports.kuiCssDistFilenames = {
v7: { dark: 'kui_dark.css', light: 'kui_light.css' },
v8: { dark: 'kui_next_dark.css', light: 'kui_next_light.css' },
v9: { dark: 'kui_v9_dark.css', light: 'kui_v9_light.css' },
+ wazuh: { dark: 'kui_wazuh_dark.css', light: 'kui_wazuh_light.css' },
};
diff --git a/packages/osd-ui-shared-deps/theme.ts b/packages/osd-ui-shared-deps/theme.ts
index 965e1aa928..55ca389df7 100644
--- a/packages/osd-ui-shared-deps/theme.ts
+++ b/packages/osd-ui-shared-deps/theme.ts
@@ -35,10 +35,12 @@ const globals: any = typeof window === 'undefined' ? {} : window;
export type Theme = typeof LightTheme;
+const DEFAULT_THEME = 'wazuh';
+
// in the OpenSearch Dashboards app we can rely on this global being defined, but in
// some cases (like jest) the global is undefined
export const tag: string = globals.__osdThemeTag__;
-const themeVersion = tag?.replace(/(light|dark)$/, '') || 'v7';
+const themeVersion = tag?.replace(/(light|dark)$/, '') || DEFAULT_THEME;
export const version = parseInt(themeVersion.replace(/[^\d]+/g, ''), 10) || 8;
export const darkMode = tag?.endsWith?.('dark');
@@ -50,6 +52,9 @@ if (themeVersion === 'v7') {
} else if (themeVersion === 'v9') {
euiLightVars = require('@elastic/eui/dist/eui_theme_v9_light.json');
euiDarkVars = require('@elastic/eui/dist/eui_theme_v9_dark.json');
+} else if (themeVersion === DEFAULT_THEME) {
+ euiLightVars = require('@elastic/eui/dist/eui_theme_wazuh_light.json');
+ euiDarkVars = require('@elastic/eui/dist/eui_theme_wazuh_dark.json');
} else {
euiLightVars = require('@elastic/eui/dist/eui_theme_next_light.json');
euiDarkVars = require('@elastic/eui/dist/eui_theme_next_dark.json');
diff --git a/packages/osd-ui-framework/Gruntfile.js b/packages/osd-ui-framework/Gruntfile.js
index e6c580f91b..2c895b80d2 100644
--- a/packages/osd-ui-framework/Gruntfile.js
+++ b/packages/osd-ui-framework/Gruntfile.js
@@ -99,6 +99,8 @@ module.exports = function (grunt) {
uiFrameworkCompile('src/kui_next_dark.scss', 'dist/kui_next_dark.css'),
uiFrameworkCompile('src/kui_v9_light.scss', 'dist/kui_v9_light.css'),
uiFrameworkCompile('src/kui_v9_dark.scss', 'dist/kui_v9_dark.css'),
+ uiFrameworkCompile('src/kui_wazuh_light.scss', 'dist/kui_wazuh_light.css'),
+ uiFrameworkCompile('src/kui_wazuh_dark.scss', 'dist/kui_wazuh_dark.css'),
]).then(done);
});
}; The following Add // EUI global scope is used for KUI variables till fully deprecated
@import "../../../node_modules/@elastic/eui/src/global_styling/functions/index";
@import "../../../node_modules/@elastic/eui/src/global_styling/variables/index";
@import "../../../node_modules/@elastic/eui/src/global_styling/mixins/index";
// Configuration
@import "global_styling/variables/index";
// Coreß
@import "global_styling/mixins/index";
@import "global_styling/reset/index";
// Components
@import "components/index"; Add // EUI global scope is used for KUI variables till fully deprecated
@import "../../../node_modules/@elastic/eui/src/global_styling/functions/index";
@import "../../../node_modules/@elastic/eui/src/global_styling/variables/index";
@import "../../../node_modules/@elastic/eui/src/global_styling/mixins/index";
// Configuration
@import "global_styling/variables/index";
// Core
@import "global_styling/mixins/index";
@import "global_styling/reset/index";
// Components
@import "components/index";
diff --git a/src/core/server/ui_settings/ui_settings_config.ts b/src/core/server/ui_settings/ui_settings_config.ts
index 1a0c0e48f5..98b90608b7 100644
--- a/src/core/server/ui_settings/ui_settings_config.ts
+++ b/src/core/server/ui_settings/ui_settings_config.ts
@@ -37,7 +37,7 @@ const deprecations: ConfigDeprecationProvider = ({ unused, renameFromRoot }) =>
renameFromRoot('server.defaultRoute', 'uiSettings.overrides.defaultRoute'),
];
-export const DEFAULT_THEME_VERSION = 'v7';
+export const DEFAULT_THEME_VERSION = 'wazuh';
/* There are 4 levels of uiSettings:
* 1) defaults hardcoded in code
diff --git a/src/core/server/ui_settings/settings/theme.ts b/src/core/server/ui_settings/settings/theme.ts
index 001a693d62..81328bbf1c 100644
--- a/src/core/server/ui_settings/settings/theme.ts
+++ b/src/core/server/ui_settings/settings/theme.ts
@@ -35,11 +35,11 @@ import type { Type } from '@osd/config-schema';
import { UiSettingsParams } from '../../../types';
import { DEFAULT_THEME_VERSION } from '../ui_settings_config';
-// Setup theme options to be backwards compatible with the fact that v8 was persisted with its
+// Setup theme options to be backwards compatible with the fact that `wazuh` was persisted with its
// label rather than with the correct themeVersion value
const THEME_VERSIONS = Object.keys(themeVersionLabelMap);
-const THEME_SCHEMA_VALUES = THEME_VERSIONS.concat(themeVersionLabelMap.v8);
-const THEME_OPTIONS = THEME_VERSIONS.map((v) => (v !== 'v8' ? v : themeVersionLabelMap.v8));
+const THEME_SCHEMA_VALUES = THEME_VERSIONS.concat(themeVersionLabelMap.wazuh);
+const THEME_OPTIONS = THEME_VERSIONS.map((v) => (v !== 'wazuh' ? v : themeVersionLabelMap.wazuh));
export const getThemeSettings = (): Record<string, UiSettingsParams> => {
return {
@@ -60,7 +60,7 @@ export const getThemeSettings = (): Record<string, UiSettingsParams> => {
defaultMessage: 'Theme version',
}),
value:
- DEFAULT_THEME_VERSION === 'v7'
+ DEFAULT_THEME_VERSION === 'wazuh'
? themeVersionLabelMap[DEFAULT_THEME_VERSION]
: DEFAULT_THEME_VERSION,
type: 'select', It is necessary to modify some files with references to files located in diff --git a/packages/osd-ui-shared-deps/webpack.config.js b/packages/osd-ui-shared-deps/webpack.config.js
index 8a9e50dd05..883525c692 100644
--- a/packages/osd-ui-shared-deps/webpack.config.js
+++ b/packages/osd-ui-shared-deps/webpack.config.js
@@ -49,6 +49,8 @@ exports.getWebpackConfig = ({ dev = false } = {}) => ({
'osd-ui-shared-deps.v8.light': ['@elastic/eui/dist/eui_theme_next_light.css'],
'osd-ui-shared-deps.v9.dark': ['@elastic/eui/dist/eui_theme_v9_dark.css'],
'osd-ui-shared-deps.v9.light': ['@elastic/eui/dist/eui_theme_v9_light.css'],
+ 'osd-ui-shared-deps.wazuh.light': ['@elastic/eui/dist/eui_theme_wazuh_light.css'],
+ 'osd-ui-shared-deps.wazuh.dark': ['@elastic/eui/dist/eui_theme_wazuh_dark.css'],
},
context: __dirname,
devtool: dev ? '#cheap-source-map' : false,
diff --git a/src/core/server/rendering/views/theme.ts b/src/core/server/rendering/views/theme.ts
index ee628a856f..173da48e46 100644
--- a/src/core/server/rendering/views/theme.ts
+++ b/src/core/server/rendering/views/theme.ts
@@ -22,10 +22,14 @@ export const THEME_SOURCES: {
[ThemeColorSchemes.LIGHT]: '@elastic/eui/dist/eui_theme_v9_light.json',
[ThemeColorSchemes.DARK]: '@elastic/eui/dist/eui_theme_v9_dark.json',
},
- default: {
+ v8: {
[ThemeColorSchemes.LIGHT]: '@elastic/eui/dist/eui_theme_next_light.json',
[ThemeColorSchemes.DARK]: '@elastic/eui/dist/eui_theme_next_dark.json',
},
+ default: {
+ [ThemeColorSchemes.LIGHT]: '@elastic/eui/dist/eui_theme_wazuh_light.json',
+ [ThemeColorSchemes.DARK]: '@elastic/eui/dist/eui_theme_wazuh_dark.json',
+ },
});
export const getThemeDefinitionSource = ( Then, you should run The following files are required by webpack: Add @import "@elastic/eui/src/themes/wazuh/wazuh_globals";
@import "./mixins"; Add @import "@elastic/eui/src/themes/wazuh/wazuh_globals";
@import "./mixins"; The files SummaryIn summary, the changes made aim to implement a custom Wazuh theme in OpenSearch Dashboards. The adjustments include:
|
Analysis of the pros and cons of copying generated files for manual editing versus forking the project to compile files from the code1. Copying and manually editing the generated filesAdvantages:
Disadvantages:
2. Forking the project and generating the compiled filesAdvantages:
Disadvantages:
ConclusionSince the goal is to maintain the customized theme long-term and ensure smooth integration with future updates of the OUI project, the best strategy is to fork, as it provides consistency, automation, and traceability. |
Description
As part of the objective Dashboard revamp, we want to implement a customized theme for the Wazuh dashboard UI. To achieve this, we have to follow the guidelines of a standard OpenSearch UI components library so we can integrate the theme as seamlessly as possible into the Wazuh dashboard platform.
Objective:
Functional requirements
Tasks
The text was updated successfully, but these errors were encountered: