Skip to content

Commit

Permalink
Fixed custom intervals not being remembered when switching tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
coesent committed Jan 2, 2025
1 parent 3b79910 commit 5c9339d
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/QueryEditor/QueryOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent, useState } from 'react'
import React, { ChangeEvent, useState, useEffect } from 'react'
import { SelectableValue } from '@grafana/data'
import { CollapsableSection, InlineField, InlineFieldRow, InlineLabel, InlineSwitch, Input, Select } from '@grafana/ui'
import { QueryTag, TagsSection } from 'components/TagsSection/TagsSection'
Expand Down Expand Up @@ -31,6 +31,22 @@ export const QueryOptions = (props: Props): JSX.Element => {
const [periods, setPeriods] = useState(getPeriods())
const [seriesLimit, setSeriesLimit] = useDebounce<number>(props.seriesLimit, 500, props.onChangeSeriesLimit)

useEffect(() => {
if (props.state.Aggregation?.Period) {
const periodExists = periods.some(
(period) => period.value === props.state.Aggregation?.Period
)

if (!periodExists) {
const customValue: SelectableValue<string> = {
value: props.state.Aggregation?.Period,
label: props.state.Aggregation?.Period
}
setPeriods((prevPeriods) => [...prevPeriods, customValue])
}
}
}, [periods, props.state.Aggregation?.Period])

const getAggregationOptions = (
datatypes: string[],
options: MeasurementQueryOptions
Expand Down

0 comments on commit 5c9339d

Please sign in to comment.