RunButton.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import React from 'react';
  2. import { RefreshPicker } from '@grafana/ui';
  3. import memoizeOne from 'memoize-one';
  4. import { css } from 'emotion';
  5. import { ResponsiveButton } from './ResponsiveButton';
  6. const getStyles = memoizeOne(() => {
  7. return {
  8. selectButtonOverride: css`
  9. label: selectButtonOverride;
  10. .select-button-value {
  11. color: white !important;
  12. }
  13. `,
  14. };
  15. });
  16. type Props = {
  17. splitted: boolean;
  18. loading: boolean;
  19. onRun: () => void;
  20. refreshInterval: string;
  21. onChangeRefreshInterval: (interval: string) => void;
  22. showDropdown: boolean;
  23. };
  24. export function RunButton(props: Props) {
  25. const { splitted, loading, onRun, onChangeRefreshInterval, refreshInterval, showDropdown } = props;
  26. const styles = getStyles();
  27. const runButton = (
  28. <ResponsiveButton
  29. splitted={splitted}
  30. title="Run Query"
  31. onClick={onRun}
  32. buttonClassName="navbar-button--secondary btn--radius-right-0 "
  33. iconClassName={loading ? 'fa fa-spinner fa-fw fa-spin run-icon' : 'fa fa-refresh fa-fw'}
  34. />
  35. );
  36. if (showDropdown) {
  37. return (
  38. <RefreshPicker
  39. onIntervalChanged={onChangeRefreshInterval}
  40. value={refreshInterval}
  41. buttonSelectClassName={`navbar-button--secondary ${styles.selectButtonOverride}`}
  42. refreshButton={runButton}
  43. />
  44. );
  45. }
  46. return runButton;
  47. }