mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Fix validation of step values to also allow e.g. ms values (#73270)
* use go duration validation * add `isValidGrafanaDuration` * use `isValidGrafanaDuration` * improve jsdoc
This commit is contained in:
@@ -140,6 +140,18 @@ describe('LokiQueryBuilderOptions', () => {
|
||||
await userEvent.click(screen.getByRole('button', { name: /Options/ }));
|
||||
expect(screen.queryByText(/Invalid step/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not shows error when valid millisecond value in step', async () => {
|
||||
setup({ expr: 'rate({foo="bar"}[5m]', step: '1ms' });
|
||||
await userEvent.click(screen.getByRole('button', { name: /Options/ }));
|
||||
expect(screen.queryByText(/Invalid step/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('does not shows error when valid day value in step', async () => {
|
||||
setup({ expr: 'rate({foo="bar"}[5m]', step: '1d' });
|
||||
await userEvent.click(screen.getByRole('button', { name: /Options/ }));
|
||||
expect(screen.queryByText(/Invalid step/)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
function setup(queryOverrides: Partial<LokiQuery> = {}) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { trim } from 'lodash';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
|
||||
import { CoreApp, isValidDuration, SelectableValue } from '@grafana/data';
|
||||
import { CoreApp, isValidDuration, isValidGrafanaDuration, SelectableValue } from '@grafana/data';
|
||||
import { EditorField, EditorRow } from '@grafana/experimental';
|
||||
import { config, reportInteraction } from '@grafana/runtime';
|
||||
import { Alert, AutoSizeInput, RadioButtonGroup, Select } from '@grafana/ui';
|
||||
@@ -71,7 +71,7 @@ export const LokiQueryBuilderOptions = React.memo<Props>(
|
||||
const isLogQuery = isLogsQuery(query.expr);
|
||||
|
||||
const isValidStep = useMemo(() => {
|
||||
if (!query.step || isValidDuration(query.step) || !isNaN(Number(query.step))) {
|
||||
if (!query.step || isValidGrafanaDuration(query.step) || !isNaN(Number(query.step))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user