Skip to content

Commit

Permalink
Preparation for High Contrast Mode, ML domain (#205540)
Browse files Browse the repository at this point in the history
## 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
#205411

**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 soon. 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.
  • Loading branch information
tsullivan authored Jan 7, 2025
1 parent 30c7ce6 commit bccf0c9
Show file tree
Hide file tree
Showing 31 changed files with 146 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const DatePickerWrapper: FC<DatePickerWrapperProps> = (props) => {
notifications: { toasts },
uiSettings: config,
uiSettingsKeys,
userProfile,
theme,
i18n: i18nStart,
} = useDatePickerContext();
Expand Down Expand Up @@ -221,7 +222,7 @@ export const DatePickerWrapper: FC<DatePickerWrapperProps> = (props) => {
}}
/>
</EuiButton>,
{ theme, i18n: i18nStart }
{ theme, i18n: i18nStart, userProfile }
),
},
{ toastLifeTimeMs: 30000 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import React, { createContext, useContext, type FC, type PropsWithChildren } fro

import type { UI_SETTINGS } from '@kbn/data-plugin/common';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { CoreSetup, I18nStart, IUiSettingsClient, ThemeServiceStart } from '@kbn/core/public';
import type {
CoreSetup,
I18nStart,
IUiSettingsClient,
ThemeServiceStart,
UserProfileService,
} from '@kbn/core/public';
import type { HttpStart } from '@kbn/core/public';

/**
Expand All @@ -28,6 +34,10 @@ export interface DatePickerDependencies {
* notifications service
*/
notifications: CoreSetup['notifications'];
/**
* Kibana Security User Profile Service
*/
userProfile: UserProfileService;
/**
* EUI theme
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,17 @@ export const DataDriftDetectionAppState: FC<DataDriftDetectionAppStateProps> = (
charts,
unifiedSearch,
};
const startServices = pick(coreStart, 'analytics', 'i18n', 'theme');
const startServices = pick(coreStart, 'analytics', 'i18n', 'theme', 'userProfile');
const datePickerDeps = {
...pick(services, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(services, [
'data',
'http',
'notifications',
'i18n',
'theme',
'userProfile',
'uiSettings',
]),
uiSettingsKeys: UI_SETTINGS,
};
const location = useLocation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const FieldStatisticsWrapper = (props: FieldStatisticTableEmbeddableProps) => {
const { overridableServices } = props;

const kibanaRenderServices = useMemo(
() => pick(coreStart, 'analytics', 'i18n', 'theme'),
() => pick(coreStart, 'analytics', 'i18n', 'theme', 'userProfile'),
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);
Expand All @@ -168,6 +168,7 @@ const FieldStatisticsWrapper = (props: FieldStatisticTableEmbeddableProps) => {
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,17 @@ export const IndexDataVisualizer: FC<Props> = ({
unifiedSearch,
};

const startServices = pick(coreStart, 'analytics', 'i18n', 'theme');
const startServices = pick(coreStart, 'analytics', 'i18n', 'theme', 'userProfile');
const datePickerDeps: DatePickerDependencies = {
...pick(services, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(services, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { AppDependencies } from '../app_dependencies';
import type { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public';
import { settingsServiceMock } from '@kbn/core-ui-settings-browser-mocks';
import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks';
import { userProfileServiceMock } from '@kbn/core-user-profile-browser-mocks';

const coreSetup = coreMock.createSetup();
const coreStart = coreMock.createStart();
Expand Down Expand Up @@ -92,6 +93,7 @@ const appDependencies: AppDependencies = {
storage: { get: jest.fn() } as unknown as Storage,
overlays: coreStart.overlays,
theme: themeServiceMock.createStartContract(),
userProfile: userProfileServiceMock.createStart(),
http: coreSetup.http,
history: {} as ScopedHistory,
share: { urlGenerators: { getUrlGenerator: jest.fn() } } as unknown as SharePluginStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
SavedObjectsStart,
ScopedHistory,
ThemeServiceStart,
UserProfileService,
} from '@kbn/core/public';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -57,6 +58,7 @@ export interface AppDependencies {
storage: Storage;
overlays: OverlayStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
history: ScopedHistory;
share: SharePluginStart;
spaces?: SpacesPluginStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export async function mountManagementSection(
i18n,
overlays,
theme,
userProfile,
savedObjects,
uiSettings,
settings,
Expand Down Expand Up @@ -79,6 +80,7 @@ export async function mountManagementSection(
notifications,
overlays,
theme,
userProfile,
savedObjects,
storage: localStorage,
uiSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,15 @@ export const Wizard: FC<WizardProps> = React.memo(({ cloneConfig, searchItems })
const stepsConfig = [stepDefine, stepDetails, stepCreate];

const datePickerDeps: DatePickerDependencies = {
...pick(appDependencies, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appDependencies, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice: showNodeInfo,
};
Expand Down
3 changes: 2 additions & 1 deletion x-pack/platform/plugins/private/transform/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
"@kbn/monaco",
"@kbn/json-schemas",
"@kbn/ml-field-stats-flyout",
"@kbn/ml-validators"
"@kbn/ml-validators",
"@kbn/core-user-profile-browser-mocks"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ export const ChangePointDetectionAppState: FC<ChangePointDetectionAppStateProps>
showFrozenDataTierChoice = true,
}) => {
const datePickerDeps: DatePickerDependencies = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ export const LogCategorizationAppState: FC<LogCategorizationAppStateProps> = ({
}

const datePickerDeps: DatePickerDependencies = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ export const LogCategorizationDiscoverWrapper: FC<LogCategorizationEmbeddableWra
const I18nContext = appContextValue.i18n.Context;

const datePickerDeps = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ export async function showCategorizeFlyout(
...coreStart,
...plugins,
};
const startServices = pick(coreStart, 'analytics', 'i18n', 'theme');
const startServices = pick(coreStart, 'analytics', 'i18n', 'theme', 'userProfile');
const datePickerDeps: DatePickerDependencies = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
]),
i18n,
uiSettingsKeys: UI_SETTINGS,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ export const LogRateAnalysisAppState: FC<LogRateAnalysisAppStateProps> = ({
const casesPermissions = appContextValue.cases?.helpers.canUseCases();

const datePickerDeps: DatePickerDependencies = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ export const LogRateAnalysisContentWrapper: FC<LogRateAnalysisContentWrapperProp
}

const datePickerDeps = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ export const ChangePointChartInitializer: FC<AnomalyChartsInitializerProps> = ({
} = appContextValue;

const datePickerDeps: DatePickerDependencies = {
...pick(appContextValue, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(appContextValue, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
HttpStart,
IUiSettingsClient,
ThemeServiceStart,
UserProfileService,
} from '@kbn/core/public';
import type { LensPublicStart } from '@kbn/lens-plugin/public';
import type { EmbeddableStart } from '@kbn/embeddable-plugin/public';
Expand Down Expand Up @@ -90,6 +91,10 @@ export interface AiopsAppContextValue {
* Usage collection.
*/
usageCollection?: UsageCollectionSetup;
/**
* User profile service.
*/
userProfile: UserProfileService;
/**
* Used to create deep links to other plugins.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const ChangePointDetectionWrapper: FC<ChangePointDetectionPropsWithDeps> = ({
}, [coreStart, pluginStart]);

const datePickerDeps = {
...pick(deps, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(deps, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'userProfile', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const LogRateAnalysisEmbeddableWrapperWithDeps: FC<LogRateAnalysisPropsWithDeps>
}, [coreStart, pluginStart]);

const datePickerDeps = {
...pick(deps, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(deps, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'userProfile', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const PatternAnalysisWrapper: FC<PatternAnalysisPropsWithDeps> = ({
}, [coreStart, pluginStart]);

const datePickerDeps = {
...pick(deps, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(deps, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'userProfile', 'i18n']),
uiSettingsKeys: UI_SETTINGS,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const ChangePointDetectionPage: FC = () => {
'uiSettings',
'unifiedSearch',
'usageCollection',
'userProfile',
]),
fieldStats: { useFieldStatsTrigger, FieldStatsFlyoutProvider },
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const LogCategorizationPage: FC = () => {
'uiActions',
'uiSettings',
'unifiedSearch',
'userProfile',
'embeddable',
'cases',
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export const LogRateAnalysisPage: FC = () => {
'theme',
'uiActions',
'uiSettings',
'userProfile',
'unifiedSearch',
'observabilityAIAssistant',
'embeddable',
Expand Down
12 changes: 10 additions & 2 deletions x-pack/platform/plugins/shared/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,17 @@ const App: FC<AppProps> = ({

if (!licenseReady || !mlCapabilities) return null;

const startServices = pick(coreStart, 'analytics', 'i18n', 'theme');
const startServices = pick(coreStart, 'analytics', 'i18n', 'theme', 'userProfile');
const datePickerDeps: DatePickerDependencies = {
...pick(services, ['data', 'http', 'notifications', 'theme', 'uiSettings', 'i18n']),
...pick(services, [
'data',
'http',
'notifications',
'theme',
'uiSettings',
'userProfile',
'i18n',
]),
uiSettingsKeys: UI_SETTINGS,
showFrozenDataTierChoice: !isServerless,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ export const StartUpdateDeploymentModal: FC<StartDeploymentModalProps> = ({
export const getUserInputModelDeploymentParamsProvider =
(
overlays: OverlayStart,
startServices: Pick<CoreStart, 'analytics' | 'i18n' | 'theme'>,
startServices: Pick<CoreStart, 'analytics' | 'i18n' | 'theme' | 'userProfile'>,
startModelDeploymentDocUrl: string,
cloudInfo: CloudInfo,
showNodeInfo: boolean,
Expand Down
Loading

0 comments on commit bccf0c9

Please sign in to comment.