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