From 76942295676ff362ea6a9b1be53380147262228f Mon Sep 17 00:00:00 2001 From: MGJamJam Date: Thu, 20 Jun 2024 10:42:26 -0300 Subject: [PATCH] implement percentile input --- .../src/components/QueryEditor.tsx | 51 +++++++++++++++---- .../src/datasource.ts | 2 + 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/bitmovin-analytics-datasource/src/components/QueryEditor.tsx b/bitmovin-analytics-datasource/src/components/QueryEditor.tsx index 086bf6a..2918c0c 100644 --- a/bitmovin-analytics-datasource/src/components/QueryEditor.tsx +++ b/bitmovin-analytics-datasource/src/components/QueryEditor.tsx @@ -1,5 +1,5 @@ import React, { ChangeEvent, useEffect, useMemo, useState } from 'react'; -import { FieldSet, InlineField, InlineSwitch, Input, Select } from '@grafana/ui'; +import { FieldSet, HorizontalGroup, InlineField, InlineSwitch, Input, Select } from '@grafana/ui'; import type { QueryEditorProps, SelectableValue } from '@grafana/data'; import { defaults } from 'lodash'; @@ -42,9 +42,13 @@ export function QueryEditor(props: Props) { const [licenseLoadingState, setLicenseLoadingState] = useState(LoadingState.Default); const [licenseErrorMessage, setLicenseErrorMessage] = useState(''); const [isTimeSeries, setIsTimeSeries] = useState(!!props.query.interval); + const [percentileValue, setPercentileValue] = useState(props.query.percentile); const isMetricSelected = useMemo(() => { return props.query.dimension ? isMetric(props.query.dimension) : false; }, [props.query.dimension]); + const isPercentileSelected = useMemo(() => { + return props.query.metric === 'percentile'; + }, [props.query.metric]); /** Fetch Licenses */ useEffect(() => { @@ -159,6 +163,21 @@ export function QueryEditor(props: Props) { props.onRunQuery(); }; + const handelPercentileValueChange = (event: ChangeEvent) => { + let percentile = parseInt(event.target.value, 10); + if (percentile < 0) { + percentile = 0; + } else if (percentile > 99) { + percentile = 99; + } + setPercentileValue(percentile); + }; + + const handlePercentileBlur = () => { + props.onChange({ ...query, percentile: percentileValue }); + props.onRunQuery(); + }; + const renderTimeSeriesOption = () => { return ( <> @@ -195,16 +214,28 @@ export function QueryEditor(props: Props) { placeholder={licenseLoadingState === LoadingState.Loading ? 'Loading Licenses' : 'Choose License'} /> - {!isMetricSelected && ( - - handleAggregationChange(item)} + width={30} + options={SELECTABLE_AGGREGATIONS} + /> + + )} + {isPercentileSelected && ( + - - )} + )} +