2019-01-17 09:27:43 +01:00
|
|
|
import React, { FC } from 'react';
|
2018-12-20 13:36:10 +01:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
|
2019-01-11 15:14:35 +01:00
|
|
|
import kbn from 'app/core/utils/kbn';
|
2019-01-02 15:07:38 +01:00
|
|
|
import { MetricSelect } from 'app/core/components/Select/MetricSelect';
|
2019-01-11 15:14:35 +01:00
|
|
|
import { alignmentPeriods, alignOptions } from '../constants';
|
2019-01-14 23:43:31 +01:00
|
|
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
2018-12-20 13:36:10 +01:00
|
|
|
|
|
|
|
|
export interface Props {
|
2019-07-01 11:11:57 +02:00
|
|
|
onChange: (alignmentPeriod: any) => void;
|
2019-01-14 23:43:31 +01:00
|
|
|
templateSrv: TemplateSrv;
|
2018-12-20 13:36:10 +01:00
|
|
|
alignmentPeriod: string;
|
2019-01-11 15:14:35 +01:00
|
|
|
perSeriesAligner: string;
|
|
|
|
|
usedAlignmentPeriod: string;
|
2018-12-20 13:36:10 +01:00
|
|
|
}
|
|
|
|
|
|
2019-01-17 09:27:43 +01:00
|
|
|
export const AlignmentPeriods: FC<Props> = ({
|
2019-01-11 15:14:35 +01:00
|
|
|
alignmentPeriod,
|
|
|
|
|
templateSrv,
|
|
|
|
|
onChange,
|
|
|
|
|
perSeriesAligner,
|
|
|
|
|
usedAlignmentPeriod,
|
|
|
|
|
}) => {
|
|
|
|
|
const alignment = alignOptions.find(ap => ap.value === templateSrv.replace(perSeriesAligner));
|
|
|
|
|
const formatAlignmentText = `${kbn.secondsToHms(usedAlignmentPeriod)} interval (${alignment ? alignment.text : ''})`;
|
|
|
|
|
|
2018-12-20 13:36:10 +01:00
|
|
|
return (
|
2019-01-08 13:00:31 +01:00
|
|
|
<>
|
2018-12-20 13:36:10 +01:00
|
|
|
<div className="gf-form-inline">
|
|
|
|
|
<div className="gf-form">
|
|
|
|
|
<label className="gf-form-label query-keyword width-9">Alignment Period</label>
|
2019-01-02 15:07:38 +01:00
|
|
|
<MetricSelect
|
2019-01-14 18:23:01 +01:00
|
|
|
onChange={onChange}
|
2019-01-02 15:07:38 +01:00
|
|
|
value={alignmentPeriod}
|
|
|
|
|
variables={templateSrv.variables}
|
|
|
|
|
options={[
|
|
|
|
|
{
|
|
|
|
|
label: 'Alignment options',
|
|
|
|
|
expanded: true,
|
|
|
|
|
options: alignmentPeriods.map(ap => ({
|
|
|
|
|
...ap,
|
|
|
|
|
label: ap.text,
|
|
|
|
|
})),
|
|
|
|
|
},
|
|
|
|
|
]}
|
2018-12-20 13:36:10 +01:00
|
|
|
placeholder="Select Alignment"
|
|
|
|
|
className="width-15"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2019-01-08 16:08:09 +01:00
|
|
|
<div className="gf-form gf-form--grow">
|
2019-01-11 15:14:35 +01:00
|
|
|
{usedAlignmentPeriod && <label className="gf-form-label gf-form-label--grow">{formatAlignmentText}</label>}
|
2019-01-08 16:08:09 +01:00
|
|
|
</div>
|
2018-12-20 13:36:10 +01:00
|
|
|
</div>
|
2019-01-08 13:00:31 +01:00
|
|
|
</>
|
2018-12-20 13:36:10 +01:00
|
|
|
);
|
|
|
|
|
};
|