mirror of
https://github.com/grafana/grafana.git
synced 2025-09-28 01:44:00 +08:00

* organize layout, make design uniform, add doc link * fix e2e test * move overhauled config parts into prometheus code * update tooltips with doc links * clean component styles for section padding, top and bottom 32px * make additional settings subsection headers h6 * use secondary gray for section descriptions * fix merge issues * change inlineswitch to switch only in prom settings because the other components are shared * remove legacy formfield and input, replace with inlinefield and input from grafana-ui * find more formfield and UI design fixes like changing inlineformlabel to inlinefield * remove unused inline form label * replace legacy duration validations with <FieldValidationMessage> * fix styles secondary gray from theme * change language, headings and datasource -> data source * update alert setting styles with new component * update prom url heading and tooltip * update default editor tooltip and set builder as default editor * update interval tooltip * update prom type tooltip * update custom query params tooltip * update exemplar internal link tooltip * fix inline form styling inconsistency * allow for using the DataSourceHTTPSettings component without the connection string * remove overhaul component, re-use dshtttps comp, and use connection input in config editor * make tooltips interactive to click links * consistent label width across the elements we can control for now, fix exemplar switch * make connection url a component * refactor onBlur validation * remove unused component * add tests for config validations * add more meaningful health check * fix e2e test * fix e2e test * fix e2e test * add error handling for more url errors * remove unnecessary conversion * health check tests * Clean up the health check * health check unit tests * health check unit tests improved * make pretty for drone * lint check go * lint check go * add required attr to connection component * Update public/app/plugins/datasource/prometheus/configuration/Connection.tsx Co-authored-by: Torkel Ödegaard <torkel@grafana.com> * fix read only issue for provisioned datasources * validate multiple durations for incremental query setting * use sentence case for headers * use className consistently for styles * add tests for url regex * remove console logs * only use query as healthcheck as the healthy api is not supported by Mimir * fix exemplar e2e test * remove overhaul prop from custom headers setting component * remove connection section and use DatasourceHttpSettings connection with custom label and interactive tooltip * add spaces back * spaces --------- Co-authored-by: ismail simsek <ismailsimsek09@gmail.com> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import React from 'react';
|
|
|
|
import { FieldValidationMessage } from '@grafana/ui';
|
|
|
|
import { validateInput } from './ConfigEditor';
|
|
import { DURATION_REGEX, MULTIPLE_DURATION_REGEX } from './PromSettings';
|
|
|
|
const VALID_URL_REGEX = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/;
|
|
|
|
const error = <FieldValidationMessage>Value is not valid</FieldValidationMessage>;
|
|
// replaces promSettingsValidationEvents to display a <FieldValidationMessage> onBlur for duration input errors
|
|
describe('promSettings validateInput', () => {
|
|
it.each`
|
|
value | expected
|
|
${'1ms'} | ${true}
|
|
${'1M'} | ${true}
|
|
${'1w'} | ${true}
|
|
${'1d'} | ${true}
|
|
${'1h'} | ${true}
|
|
${'1m'} | ${true}
|
|
${'1s'} | ${true}
|
|
${'1y'} | ${true}
|
|
`(
|
|
"Single duration regex, when calling the rule with correct formatted value: '$value' then result should be '$expected'",
|
|
({ value, expected }) => {
|
|
expect(validateInput(value, DURATION_REGEX)).toBe(expected);
|
|
}
|
|
);
|
|
|
|
it.each`
|
|
value | expected
|
|
${'1M 2s'} | ${true}
|
|
${'1w 2d'} | ${true}
|
|
${'1d 2m'} | ${true}
|
|
${'1h 2m'} | ${true}
|
|
${'1m 2s'} | ${true}
|
|
`(
|
|
"Multiple duration regex, when calling the rule with correct formatted value: '$value' then result should be '$expected'",
|
|
({ value, expected }) => {
|
|
expect(validateInput(value, MULTIPLE_DURATION_REGEX)).toBe(expected);
|
|
}
|
|
);
|
|
|
|
it.each`
|
|
value | expected
|
|
${'1 ms'} | ${error}
|
|
${'1x'} | ${error}
|
|
${' '} | ${error}
|
|
${'w'} | ${error}
|
|
${'1.0s'} | ${error}
|
|
`(
|
|
"when calling the rule with incorrect formatted value: '$value' then result should be '$expected'",
|
|
({ value, expected }) => {
|
|
expect(validateInput(value, DURATION_REGEX)).toStrictEqual(expected);
|
|
}
|
|
);
|
|
|
|
it.each`
|
|
value | expected
|
|
${'frp://'} | ${error}
|
|
${'htp://'} | ${error}
|
|
${'httpss:??'} | ${error}
|
|
${'http@//'} | ${error}
|
|
${'http:||'} | ${error}
|
|
${'http://'} | ${error}
|
|
${'https://'} | ${error}
|
|
${'ftp://'} | ${error}
|
|
`(
|
|
"Url incorrect formatting, when calling the rule with correct formatted value: '$value' then result should be '$expected'",
|
|
({ value, expected }) => {
|
|
expect(validateInput(value, VALID_URL_REGEX)).toStrictEqual(expected);
|
|
}
|
|
);
|
|
|
|
it.each`
|
|
value | expected
|
|
${'ftp://example'} | ${true}
|
|
${'http://example'} | ${true}
|
|
${'https://example'} | ${true}
|
|
`(
|
|
"Url correct formatting, when calling the rule with correct formatted value: '$value' then result should be '$expected'",
|
|
({ value, expected }) => {
|
|
expect(validateInput(value, VALID_URL_REGEX)).toBe(expected);
|
|
}
|
|
);
|
|
|
|
it('should display a custom validation message', () => {
|
|
const invalidDuration = 'invalid';
|
|
const customMessage = 'This is invalid';
|
|
const errorWithCustomMessage = <FieldValidationMessage>{customMessage}</FieldValidationMessage>;
|
|
expect(validateInput(invalidDuration, DURATION_REGEX, customMessage)).toStrictEqual(errorWithCustomMessage);
|
|
});
|
|
});
|