From 18b3cc1900165ed34a78726b66279da42e2b0021 Mon Sep 17 00:00:00 2001 From: Myriam Gantner <48029745+MGJamJam@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:01:28 +0200 Subject: [PATCH] add default value for percentileValue (#95) * set default value for percentile and deletes percentile value when percentile is deselected * update changelog * delete unnecessary if statement * fmt --- CHANGELOG.md | 4 ++++ src/components/QueryEditor.tsx | 12 +++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4486992..2ebe70f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Development +### Added + +- Default Percentile Value when percentile metric is selected + ## 1.1.1 ### Added diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx index b74ae5e..ce3c8c5 100644 --- a/src/components/QueryEditor.tsx +++ b/src/components/QueryEditor.tsx @@ -69,7 +69,17 @@ export function QueryEditor(props: Props) { }; const handleAggregationChange = (item: SelectableValue) => { - props.onChange({ ...query, metric: item.value }); + // set a default value when percentile is selected and delete percentileValue when percentile is deselected + // to not pollute the dashboard.json file + let percentile = undefined; + if (item.value === 'percentile' && percentileValue == null) { + setPercentileValue(95); + percentile = 95; + } else { + setPercentileValue(undefined); + } + + props.onChange({ ...query, metric: item.value, percentileValue: percentile }); props.onRunQuery(); };