Skip to content

Commit

Permalink
Merge branch 'elastic:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ek-so authored Jan 20, 2025
2 parents 6ed3e0b + 8d2a43a commit 575ebf8
Show file tree
Hide file tree
Showing 112 changed files with 5,400 additions and 1,227 deletions.
3 changes: 3 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,6 @@ discover.enableUiSettingsValidations: true
xpack.dataUsage.enabled: true
# This feature is disabled in Serverless until fully tested within a Serverless environment
xpack.dataUsage.enableExperimental: ['dataUsageDisabled']

# Ensure Serverless is using the Amsterdam theme
uiSettings.experimental.defaultTheme: "amsterdam"
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import type { ThemeService } from '@kbn/core-theme-browser-internal';

const mockTheme: CoreTheme = {
darkMode: false,
name: 'amsterdam',
name: 'borealis',
};

const createThemeMock = (): CoreTheme => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { PluginName, DiscoveredPlugin } from '@kbn/core-base-common';
import type { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import type { EnvironmentMode, PackageInfo } from '@kbn/config';
import type { CustomBranding } from '@kbn/core-custom-branding-common';
import type { DarkModeValue } from '@kbn/core-ui-settings-common';
import type { DarkModeValue, ThemeName } from '@kbn/core-ui-settings-common';
import type { BrowserLoggingConfig } from '@kbn/core-logging-common-internal';

/** @internal */
Expand Down Expand Up @@ -41,7 +41,7 @@ export interface InjectedMetadataExternalUrlPolicy {
/** @internal */
export interface InjectedMetadataTheme {
darkMode: DarkModeValue;
name: string;
name: ThemeName;
version: ThemeVersion;
stylesheetPaths: {
default: string[];
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ const createPackageInfo = (parts: Partial<PackageInfo> = {}): PackageInfo => ({
});

const getClientGetMockImplementation =
({ darkMode, name }: { darkMode?: boolean; name?: string } = {}) =>
({ darkMode, name }: { darkMode?: boolean | string; name?: string } = {}) =>
(key: string) => {
switch (key) {
case 'theme:darkMode':
return Promise.resolve(darkMode ?? false);
case 'theme:name':
return Promise.resolve(name ?? 'amsterdam');
return Promise.resolve(name ?? 'borealis');
}
return Promise.resolve();
};
Expand All @@ -67,7 +67,7 @@ describe('bootstrapRenderer', () => {
packageInfo = createPackageInfo();
userSettingsService = userSettingsServiceMock.createSetupContract();

getThemeTagMock.mockReturnValue('v8light');
getThemeTagMock.mockReturnValue('borealislight');
getPluginsBundlePathsMock.mockReturnValue(new Map());
renderTemplateMock.mockReturnValue('__rendered__');
getJsDependencyPathsMock.mockReturnValue([]);
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});
Expand All @@ -141,7 +141,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand All @@ -167,7 +167,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});
Expand All @@ -192,7 +192,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand All @@ -217,7 +217,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand Down Expand Up @@ -247,7 +247,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});
Expand Down Expand Up @@ -290,13 +290,17 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: true,
});
});

it('calls getThemeTag with the correct parameters when darkMode is `system`', async () => {
uiSettingsClient.get.mockResolvedValue('system');
uiSettingsClient.get.mockImplementation(
getClientGetMockImplementation({
darkMode: 'system',
})
);

const request = httpServerMock.createKibanaRequest();

Expand All @@ -307,7 +311,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'system',
name: 'borealis',
darkMode: false,
});
});
Expand All @@ -321,15 +325,15 @@ describe('bootstrapRenderer', () => {
});
});

it('does not call uiSettingsClient.get', async () => {
it('does not call uiSettingsClient.get with `theme:darkMode`', async () => {
const request = httpServerMock.createKibanaRequest();

await renderer({
request,
uiSettingsClient,
});

expect(uiSettingsClient.get).not.toHaveBeenCalled();
expect(uiSettingsClient.get).not.toHaveBeenCalledWith('theme:darkMode');
});

it('calls getThemeTag with the default parameters', async () => {
Expand Down Expand Up @@ -367,7 +371,7 @@ describe('bootstrapRenderer', () => {

expect(getThemeTagMock).toHaveBeenCalledTimes(1);
expect(getThemeTagMock).toHaveBeenCalledWith({
name: 'v8',
name: 'borealis',
darkMode: false,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import { PackageInfo } from '@kbn/config';
import type { KibanaRequest, HttpAuth } from '@kbn/core-http-server';
import {
type DarkModeValue,
type ThemeName,
DEFAULT_THEME_NAME,
parseDarkModeValue,
parseThemeNameValue,
} from '@kbn/core-ui-settings-common';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-server';
import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
Expand Down Expand Up @@ -62,13 +64,11 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({

return async function bootstrapRenderer({ uiSettingsClient, request, isAnonymousPage = false }) {
let darkMode: DarkModeValue = false;
let themeName: string = DEFAULT_THEME_NAME;

if (packageInfo.buildFlavor !== 'serverless') {
themeName = 'borealis';
}
let themeName: ThemeName = DEFAULT_THEME_NAME;

try {
themeName = parseThemeNameValue(await uiSettingsClient.get('theme:name'));

const authenticated = isAuthenticated(request);

if (authenticated) {
Expand All @@ -79,8 +79,6 @@ export const bootstrapRendererFactory: BootstrapRendererFactory = ({
} else {
darkMode = parseDarkModeValue(await uiSettingsClient.get('theme:darkMode'));
}

themeName = await uiSettingsClient.get('theme:name');
}
} catch (e) {
// just use the default values in case of connectivity issues with ES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type { UiPlugins } from '@kbn/core-plugins-base-server-internal';
import type { CustomBranding } from '@kbn/core-custom-branding-common';
import {
type DarkModeValue,
type ThemeName,
parseDarkModeValue,
parseThemeNameValue,
type UiSettingsParams,
Expand Down Expand Up @@ -212,7 +213,7 @@ export class RenderingService {
darkMode = getSettingValue<DarkModeValue>('theme:darkMode', settings, parseDarkModeValue);
}

const themeName = getSettingValue<string>('theme:name', settings, parseThemeNameValue);
const themeName = getSettingValue<ThemeName>('theme:name', settings, parseThemeNameValue);

const themeStylesheetPaths = (mode: boolean) =>
getThemeStylesheetPaths({
Expand Down
Loading

0 comments on commit 575ebf8

Please sign in to comment.