mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Chore: initial commit * Tests: fixes MetricsQueryEditor.test.tsx * Tests: fixes cloudwatch/specs/datasource.test.ts * Tests: fixes stackdriver/specs/datasource.test.ts * Tests: remove refrences to CustomVariable * Refactor: moves DefaultVariableQueryEditor * Refactor: moves utils * Refactor: moves types * Refactor: removes variableSrv * Refactor: removes feature toggle newVariables * Refactor: removes valueSelectDropDown * Chore: removes GeneralTabCtrl * Chore: migrates RowOptions * Refactor: adds RowOptionsButton * Refactor: makes the interface more explicit * Refactor: small changes * Refactor: changed type as it can be any variable type * Tests: fixes broken test * Refactor: changes after PR comments * Refactor: adds loading state and call to onChange in componentDidMount
80 lines
2.6 KiB
TypeScript
80 lines
2.6 KiB
TypeScript
import React, { ChangeEvent, FocusEvent, PureComponent } from 'react';
|
|
import { CustomVariableModel, VariableWithMultiSupport } from '../types';
|
|
import { SelectionOptionsEditor } from '../editor/SelectionOptionsEditor';
|
|
import { OnPropChangeArguments, VariableEditorProps } from '../editor/types';
|
|
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
|
|
import { MapDispatchToProps, MapStateToProps } from 'react-redux';
|
|
import { StoreState } from 'app/types';
|
|
import { changeVariableMultiValue } from '../state/actions';
|
|
|
|
interface OwnProps extends VariableEditorProps<CustomVariableModel> {}
|
|
|
|
interface ConnectedProps {}
|
|
|
|
interface DispatchProps {
|
|
changeVariableMultiValue: typeof changeVariableMultiValue;
|
|
}
|
|
|
|
export type Props = OwnProps & ConnectedProps & DispatchProps;
|
|
|
|
class CustomVariableEditorUnconnected extends PureComponent<Props> {
|
|
onChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
this.props.onPropChange({
|
|
propName: 'query',
|
|
propValue: event.target.value,
|
|
});
|
|
};
|
|
|
|
onSelectionOptionsChange = async ({ propName, propValue }: OnPropChangeArguments<VariableWithMultiSupport>) => {
|
|
this.props.onPropChange({ propName, propValue, updateOptions: true });
|
|
};
|
|
|
|
onBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
this.props.onPropChange({
|
|
propName: 'query',
|
|
propValue: event.target.value,
|
|
updateOptions: true,
|
|
});
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<>
|
|
<div className="gf-form-group">
|
|
<h5 className="section-heading">Custom Options</h5>
|
|
<div className="gf-form">
|
|
<span className="gf-form-label width-14">Values separated by comma</span>
|
|
<input
|
|
type="text"
|
|
className="gf-form-input"
|
|
value={this.props.variable.query}
|
|
onChange={this.onChange}
|
|
onBlur={this.onBlur}
|
|
placeholder="1, 10, 20, myvalue, escaped\,value"
|
|
required
|
|
aria-label="Variable editor Form Custom Query field"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<SelectionOptionsEditor
|
|
variable={this.props.variable}
|
|
onPropChange={this.onSelectionOptionsChange}
|
|
onMultiChanged={this.props.changeVariableMultiValue}
|
|
/>
|
|
</>
|
|
);
|
|
}
|
|
}
|
|
|
|
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state, ownProps) => ({});
|
|
|
|
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = {
|
|
changeVariableMultiValue,
|
|
};
|
|
|
|
export const CustomVariableEditor = connectWithStore(
|
|
CustomVariableEditorUnconnected,
|
|
mapStateToProps,
|
|
mapDispatchToProps
|
|
);
|