Skip to content

Commit

Permalink
[8.x] [ML] Migrate anomaly explorer components from SCSS to Emotion (#…
Browse files Browse the repository at this point in the history
…212793) (#213352)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ML] Migrate anomaly explorer components from SCSS to Emotion
(#212793)](#212793)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Pete
Harverson","email":"pete@elastic.co"},"sourceCommit":{"committedDate":"2025-03-05T17:27:03Z","message":"[ML]
Migrate anomaly explorer components from SCSS to Emotion (#212793)\n\n##
Summary\n\nPart of:
https://github.com/elastic/kibana/issues/140695\nMigrates SCSS to
emotion for several of the components used across the\nAnomaly Explorer
and Single Metric Viewer.\n\nRemoves the following SCSS files:\n\n```\n-
x-pack/platform/plugins/shared/m/public/application/components/annotations/annotation_description_list/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/entity_cell/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/entity_cell/entity_cell.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/help_popover/help_popover.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/detector_description_list/_detector_description_list.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/rule_editor/components/detector_description_list/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/explorer/explorer_charts/components/explorer_chart_label/_explorer_chart_label_badge.scss\n-
x-pack/platform/plugins/shared/ml/public/application/explorer/explorer_charts/components/explorer_chart_label/entity_filter/_entity_filter.scss\n```\n\nComponents
edited:\n- Help popover\n\n<img width=\"759\" alt=\"Screenshot
2025-02-28 at 16 28
27\"\nsrc=\"https://github.com/user-attachments/assets/bc182d45-465b-406c-b122-921576ae8304\"\n/>\n\n-
Annotation description list:\n\n<img width=\"952\" alt=\"Screenshot
2025-02-28 at 16 29
16\"\nsrc=\"https://github.com/user-attachments/assets/71cae50c-41be-4299-8362-92567b73188e\"\n/>\n\n\n-
Rule editor detector description list:\n\n<img width=\"674\"
alt=\"Screenshot 2025-02-28 at 16 30
02\"\nsrc=\"https://github.com/user-attachments/assets/f94a6878-3063-488f-85c5-2e6ee77bf1ad\"\n/>\n\n-
Anomalies table entity filters:\n\n<img width=\"506\" alt=\"Screenshot
2025-02-28 at 16 30
53\"\nsrc=\"https://github.com/user-attachments/assets/f074f175-9310-4a70-97b6-09be44af2ad2\"\n/>\n\n-
Explorer chart label badge and entity filters:\n\n<img width=\"362\"
alt=\"Screenshot 2025-02-28 at 16 31
37\"\nsrc=\"https://github.com/user-attachments/assets/dd46ab81-e115-4e8c-ae00-864c83127c16\"\n/>\n\n---------\n\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"a1c520c49d26c2292d15d148a759d1dc72efc7d1","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["chore",":ml","release_note:skip","backport:version","v9.1.0","v8.19.0"],"title":"[ML]
Migrate anomaly explorer components from SCSS to
Emotion","number":212793,"url":"https://github.com/elastic/kibana/pull/212793","mergeCommit":{"message":"[ML]
Migrate anomaly explorer components from SCSS to Emotion (#212793)\n\n##
Summary\n\nPart of:
https://github.com/elastic/kibana/issues/140695\nMigrates SCSS to
emotion for several of the components used across the\nAnomaly Explorer
and Single Metric Viewer.\n\nRemoves the following SCSS files:\n\n```\n-
x-pack/platform/plugins/shared/m/public/application/components/annotations/annotation_description_list/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/entity_cell/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/entity_cell/entity_cell.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/help_popover/help_popover.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/detector_description_list/_detector_description_list.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/rule_editor/components/detector_description_list/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/explorer/explorer_charts/components/explorer_chart_label/_explorer_chart_label_badge.scss\n-
x-pack/platform/plugins/shared/ml/public/application/explorer/explorer_charts/components/explorer_chart_label/entity_filter/_entity_filter.scss\n```\n\nComponents
edited:\n- Help popover\n\n<img width=\"759\" alt=\"Screenshot
2025-02-28 at 16 28
27\"\nsrc=\"https://github.com/user-attachments/assets/bc182d45-465b-406c-b122-921576ae8304\"\n/>\n\n-
Annotation description list:\n\n<img width=\"952\" alt=\"Screenshot
2025-02-28 at 16 29
16\"\nsrc=\"https://github.com/user-attachments/assets/71cae50c-41be-4299-8362-92567b73188e\"\n/>\n\n\n-
Rule editor detector description list:\n\n<img width=\"674\"
alt=\"Screenshot 2025-02-28 at 16 30
02\"\nsrc=\"https://github.com/user-attachments/assets/f94a6878-3063-488f-85c5-2e6ee77bf1ad\"\n/>\n\n-
Anomalies table entity filters:\n\n<img width=\"506\" alt=\"Screenshot
2025-02-28 at 16 30
53\"\nsrc=\"https://github.com/user-attachments/assets/f074f175-9310-4a70-97b6-09be44af2ad2\"\n/>\n\n-
Explorer chart label badge and entity filters:\n\n<img width=\"362\"
alt=\"Screenshot 2025-02-28 at 16 31
37\"\nsrc=\"https://github.com/user-attachments/assets/dd46ab81-e115-4e8c-ae00-864c83127c16\"\n/>\n\n---------\n\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"a1c520c49d26c2292d15d148a759d1dc72efc7d1"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/212793","number":212793,"mergeCommit":{"message":"[ML]
Migrate anomaly explorer components from SCSS to Emotion (#212793)\n\n##
Summary\n\nPart of:
https://github.com/elastic/kibana/issues/140695\nMigrates SCSS to
emotion for several of the components used across the\nAnomaly Explorer
and Single Metric Viewer.\n\nRemoves the following SCSS files:\n\n```\n-
x-pack/platform/plugins/shared/m/public/application/components/annotations/annotation_description_list/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/entity_cell/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/entity_cell/entity_cell.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/help_popover/help_popover.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/detector_description_list/_detector_description_list.scss\n-
x-pack/platform/plugins/shared/ml/public/application/components/rule_editor/components/detector_description_list/_index.scss\n-
x-pack/platform/plugins/shared/ml/public/application/explorer/explorer_charts/components/explorer_chart_label/_explorer_chart_label_badge.scss\n-
x-pack/platform/plugins/shared/ml/public/application/explorer/explorer_charts/components/explorer_chart_label/entity_filter/_entity_filter.scss\n```\n\nComponents
edited:\n- Help popover\n\n<img width=\"759\" alt=\"Screenshot
2025-02-28 at 16 28
27\"\nsrc=\"https://github.com/user-attachments/assets/bc182d45-465b-406c-b122-921576ae8304\"\n/>\n\n-
Annotation description list:\n\n<img width=\"952\" alt=\"Screenshot
2025-02-28 at 16 29
16\"\nsrc=\"https://github.com/user-attachments/assets/71cae50c-41be-4299-8362-92567b73188e\"\n/>\n\n\n-
Rule editor detector description list:\n\n<img width=\"674\"
alt=\"Screenshot 2025-02-28 at 16 30
02\"\nsrc=\"https://github.com/user-attachments/assets/f94a6878-3063-488f-85c5-2e6ee77bf1ad\"\n/>\n\n-
Anomalies table entity filters:\n\n<img width=\"506\" alt=\"Screenshot
2025-02-28 at 16 30
53\"\nsrc=\"https://github.com/user-attachments/assets/f074f175-9310-4a70-97b6-09be44af2ad2\"\n/>\n\n-
Explorer chart label badge and entity filters:\n\n<img width=\"362\"
alt=\"Screenshot 2025-02-28 at 16 31
37\"\nsrc=\"https://github.com/user-attachments/assets/dd46ab81-e115-4e8c-ae00-864c83127c16\"\n/>\n\n---------\n\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"a1c520c49d26c2292d15d148a759d1dc72efc7d1"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
  • Loading branch information
peteharverson authored Mar 6, 2025
1 parent 2e9c3e3 commit 6fd617c
Show file tree
Hide file tree
Showing 31 changed files with 351 additions and 351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28519,10 +28519,8 @@
"xpack.ml.anomaliesTable.hideDetailsAriaLabel": "Masquer les détails",
"xpack.ml.anomaliesTable.influencersCell.addFilterAriaLabel": "Ajouter un filtre",
"xpack.ml.anomaliesTable.influencersCell.addFilterTooltip": "Ajouter un filtre",
"xpack.ml.anomaliesTable.influencersCell.moreInfluencersLinkText": "et {othersCount} de plus",
"xpack.ml.anomaliesTable.influencersCell.removeFilterAriaLabel": "Supprimer le filtre",
"xpack.ml.anomaliesTable.influencersCell.removeFilterTooltip": "Supprimer le filtre",
"xpack.ml.anomaliesTable.influencersCell.showLessInfluencersLinkText": "afficher moins",
"xpack.ml.anomaliesTable.influencersColumnName": "Influencé par",
"xpack.ml.anomaliesTable.jobIdColumnName": "ID tâche",
"xpack.ml.anomaliesTable.linksMenu.autoGeneratedDiscoverLinkErrorMessage": "Liaison avec Discover impossible ; aucune vue de données n’existe pour le modèle d'index \"{index}\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28381,10 +28381,8 @@
"xpack.ml.anomaliesTable.hideDetailsAriaLabel": "詳細を非表示",
"xpack.ml.anomaliesTable.influencersCell.addFilterAriaLabel": "フィルターを追加します",
"xpack.ml.anomaliesTable.influencersCell.addFilterTooltip": "フィルターを追加します",
"xpack.ml.anomaliesTable.influencersCell.moreInfluencersLinkText": "他 {othersCount} 件",
"xpack.ml.anomaliesTable.influencersCell.removeFilterAriaLabel": "フィルターを削除",
"xpack.ml.anomaliesTable.influencersCell.removeFilterTooltip": "フィルターを削除",
"xpack.ml.anomaliesTable.influencersCell.showLessInfluencersLinkText": "縮小表示",
"xpack.ml.anomaliesTable.influencersColumnName": "影響因子:",
"xpack.ml.anomaliesTable.jobIdColumnName": "ジョブID",
"xpack.ml.anomaliesTable.linksMenu.autoGeneratedDiscoverLinkErrorMessage": "Discoverにリンクできません。インデックスパターン''{index}''のデータビューが存在しません",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28465,10 +28465,8 @@
"xpack.ml.anomaliesTable.hideDetailsAriaLabel": "隐藏详情",
"xpack.ml.anomaliesTable.influencersCell.addFilterAriaLabel": "添加筛选",
"xpack.ml.anomaliesTable.influencersCell.addFilterTooltip": "添加筛选",
"xpack.ml.anomaliesTable.influencersCell.moreInfluencersLinkText": "及另外 {othersCount} 个",
"xpack.ml.anomaliesTable.influencersCell.removeFilterAriaLabel": "移除筛选",
"xpack.ml.anomaliesTable.influencersCell.removeFilterTooltip": "移除筛选",
"xpack.ml.anomaliesTable.influencersCell.showLessInfluencersLinkText": "显示更少",
"xpack.ml.anomaliesTable.influencersColumnName": "影响因素",
"xpack.ml.anomaliesTable.jobIdColumnName": "作业 ID",
"xpack.ml.anomaliesTable.linksMenu.autoGeneratedDiscoverLinkErrorMessage": "无法链接到 Discover;索引模式“{index}”的数据视图不存在",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
@import 'explorer/index'; // SASSTODO: This file needs to be rewritten

// Components
@import 'components/annotations/annotation_description_list/index'; // SASSTODO: This file overwrites EUI directly
@import 'components/anomalies_table/index'; // SASSTODO: This file overwrites EUI directly
@import 'components/entity_cell/index';
@import 'components/job_selector/index';
@import 'components/rule_editor/index'; // SASSTODO: This file overwrites EUI directly

Expand Down

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export const AnnotationDescriptionList = ({ annotation, detectorDescription }: P
return (
<EuiDescriptionList
data-test-subj={'mlAnnotationDescriptionList'}
className="ml-annotation-description-list"
type="column"
columnWidths={[3, 7]}
listItems={listItems}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
/*
* 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 type { FC } from 'react';
import React, { useState } from 'react';

import { EuiLink, EuiButtonIcon, EuiToolTip } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { useEntityCellStyles } from '../entity_cell/entity_cell_styles';
import { blurButtonOnClick } from '../../util/component_utils';

type InfluencerCellFilter = (
influencerFieldName: string,
influencerFieldValue: string,
direction: '+' | '-'
) => void;

interface Influencer {
influencerFieldName: string;
influencerFieldValue: string;
}

interface InfluencerCellProps {
influencerFilter: InfluencerCellFilter | undefined;
influencers: Influencer[] | undefined;
limit: number;
}

/*
* Component for rendering a list of record influencers inside a cell in the anomalies table.
* Truncates long lists of influencers to the supplied limit, with the full list of influencers
* expanded or collapsed via 'and x more' / 'show less' links.
*/
export const InfluencersCell: FC<InfluencerCellProps> = ({
influencers = [],
influencerFilter,
limit,
}) => {
const { filterButton } = useEntityCellStyles();

const [showAllInfluencers, setShowAllInfluencers] = useState(false);
const toggleAllInfluencers = () => setShowAllInfluencers((prev) => !prev);

let numberToDisplay = showAllInfluencers === false ? limit : influencers.length;
let othersCount = 0;
if (influencers !== undefined) {
othersCount = Math.max(influencers.length - numberToDisplay, 0);
}
if (othersCount === 1) {
// Display the additional influencer.
numberToDisplay++;
othersCount = 0;
}

const displayInfluencers = influencers
.reduce<Influencer[]>((acc, influencer) => {
const [influencerFieldName, influencerFieldValue] = Object.entries(influencer)[0] ?? [];
if (typeof influencerFieldName === 'string' && typeof influencerFieldValue === 'string') {
acc.push({
influencerFieldName,
influencerFieldValue,
});
}
return acc;
}, [])
.slice(0, numberToDisplay);

return (
<div>
{displayInfluencers.map((influencer, index) => (
<div key={index}>
{influencer.influencerFieldName}: {influencer.influencerFieldValue}
{influencerFilter !== undefined && (
<>
<EuiToolTip
content={
<FormattedMessage
id="xpack.ml.anomaliesTable.influencersCell.addFilterTooltip"
defaultMessage="Add filter"
/>
}
>
<EuiButtonIcon
size="s"
css={filterButton}
onClick={blurButtonOnClick(() => {
influencerFilter(
influencer.influencerFieldName,
influencer.influencerFieldValue,
'+'
);
})}
iconType="plusInCircle"
aria-label={i18n.translate(
'xpack.ml.anomaliesTable.influencersCell.addFilterAriaLabel',
{
defaultMessage: 'Add filter',
}
)}
/>
</EuiToolTip>
<EuiToolTip
content={
<FormattedMessage
id="xpack.ml.anomaliesTable.influencersCell.removeFilterTooltip"
defaultMessage="Remove filter"
/>
}
>
<EuiButtonIcon
size="s"
css={filterButton}
onClick={blurButtonOnClick(() => {
influencerFilter(
influencer.influencerFieldName,
influencer.influencerFieldValue,
'-'
);
})}
iconType="minusInCircle"
aria-label={i18n.translate(
'xpack.ml.anomaliesTable.influencersCell.removeFilterAriaLabel',
{
defaultMessage: 'Remove filter',
}
)}
/>
</EuiToolTip>
</>
)}
</div>
))}
{othersCount > 0 && (
<EuiLink onClick={() => toggleAllInfluencers()}>
<FormattedMessage
id="xpack.ml.anomaliesTable.anomalyDetails.anomalyDescriptionListMoreLinkText"
defaultMessage="and {othersCount} more"
values={{ othersCount }}
/>
</EuiLink>
)}
{numberToDisplay > limit + 1 && (
<EuiLink onClick={() => toggleAllInfluencers()}>
<FormattedMessage
id="xpack.ml.anomaliesTable.anomalyDetails.anomalyDescriptionShowLessLinkText"
defaultMessage="Show less"
/>
</EuiLink>
)}
</div>
);
};
Loading

0 comments on commit 6fd617c

Please sign in to comment.