mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 05:30:12 +08:00

* user essentials mob! 🔱 lastFile:public/app/features/variables/textbox/TextBoxVariablePicker.tsx * user essentials mob! 🔱 * user essentials mob! 🔱 lastFile:public/app/features/variables/adhoc/picker/AdHocFilter.tsx * finish up disabling variables in snapshots * remove accident * use theme.spacing instead of the v1 shim Co-authored-by: Joao Silva <joao.silva@grafana.com> Co-authored-by: Leodegario Pasakdal <leodegario.pasakdal@grafana.com>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import React, { PureComponent } from 'react';
|
|
import { connect, ConnectedProps } from 'react-redux';
|
|
|
|
import { AdHocVariableFilter, AdHocVariableModel } from 'app/features/variables/types';
|
|
|
|
import { VariablePickerProps } from '../../pickers/types';
|
|
import { toKeyedVariableIdentifier } from '../../utils';
|
|
import { addFilter, changeFilter, removeFilter } from '../actions';
|
|
|
|
import { AdHocFilter } from './AdHocFilter';
|
|
|
|
const mapDispatchToProps = {
|
|
addFilter,
|
|
removeFilter,
|
|
changeFilter,
|
|
};
|
|
|
|
const connector = connect(null, mapDispatchToProps);
|
|
|
|
interface OwnProps extends VariablePickerProps<AdHocVariableModel> {}
|
|
|
|
type Props = OwnProps & ConnectedProps<typeof connector>;
|
|
|
|
/**
|
|
* Thin wrapper over AdHocFilter to add redux actions and change the props so it can be used for ad hoc variable
|
|
* control.
|
|
*/
|
|
export class AdHocPickerUnconnected extends PureComponent<Props> {
|
|
addFilter = (filter: AdHocVariableFilter) => {
|
|
this.props.addFilter(toKeyedVariableIdentifier(this.props.variable), filter);
|
|
};
|
|
|
|
removeFilter = (index: number) => {
|
|
this.props.removeFilter(toKeyedVariableIdentifier(this.props.variable), index);
|
|
};
|
|
|
|
changeFilter = (index: number, filter: AdHocVariableFilter) => {
|
|
this.props.changeFilter(toKeyedVariableIdentifier(this.props.variable), {
|
|
index,
|
|
filter,
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const { filters, datasource } = this.props.variable;
|
|
|
|
return (
|
|
<AdHocFilter
|
|
datasource={datasource}
|
|
filters={filters}
|
|
disabled={this.props.readOnly}
|
|
addFilter={this.addFilter}
|
|
removeFilter={this.removeFilter}
|
|
changeFilter={this.changeFilter}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
|
|
export const AdHocPicker = connector(AdHocPickerUnconnected);
|
|
AdHocPicker.displayName = 'AdHocPicker';
|