Skip to content

Commit ec6fd9e

Browse files
authored
[ML] DF Analytics: Collapsable sections on results pages (#76641) (#79188)
- Fixes cell color coding based on influence score for outlier detection results page data grid. (Part of #77046) - Introduces expandable sections (<ExpandableSection />). In contrast to plain accordions, the main idea of this component is that it should also provide some sort of useful summary when collapsed instead of just being an expandable title. For example, the "Analysis" section is collapsed by default, but still offers information like analysis type, source and destination index. This concept should allow us to keep the analytics results pages usable with more content (additional results, evaluations, visualizations) being added over time. - The "Analysis" section is a reuse of the expandable row from the analytics jobs list. Some design adjustments have been made to make it usable in both places.
1 parent 86f628d commit ec6fd9e

File tree

15 files changed

+390
-115
lines changed

15 files changed

+390
-115
lines changed

x-pack/plugins/ml/public/application/components/color_range_legend/color_range_legend.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import React, { useEffect, useRef, FC } from 'react';
88
import d3 from 'd3';
99

10-
import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui';
10+
import { EuiText } from '@elastic/eui';
1111

1212
const COLOR_RANGE_RESOLUTION = 10;
1313

@@ -134,15 +134,11 @@ export const ColorRangeLegend: FC<ColorRangeLegendProps> = ({
134134
}
135135

136136
return (
137-
<EuiFlexGroup gutterSize="s">
138-
<EuiFlexItem grow={false}>
139-
<EuiText size="xs">
140-
<strong>{title}</strong>
141-
</EuiText>
142-
</EuiFlexItem>
143-
<EuiFlexItem grow={false}>
144-
<svg ref={d3Container} />
145-
</EuiFlexItem>
146-
</EuiFlexGroup>
137+
<>
138+
<EuiText size="xs" color="subdued">
139+
<p>{title}</p>
140+
</EuiText>
141+
<svg ref={d3Container} />
142+
</>
147143
);
148144
};

x-pack/plugins/ml/public/application/data_frame_analytics/common/fields.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export const EXTENDED_NUMERICAL_TYPES = new Set([
4848

4949
// eslint-disable-next-line @typescript-eslint/naming-convention
5050
export const ML__ID_COPY = 'ml__id_copy';
51+
// eslint-disable-next-line @typescript-eslint/naming-convention
52+
export const ML__INCREMENTAL_ID = 'ml__incremental_id';
5153

5254
export const isKeywordAndTextType = (fieldName: string): boolean => {
5355
const { fields } = newJobCapsService;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.mlExpandableSection {
2+
padding: 0 $euiSizeS $euiSizeS $euiSizeS;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import './expandable_section.scss';
8+
9+
import React, { useState, FC, ReactNode } from 'react';
10+
11+
import {
12+
EuiBadge,
13+
EuiButtonEmpty,
14+
EuiFlexGroup,
15+
EuiFlexItem,
16+
EuiLoadingContent,
17+
EuiPanel,
18+
EuiText,
19+
} from '@elastic/eui';
20+
21+
interface HeaderItem {
22+
// id is used as the React key and to construct a data-test-subj
23+
id: string;
24+
label?: ReactNode;
25+
value: ReactNode;
26+
}
27+
28+
const isHeaderItems = (arg: any): arg is HeaderItem[] => {
29+
return Array.isArray(arg);
30+
};
31+
32+
export interface ExpandableSectionProps {
33+
content: ReactNode;
34+
headerItems?: HeaderItem[] | 'loading';
35+
isExpanded?: boolean;
36+
dataTestId: string;
37+
title: ReactNode;
38+
}
39+
40+
export const ExpandableSection: FC<ExpandableSectionProps> = ({
41+
headerItems,
42+
// For now we don't have a need for complete external control
43+
// and just want to pass in a default value. If we wanted
44+
// full external control we'd also need to add a onToggleExpanded()
45+
// callback.
46+
isExpanded: isExpandedDefault = true,
47+
content,
48+
dataTestId,
49+
title,
50+
}) => {
51+
const [isExpanded, setIsExpanded] = useState(isExpandedDefault);
52+
const toggleExpanded = () => {
53+
setIsExpanded(!isExpanded);
54+
};
55+
56+
return (
57+
<EuiPanel paddingSize="none" data-test-subj={`mlDFExpandableSection-${dataTestId}`}>
58+
<div className="mlExpandableSection">
59+
<EuiButtonEmpty
60+
onClick={toggleExpanded}
61+
iconType={isExpanded ? 'arrowUp' : 'arrowDown'}
62+
size="l"
63+
iconSide="right"
64+
flush="left"
65+
>
66+
{title}
67+
</EuiButtonEmpty>
68+
{headerItems === 'loading' && <EuiLoadingContent lines={1} />}
69+
{isHeaderItems(headerItems) && (
70+
<EuiFlexGroup>
71+
{headerItems.map(({ label, value, id }) => (
72+
<EuiFlexItem
73+
grow={false}
74+
key={id}
75+
data-test-subj={`mlDFExpandableSectionItem-${dataTestId}-${id}`}
76+
>
77+
{label !== undefined && value !== undefined && (
78+
<>
79+
<EuiText size="xs" color="subdued">
80+
<p>{label}</p>
81+
</EuiText>
82+
<EuiBadge>{value}</EuiBadge>
83+
</>
84+
)}
85+
{label === undefined && value}
86+
</EuiFlexItem>
87+
))}
88+
</EuiFlexGroup>
89+
)}
90+
</div>
91+
{isExpanded && content}
92+
</EuiPanel>
93+
);
94+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export { ExpandableSection, ExpandableSectionProps } from './expandable_section';

0 commit comments

Comments
 (0)