Skip to content

Commit

Permalink
[ML] Single metric viewer: Fix detector/entity selection (#44772)
Browse files Browse the repository at this point in the history
This fixes switching to another detector on single metric viewer. There is no longer a Refresh button next to the dropdowns, instead the charts will reload when one of the dropdowns (detector or entity selection) changes.
  • Loading branch information
walterra committed Sep 4, 2019
1 parent b14d17d commit cf8dfbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
EuiFlexGroup,
EuiFlexItem,
EuiFormRow,
EuiButton,
EuiSelect,
EuiSpacer,
EuiText,
Expand Down Expand Up @@ -170,10 +169,14 @@ export class TimeSeriesExplorer extends React.Component {
detectorIndexChangeHandler = (e) => {
const id = e.target.value;
if (id !== undefined) {
this.setState({ detectorId: id });
this.setState({ detectorId: id }, () => {
this.updateControlsForDetector(
() => this.loadEntityValues(
() => this.saveSeriesPropertiesAndRefresh()
)
);
});
}
this.updateControlsForDetector();
this.loadEntityValues();
};

toggleShowAnnotationsHandler = () => {
Expand Down Expand Up @@ -322,7 +325,7 @@ export class TimeSeriesExplorer extends React.Component {
}
return stateEntity;
})
}));
}), () => this.saveSeriesPropertiesAndRefresh());
};

loadAnomaliesTableData = (earliestMs, latestMs) => {
Expand Down Expand Up @@ -378,7 +381,7 @@ export class TimeSeriesExplorer extends React.Component {
});
}

loadEntityValues = () => {
loadEntityValues = (callback = () => {}) => {
const { timefilter } = this.props;
const { detectorId, entities, selectedJob } = this.state;

Expand Down Expand Up @@ -411,7 +414,7 @@ export class TimeSeriesExplorer extends React.Component {
}
return entity;
})
});
}, callback);
}
});
}
Expand Down Expand Up @@ -653,7 +656,7 @@ export class TimeSeriesExplorer extends React.Component {
});
}

updateControlsForDetector = () => {
updateControlsForDetector = (callback = () => {}) => {
const { appStateHandler } = this.props;
const { detectorId, selectedJob } = this.state;
// Update the entity dropdown control(s) according to the partitioning fields for the selected detector.
Expand Down Expand Up @@ -684,7 +687,7 @@ export class TimeSeriesExplorer extends React.Component {
entities.push({ fieldName: byFieldName, fieldValue: byFieldValue });
}

this.setState({ entities });
this.setState({ entities }, callback);
}

loadForJobId(jobId, jobs) {
Expand Down Expand Up @@ -739,16 +742,16 @@ export class TimeSeriesExplorer extends React.Component {
this.setState(
{ detectorId, detectors, selectedJob },
() => {
this.updateControlsForDetector();

// Populate the map of jobs / detectors / field formatters for the selected IDs and refresh.
mlFieldFormatService.populateFormats([jobId], getIndexPatterns())
.catch((err) => { console.log('Error populating field formats:', err); })
this.updateControlsForDetector(() => {
// Populate the map of jobs / detectors / field formatters for the selected IDs and refresh.
mlFieldFormatService.populateFormats([jobId], getIndexPatterns())
.catch((err) => { console.log('Error populating field formats:', err); })
// Load the data - if the FieldFormats failed to populate
// the default formatting will be used for metric values.
.then(() => {
this.refresh();
});
.then(() => {
this.refresh();
});
});
}
);
}
Expand Down Expand Up @@ -1024,19 +1027,6 @@ export class TimeSeriesExplorer extends React.Component {
/>
);
})}
<EuiFlexItem grow={false}>
<EuiFormRow hasEmptyLabelSpace>
<EuiButton
fill
iconType="refresh"
onClick={this.saveSeriesPropertiesAndRefresh}
>
{i18n.translate('xpack.ml.timeSeriesExplorer.refreshButtonAriaLabel', {
defaultMessage: 'Refresh'
})}
</EuiButton>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ textAlign: 'right' }}>
<EuiFormRow hasEmptyLabelSpace style={{ maxWidth: '100%' }}>
<ForecastingModal
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -7183,7 +7183,6 @@
"xpack.ml.timeSeriesExplorer.loadingLabel": "読み込み中",
"xpack.ml.timeSeriesExplorer.noResultsFoundLabel": "結果が見つかりませんでした",
"xpack.ml.timeSeriesExplorer.noSingleMetricJobsFoundLabel": "シングルメトリックジョブが見つかりませんでした",
"xpack.ml.timeSeriesExplorer.refreshButtonAriaLabel": "更新",
"xpack.ml.timeSeriesExplorer.requestedDetectorIndexNotValidWarningMessage": "リクエストされた検知器インデックス {detectorIndex} はジョブ {jobId} に有効ではありません",
"xpack.ml.timeSeriesExplorer.runControls.durationLabel": "期間",
"xpack.ml.timeSeriesExplorer.runControls.forecastMaximumLengthHelpText": "予想の長さで、最長 {maximumForecastDurationDays} 日です。秒には s、分には m、時間には h、日には d、週には w を使います。",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -7325,7 +7325,6 @@
"xpack.ml.timeSeriesExplorer.loadingLabel": "正在加载",
"xpack.ml.timeSeriesExplorer.noResultsFoundLabel": "找不到结果",
"xpack.ml.timeSeriesExplorer.noSingleMetricJobsFoundLabel": "未找到单指标作业",
"xpack.ml.timeSeriesExplorer.refreshButtonAriaLabel": "刷新",
"xpack.ml.timeSeriesExplorer.requestedDetectorIndexNotValidWarningMessage": "请求的检测工具索引 {detectorIndex} 对于作业 {jobId} 无效",
"xpack.ml.timeSeriesExplorer.runControls.durationLabel": "持续时间",
"xpack.ml.timeSeriesExplorer.runControls.forecastMaximumLengthHelpText": "预测时长,最多 {maximumForecastDurationDays} 天。使用 s 表示秒,m 表示分钟,h 表示小时,d 表示天,w 表示周。",
Expand Down

0 comments on commit cf8dfbf

Please sign in to comment.