williaster commented on a change in pull request #4909: [Explore] Adding Adhoc
Filters
URL:
https://github.com/apache/incubator-superset/pull/4909#discussion_r186492476
##########
File path: superset/assets/src/explore/components/AdhocFilterOption.jsx
##########
@@ -0,0 +1,89 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Label, OverlayTrigger } from 'react-bootstrap';
+
+import AdhocFilterEditPopover from './AdhocFilterEditPopover';
+import AdhocFilter from '../AdhocFilter';
+import columnType from '../propTypes/columnType';
+import adhocMetricType from '../propTypes/adhocMetricType';
+
+const propTypes = {
+ adhocFilter: PropTypes.instanceOf(AdhocFilter).isRequired,
+ onFilterEdit: PropTypes.func.isRequired,
+ options: PropTypes.arrayOf(PropTypes.oneOfType([
+ columnType,
+ PropTypes.shape({ saved_metric_name: PropTypes.string.isRequired }),
+ adhocMetricType,
+ ])).isRequired,
+ datasource: PropTypes.object,
+};
+
+export default class AdhocFilterOption extends React.PureComponent {
+ constructor(props) {
+ super(props);
+ this.closeFilterEditOverlay = this.closeFilterEditOverlay.bind(this);
+ this.onPopoverResize = this.onPopoverResize.bind(this);
+ this.onOverlayEntered = this.onOverlayEntered.bind(this);
+ this.onOverlayExited = this.onOverlayExited.bind(this);
+ this.state = { overlayShown: !this.props.adhocFilter.fromFormData };
+ }
+
+ onPopoverResize() {
+ this.forceUpdate();
+ }
+
+ onOverlayEntered() {
+ this.setState({ overlayShown: true });
+ }
+
+ onOverlayExited() {
+ this.setState({ overlayShown: false });
+ }
+
+ closeFilterEditOverlay() {
+ this.refs.overlay.hide();
+ }
+
+ render() {
+ const { adhocFilter } = this.props;
+ const overlay = (
+ <AdhocFilterEditPopover
+ onResize={this.onPopoverResize}
+ adhocFilter={adhocFilter}
+ onChange={this.props.onFilterEdit}
+ onClose={this.closeFilterEditOverlay}
+ options={this.props.options}
+ datasource={this.props.datasource}
+ />
+ );
+
+ return (
+ <OverlayTrigger
+ ref="overlay"
+ placement="right"
+ trigger="click"
+ disabled
+ overlay={overlay}
+ rootClose
+ shouldUpdatePosition
+ defaultOverlayShown={!adhocFilter.fromFormData}
+ onEntered={this.onOverlayEntered}
+ onExited={this.onOverlayExited}
+ >
+ <Label className="adhoc-filter-option">
+ <div onMouseDownCapture={(e) => { e.stopPropagation(); }}>
Review comment:
could you define this as a class function so it's not initialized every
render?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]