Files
grafana/public/app/features/variables/custom/CustomVariableEditor.tsx
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

68 lines
2.3 KiB
TypeScript

import { FormEvent, PureComponent } from 'react';
import { MapDispatchToProps, MapStateToProps } from 'react-redux';
import { CustomVariableModel, VariableWithMultiSupport } from '@grafana/data';
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
import { CustomVariableForm } from 'app/features/dashboard-scene/settings/variables/components/CustomVariableForm';
import { StoreState } from 'app/types';
import { OnPropChangeArguments, VariableEditorProps } from '../editor/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> {
onSelectionOptionsChange = async ({ propName, propValue }: OnPropChangeArguments<VariableWithMultiSupport>) => {
this.props.onPropChange({ propName, propValue, updateOptions: true });
};
onQueryChange = (event: FormEvent<HTMLTextAreaElement>) => {
this.props.onPropChange({
propName: 'query',
propValue: event.currentTarget.value,
updateOptions: true,
});
};
render() {
return (
<CustomVariableForm
query={this.props.variable.query}
multi={this.props.variable.multi}
allValue={this.props.variable.allValue}
includeAll={this.props.variable.includeAll}
onQueryChange={this.onQueryChange}
onMultiChange={(event) =>
this.onSelectionOptionsChange({ propName: 'multi', propValue: event.currentTarget.checked })
}
onIncludeAllChange={(event) =>
this.onSelectionOptionsChange({ propName: 'includeAll', propValue: event.currentTarget.checked })
}
onAllValueChange={(event) =>
this.onSelectionOptionsChange({ propName: 'allValue', propValue: event.currentTarget.value })
}
/>
);
}
}
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = (state, ownProps) => ({});
const mapDispatchToProps: MapDispatchToProps<DispatchProps, OwnProps> = {
changeVariableMultiValue,
};
export const CustomVariableEditor = connectWithStore(
CustomVariableEditorUnconnected,
mapStateToProps,
mapDispatchToProps
);