mistercrunch commented on a change in pull request #4663: [Request For
Comments][Explore] Streamlined metric definitions for SQLA and Druid
URL:
https://github.com/apache/incubator-superset/pull/4663#discussion_r176307239
##########
File path: superset/assets/javascripts/explore/components/AdhocMetricOption.jsx
##########
@@ -0,0 +1,56 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { Label, OverlayTrigger } from 'react-bootstrap';
+
+import AdhocMetricEditPopover from './AdhocMetricEditPopover';
+import AdhocMetric from '../AdhocMetric';
+import columnType from '../propTypes/columnType';
+
+const propTypes = {
+ adhocMetric: PropTypes.instanceOf(AdhocMetric),
+ onMetricEdit: PropTypes.func.isRequired,
+ columns: PropTypes.arrayOf(columnType),
+};
+
+export default class AdhocMetricOption extends React.PureComponent {
+ constructor(props) {
+ super(props);
+ this.closeMetricEditOverlay = this.closeMetricEditOverlay.bind(this);
+ }
+
+ closeMetricEditOverlay() {
+ this.refs.overlay.hide();
+ }
+
+ render() {
+ const { adhocMetric } = this.props;
+ const overlay = (
+ <AdhocMetricEditPopover
+ adhocMetric={adhocMetric}
+ onChange={this.props.onMetricEdit}
+ onClose={this.closeMetricEditOverlay}
+ columns={this.props.columns}
+ />
+ );
+
+ return (
+ <div onMouseDownCapture={(e) => { e.stopPropagation(); }} >
+ <OverlayTrigger
+ ref="overlay"
+ placement="right"
+ trigger="click"
+ disabled
+ overlay={overlay}
+ rootClose
+ >
+ <Label style={{ cursor: 'pointer' }}>
Review comment:
I was told to avoid double curlies whenever possible since they generate new
objectids at every render and will trigger `PureComponent`s to rerender when
they don't need to, just declare `labelStyle` in module scope and reference it
here.
----------------------------------------------------------------
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