TimeSelect.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React from 'react';
  2. import { SelectableValue } from '@grafana/data';
  3. import { Field, Select } from '@grafana/ui';
  4. type TSProps = {
  5. label: string;
  6. description: string;
  7. value: number;
  8. onChange: (s: number) => void;
  9. };
  10. export const timeIntervals: Array<SelectableValue<number>> = [
  11. { label: '30 seconds', value: 30 },
  12. { label: '1 minute', value: 60 },
  13. { label: '5 minutes', value: 300 },
  14. { label: '30 minutes', value: 1800 },
  15. { label: '1 hour', value: 3600 },
  16. { label: '12 hours', value: 43200 },
  17. { label: '24 hours', value: 86400 },
  18. { label: '1 week', value: 604800 },
  19. { label: '1 month', value: 2592000 },
  20. ];
  21. export const TimeSelect = ({ label, description, value, onChange }: TSProps) => {
  22. return (
  23. <div>
  24. <Field label={label} description={description} required={true}>
  25. <Select
  26. options={timeIntervals}
  27. onChange={(v: SelectableValue<number>) => {
  28. onChange(v.value!);
  29. }}
  30. value={value}
  31. aria-label={`${label}-select`}
  32. menuShouldPortal
  33. />
  34. </Field>
  35. </div>
  36. );
  37. };