2019-09-17 11:25:12 +02:00
|
|
|
import React from 'react';
|
2020-10-16 12:10:25 +01:00
|
|
|
import { RefreshPicker, defaultIntervals } from '@grafana/ui';
|
|
|
|
|
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
|
|
|
|
|
|
|
|
|
export type Props = {
|
2021-01-23 08:17:50 +01:00
|
|
|
isSmall?: boolean;
|
2019-09-17 11:25:12 +02:00
|
|
|
loading: boolean;
|
2020-05-05 09:40:47 +01:00
|
|
|
isLive: boolean;
|
2020-03-25 10:38:14 +00:00
|
|
|
onRun: (loading: boolean) => void;
|
2019-11-26 09:01:32 +00:00
|
|
|
refreshInterval?: string;
|
2019-09-17 11:25:12 +02:00
|
|
|
onChangeRefreshInterval: (interval: string) => void;
|
|
|
|
|
showDropdown: boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function RunButton(props: Props) {
|
2021-01-23 08:17:50 +01:00
|
|
|
const { isSmall, loading, onRun, onChangeRefreshInterval, refreshInterval, showDropdown, isLive } = props;
|
2020-10-16 12:10:25 +01:00
|
|
|
const intervals = getTimeSrv().getValidIntervals(defaultIntervals);
|
2021-01-23 08:17:50 +01:00
|
|
|
let text: string | undefined;
|
2020-03-25 10:38:14 +00:00
|
|
|
|
2021-01-23 08:17:50 +01:00
|
|
|
if (isLive) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2019-09-17 11:25:12 +02:00
|
|
|
|
2021-01-23 08:17:50 +01:00
|
|
|
if (!isSmall) {
|
|
|
|
|
text = loading ? 'Cancel' : 'Run query';
|
2019-09-17 11:25:12 +02:00
|
|
|
}
|
2021-01-23 08:17:50 +01:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<RefreshPicker
|
|
|
|
|
onIntervalChanged={onChangeRefreshInterval}
|
|
|
|
|
value={refreshInterval}
|
|
|
|
|
isLoading={loading}
|
|
|
|
|
text={text}
|
|
|
|
|
intervals={intervals}
|
|
|
|
|
isLive={isLive}
|
|
|
|
|
onRefresh={() => onRun(loading)}
|
|
|
|
|
noIntervalPicker={!showDropdown}
|
|
|
|
|
primary={true}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2019-09-17 11:25:12 +02:00
|
|
|
}
|