Variable editor: fix styles in Grafana 7
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import { parseLegacyVariableQuery } from '../utils';
|
import { parseLegacyVariableQuery } from '../utils';
|
||||||
import { Select, Input } from '@grafana/ui';
|
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue } from '@grafana/data';
|
||||||
import { VariableQuery, VariableQueryTypes, VariableQueryProps, VariableQueryData } from '../types';
|
import { VariableQuery, VariableQueryTypes, VariableQueryProps, VariableQueryData } from '../types';
|
||||||
import { ZabbixInput } from './ZabbixInput';
|
import { ZabbixInput } from './ZabbixInput';
|
||||||
@@ -8,6 +7,8 @@ import { ZabbixInput } from './ZabbixInput';
|
|||||||
// FormLabel was renamed to InlineFormLabel in Grafana 7.0
|
// FormLabel was renamed to InlineFormLabel in Grafana 7.0
|
||||||
import * as grafanaUi from '@grafana/ui';
|
import * as grafanaUi from '@grafana/ui';
|
||||||
const FormLabel = grafanaUi.FormLabel || (grafanaUi as any).InlineFormLabel;
|
const FormLabel = grafanaUi.FormLabel || (grafanaUi as any).InlineFormLabel;
|
||||||
|
const Select = (grafanaUi as any).LegacyForms?.Select || (grafanaUi as any).Select;
|
||||||
|
const Input = (grafanaUi as any).LegacyForms?.Input || (grafanaUi as any).Input;
|
||||||
|
|
||||||
export class ZabbixVariableQueryEditor extends PureComponent<VariableQueryProps, VariableQueryData> {
|
export class ZabbixVariableQueryEditor extends PureComponent<VariableQueryProps, VariableQueryData> {
|
||||||
queryTypes: Array<SelectableValue<VariableQueryTypes>> = [
|
queryTypes: Array<SelectableValue<VariableQueryTypes>> = [
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { css, cx } from 'emotion';
|
import { css, cx } from 'emotion';
|
||||||
import { Themeable, withTheme, Input, EventsWithValidation, ValidationEvents } from '@grafana/ui';
|
import { EventsWithValidation, ValidationEvents, useTheme } from '@grafana/ui';
|
||||||
import { isRegex, variableRegex } from '../utils';
|
|
||||||
import { GrafanaTheme } from '@grafana/data';
|
import { GrafanaTheme } from '@grafana/data';
|
||||||
|
import { isRegex, variableRegex } from '../utils';
|
||||||
|
|
||||||
|
import * as grafanaUi from '@grafana/ui';
|
||||||
|
const Input = (grafanaUi as any).LegacyForms?.Input || (grafanaUi as any).Input;
|
||||||
|
|
||||||
const variablePattern = RegExp(`^${variableRegex.source}`);
|
const variablePattern = RegExp(`^${variableRegex.source}`);
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme) => ({
|
const getStyles = (theme: GrafanaTheme) => ({
|
||||||
inputRegex: css`
|
inputRegex: css`
|
||||||
color: ${theme.colors.orange}
|
color: ${theme.colors.orange || (theme as any).palette.orange}
|
||||||
`,
|
`,
|
||||||
inputVariable: css`
|
inputVariable: css`
|
||||||
color: ${theme.colors.variable}
|
color: ${theme.colors.variable || (theme as any).palette.variable}
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -43,17 +46,14 @@ const zabbixInputValidationEvents: ValidationEvents = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Props extends React.ComponentProps<typeof Input>, Themeable {
|
export const ZabbixInput: FC<any> = ({ value, ref, validationEvents, ...restProps }) => {
|
||||||
}
|
const theme = useTheme();
|
||||||
|
|
||||||
const UnthemedZabbixInput: FC<Props> = ({ theme, value, ref, validationEvents, ...restProps }) => {
|
|
||||||
const styles = getStyles(theme);
|
const styles = getStyles(theme);
|
||||||
|
|
||||||
let inputClass;
|
let inputClass = styles.inputRegex;
|
||||||
if (variablePattern.test(value as string)) {
|
if (variablePattern.test(value as string)) {
|
||||||
inputClass = styles.inputVariable;
|
inputClass = styles.inputVariable;
|
||||||
}
|
} else if (isRegex(value)) {
|
||||||
if (isRegex(value)) {
|
|
||||||
inputClass = styles.inputRegex;
|
inputClass = styles.inputRegex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,5 +66,3 @@ const UnthemedZabbixInput: FC<Props> = ({ theme, value, ref, validationEvents, .
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ZabbixInput = withTheme(UnthemedZabbixInput);
|
|
||||||
|
|||||||
Reference in New Issue
Block a user