import React, { FC } from 'react'; import _ from 'lodash'; import { TemplateSrv } from '@grafana/runtime'; import { SelectableValue, rangeUtil } from '@grafana/data'; import { Segment } from '@grafana/ui'; import { alignmentPeriods, alignOptions } from '../constants'; export interface Props { onChange: (alignmentPeriod: string) => void; templateSrv: TemplateSrv; templateVariableOptions: Array>; alignmentPeriod: string; perSeriesAligner: string; usedAlignmentPeriod?: number; } export const AlignmentPeriods: FC = ({ alignmentPeriod, templateSrv, templateVariableOptions, onChange, perSeriesAligner, usedAlignmentPeriod, }) => { const alignment = alignOptions.find((ap) => ap.value === templateSrv.replace(perSeriesAligner)); const formatAlignmentText = usedAlignmentPeriod ? `${rangeUtil.secondsToHms(usedAlignmentPeriod)} interval (${alignment ? alignment.text : ''})` : ''; const options = alignmentPeriods.map((ap) => ({ ...ap, label: ap.text, })); const visibleOptions = options.filter((ap) => !ap.hidden); return ( <>
onChange(value!)} value={[...options, ...templateVariableOptions].find((s) => s.value === alignmentPeriod)} options={[ { label: 'Template Variables', options: templateVariableOptions, }, { label: 'Aggregations', expanded: true, options: visibleOptions, }, ]} placeholder="Select Alignment" >
{usedAlignmentPeriod && }
); };