import React, { ChangeEvent, FocusEvent, PureComponent } from 'react'; import { DataSourceVariableModel, VariableWithMultiSupport } from '../../templating/types'; import { OnPropChangeArguments, VariableEditorProps } from '../editor/types'; import { SelectionOptionsEditor } from '../editor/SelectionOptionsEditor'; import { FormLabel } from '@grafana/ui'; import { VariableEditorState } from '../editor/reducer'; import { DataSourceVariableEditorState } from './reducer'; import { initDataSourceVariableEditor } from './actions'; import { MapDispatchToProps, MapStateToProps } from 'react-redux'; import { StoreState } from '../../../types'; import { connectWithStore } from '../../../core/utils/connectWithReduxStore'; export interface OwnProps extends VariableEditorProps {} interface ConnectedProps { editor: VariableEditorState; } interface DispatchProps { initDataSourceVariableEditor: typeof initDataSourceVariableEditor; } type Props = OwnProps & ConnectedProps & DispatchProps; export class DataSourceVariableEditorUnConnected extends PureComponent { async componentDidMount() { await this.props.initDataSourceVariableEditor(); } onRegExChange = (event: ChangeEvent) => { this.props.onPropChange({ propName: 'regex', propValue: event.target.value, }); }; onRegExBlur = (event: FocusEvent) => { this.props.onPropChange({ propName: 'regex', propValue: event.target.value, updateOptions: true, }); }; onSelectionOptionsChange = async ({ propValue, propName }: OnPropChangeArguments) => { this.props.onPropChange({ propName, propValue, updateOptions: true }); }; getSelectedDataSourceTypeValue = (): string => { if (!this.props.editor.extended?.dataSourceTypes?.length) { return ''; } const foundItem = this.props.editor.extended?.dataSourceTypes.find(ds => ds.value === this.props.variable.query); const value = foundItem ? foundItem.value : this.props.editor.extended?.dataSourceTypes[0].value; return value ?? ''; }; onDataSourceTypeChanged = (event: ChangeEvent) => { this.props.onPropChange({ propName: 'query', propValue: event.target.value, updateOptions: true }); }; render() { return ( <>
Data source options
Regex filter for which data source instances to choose from in the variable value dropdown. Leave empty for all.

Example: /^prod/
} > Instance name filter
); } } const mapStateToProps: MapStateToProps = (state, ownProps) => ({ editor: state.templating.editor as VariableEditorState, }); const mapDispatchToProps: MapDispatchToProps = { initDataSourceVariableEditor, }; export const DataSourceVariableEditor = connectWithStore( DataSourceVariableEditorUnConnected, mapStateToProps, mapDispatchToProps );