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/variables/editor/SelectionOptionsEditor.tsx

71 lines
2.4 KiB

import React, { ChangeEvent, FormEvent, FunctionComponent, useCallback } from 'react';
import { selectors } from '@grafana/e2e-selectors';
import { VerticalGroup } from '@grafana/ui';
import { KeyedVariableIdentifier } from '../state/types';
import { VariableWithMultiSupport } from '../types';
import { toKeyedVariableIdentifier } from '../utils';
import { VariableCheckboxField } from './VariableCheckboxField';
import { VariableTextField } from './VariableTextField';
import { VariableEditorProps } from './types';
export interface SelectionOptionsEditorProps<Model extends VariableWithMultiSupport = VariableWithMultiSupport>
extends VariableEditorProps<Model> {
onMultiChanged: (identifier: KeyedVariableIdentifier, value: boolean) => void;
}
export const SelectionOptionsEditor: FunctionComponent<SelectionOptionsEditorProps> = ({
onMultiChanged: onMultiChangedProps,
onPropChange,
variable,
}) => {
const onMultiChanged = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
onMultiChangedProps(toKeyedVariableIdentifier(variable), event.target.checked);
},
[onMultiChangedProps, variable]
);
const onIncludeAllChanged = useCallback(
(event: ChangeEvent<HTMLInputElement>) => {
onPropChange({ propName: 'includeAll', propValue: event.target.checked });
},
[onPropChange]
);
const onAllValueChanged = useCallback(
(event: FormEvent<HTMLInputElement>) => {
onPropChange({ propName: 'allValue', propValue: event.currentTarget.value });
},
[onPropChange]
);
return (
<VerticalGroup spacing="md" height="inherit">
<VariableCheckboxField
value={variable.multi}
name="Multi-value"
description="Enables multiple values to be selected at the same time"
onChange={onMultiChanged}
/>
<VariableCheckboxField
value={variable.includeAll}
name="Include All option"
description="Enables an option to include all variables"
onChange={onIncludeAllChanged}
/>
{variable.includeAll && (
<VariableTextField
value={variable.allValue ?? ''}
onChange={onAllValueChanged}
name="Custom all value"
placeholder="blank = auto"
testId={selectors.pages.Dashboard.Settings.Variables.Edit.General.selectionOptionsCustomAllInputV2}
/>
)}
</VerticalGroup>
);
};
SelectionOptionsEditor.displayName = 'SelectionOptionsEditor';