Skip to content

Commit

Permalink
[ML] Fix entity controls update. (#55524) (#55550)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
walterra committed Jan 22, 2020
1 parent f7ef068 commit f5a19ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { isEqual } from 'lodash';
import React, { Component } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -47,8 +48,8 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
};

componentDidUpdate(prevProps: EntityControlProps) {
const { entity, forceSelection, isLoading, options } = this.props;
const { selectedOptions } = this.state;
const { entity, forceSelection, isLoading, options: propOptions } = this.props;
const { options: stateOptions, selectedOptions } = this.state;

const { fieldValue } = entity;

Expand All @@ -68,11 +69,16 @@ export class EntityControl extends Component<EntityControlProps, EntityControlSt
if (prevProps.isLoading === true && isLoading === false) {
this.setState({
isLoading: false,
options,
selectedOptions: selectedOptionsUpdate,
});
}

if (!isEqual(propOptions, stateOptions)) {
this.setState({
options: propOptions,
});
}

if (forceSelection && this.inputRef) {
this.inputRef.focus();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ function getEntityControlOptions(fieldValues) {
return [];
}

fieldValues.sort();

return fieldValues.map(value => {
return { label: value };
});
Expand Down Expand Up @@ -163,7 +165,6 @@ export class TimeSeriesExplorer extends React.Component {
selectedDetectorIndex: PropTypes.number,
selectedEntities: PropTypes.object,
selectedForecastId: PropTypes.string,
setGlobalState: PropTypes.func.isRequired,
tableInterval: PropTypes.string,
tableSeverity: PropTypes.number,
zoom: PropTypes.object,
Expand Down

0 comments on commit f5a19ed

Please sign in to comment.