AlignmentPeriods.tsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { SFC } from 'react';
  2. import _ from 'lodash';
  3. import kbn from 'app/core/utils/kbn';
  4. import { MetricSelect } from 'app/core/components/Select/MetricSelect';
  5. import { alignmentPeriods, alignOptions } from '../constants';
  6. export interface Props {
  7. onChange: (alignmentPeriod) => void;
  8. templateSrv: any;
  9. alignmentPeriod: string;
  10. perSeriesAligner: string;
  11. usedAlignmentPeriod: string;
  12. }
  13. export const AlignmentPeriods: SFC<Props> = ({
  14. alignmentPeriod,
  15. templateSrv,
  16. onChange,
  17. perSeriesAligner,
  18. usedAlignmentPeriod,
  19. }) => {
  20. const alignment = alignOptions.find(ap => ap.value === templateSrv.replace(perSeriesAligner));
  21. const formatAlignmentText = `${kbn.secondsToHms(usedAlignmentPeriod)} interval (${alignment ? alignment.text : ''})`;
  22. return (
  23. <>
  24. <div className="gf-form-inline">
  25. <div className="gf-form">
  26. <label className="gf-form-label query-keyword width-9">Alignment Period</label>
  27. <MetricSelect
  28. onChange={onChange}
  29. value={alignmentPeriod}
  30. variables={templateSrv.variables}
  31. options={[
  32. {
  33. label: 'Alignment options',
  34. expanded: true,
  35. options: alignmentPeriods.map(ap => ({
  36. ...ap,
  37. label: ap.text,
  38. })),
  39. },
  40. ]}
  41. placeholder="Select Alignment"
  42. className="width-15"
  43. />
  44. </div>
  45. <div className="gf-form gf-form--grow">
  46. {usedAlignmentPeriod && <label className="gf-form-label gf-form-label--grow">{formatAlignmentText}</label>}
  47. </div>
  48. </div>
  49. </>
  50. );
  51. };