Skip to content

Commit b8a4e75

Browse files
committed
[ML] Fix Single Metric Viewer not loading if job is metric with no partition (#83880)
1 parent d3e7dc5 commit b8a4e75

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

x-pack/plugins/ml/public/application/timeseriesexplorer/components/plot_function_controls/plot_function_controls.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ export const PlotByFunctionControls = ({
3838
selectedDetectorIndex,
3939
selectedJobId,
4040
selectedEntities,
41+
entityControlsCount,
4142
}: {
4243
functionDescription: undefined | string;
4344
setFunctionDescription: (func: string) => void;
4445
selectedDetectorIndex: number;
4546
selectedJobId: string;
4647
selectedEntities: Record<string, any>;
48+
entityControlsCount: number;
4749
}) => {
4850
const toastNotificationService = useToastNotificationService();
4951

@@ -73,9 +75,12 @@ export const PlotByFunctionControls = ({
7375
return;
7476
}
7577
const selectedJob = mlJobService.getJob(selectedJobId);
78+
// if no controls, it's okay to fetch
79+
// if there are series controls, only fetch if user has selected something
80+
const validEntities =
81+
entityControlsCount === 0 || (entityControlsCount > 0 && selectedEntities !== undefined);
7682
if (
77-
// set if only entity controls are picked
78-
selectedEntities !== undefined &&
83+
validEntities &&
7984
functionDescription === undefined &&
8085
isMetricDetector(selectedJob, selectedDetectorIndex)
8186
) {
@@ -95,6 +100,7 @@ export const PlotByFunctionControls = ({
95100
selectedEntities,
96101
selectedJobId,
97102
functionDescription,
103+
entityControlsCount,
98104
]);
99105

100106
if (functionDescription === undefined) return null;

x-pack/plugins/ml/public/application/timeseriesexplorer/components/series_controls/series_controls.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { useStorage } from '../../../contexts/ml/use_storage';
2828
import { EntityFieldType } from '../../../../../common/types/anomalies';
2929
import { FieldDefinition } from '../../../services/results_service/result_service_rx';
3030
import { getViewableDetectors } from '../../timeseriesexplorer_utils/get_viewable_detectors';
31+
import { PlotByFunctionControls } from '../plot_function_controls';
3132

3233
function getEntityControlOptions(fieldValues: FieldDefinition['values']): ComboBoxOption[] {
3334
if (!Array.isArray(fieldValues)) {
@@ -67,6 +68,8 @@ interface SeriesControlsProps {
6768
bounds: any;
6869
appStateHandler: Function;
6970
selectedEntities: Record<string, any>;
71+
functionDescription: string;
72+
setFunctionDescription: (func: string) => void;
7073
}
7174

7275
/**
@@ -79,6 +82,8 @@ export const SeriesControls: FC<SeriesControlsProps> = ({
7982
appStateHandler,
8083
children,
8184
selectedEntities,
85+
functionDescription,
86+
setFunctionDescription,
8287
}) => {
8388
const {
8489
services: {
@@ -306,6 +311,15 @@ export const SeriesControls: FC<SeriesControlsProps> = ({
306311
/>
307312
);
308313
})}
314+
<PlotByFunctionControls
315+
selectedJobId={selectedJobId}
316+
selectedDetectorIndex={selectedDetectorIndex}
317+
selectedEntities={selectedEntities}
318+
functionDescription={functionDescription}
319+
setFunctionDescription={setFunctionDescription}
320+
entityControlsCount={entityControls.length}
321+
/>
322+
309323
{children}
310324
</EuiFlexGroup>
311325
</div>

x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ import { ANOMALY_DETECTION_DEFAULT_TIME_RANGE } from '../../../common/constants/
8181
import { getControlsForDetector } from './get_controls_for_detector';
8282
import { SeriesControls } from './components/series_controls';
8383
import { TimeSeriesChartWithTooltips } from './components/timeseries_chart/timeseries_chart_with_tooltip';
84-
import { PlotByFunctionControls } from './components/plot_function_controls';
8584
import { aggregationTypeTransform } from '../../../common/util/anomaly_utils';
8685
import { isMetricDetector } from './get_function_description';
8786
import { getViewableDetectors } from './timeseriesexplorer_utils/get_viewable_detectors';
@@ -1013,15 +1012,9 @@ export class TimeSeriesExplorer extends React.Component {
10131012
selectedDetectorIndex={selectedDetectorIndex}
10141013
selectedEntities={this.props.selectedEntities}
10151014
bounds={bounds}
1015+
functionDescription={this.props.functionDescription}
1016+
setFunctionDescription={this.setFunctionDescription}
10161017
>
1017-
<PlotByFunctionControls
1018-
selectedJobId={selectedJobId}
1019-
selectedDetectorIndex={selectedDetectorIndex}
1020-
selectedEntities={this.props.selectedEntities}
1021-
functionDescription={this.props.functionDescription}
1022-
setFunctionDescription={this.setFunctionDescription}
1023-
/>
1024-
10251018
{arePartitioningFieldsProvided && (
10261019
<EuiFlexItem style={{ textAlign: 'right' }}>
10271020
<EuiFormRow hasEmptyLabelSpace style={{ maxWidth: '100%' }}>

0 commit comments

Comments
 (0)