RunButton.tsx 1.4 KB

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