Loki: Fix misaligned derived fields settings (#61475)

* fix loki datasource settings

* remove unnecessary spacing

* remove unused import
This commit is contained in:
Sven Grossmann 2023-01-13 14:25:03 +01:00 committed by GitHub
parent 117874176d
commit b816538e09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,15 +2,15 @@ import { css } from '@emotion/css';
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { usePrevious } from 'react-use'; import { usePrevious } from 'react-use';
import { VariableSuggestion } from '@grafana/data'; import { GrafanaTheme2, VariableSuggestion } from '@grafana/data';
import { DataSourcePicker } from '@grafana/runtime'; import { DataSourcePicker } from '@grafana/runtime';
import { Button, DataLinkInput, stylesFactory, LegacyForms } from '@grafana/ui'; import { Button, DataLinkInput, LegacyForms, useStyles2 } from '@grafana/ui';
import { DerivedFieldConfig } from '../types'; import { DerivedFieldConfig } from '../types';
const { Switch, FormField } = LegacyForms; const { Switch, FormField } = LegacyForms;
const getStyles = stylesFactory(() => ({ const getStyles = (theme: GrafanaTheme2) => ({
row: css` row: css`
display: flex; display: flex;
align-items: baseline; align-items: baseline;
@ -23,11 +23,12 @@ const getStyles = stylesFactory(() => ({
`, `,
urlField: css` urlField: css`
flex: 1; flex: 1;
margin-right: ${theme.spacing(0.5)};
`, `,
urlDisplayLabelField: css` urlDisplayLabelField: css`
flex: 1; flex: 1;
`, `,
})); });
type Props = { type Props = {
value: DerivedFieldConfig; value: DerivedFieldConfig;
@ -38,7 +39,7 @@ type Props = {
}; };
export const DerivedField = (props: Props) => { export const DerivedField = (props: Props) => {
const { value, onChange, onDelete, suggestions, className } = props; const { value, onChange, onDelete, suggestions, className } = props;
const styles = getStyles(); const styles = useStyles2(getStyles);
const [showInternalLink, setShowInternalLink] = useState(!!value.datasourceUid); const [showInternalLink, setShowInternalLink] = useState(!!value.datasourceUid);
const previousUid = usePrevious(value.datasourceUid); const previousUid = usePrevious(value.datasourceUid);
@ -61,10 +62,10 @@ export const DerivedField = (props: Props) => {
return ( return (
<div className={className} data-testid="derived-field"> <div className={className} data-testid="derived-field">
<div className={styles.row}> <div className="gf-form">
<FormField <FormField
labelWidth={10}
className={styles.nameField} className={styles.nameField}
labelWidth={5}
// A bit of a hack to prevent using default value for the width from FormField // A bit of a hack to prevent using default value for the width from FormField
inputWidth={null} inputWidth={null}
label="Name" label="Name"
@ -73,6 +74,7 @@ export const DerivedField = (props: Props) => {
onChange={handleChange('name')} onChange={handleChange('name')}
/> />
<FormField <FormField
labelWidth={10}
className={styles.regexField} className={styles.regexField}
inputWidth={null} inputWidth={null}
label="Regex" label="Regex"
@ -91,14 +93,12 @@ export const DerivedField = (props: Props) => {
event.preventDefault(); event.preventDefault();
onDelete(); onDelete();
}} }}
className={css`
margin-left: 8px;
`}
/> />
</div> </div>
<div className={styles.row}> <div className="gf-form">
<FormField <FormField
labelWidth={10}
label={showInternalLink ? 'Query' : 'URL'} label={showInternalLink ? 'Query' : 'URL'}
inputEl={ inputEl={
<DataLinkInput <DataLinkInput
@ -117,6 +117,7 @@ export const DerivedField = (props: Props) => {
/> />
<FormField <FormField
className={styles.urlDisplayLabelField} className={styles.urlDisplayLabelField}
labelWidth={10}
inputWidth={null} inputWidth={null}
label="URL Label" label="URL Label"
type="text" type="text"