The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard-scene/settings/variables/components/DataSourceVariableForm.tsx

85 lines
2.6 KiB

import { FormEvent } from 'react';
import { SelectableValue } from '@grafana/data';
import { selectors } from '@grafana/e2e-selectors';
import { SelectionOptionsForm } from './SelectionOptionsForm';
import { VariableLegend } from './VariableLegend';
import { VariableSelectField } from './VariableSelectField';
import { VariableTextField } from './VariableTextField';
interface DataSourceVariableFormProps {
query: string;
regex: string;
multi: boolean;
allValue?: string | null;
allowCustomValue?: boolean;
includeAll: boolean;
onChange: (option: SelectableValue) => void;
optionTypes: Array<{ value: string; label: string }>;
onRegExBlur: (event: FormEvent<HTMLInputElement>) => void;
onMultiChange: (event: FormEvent<HTMLInputElement>) => void;
onIncludeAllChange: (event: FormEvent<HTMLInputElement>) => void;
onAllValueChange: (event: FormEvent<HTMLInputElement>) => void;
onAllowCustomValueChange?: (event: FormEvent<HTMLInputElement>) => void;
onQueryBlur?: (event: FormEvent<HTMLTextAreaElement>) => void;
onAllValueBlur?: (event: FormEvent<HTMLInputElement>) => void;
}
export function DataSourceVariableForm({
query,
regex,
optionTypes,
allowCustomValue,
onChange,
onRegExBlur,
multi,
includeAll,
allValue,
onMultiChange,
onIncludeAllChange,
onAllValueChange,
onAllowCustomValueChange,
}: DataSourceVariableFormProps) {
const typeValue = optionTypes.find((o) => o.value === query) ?? optionTypes[0];
return (
<>
<VariableLegend>Data source options</VariableLegend>
<VariableSelectField
name="Type"
value={typeValue}
options={optionTypes}
onChange={onChange}
testId={selectors.pages.Dashboard.Settings.Variables.Edit.DatasourceVariable.datasourceSelect}
/>
<VariableTextField
defaultValue={regex}
name="Instance name filter"
placeholder="/.*-(.*)-.*/"
onBlur={onRegExBlur}
description={
<div>
Regex filter for which data source instances to choose from in the variable value list. Leave empty for all.
<br />
<br />
Example: <code>/^prod/</code>
</div>
}
/>
<VariableLegend>Selection options</VariableLegend>
<SelectionOptionsForm
multi={multi}
includeAll={includeAll}
allValue={allValue}
allowCustomValue={allowCustomValue}
onMultiChange={onMultiChange}
onIncludeAllChange={onIncludeAllChange}
onAllValueChange={onAllValueChange}
onAllowCustomValueChange={onAllowCustomValueChange}
/>
</>
);
}