Skip to content

Commit 07d1dac

Browse files
authored
[ML] Fix entity controls update. (#55524)
Fixes an issue where the options in the internal state of the EntityControl component wouldn't update after a prop change. This had the effect that after a job change via the job selector, the entity control dropdown would stay empty.
1 parent d47d20e commit 07d1dac

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { isEqual } from 'lodash';
78
import React, { Component } from 'react';
89
import { FormattedMessage } from '@kbn/i18n/react';
910
import { i18n } from '@kbn/i18n';
@@ -47,8 +48,8 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
4748
};
4849

4950
componentDidUpdate(prevProps: EntityControlProps) {
50-
const { entity, forceSelection, isLoading, options } = this.props;
51-
const { selectedOptions } = this.state;
51+
const { entity, forceSelection, isLoading, options: propOptions } = this.props;
52+
const { options: stateOptions, selectedOptions } = this.state;
5253

5354
const { fieldValue } = entity;
5455

@@ -68,11 +69,16 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
6869
if (prevProps.isLoading === true && isLoading === false) {
6970
this.setState({
7071
isLoading: false,
71-
options,
7272
selectedOptions: selectedOptionsUpdate,
7373
});
7474
}
7575

76+
if (!isEqual(propOptions, stateOptions)) {
77+
this.setState({
78+
options: propOptions,
79+
});
80+
}
81+
7682
if (forceSelection && this.inputRef) {
7783
this.inputRef.focus();
7884
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ function getEntityControlOptions(fieldValues) {
9494
return [];
9595
}
9696

97+
fieldValues.sort();
98+
9799
return fieldValues.map(value => {
98100
return { label: value };
99101
});
@@ -163,7 +165,6 @@ export class TimeSeriesExplorer extends React.Component {
163165
selectedDetectorIndex: PropTypes.number,
164166
selectedEntities: PropTypes.object,
165167
selectedForecastId: PropTypes.string,
166-
setGlobalState: PropTypes.func.isRequired,
167168
tableInterval: PropTypes.string,
168169
tableSeverity: PropTypes.number,
169170
zoom: PropTypes.object,

0 commit comments

Comments
 (0)