mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Refresh label when time range changes * Refactor solution * Add tests * Update tests comments * Update test * Update public/app/plugins/datasource/loki/components/LokiQueryField.tsx * Update public/app/plugins/datasource/loki/components/LokiQueryField.tsx
20 lines
672 B
TypeScript
20 lines
672 B
TypeScript
import { TimeRange } from '@grafana/data';
|
|
|
|
function roundMsToMin(milliseconds: number): number {
|
|
return roundSecToMin(milliseconds / 1000);
|
|
}
|
|
|
|
function roundSecToMin(seconds: number): number {
|
|
return Math.floor(seconds / 60);
|
|
}
|
|
|
|
export function shouldRefreshLabels(range?: TimeRange, prevRange?: TimeRange): boolean {
|
|
if (range && prevRange) {
|
|
const sameMinuteFrom = roundMsToMin(range.from.valueOf()) === roundMsToMin(prevRange.from.valueOf());
|
|
const sameMinuteTo = roundMsToMin(range.to.valueOf()) === roundMsToMin(prevRange.to.valueOf());
|
|
// If both are same, don't need to refresh
|
|
return !(sameMinuteFrom && sameMinuteTo);
|
|
}
|
|
return false;
|
|
}
|