Skip to content

Commit

Permalink
[8.x] Preparation for High Contrast Mode, ResponseOps domains (#202610)…
Browse files Browse the repository at this point in the history
… (#204128)

# Backport

This will backport the following commits from `main` to `8.x`:
- [Preparation for High Contrast Mode, ResponseOps domains
(#202610)](#202610)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tim
Sullivan","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-12T20:34:44Z","message":"Preparation
for High Contrast Mode, ResponseOps domains (#202610)\n\n##
Summary\r\n\r\n**Reviewers: Please test the code paths affected by this
PR. See the\r\n\"Risks\" section below.**\r\n\r\nPart of work for
enabling \"high contrast mode\" in Kibana.
See\r\nhttps://github.com//issues/176219.\r\n\r\n**Background:**\r\nKibana
will soon have a user profile setting to allow users to enable\r\n\"high
contrast mode.\" This setting will activate a flag
with\r\n`<EuiProvider>` that causes EUI components to render with
higher\r\ncontrast visual elements. Consumer plugins and packages need
to be\r\nupdated selected places where `<EuiProvider>` is wrapped, to
pass the\r\n`UserProfileService` service dependency from the CoreStart
contract.\r\n\r\n**NOTE:** **EUI currently does not yet support the
high-contrast mode\r\nflag**, but support for that is expected to come
in around 2 weeks.\r\nThese first PRs are simply preparing the code by
wiring up the\r\n`UserProvideService`.\r\n\r\n### Checklist\r\n\r\nCheck
the PR satisfies following conditions. \r\n\r\nReviewers should verify
this PR satisfies this list as well.\r\n\r\n- [X] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [X] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Risks\r\n\r\nDoes this PR introduce any risks? For example, consider
risks like hard\r\nto test bugs, performance regression, potential of
data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for
each identified\r\nrisk. Invite stakeholders and evaluate how to proceed
before merging.\r\n\r\n- [ ] [medium/high] The implementor of this
change did not manually test\r\nthe affected code paths and relied on
type-checking and functional tests\r\nto drive the changes. Code owners
for this PR need to manually test the\r\naffected code paths.\r\n- [ ]
[medium] The `UserProfileService` dependency comes from the\r\nCoreStart
contract. If acquiring the service causes synchronous code to\r\nbecome
asynchronous, check for race conditions or errors in rendering\r\nReact
components. Code owners for this PR need to manually test
the\r\naffected code paths.\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"80160cbf8fe21b904fe109470ae96e1dc5d42052","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.18.0"],"number":202610,"url":"https://github.com/elastic/kibana/pull/202610","mergeCommit":{"message":"Preparation
for High Contrast Mode, ResponseOps domains (#202610)\n\n##
Summary\r\n\r\n**Reviewers: Please test the code paths affected by this
PR. See the\r\n\"Risks\" section below.**\r\n\r\nPart of work for
enabling \"high contrast mode\" in Kibana.
See\r\nhttps://github.com//issues/176219.\r\n\r\n**Background:**\r\nKibana
will soon have a user profile setting to allow users to enable\r\n\"high
contrast mode.\" This setting will activate a flag
with\r\n`<EuiProvider>` that causes EUI components to render with
higher\r\ncontrast visual elements. Consumer plugins and packages need
to be\r\nupdated selected places where `<EuiProvider>` is wrapped, to
pass the\r\n`UserProfileService` service dependency from the CoreStart
contract.\r\n\r\n**NOTE:** **EUI currently does not yet support the
high-contrast mode\r\nflag**, but support for that is expected to come
in around 2 weeks.\r\nThese first PRs are simply preparing the code by
wiring up the\r\n`UserProvideService`.\r\n\r\n### Checklist\r\n\r\nCheck
the PR satisfies following conditions. \r\n\r\nReviewers should verify
this PR satisfies this list as well.\r\n\r\n- [X] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [X] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Risks\r\n\r\nDoes this PR introduce any risks? For example, consider
risks like hard\r\nto test bugs, performance regression, potential of
data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for
each identified\r\nrisk. Invite stakeholders and evaluate how to proceed
before merging.\r\n\r\n- [ ] [medium/high] The implementor of this
change did not manually test\r\nthe affected code paths and relied on
type-checking and functional tests\r\nto drive the changes. Code owners
for this PR need to manually test the\r\naffected code paths.\r\n- [ ]
[medium] The `UserProfileService` dependency comes from the\r\nCoreStart
contract. If acquiring the service causes synchronous code to\r\nbecome
asynchronous, check for race conditions or errors in rendering\r\nReact
components. Code owners for this PR need to manually test
the\r\naffected code paths.\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"80160cbf8fe21b904fe109470ae96e1dc5d42052"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/202610","number":202610,"mergeCommit":{"message":"Preparation
for High Contrast Mode, ResponseOps domains (#202610)\n\n##
Summary\r\n\r\n**Reviewers: Please test the code paths affected by this
PR. See the\r\n\"Risks\" section below.**\r\n\r\nPart of work for
enabling \"high contrast mode\" in Kibana.
See\r\nhttps://github.com//issues/176219.\r\n\r\n**Background:**\r\nKibana
will soon have a user profile setting to allow users to enable\r\n\"high
contrast mode.\" This setting will activate a flag
with\r\n`<EuiProvider>` that causes EUI components to render with
higher\r\ncontrast visual elements. Consumer plugins and packages need
to be\r\nupdated selected places where `<EuiProvider>` is wrapped, to
pass the\r\n`UserProfileService` service dependency from the CoreStart
contract.\r\n\r\n**NOTE:** **EUI currently does not yet support the
high-contrast mode\r\nflag**, but support for that is expected to come
in around 2 weeks.\r\nThese first PRs are simply preparing the code by
wiring up the\r\n`UserProvideService`.\r\n\r\n### Checklist\r\n\r\nCheck
the PR satisfies following conditions. \r\n\r\nReviewers should verify
this PR satisfies this list as well.\r\n\r\n- [X] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [X] The PR
description includes the appropriate Release Notes section,\r\nand the
correct `release_note:*` label is applied per
the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n###
Risks\r\n\r\nDoes this PR introduce any risks? For example, consider
risks like hard\r\nto test bugs, performance regression, potential of
data loss.\r\n\r\nDescribe the risk, its severity, and mitigation for
each identified\r\nrisk. Invite stakeholders and evaluate how to proceed
before merging.\r\n\r\n- [ ] [medium/high] The implementor of this
change did not manually test\r\nthe affected code paths and relied on
type-checking and functional tests\r\nto drive the changes. Code owners
for this PR need to manually test the\r\naffected code paths.\r\n- [ ]
[medium] The `UserProfileService` dependency comes from the\r\nCoreStart
contract. If acquiring the service causes synchronous code to\r\nbecome
asynchronous, check for race conditions or errors in rendering\r\nReact
components. Code owners for this PR need to manually test
the\r\naffected code paths.\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"80160cbf8fe21b904fe109470ae96e1dc5d42052"}},{"branch":"8.x","label":"v8.18.0","labelRegex":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
tsullivan authored Dec 13, 2024
1 parent ada10e3 commit 3e96c57
Show file tree
Hide file tree
Showing 28 changed files with 124 additions and 68 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-alerts-ui-shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"@kbn/alerts-as-data-utils",
"@kbn/core-http-browser-mocks",
"@kbn/core-notifications-browser-mocks",
"@kbn/shared-ux-table-persist"
"@kbn/shared-ux-table-persist",
]
}
4 changes: 2 additions & 2 deletions packages/response-ops/rule_form/src/create_rule_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
onSubmit,
} = props;

const { http, docLinks, notifications, ruleTypeRegistry, i18n, theme } = plugins;
const { http, docLinks, notifications, ruleTypeRegistry, ...deps } = plugins;
const { toasts } = notifications;

const { mutate, isLoading: isSaving } = useCreateRule({
Expand All @@ -82,7 +82,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
...(message.details && {
text: toMountPoint(
<RuleFormCircuitBreakerError>{message.details}</RuleFormCircuitBreakerError>,
{ i18n, theme }
deps
),
}),
});
Expand Down
4 changes: 2 additions & 2 deletions packages/response-ops/rule_form/src/edit_rule_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
onCancel,
onSubmit,
} = props;
const { http, notifications, docLinks, ruleTypeRegistry, i18n, theme, application } = plugins;
const { http, notifications, docLinks, ruleTypeRegistry, application, ...deps } = plugins;
const { toasts } = notifications;

const { mutate, isLoading: isSaving } = useUpdateRule({
Expand All @@ -63,7 +63,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
...(message.details && {
text: toMountPoint(
<RuleFormCircuitBreakerError>{message.details}</RuleFormCircuitBreakerError>,
{ i18n, theme }
deps
),
}),
});
Expand Down
56 changes: 54 additions & 2 deletions packages/response-ops/rule_form/src/rule_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,46 @@ export interface RuleFormProps {
}

export const RuleForm = (props: RuleFormProps) => {
const { plugins, onCancel, onSubmit } = props;
const { plugins: _plugins, onCancel, onSubmit } = props;
const { id, ruleTypeId } = useParams<{
id?: string;
ruleTypeId?: string;
}>();

const {
http,
i18n,
theme,
userProfile,
application,
notifications,
charts,
settings,
data,
dataViews,
unifiedSearch,
docLinks,
ruleTypeRegistry,
actionTypeRegistry,
} = _plugins;

const ruleFormComponent = useMemo(() => {
const plugins = {
http,
i18n,
theme,
userProfile,
application,
notifications,
charts,
settings,
data,
dataViews,
unifiedSearch,
docLinks,
ruleTypeRegistry,
actionTypeRegistry,
};
if (id) {
return <EditRuleForm id={id} plugins={plugins} onCancel={onCancel} onSubmit={onSubmit} />;
}
Expand All @@ -60,7 +93,26 @@ export const RuleForm = (props: RuleFormProps) => {
}
/>
);
}, [id, ruleTypeId, plugins, onCancel, onSubmit]);
}, [
http,
i18n,
theme,
userProfile,
application,
notifications,
charts,
settings,
data,
dataViews,
unifiedSearch,
docLinks,
ruleTypeRegistry,
actionTypeRegistry,
id,
ruleTypeId,
onCancel,
onSubmit,
]);

