Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed custom intervals not being remembered when switching tabs #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading