mirror of
https://github.com/grafana/grafana.git
synced 2025-09-21 15:23:44 +08:00

* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
29 lines
1004 B
TypeScript
29 lines
1004 B
TypeScript
import React, { FC, useMemo } from 'react';
|
|
|
|
import { rangeUtil } from '@grafana/data';
|
|
|
|
import { ALIGNMENTS } from '../constants';
|
|
import CloudMonitoringDatasource from '../datasource';
|
|
import { CustomMetaData } from '../types';
|
|
|
|
export interface Props {
|
|
customMetaData: CustomMetaData;
|
|
datasource: CloudMonitoringDatasource;
|
|
}
|
|
|
|
export const AlignmentPeriodLabel: FC<Props> = ({ customMetaData, datasource }) => {
|
|
const { perSeriesAligner, alignmentPeriod } = customMetaData;
|
|
const formatAlignmentText = useMemo(() => {
|
|
if (!alignmentPeriod || !perSeriesAligner) {
|
|
return '';
|
|
}
|
|
|
|
const alignment = ALIGNMENTS.find((ap) => ap.value === datasource.templateSrv.replace(perSeriesAligner));
|
|
const seconds = parseInt(alignmentPeriod ?? ''.replace(/[^0-9]/g, ''), 10);
|
|
const hms = rangeUtil.secondsToHms(seconds);
|
|
return `${hms} interval (${alignment?.text ?? ''})`;
|
|
}, [datasource, perSeriesAligner, alignmentPeriod]);
|
|
|
|
return <label>{formatAlignmentText}</label>;
|
|
};
|