return <QueryClientProvider client={queryClient}>{ruleFormComponent}</QueryClientProvider>;
};
2 changes: 2 additions & 0 deletions packages/response-ops/rule_form/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type { HttpStart } from '@kbn/core-http-browser';
import type { I18nStart } from '@kbn/core-i18n-browser';
import type { NotificationsStart } from '@kbn/core-notifications-browser';
import type { ThemeServiceStart } from '@kbn/core-theme-browser';
import type { UserProfileService } from '@kbn/core-user-profile-browser';
import type { SettingsStart } from '@kbn/core-ui-settings-browser';
import type { DataPublicPluginStart } from '@kbn/data-plugin/public';
import type { DataViewsPublicPluginStart } from '@kbn/data-views-plugin/public';
Expand Down Expand Up @@ -54,6 +55,7 @@ export interface RuleFormPlugins {
http: HttpStart;
i18n: I18nStart;
theme: ThemeServiceStart;
userProfile: UserProfileService;
application: ApplicationStart;
notifications: NotificationsStart;
charts: ChartsPluginSetup;
Expand Down
1 change: 1 addition & 0 deletions packages/response-ops/rule_form/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
"@kbn/kibana-react-plugin",
"@kbn/core-i18n-browser",
"@kbn/core-theme-browser",
"@kbn/core-user-profile-browser",
]
}
19 changes: 5 additions & 14 deletions x-pack/examples/triggers_actions_ui_example/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface TriggersActionsUiExampleComponentParams {
docLinks: CoreStart['docLinks'];
i18n: CoreStart['i18n'];
theme: CoreStart['theme'];
userProfile: CoreStart['userProfile'];
settings: CoreStart['settings'];
history: ScopedHistory;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
Expand All @@ -63,12 +64,11 @@ const TriggersActionsUiExampleApp = ({
notifications,
settings,
docLinks,
i18n,
theme,
data,
charts,
dataViews,
unifiedSearch,
...startServices
}: TriggersActionsUiExampleComponentParams) => {
return (
<Router history={history}>
Expand Down Expand Up @@ -193,15 +193,14 @@ const TriggersActionsUiExampleApp = ({
application,
notifications,
docLinks,
i18n,
theme,
charts,
data,
dataViews,
unifiedSearch,
settings,
ruleTypeRegistry: triggersActionsUi.ruleTypeRegistry,
actionTypeRegistry: triggersActionsUi.actionTypeRegistry,
...startServices,
}}
/>
</Page>
Expand All @@ -218,15 +217,14 @@ const TriggersActionsUiExampleApp = ({
application,
notifications,
docLinks,
theme,
i18n,
charts,
data,
dataViews,
unifiedSearch,
settings,
ruleTypeRegistry: triggersActionsUi.ruleTypeRegistry,
actionTypeRegistry: triggersActionsUi.actionTypeRegistry,
...startServices,
}}
/>
</Page>
Expand All @@ -245,7 +243,6 @@ export const renderApp = (
deps: TriggersActionsUiExamplePublicStartDeps,
{ appBasePath, element, history }: AppMountParameters
) => {
const { http, notifications, docLinks, application, i18n, theme, settings } = core;
const { triggersActionsUi } = deps;
const { ruleTypeRegistry, actionTypeRegistry } = triggersActionsUi;

Expand All @@ -263,19 +260,13 @@ export const renderApp = (
<IntlProvider locale="en">
<TriggersActionsUiExampleApp
history={history}
http={http}
notifications={notifications}
application={application}
docLinks={docLinks}
i18n={i18n}
theme={theme}
settings={settings}
triggersActionsUi={deps.triggersActionsUi}
data={deps.data}
charts={deps.charts}
dataViews={deps.dataViews}
dataViewsEditor={deps.dataViewsEditor}
unifiedSearch={deps.unifiedSearch}
{...core}
/>
</IntlProvider>
</QueryClientProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,11 @@ export const renderApp = ({
kibanaVersion: string;
}) => {
const { element, history } = mountParams;
const { i18n, theme } = core;

const queryClient = new QueryClient();

ReactDOM.render(
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...core}>
<KibanaContextProvider
services={{
...core,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/cases/public/common/lib/kibana/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { CoreStart } from '@kbn/core/public';
import type { CasesUiConfigType } from '../../../../common/ui/types';
import type { CasesPublicStartDependencies } from '../../../types';

type GlobalServices = Pick<CoreStart, 'application' | 'http' | 'theme'> &
type GlobalServices = Pick<CoreStart, 'application' | 'http' | 'theme' | 'userProfile'> &
Pick<CasesPublicStartDependencies, 'serverless'>;

export class KibanaServices {
Expand All @@ -23,12 +23,12 @@ export class KibanaServices {
http,
serverless,
kibanaVersion,
theme,
...startServices
}: GlobalServices & {
kibanaVersion: string;
config: CasesUiConfigType;
}) {
this.services = { application, http, theme, serverless };
this.services = { application, http, serverless, ...startServices };
this.kibanaVersion = kibanaVersion;
this.config = config;
}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/common/mock/test_providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ const TestProvidersComponent: React.FC<TestProviderProps> = ({
};

return (
<KibanaRenderContextProvider i18n={coreStart.i18n} theme={coreStart.theme}>
<KibanaRenderContextProvider {...coreStart}>
<KibanaContextProvider services={services}>
<MemoryRouter>
<CasesProvider value={casesProviderValue} queryClient={queryClient}>
Expand Down Expand Up @@ -178,7 +178,7 @@ export const createAppMockRenderer = ({
getFilesClient,
};
const AppWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
<KibanaRenderContextProvider i18n={coreStart.i18n} theme={coreStart.theme}>
<KibanaRenderContextProvider {...coreStart}>
<KibanaContextProvider services={services}>
<MemoryRouter>
<CasesProvider value={casesProviderValue} queryClient={queryClient}>
Expand Down
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/public/common/use_cases_toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const getErrorMessage = (error: Error | ServerError): string => {

export const useCasesToast = () => {
const { appId } = useApplication();
const { application, i18n, theme } = useKibana().services;
const { application, i18n, theme, userProfile } = useKibana().services;
const { getUrlForApp, navigateToUrl } = application;

const toasts = useToasts();
Expand Down Expand Up @@ -148,13 +148,13 @@ export const useCasesToast = () => {
return toasts.addSuccess({
color: 'success',
iconType: 'check',
title: toMountPoint(<TruncatedText text={renderTitle} />, { i18n, theme }),
title: toMountPoint(<TruncatedText text={renderTitle} />, { i18n, theme, userProfile }),
text: toMountPoint(
<CaseToastSuccessContent
content={renderContent}
onViewCaseClick={url != null ? onViewCaseClick : undefined}
/>,
{ i18n, theme }
{ i18n, theme, userProfile }
),
});
},
Expand All @@ -177,7 +177,7 @@ export const useCasesToast = () => {
});
},
}),
[i18n, theme, appId, getUrlForApp, navigateToUrl, toasts]
[i18n, theme, userProfile, appId, getUrlForApp, navigateToUrl, toasts]
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const ActionWrapperWithContext: React.FC<PropsWithChildren<Props>> = ({
casesActionContextProps,
currentAppId,
}) => {
const { application, i18n, theme } = useKibana().services;
const { application, ...startServices } = useKibana().services;

const owner = getCaseOwnerByAppId(currentAppId);
const casePermissions = canUseCases(application.capabilities)(owner ? [owner] : undefined);
// TODO: Remove when https://github.com/elastic/kibana/issues/143201 is developed
const syncAlerts = owner === SECURITY_SOLUTION_OWNER;

return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...startServices}>
<CasesProvider
value={{
...casesActionContextProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function openModal(
>
<AddExistingCaseModalWrapper lensApi={lensApi} onClose={onClose} onSuccess={onSuccess} />
</ActionWrapper>,
{ i18n: services.core.i18n, theme: services.core.theme }
services.core
);

mount(targetDomElement);
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/triggers_actions_ui/.storybook/decorator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const notifications: NotificationsStart = {
showErrorDialog: () => {},
};

const userProfile = { getUserProfile$: () => of(null) };

export const StorybookContextDecorator: FC<PropsWithChildren<StorybookContextDecoratorProps>> = (
props
) => {
Expand All @@ -75,7 +77,7 @@ export const StorybookContextDecorator: FC<PropsWithChildren<StorybookContextDec
return (
<I18nProvider>
<EuiThemeProvider darkMode={darkMode}>
<KibanaThemeProvider theme$={EMPTY}>
<KibanaThemeProvider theme$={EMPTY} userProfile={userProfile}>
<KibanaContextProvider
services={{
notifications,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export const renderApp = (deps: TriggersAndActionsUiServices) => {
};

export const App = ({ deps }: { deps: TriggersAndActionsUiServices }) => {
const { dataViews, i18n, theme } = deps;
const { dataViews } = deps;

setDataViewsService(dataViews);
return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...deps}>
<KibanaContextProvider services={{ ...deps }}>
<Router history={deps.history}>
<Routes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export const renderApp = (deps: TriggersAndActionsUiServices) => {
};

export const App = ({ deps }: { deps: TriggersAndActionsUiServices }) => {
const { dataViews, i18n, theme } = deps;
const { dataViews } = deps;
const sections: Section[] = ['connectors', 'logs'];
const sectionsRegex = sections.join('|');

setDataViewsService(dataViews);
return (
<KibanaRenderContextProvider i18n={i18n} theme={theme}>
<KibanaRenderContextProvider {...deps}>
<KibanaContextProvider services={{ ...deps }}>
<Router history={deps.history}>
<QueryClientProvider client={queryClient}>
Expand Down
Loading

0 comments on commit 3e96c57

Please sign in to comment.