AlignmentPeriods.tsx 1.7 KB

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