-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] DF Analytics: Collapsable sections on results pages #76641
Changes from 7 commits
7fb7183
13872ee
cdd66b4
fddf9c9
d5d692b
583aef1
f6da6ed
7cc2ead
819cf7d
486511a
b228018
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.mlExpandableSection { | ||
padding: 0 $euiSizeS $euiSizeS $euiSizeS; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import './expandable_section.scss'; | ||
|
||
import React, { useState, FC, ReactNode } from 'react'; | ||
|
||
import { EuiButtonEmpty, EuiPanel } from '@elastic/eui'; | ||
|
||
interface ExpandableSectionProps { | ||
content: ReactNode; | ||
headerContent: ReactNode; | ||
isExpanded?: boolean; | ||
title: ReactNode; | ||
} | ||
|
||
export const ExpandableSection: FC<ExpandableSectionProps> = ({ | ||
headerContent, | ||
// For now we don't have a need for complete external control | ||
// and just want to pass in a default value. If we wanted | ||
// full external control we'd also need to add a onToggleExpanded() | ||
// callback. | ||
isExpanded: isExpandedDefault = true, | ||
content, | ||
title, | ||
}) => { | ||
const [isExpanded, setIsExpanded] = useState(isExpandedDefault); | ||
const toggleExpanded = () => { | ||
setIsExpanded(!isExpanded); | ||
}; | ||
|
||
return ( | ||
<EuiPanel paddingSize="none" data-test-subj="mlDFAnalyticsOutlierExplorationTablePanel"> | ||
<div className="mlExpandableSection"> | ||
<EuiButtonEmpty | ||
onClick={toggleExpanded} | ||
iconType={isExpanded ? 'arrowUp' : 'arrowDown'} | ||
size="l" | ||
iconSide="right" | ||
flush="left" | ||
> | ||
{title} | ||
</EuiButtonEmpty> | ||
{headerContent} | ||
</div> | ||
{isExpanded && content} | ||
</EuiPanel> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { ExpandableSection } from './expandable_section'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,23 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useState, FC } from 'react'; | ||
import React, { useEffect, useState, FC } from 'react'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
|
||
import { EuiFlexGroup, EuiFlexItem, EuiHorizontalRule, EuiPanel, EuiSpacer } from '@elastic/eui'; | ||
import { | ||
EuiBadge, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHorizontalRule, | ||
EuiLoadingContent, | ||
EuiLoadingSpinner, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
|
||
import type { DataFrameAnalysisConfigType } from '../../../../../../../common/types/data_frame_analytics'; | ||
|
||
import { | ||
useColorRange, | ||
|
@@ -19,13 +31,20 @@ import { ColorRangeLegend } from '../../../../../components/color_range_legend'; | |
import { DataGrid } from '../../../../../components/data_grid'; | ||
import { SavedSearchQuery } from '../../../../../contexts/ml'; | ||
import { getToastNotifications } from '../../../../../util/dependency_cache'; | ||
import { ml } from '../../../../../services/ml_api_service'; | ||
|
||
import { defaultSearchQuery, useResultsViewConfig } from '../../../../common'; | ||
|
||
import { getTaskStateBadge } from '../../../analytics_management/components/analytics_list/use_columns'; | ||
import { isGetDataFrameAnalyticsStatsResponseOk } from '../../../analytics_management/services/analytics_service/get_analytics'; | ||
|
||
import { | ||
DataFrameAnalyticsListRow, | ||
DATA_FRAME_MODE, | ||
} from '../../../analytics_management/components/analytics_list/common'; | ||
import { ExpandedRow } from '../../../analytics_management/components/analytics_list/expanded_row'; | ||
|
||
import { ExpandableSection } from '../expandable_section'; | ||
import { ExplorationQueryBar } from '../exploration_query_bar'; | ||
import { ExplorationTitle } from '../exploration_title'; | ||
import { IndexPatternPrompt } from '../index_pattern_prompt'; | ||
|
||
import { getFeatureCount } from './common'; | ||
|
@@ -38,12 +57,7 @@ interface ExplorationProps { | |
} | ||
|
||
export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) => { | ||
const explorationTitle = i18n.translate('xpack.ml.dataframe.analytics.exploration.jobIdTitle', { | ||
defaultMessage: 'Outlier detection job ID {jobId}', | ||
values: { jobId }, | ||
}); | ||
|
||
const { indexPattern, jobConfig, jobStatus, needsDestIndexPattern } = useResultsViewConfig(jobId); | ||
const { indexPattern, jobConfig, needsDestIndexPattern } = useResultsViewConfig(jobId); | ||
const [searchQuery, setSearchQuery] = useState<SavedSearchQuery>(defaultSearchQuery); | ||
const outlierData = useOutlierData(indexPattern, jobConfig, searchQuery); | ||
|
||
|
@@ -55,57 +69,182 @@ export const OutlierExploration: FC<ExplorationProps> = React.memo(({ jobId }) = | |
jobConfig !== undefined ? getFeatureCount(jobConfig.dest.results_field, tableItems) : 1 | ||
); | ||
|
||
const [expandedRowItem, setExpandedRowItem] = useState<DataFrameAnalyticsListRow | undefined>( | ||
undefined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to pass undefined explicitly here, I don't think. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b228018. |
||
); | ||
|
||
const fetchStats = async () => { | ||
const analyticsConfigs = await ml.dataFrameAnalytics.getDataFrameAnalytics(jobId); | ||
const analyticsStats = await ml.dataFrameAnalytics.getDataFrameAnalyticsStats(jobId); | ||
|
||
const config = analyticsConfigs.data_frame_analytics[0]; | ||
const stats = isGetDataFrameAnalyticsStatsResponseOk(analyticsStats) | ||
? analyticsStats.data_frame_analytics[0] | ||
: undefined; | ||
|
||
if (stats === undefined) { | ||
return; | ||
} | ||
|
||
const newExpandedRowItem: DataFrameAnalyticsListRow = { | ||
checkpointing: {}, | ||
config, | ||
id: config.id, | ||
job_type: Object.keys(config.analysis)[0] as DataFrameAnalysisConfigType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 819cf7d. |
||
mode: DATA_FRAME_MODE.BATCH, | ||
state: stats.state, | ||
stats, | ||
}; | ||
|
||
setExpandedRowItem(newExpandedRowItem); | ||
}; | ||
|
||
useEffect(() => { | ||
fetchStats(); | ||
}, [jobConfig?.id]); | ||
|
||
return ( | ||
<EuiPanel data-test-subj="mlDFAnalyticsOutlierExplorationTablePanel"> | ||
{jobConfig !== undefined && needsDestIndexPattern && ( | ||
<IndexPatternPrompt destIndex={jobConfig.dest.index} /> | ||
)} | ||
<EuiFlexGroup | ||
alignItems="center" | ||
justifyContent="spaceBetween" | ||
responsive={false} | ||
gutterSize="s" | ||
> | ||
<EuiFlexItem grow={false}> | ||
<ExplorationTitle title={explorationTitle} /> | ||
</EuiFlexItem> | ||
{jobStatus !== undefined && ( | ||
<EuiFlexItem grow={false}> | ||
<span>{getTaskStateBadge(jobStatus)}</span> | ||
</EuiFlexItem> | ||
)} | ||
</EuiFlexGroup> | ||
<EuiHorizontalRule margin="xs" /> | ||
<> | ||
{(columnsWithCharts.length > 0 || searchQuery !== defaultSearchQuery) && | ||
indexPattern !== undefined && ( | ||
<> | ||
<EuiFlexGroup justifyContent="spaceBetween"> | ||
<EuiFlexItem> | ||
<ExplorationQueryBar indexPattern={indexPattern} setSearchQuery={setSearchQuery} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiSpacer size="s" /> | ||
<ColorRangeLegend | ||
colorRange={colorRange} | ||
title={i18n.translate( | ||
'xpack.ml.dataframe.analytics.exploration.colorRangeLegendTitle', | ||
{ | ||
defaultMessage: 'Feature influence score', | ||
} | ||
<ExplorationQueryBar indexPattern={indexPattern} setSearchQuery={setSearchQuery} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you consider moving the query bar below the Analysis section? I can't decide where it fits best - on the one hand most views place the query bar at the top, but on the other hand the query bar would sit well directly above the panels on which it has an effect (in this view just the result table for now). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it during design phase and had a look at other plugin/kibana pages, most have them at the very top, even if some sections below it might not be in complete context of the search bar. There are also other plugins that keep the search bar pinned at the top when you scroll down the page which is an idea I'd like to explore but seemed overkill for this iteration. With these considerations I went for having it at the top for this PR. |
||
<EuiSpacer size="m" /> | ||
</> | ||
)} | ||
|
||
<ExpandableSection | ||
content={ | ||
<> | ||
<EuiHorizontalRule size="full" margin="none" /> | ||
{expandedRowItem === undefined && ( | ||
<EuiText textAlign="center"> | ||
<EuiSpacer size="l" /> | ||
<EuiLoadingSpinner size="l" /> | ||
<EuiSpacer size="l" /> | ||
</EuiText> | ||
)} | ||
{(columnsWithCharts.length > 0 || searchQuery !== defaultSearchQuery) && | ||
indexPattern !== undefined && | ||
jobConfig !== undefined && | ||
columnsWithCharts.length > 0 && | ||
tableItems.length > 0 && | ||
expandedRowItem !== undefined && <ExpandedRow item={expandedRowItem} />} | ||
</> | ||
} | ||
headerContent={ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth adding description into the collapsed header (if it is non-blank), especially as there is normally a lot of available space in this section. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, I revisit it in the follow up that will also add the same section to regression and classification results pages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Might be worth breaking out the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion, refactored in 819cf7d. |
||
<> | ||
{expandedRowItem === undefined && <EuiLoadingContent lines={1} />} | ||
{expandedRowItem !== undefined && ( | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="xs" color="subdued"> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.exploration.analysisTypeLabel" | ||
defaultMessage="Type" | ||
/> | ||
</p> | ||
</EuiText> | ||
<EuiBadge>{expandedRowItem.job_type}</EuiBadge> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="xs" color="subdued"> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.exploration.analysisSourceIndexLabel" | ||
defaultMessage="Source index" | ||
/> | ||
</p> | ||
</EuiText> | ||
<EuiBadge>{expandedRowItem.config.source.index}</EuiBadge> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="xs" color="subdued"> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.exploration.analysisDestinationIndexLabel" | ||
defaultMessage="Destination index" | ||
/> | ||
</p> | ||
</EuiText> | ||
<EuiBadge>{expandedRowItem.config.dest.index}</EuiBadge> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
</> | ||
} | ||
isExpanded={false} | ||
title={ | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.exploration.analysisSectionTitle" | ||
defaultMessage="Analysis" | ||
/> | ||
} | ||
/> | ||
<EuiSpacer size="m" /> | ||
<ExpandableSection | ||
content={ | ||
<> | ||
{jobConfig !== undefined && needsDestIndexPattern && ( | ||
<IndexPatternPrompt destIndex={jobConfig.dest.index} /> | ||
)} | ||
{(columnsWithCharts.length > 0 || searchQuery !== defaultSearchQuery) && | ||
indexPattern !== undefined && ( | ||
<> | ||
<EuiSpacer size="s" /> | ||
{columnsWithCharts.length > 0 && tableItems.length > 0 && ( | ||
<DataGrid | ||
{...outlierData} | ||
dataTestSubj="mlExplorationDataGrid" | ||
toastNotifications={getToastNotifications()} | ||
/> | ||
)} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
<EuiSpacer size="s" /> | ||
</> | ||
)} | ||
</> | ||
} | ||
headerContent={ | ||
<> | ||
{(columnsWithCharts.length === 0 || tableItems.length === 0) && ( | ||
<EuiLoadingContent lines={1} /> | ||
)} | ||
{columnsWithCharts.length > 0 && tableItems.length > 0 && ( | ||
<DataGrid | ||
{...outlierData} | ||
dataTestSubj="mlExplorationDataGrid" | ||
toastNotifications={getToastNotifications()} | ||
/> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={false}> | ||
<EuiText size="xs" color="subdued"> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.exploration.explorationTableTotalDocsLabel" | ||
defaultMessage="Total docs" | ||
/> | ||
</p> | ||
</EuiText> | ||
<EuiBadge>{outlierData.rowCount}</EuiBadge> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<ColorRangeLegend | ||
colorRange={colorRange} | ||
title={i18n.translate( | ||
'xpack.ml.dataframe.analytics.exploration.colorRangeLegendTitle', | ||
{ | ||
defaultMessage: 'Feature influence score', | ||
} | ||
)} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
)} | ||
</> | ||
)} | ||
</EuiPanel> | ||
} | ||
title={ | ||
<FormattedMessage | ||
id="xpack.ml.dataframe.analytics.exploration.explorationTableTitle" | ||
defaultMessage="Results" | ||
/> | ||
} | ||
/> | ||
<EuiSpacer size="m" /> | ||
</> | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this data-test-subject accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed in 486511a.
ExpandableSection
now takes in an ID to create a dynamicdata-test-subj
.