Skip to content

Commit

Permalink
Preparation for High Contrast Mode, Core/SharedUX domains (elastic#20…
Browse files Browse the repository at this point in the history
…2606)

## Summary

**Reviewers: Please test the code paths affected by this PR. See the
"Risks" section below.**

Part of work for enabling "high contrast mode" in Kibana. See
elastic#176219.

**Background:**
Kibana will soon have a user profile setting to allow users to enable
"high contrast mode." This setting will activate a flag with
`<EuiProvider>` that causes EUI components to render with higher
contrast visual elements. Consumer plugins and packages need to be
updated selected places where `<EuiProvider>` is wrapped, to pass the
`UserProfileService` service dependency from the CoreStart contract.

**NOTE:** **EUI currently does not yet support the high-contrast mode
flag**, but support for that is expected to come in around 2 weeks.
These first PRs are simply preparing the code by wiring up the
`UserProvideService`.

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [X] [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
- [X] The PR description includes the appropriate Release Notes section,
and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

### Risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified
risk. Invite stakeholders and evaluate how to proceed before merging.

- [ ] [medium/high] The implementor of this change did not manually test
the affected code paths and relied on type-checking and functional tests
to drive the changes. Code owners for this PR need to manually test the
affected code paths.
- [ ] [medium] The `UserProfileService` dependency comes from the
CoreStart contract. If acquiring the service causes synchronous code to
become asynchronous, check for race conditions or errors in rendering
React components. Code owners for this PR need to manually test the
affected code paths.

---------

Co-authored-by: kibanamachine <[email protected]>
tsullivan and kibanamachine authored Dec 5, 2024
1 parent 3579425 commit 6178e82
Showing 95 changed files with 514 additions and 164 deletions.
2 changes: 2 additions & 0 deletions examples/developer_examples/public/app.tsx
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ import {
AppMountParameters,
I18nStart,
ThemeServiceStart,
UserProfileService,
} from '@kbn/core/public';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { ExampleDefinition } from './types';
@@ -36,6 +37,7 @@ interface StartServices {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
userProfile: UserProfileService;
}

interface Props {
4 changes: 2 additions & 2 deletions examples/developer_examples/public/plugin.ts
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@ export class DeveloperExamplesPlugin implements Plugin<DeveloperExamplesSetup, v
async mount(params: AppMountParameters) {
const { renderApp } = await import('./app');
const [coreStart] = await core.getStartServices();
const { analytics, i18n, theme } = coreStart;
const { analytics, i18n, theme, userProfile } = coreStart;
return renderApp(
{
startServices: { analytics, i18n, theme },
startServices: { analytics, i18n, theme, userProfile },
examples,
navigateToApp: (appId: string) => coreStart.application.navigateToApp(appId),
getUrlForApp: (appId: string) => coreStart.application.getUrlForApp(appId),
6 changes: 4 additions & 2 deletions examples/routing_example/public/services.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import type {
CoreStart,
I18nStart,
ThemeServiceStart,
UserProfileService,
} from '@kbn/core/public';
import type { IHttpFetchError } from '@kbn/core-http-browser';
import {
@@ -25,6 +26,7 @@ interface StartServices {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
userProfile: UserProfileService;
}

export interface Services {
@@ -37,8 +39,8 @@ export interface Services {
}

export function getServices(core: CoreStart): Services {
const { analytics, i18n, theme } = core;
const startServices = { analytics, i18n, theme };
const { analytics, i18n, theme, userProfile } = core;
const startServices = { analytics, i18n, theme, userProfile };

return {
startServices,
2 changes: 1 addition & 1 deletion examples/ui_action_examples/public/hello_world_action.tsx
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import { toMountPoint } from '@kbn/react-kibana-mount';

export const ACTION_HELLO_WORLD = 'ACTION_HELLO_WORLD';

type StartServices = Pick<CoreStart, 'overlays' | 'analytics' | 'i18n' | 'theme'>;
type StartServices = Pick<CoreStart, 'overlays' | 'analytics' | 'i18n' | 'theme' | 'userProfile'>;

export const createHelloWorldActionDefinition = (
getStartServices: () => Promise<StartServices>
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ const DYNAMIC_ACTION_ID = `${ACTION_HELLO_WORLD}-Waldo`;

interface Props {
uiActionsStartService: UiActionsStart;
startServices: Pick<CoreStart, 'overlays' | 'analytics' | 'i18n' | 'theme'>;
startServices: Pick<CoreStart, 'overlays' | 'analytics' | 'i18n' | 'theme' | 'userProfile'>;
}

export const HelloWorldExample = ({ uiActionsStartService, startServices }: Props) => {
1 change: 1 addition & 0 deletions packages/cloud/connection_details/kibana/global.ts
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ export interface ConnectionDetailsGlobalDependencies {
http: CoreStart['http'];
application: CoreStart['application'];
overlays: CoreStart['overlays'];
userProfile: CoreStart['userProfile'];
};
plugins: {
cloud?: CloudStart;
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ export interface OpenConnectionDetailsParams {
i18n: CoreStart['i18n'];
analytics?: CoreStart['analytics'];
theme: CoreStart['theme'];
userProfile: CoreStart['userProfile'];
};
};
}
2 changes: 2 additions & 0 deletions packages/content-management/content_editor/src/services.tsx
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import type { I18nStart } from '@kbn/core-i18n-browser';
import type { MountPoint, OverlayRef } from '@kbn/core-mount-utils-browser';
import type { OverlayFlyoutOpenOptions } from '@kbn/core-overlays-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import { toMountPoint } from '@kbn/react-kibana-mount';

type NotifyFn = (title: JSX.Element, text?: string) => void;
@@ -68,6 +69,7 @@ interface ContentEditorStartServices {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
userProfile: UserProfileService;
}

/**
1 change: 1 addition & 0 deletions packages/content-management/content_editor/tsconfig.json
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@
"@kbn/test-jest-helpers",
"@kbn/react-kibana-mount",
"@kbn/content-management-user-profiles",
"@kbn/core-user-profile-browser",
],
"exclude": [
"target/**/*"
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import type { I18nStart } from '@kbn/core-i18n-browser';
import type { MountPoint, OverlayRef } from '@kbn/core-mount-utils-browser';
import type { OverlayFlyoutOpenOptions } from '@kbn/core-overlays-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileServiceStart } from '@kbn/core-user-profile-browser';
import type { UserProfileService, UserProfileServiceStart } from '@kbn/core-user-profile-browser';
import type { FormattedRelative } from '@kbn/i18n-react';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { RedirectAppLinksKibanaProvider } from '@kbn/shared-ux-link-redirect-app';
@@ -100,6 +100,7 @@ interface TableListViewStartServices {
analytics: Pick<AnalyticsServiceStart, 'reportEvent'>;
i18n: I18nStart;
theme: Pick<ThemeServiceStart, 'theme$'>;
userProfile: UserProfileService;
}

/**
8 changes: 4 additions & 4 deletions packages/core/apps/core-apps-browser-internal/src/core_app.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ import type {
import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import { renderApp as renderStatusApp } from './status';
import {
renderApp as renderErrorApp,
@@ -45,6 +46,7 @@ export interface CoreAppsServiceStartDeps {
analytics: AnalyticsServiceStart;
i18n: I18nStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
}

export class CoreAppsService {
@@ -86,9 +88,7 @@ export class CoreAppsService {
http,
notifications,
uiSettings,
analytics,
i18n,
theme,
...startDeps
}: CoreAppsServiceStartDeps) {
if (!application.history) {
return;
@@ -101,7 +101,7 @@ export class CoreAppsService {
uiSettings,
});

setupPublicBaseUrlConfigWarning({ docLinks, http, notifications, analytics, i18n, theme });
setupPublicBaseUrlConfigWarning({ docLinks, http, notifications, ...startDeps });
}

public stop() {
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import { httpServiceMock } from '@kbn/core-http-browser-mocks';
import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks';
import { notificationServiceMock } from '@kbn/core-notifications-browser-mocks';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { userProfileServiceMock } from '@kbn/core-user-profile-browser-mocks';

import { setupPublicBaseUrlConfigWarning } from './public_base_url';

@@ -22,12 +23,8 @@ describe('publicBaseUrl warning', () => {
const i18nStart = i18nServiceMock.createStartContract();
const analytics = analyticsServiceMock.createAnalyticsServiceStart();
const theme = themeServiceMock.createStartContract();
const startServices = {
notifications,
analytics,
i18n: i18nStart,
theme,
};
const userProfile = userProfileServiceMock.createStart();
const startServices = { notifications, analytics, i18n: i18nStart, theme, userProfile };
const addWarningToastSpy = jest.spyOn(notifications.toasts, 'addWarning');

beforeEach(() => {
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ import type { DocLinksStart } from '@kbn/core-doc-links-browser';
import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import type { InternalHttpStart } from '@kbn/core-http-browser-internal';
import type { NotificationsStart } from '@kbn/core-notifications-browser';
import { mountReactNode } from '@kbn/core-mount-utils-browser-internal';
@@ -35,6 +36,7 @@ interface Deps {
analytics: AnalyticsServiceStart;
i18n: I18nStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
}

export const setupPublicBaseUrlConfigWarning = ({
4 changes: 3 additions & 1 deletion packages/core/apps/core-apps-browser-internal/tsconfig.json
Original file line number Diff line number Diff line change
@@ -40,7 +40,9 @@
"@kbn/react-kibana-context-render",
"@kbn/core-analytics-browser-mocks",
"@kbn/core-i18n-browser-mocks",
"@kbn/core-theme-browser-mocks"
"@kbn/core-theme-browser-mocks",
"@kbn/core-user-profile-browser",
"@kbn/core-user-profile-browser-mocks"
],
"exclude": [
"target/**/*"
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@ import { customBrandingServiceMock } from '@kbn/core-custom-branding-browser-moc
import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { userProfileServiceMock } from '@kbn/core-user-profile-browser-mocks';
import { getAppInfo } from '@kbn/core-application-browser-internal';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import { findTestSubject } from '@kbn/test-jest-helpers';
@@ -55,6 +56,7 @@ function defaultStartDeps(availableApps?: App[], currentAppId?: string) {
analytics: analyticsServiceMock.createAnalyticsServiceStart(),
i18n: i18nServiceMock.createStartContract(),
theme: themeServiceMock.createStartContract(),
userProfile: userProfileServiceMock.createStart(),
application: applicationServiceMock.createInternalStartContract(currentAppId),
docLinks: docLinksServiceMock.createStartContract(),
http: httpServiceMock.createStartContract(),
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
"@kbn/core-theme-browser-mocks",
"@kbn/react-kibana-context-render",
"@kbn/recently-accessed",
"@kbn/core-user-profile-browser-mocks",
],
"exclude": [
"target/**/*",
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import { i18n } from '@kbn/i18n';
import { Subscription } from 'rxjs';
import type { AnalyticsServiceStart, AnalyticsServiceSetup } from '@kbn/core-analytics-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { IUiSettingsClient } from '@kbn/core-ui-settings-browser';
import type { OverlayStart } from '@kbn/core-overlays-browser';
@@ -29,6 +30,7 @@ export interface StartDeps {
i18n: I18nStart;
overlays: OverlayStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
analytics: AnalyticsServiceStart;
targetDomElement: HTMLElement;
}
@@ -62,36 +64,26 @@ export class NotificationsService {
return notificationSetup;
}

public start({
analytics,
i18n: i18nDep,
overlays,
theme,
targetDomElement,
}: StartDeps): NotificationsStart {
public start({ overlays, targetDomElement, ...startDeps }: StartDeps): NotificationsStart {
this.targetDomElement = targetDomElement;
const toastsContainer = document.createElement('div');
targetDomElement.appendChild(toastsContainer);

const eventReporter = new EventReporter({ analytics });
const eventReporter = new EventReporter({ analytics: startDeps.analytics });

return {
toasts: this.toasts.start({
eventReporter,
i18n: i18nDep,
overlays,
analytics,
theme,
targetDomElement: toastsContainer,
...startDeps,
}),
showErrorDialog: ({ title, error }) =>
showErrorDialog({
title,
error,
openModal: overlays.openModal,
analytics,
i18n: i18nDep,
theme,
...startDeps,
}),
};
}

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

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
@@ -14,6 +14,7 @@ import { mountWithIntl } from '@kbn/test-jest-helpers';
import { analyticsServiceMock } from '@kbn/core-analytics-browser-mocks';
import { ErrorToast } from './error_toast';
import { themeServiceMock } from '@kbn/core-theme-browser-mocks';
import { userProfileServiceMock } from '@kbn/core-user-profile-browser-mocks';
import { i18nServiceMock } from '@kbn/core-i18n-browser-mocks';

interface ErrorToastProps {
@@ -25,6 +26,7 @@ interface ErrorToastProps {
let openModal: jest.Mock;
const mockAnalytics = analyticsServiceMock.createAnalyticsServiceStart();
const mockTheme = themeServiceMock.createStartContract();
const mockUserProfile = userProfileServiceMock.createStart();
const mockI18n = i18nServiceMock.createStartContract();

beforeEach(() => (openModal = jest.fn()));
@@ -39,6 +41,7 @@ function render(props: ErrorToastProps = {}) {
analytics={mockAnalytics}
i18n={mockI18n}
theme={mockTheme}
userProfile={mockUserProfile}
/>
);
}
Original file line number Diff line number Diff line change
@@ -25,11 +25,13 @@ import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { OverlayStart } from '@kbn/core-overlays-browser';
import { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';

interface StartServices {
analytics: AnalyticsServiceStart;
i18n: I18nStart;
userProfile: UserProfileService;
theme: ThemeServiceStart;
}

@@ -62,7 +64,10 @@ export function showErrorDialog({
error,
openModal,
...startServices
}: Pick<ErrorToastProps, 'error' | 'title' | 'openModal' | 'analytics' | 'i18n' | 'theme'>) {
}: Pick<
ErrorToastProps,
'error' | 'title' | 'openModal' | 'analytics' | 'i18n' | 'userProfile' | 'theme'
>) {
let text = '';

if (isRequestError(error)) {
Loading

0 comments on commit 6178e82

Please sign in to comment.