Skip to content

Commit

Permalink
[ML] Single Metric Viewer embeddable: ensure detector index is passed…
Browse files Browse the repository at this point in the history
… to chart correctly (elastic#179761)

## Summary

This PR fixes bug where `selectedDetectorIndex` was not being passed to
the chart component correctly and always defaulted to the first
detector.

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

(cherry picked from commit 80e2805)
  • Loading branch information
alvarezmelissa87 committed Apr 3, 2024
1 parent 13fb5dd commit fd5087f
Showing 1 changed file with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export const EmbeddableSingleMetricViewerContainer: FC<
const [chartWidth, setChartWidth] = useState<number>(0);
const [zoom, setZoom] = useState<AppStateZoom | undefined>();
const [selectedForecastId, setSelectedForecastId] = useState<string | undefined>();
const [detectorIndex, setDetectorIndex] = useState<number>(0);
const [selectedJob, setSelectedJob] = useState<MlJob | undefined>();
const [autoZoomDuration, setAutoZoomDuration] = useState<number | undefined>();

Expand Down Expand Up @@ -135,10 +134,6 @@ export const EmbeddableSingleMetricViewerContainer: FC<
*/

switch (action) {
case APP_STATE_ACTION.SET_DETECTOR_INDEX:
setDetectorIndex(payload);
break;

case APP_STATE_ACTION.SET_FORECAST_ID:
setSelectedForecastId(payload);
setZoom(undefined);
Expand All @@ -154,7 +149,7 @@ export const EmbeddableSingleMetricViewerContainer: FC<
}
},

[setZoom, setDetectorIndex, setSelectedForecastId]
[setZoom, setSelectedForecastId]
);

const containerPadding = 10;
Expand Down Expand Up @@ -185,7 +180,7 @@ export const EmbeddableSingleMetricViewerContainer: FC<
lastRefresh={lastRefresh ?? 0}
previousRefresh={previousRefresh}
selectedJobId={selectedJobId}
selectedDetectorIndex={detectorIndex}
selectedDetectorIndex={data.selectedDetectorIndex}
selectedEntities={data.selectedEntities}
selectedForecastId={selectedForecastId}
zoom={zoom}
Expand Down

0 comments on commit fd5087f

Please sign in to comment.