mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
RefreshPicker: Handle empty intervals (#17585)
* Refresh picker empty * RefreshPicker: refactoring
This commit is contained in:
committed by
Torkel Ödegaard
parent
f9b691bd54
commit
2f00087a08
@@ -19,29 +19,20 @@ export interface Props {
|
||||
}
|
||||
|
||||
export class RefreshPicker extends PureComponent<Props> {
|
||||
static defaultProps = {
|
||||
intervals: defaultIntervals,
|
||||
};
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
hasNoIntervals = () => {
|
||||
const { intervals } = this.props;
|
||||
// Current implementaion returns an array with length of 1 consisting of
|
||||
// an empty string when auto-refresh is empty in dashboard settings
|
||||
if (!intervals || intervals.length < 1 || (intervals.length === 1 && intervals[0] === '')) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
intervalsToOptions = (intervals: string[] | undefined): Array<SelectOptionItem<string>> => {
|
||||
const intervalsOrDefault = intervals || defaultIntervals;
|
||||
const options = intervalsOrDefault
|
||||
.filter(str => str !== '')
|
||||
.map(interval => ({ label: interval, value: interval }));
|
||||
|
||||
intervalsToOptions = (intervals: string[] = defaultIntervals): Array<SelectOptionItem<string>> => {
|
||||
const options = intervals.map(interval => ({ label: interval, value: interval }));
|
||||
if (this.props.hasLiveOption) {
|
||||
options.unshift(liveOption);
|
||||
}
|
||||
|
||||
options.unshift(offOption);
|
||||
return options;
|
||||
};
|
||||
@@ -56,7 +47,7 @@ export class RefreshPicker extends PureComponent<Props> {
|
||||
|
||||
render() {
|
||||
const { onRefresh, intervals, tooltip, value } = this.props;
|
||||
const options = this.intervalsToOptions(this.hasNoIntervals() ? defaultIntervals : intervals);
|
||||
const options = this.intervalsToOptions(intervals);
|
||||
const currentValue = value || '';
|
||||
const selectedValue = options.find(item => item.value === currentValue) || offOption;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user