[8.x] make emotion typing global (#200958) (#203162)

# Backport

This will backport the following commits from `main` to `8.x`:
- [make emotion typing global
(#200958)](https://github.com/elastic/kibana/pull/200958)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Eyo O.
Eyo","email":"7893459+eokoneyo@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-05T18:20:43Z","message":"make
emotion typing global (#200958)\n\n## Summary\r\n\r\nInformed
by\r\nhttps://github.com/elastic/eui/discussions/6828#discussioncomment-11247425,\r\ncloses
https://github.com/elastic/kibana-team/issues/1299\r\n\r\nThis PR
consolidates typings to provide adequate typing for the `css`\r\nprop
EUI components accept. Placing the required typing file in the\r\ntyping
directory means that all other plugins that already reference\r\nthis
directory in their `tsconfig.json` would get this improvement
by\r\ndefault.\r\n\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- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [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- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` 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###
Identify 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- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...\r\n\r\n\r\n-->","sha":"c5cc1532d74e8d733f57329959253e698105b447","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:SharedUX","backport:prev-minor","ci:project-deploy-observability","Team:obs-ux-management"],"title":"make
emotion typing
global","number":200958,"url":"https://github.com/elastic/kibana/pull/200958","mergeCommit":{"message":"make
emotion typing global (#200958)\n\n## Summary\r\n\r\nInformed
by\r\nhttps://github.com/elastic/eui/discussions/6828#discussioncomment-11247425,\r\ncloses
https://github.com/elastic/kibana-team/issues/1299\r\n\r\nThis PR
consolidates typings to provide adequate typing for the `css`\r\nprop
EUI components accept. Placing the required typing file in the\r\ntyping
directory means that all other plugins that already reference\r\nthis
directory in their `tsconfig.json` would get this improvement
by\r\ndefault.\r\n\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- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [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- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` 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###
Identify 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- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...\r\n\r\n\r\n-->","sha":"c5cc1532d74e8d733f57329959253e698105b447"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200958","number":200958,"mergeCommit":{"message":"make
emotion typing global (#200958)\n\n## Summary\r\n\r\nInformed
by\r\nhttps://github.com/elastic/eui/discussions/6828#discussioncomment-11247425,\r\ncloses
https://github.com/elastic/kibana-team/issues/1299\r\n\r\nThis PR
consolidates typings to provide adequate typing for the `css`\r\nprop
EUI components accept. Placing the required typing file in the\r\ntyping
directory means that all other plugins that already reference\r\nthis
directory in their `tsconfig.json` would get this improvement
by\r\ndefault.\r\n\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- [ ] Any text added follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [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- [ ] If a plugin
configuration key changed, check if it needs to be\r\nallowlisted in the
cloud and added to the
[docker\r\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)\r\n-
[ ] This was checked for breaking HTTP API changes, and any
breaking\r\nchanges have been approved by the breaking-change committee.
The\r\n`release_note:breaking` label should be applied in these
situations.\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [ ] The PR description includes
the appropriate Release Notes section,\r\nand the correct
`release_node:*` 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###
Identify 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- [ ] [See some
risk\r\nexamples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx)\r\n-
[ ]
...\r\n\r\n\r\n-->","sha":"c5cc1532d74e8d733f57329959253e698105b447"}}]}]
BACKPORT-->

Co-authored-by: Eyo O. Eyo <7893459+eokoneyo@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2024-12-06 07:10:16 +11:00 committed by GitHub
parent e9cb539f79
commit c4c00af4e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 40 additions and 60 deletions

16
typings/emotion.d.ts vendored Normal file
View file

@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import '@emotion/react';
import type { UseEuiTheme } from '@elastic/eui';
declare module '@emotion/react' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends UseEuiTheme {}
}

View file

@ -1,14 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import '@emotion/react';
import type { UseEuiTheme } from '@elastic/eui';
declare module '@emotion/react' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends UseEuiTheme {}
}

View file

@ -14,7 +14,7 @@
"include": [
"**/*.ts",
"**/*.tsx",
"./emotion.d.ts", // Emotion EUI theme typing
"../../../../typings/emotion.d.ts"
],
"exclude": [
"target/**/*"

View file

@ -15,7 +15,7 @@ import { coreMock } from '@kbn/core/public/mocks';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import type { ILicense } from '@kbn/licensing-plugin/public';
import type { StartServices } from '../../../types';
import type { EuiTheme } from '@kbn/kibana-react-plugin/common';
import type { UseEuiTheme } from '@elastic/eui';
import { securityMock } from '@kbn/security-plugin/public/mocks';
import { spacesPluginMock } from '@kbn/spaces-plugin/public/mocks';
import { triggersActionsUiMock } from '@kbn/triggers-actions-ui-plugin/public/mocks';
@ -118,5 +118,5 @@ export const createKibanaContextProviderMock = () => {
React.createElement(KibanaContextProvider, { services }, children);
};
export const getMockTheme = (partialTheme: RecursivePartial<EuiTheme>): EuiTheme =>
partialTheme as EuiTheme;
export const getMockTheme = (partialTheme: RecursivePartial<UseEuiTheme>): UseEuiTheme =>
partialTheme as UseEuiTheme;

View file

@ -21,7 +21,7 @@ import {
import { getMockTheme } from '../../common/lib/kibana/kibana_react.mock';
describe('EmptyValue', () => {
const mockTheme = getMockTheme({ eui: { euiColorMediumShade: '#ece' } });
const mockTheme = getMockTheme({ euiTheme: { colors: { mediumShade: '#ece' } } });
test('it renders against snapshot', () => {
const wrapper = shallow(<p>{getEmptyString()}</p>);

View file

@ -7,14 +7,11 @@
import { get, isString } from 'lodash/fp';
import React from 'react';
import { css } from '@emotion/react';
import { euiThemeVars } from '@kbn/ui-theme';
import type { UseEuiTheme } from '@elastic/eui';
import * as i18n from './translations';
const emptyWrapperCss = css`
color: ${euiThemeVars.euiColorMediumShade};
`;
const emptyWrapperCss = ({ euiTheme }: UseEuiTheme) => ({ color: euiTheme.colors.mediumShade });
export const getEmptyValue = () => '—';
export const getEmptyString = () => `(${i18n.EMPTY_STRING})`;

View file

@ -93,6 +93,7 @@ const AlertDetailsAppSection = ({ rule, alert }: AlertDetailsAppSectionProps) =>
<EuiSpacer size="s" />
<Threshold
title={`Threshold breached`}
// @ts-expect-error this chart needs to be migrated to the new chart theming system, comment should be removed once https://github.com/elastic/kibana/issues/202138 is resolved
chartProps={{ theme, baseTheme: LEGACY_LIGHT_THEME }}
comparator={ComparatorToi18nSymbolsMap[rule.params.count.comparator]}
id={'threshold-ratio-chart'}
@ -160,6 +161,7 @@ const AlertDetailsAppSection = ({ rule, alert }: AlertDetailsAppSectionProps) =>
<EuiSpacer size="s" />
<Threshold
title={`Threshold breached`}
// @ts-expect-error this chart needs to be migrated to the new chart theming system, comment should be removed once https://github.com/elastic/kibana/issues/202138 is resolved
chartProps={{ theme, baseTheme: LEGACY_LIGHT_THEME }}
comparator={ComparatorToi18nSymbolsMap[rule.params.count.comparator]}
id="logCountThreshold"

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import { ThemeProvider } from '@emotion/react';
import { EuiThemeProvider as ThemeProvider } from '@elastic/eui';
import { MAINTENANCE_WINDOW_FEATURE_ID } from '@kbn/alerting-plugin/common/maintenance_window';
import { fetchActiveMaintenanceWindows } from '@kbn/alerts-ui-shared/src/maintenance_window_callout/api';
import { RUNNING_MAINTENANCE_WINDOW_1 } from '@kbn/alerts-ui-shared/src/maintenance_window_callout/mock';
@ -14,7 +14,6 @@ import { TimeBuckets } from '@kbn/data-plugin/common';
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
import { observabilityAIAssistantPluginMock } from '@kbn/observability-ai-assistant-plugin/public/mock';
import { KibanaPageTemplate } from '@kbn/shared-ux-page-kibana-template';
import { euiDarkVars } from '@kbn/ui-theme';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, waitFor } from '@testing-library/react';
import React from 'react';
@ -121,9 +120,7 @@ const queryClient = new QueryClient({
});
function AllTheProviders({ children }: { children: any }) {
return (
<ThemeProvider
theme={() => ({ eui: { ...euiDarkVars, euiColorLightShade: '#ece' }, darkMode: true })}
>
<ThemeProvider>
<IntlProvider locale="en">
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</IntlProvider>

View file

@ -1,14 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import '@emotion/react';
import type { UseEuiTheme } from '@elastic/eui';
declare module '@emotion/react' {
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface Theme extends UseEuiTheme {}
}

View file

@ -13,9 +13,7 @@
"server/**/*",
"../../../typings/**/*",
// ECS and Osquery schema files
"public/common/schemas/*/**.json",
// Emotion theme typing
"./emotion.d.ts"
"public/common/schemas/*/**.json"
],
"kbn_references": [
"@kbn/core",

View file

@ -14,11 +14,9 @@ import {
EXPANDABLE_PANEL_HEADER_TITLE_ICON_TEST_ID,
EXPANDABLE_PANEL_TOGGLE_ICON_TEST_ID,
} from './test_ids';
import { ThemeProvider } from '@emotion/react';
import { EuiThemeProvider as ThemeProvider } from '@elastic/eui';
import { ExpandablePanel } from './expandable_panel';
const mockTheme = { eui: { euiColorMediumShade: '#ece' } };
const TEST_ID = 'test-id';
const defaultProps = {
header: {
@ -33,7 +31,7 @@ describe('<ExpandablePanel />', () => {
describe('panel is not expandable by default', () => {
it('should render non-expandable panel by default', () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...defaultProps}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -54,7 +52,7 @@ describe('<ExpandablePanel />', () => {
},
};
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...props}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -70,7 +68,7 @@ describe('<ExpandablePanel />', () => {
it('should only render left section of panel header when headerContent is not passed', () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...defaultProps}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -88,7 +86,7 @@ describe('<ExpandablePanel />', () => {
header: { ...defaultProps.header, headerContent: <>{'test header content'}</> },
};
const { getByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...props}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -105,7 +103,7 @@ describe('<ExpandablePanel />', () => {
it('should not render content when content is null', () => {
const { queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...defaultProps} />
</ThemeProvider>
);
@ -123,7 +121,7 @@ describe('<ExpandablePanel />', () => {
it('should render panel with toggle and collapsed by default', () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...expandableDefaultProps}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -135,7 +133,7 @@ describe('<ExpandablePanel />', () => {
it('click toggle button should expand the panel', () => {
const { getByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...expandableDefaultProps}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -152,7 +150,7 @@ describe('<ExpandablePanel />', () => {
it('should not render toggle or content when content is null', () => {
const { queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...expandableDefaultProps} />
</ThemeProvider>
);
@ -169,7 +167,7 @@ describe('<ExpandablePanel />', () => {
it('should render header and content', () => {
const { getByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...expandedDefaultProps}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -184,7 +182,7 @@ describe('<ExpandablePanel />', () => {
it('click toggle button should collapse the panel', () => {
const { getByTestId, queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...expandedDefaultProps}>{children}</ExpandablePanel>
</ThemeProvider>
);
@ -200,7 +198,7 @@ describe('<ExpandablePanel />', () => {
it('should not render content when content is null', () => {
const { queryByTestId } = render(
<ThemeProvider theme={mockTheme}>
<ThemeProvider>
<ExpandablePanel {...expandedDefaultProps} />
</ThemeProvider>
);