mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Starting moving more stuff into data source picker * WIP progress * Progress on datasource picker rethink * Things are working now some details to figure out * Removed commented part * Complex work on getting data source lists * Fixed variable support showing correct data sources * Tried fixing dashboard import but failed * Fixes * Fixed import dashboard * Fixed unit test * Fixed explore test * Fixed test * Fix * fixed more tests * fixed more tests * fixed showing which option is default in picker * Changed query variable to use data source picker, updated tests and e2e * Fixed more tests * Updated snapshots, had wrong typescript version
68 lines
1.6 KiB
TypeScript
68 lines
1.6 KiB
TypeScript
import React, { FormEvent, PropsWithChildren, ReactElement, useCallback } from 'react';
|
|
import { InlineField, TextArea, useStyles } from '@grafana/ui';
|
|
import { GrafanaTheme } from '@grafana/data';
|
|
import { css } from 'emotion';
|
|
|
|
interface VariableTextAreaFieldProps<T> {
|
|
name: string;
|
|
value: string;
|
|
placeholder: string;
|
|
onChange: (event: FormEvent<HTMLTextAreaElement>) => void;
|
|
width: number;
|
|
tooltip?: string;
|
|
ariaLabel?: string;
|
|
required?: boolean;
|
|
labelWidth?: number;
|
|
onBlur?: (event: FormEvent<HTMLTextAreaElement>) => void;
|
|
}
|
|
|
|
export function VariableTextAreaField({
|
|
name,
|
|
value,
|
|
placeholder,
|
|
tooltip,
|
|
onChange,
|
|
onBlur,
|
|
ariaLabel,
|
|
required,
|
|
width,
|
|
labelWidth,
|
|
}: PropsWithChildren<VariableTextAreaFieldProps<any>>): ReactElement {
|
|
const styles = useStyles(getStyles);
|
|
const getLineCount = useCallback((value: any) => {
|
|
if (value && typeof value === 'string') {
|
|
return value.split('\n').length;
|
|
}
|
|
|
|
return 1;
|
|
}, []);
|
|
|
|
return (
|
|
<InlineField label={name} labelWidth={labelWidth ?? 12} tooltip={tooltip}>
|
|
<TextArea
|
|
rows={getLineCount(value)}
|
|
value={value}
|
|
onChange={onChange}
|
|
onBlur={onBlur}
|
|
placeholder={placeholder}
|
|
required={required}
|
|
aria-label={ariaLabel}
|
|
cols={width}
|
|
className={styles.textarea}
|
|
/>
|
|
</InlineField>
|
|
);
|
|
}
|
|
|
|
function getStyles(theme: GrafanaTheme) {
|
|
return {
|
|
textarea: css`
|
|
white-space: pre-wrap;
|
|
min-height: 32px;
|
|
height: auto;
|
|
overflow: auto;
|
|
padding: 6px 8px;
|
|
`,
|
|
};
|
|
}
|