From 0893b97f0a1c95d0317636ba8cf009338f5fc4ab Mon Sep 17 00:00:00 2001 From: Kamil Gabryjelski Date: Fri, 6 Nov 2020 05:00:43 +0100 Subject: [PATCH] fix: Issues with filters and metrics popovers (#11578) * Fix bugs in AdhocFilterEditPopover * Fix bugs in AdhocMetricEditPopover * Remove handleMultiComparatorInputHeightChange function * Fix tests --- ...FilterEditPopoverSimpleTabContent_spec.jsx | 12 ----- .../AdhocFilterEditPopover_spec.jsx | 4 +- .../AdhocMetricEditPopover_spec.jsx | 4 +- .../components/AdhocFilterEditPopover.jsx | 14 +++-- ...AdhocFilterEditPopoverSimpleTabContent.jsx | 51 +++++-------------- .../AdhocFilterEditPopoverSqlTabContent.jsx | 2 +- .../components/AdhocMetricEditPopover.jsx | 43 +++++++++++----- .../components/controls/SelectControl.jsx | 6 +++ 8 files changed, 64 insertions(+), 72 deletions(-) diff --git a/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopoverSimpleTabContent_spec.jsx b/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopoverSimpleTabContent_spec.jsx index f58588e0b614c..442527b77b4aa 100644 --- a/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopoverSimpleTabContent_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopoverSimpleTabContent_spec.jsx @@ -199,16 +199,4 @@ describe('AdhocFilterEditPopoverSimpleTabContent', () => { }), ); }); - - it('expands when its multi comparator input field expands', () => { - const { wrapper, onHeightChange } = setup(); - - wrapper.instance().multiComparatorComponent = { - select: { select: { controlRef: { clientHeight: 57 } } }, - }; - wrapper.instance().handleMultiComparatorInputHeightChange(); - - expect(onHeightChange.calledOnce).toBe(true); - expect(onHeightChange.lastCall.args[0]).toBe(27); - }); }); diff --git a/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopover_spec.jsx b/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopover_spec.jsx index c28ac9a425670..606e0930cb5ad 100644 --- a/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopover_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/AdhocFilterEditPopover_spec.jsx @@ -126,9 +126,9 @@ describe('AdhocFilterEditPopover', () => { wrapper.instance().onDragDown = sinon.spy(); wrapper.instance().forceUpdate(); - expect(wrapper.find('i.fa-expand')).toExist(); + expect(wrapper.find('.fa-expand')).toExist(); expect(wrapper.instance().onDragDown.calledOnce).toBe(false); - wrapper.find('i.fa-expand').simulate('mouseDown', {}); + wrapper.find('.fa-expand').simulate('mouseDown', {}); expect(wrapper.instance().onDragDown.calledOnce).toBe(true); }); }); diff --git a/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx b/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx index 4886760a6222e..5aff466065f2e 100644 --- a/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/AdhocMetricEditPopover_spec.jsx @@ -113,9 +113,9 @@ describe('AdhocMetricEditPopover', () => { wrapper.instance().onDragDown = sinon.spy(); wrapper.instance().forceUpdate(); - expect(wrapper.find('i.fa-expand')).toExist(); + expect(wrapper.find('.fa-expand')).toExist(); expect(wrapper.instance().onDragDown.calledOnce).toBe(false); - wrapper.find('i.fa-expand').simulate('mouseDown'); + wrapper.find('.fa-expand').simulate('mouseDown'); expect(wrapper.instance().onDragDown.calledOnce).toBe(true); }); }); diff --git a/superset-frontend/src/explore/components/AdhocFilterEditPopover.jsx b/superset-frontend/src/explore/components/AdhocFilterEditPopover.jsx index 11b5b6924a4fa..e12adb9fa8ab9 100644 --- a/superset-frontend/src/explore/components/AdhocFilterEditPopover.jsx +++ b/superset-frontend/src/explore/components/AdhocFilterEditPopover.jsx @@ -19,7 +19,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import Button from 'src/components/Button'; -import { t } from '@superset-ui/core'; +import { styled, t } from '@superset-ui/core'; import Tabs from 'src/common/components/Tabs'; import columnType from '../propTypes/columnType'; @@ -45,7 +45,11 @@ const propTypes = { theme: PropTypes.object, }; -const startingWidth = 300; +const ResizeIcon = styled.i` + margin-left: ${({ theme }) => theme.gridUnit * 2}px; +`; + +const startingWidth = 320; const startingHeight = 240; export default class AdhocFilterEditPopover extends React.Component { @@ -63,6 +67,8 @@ export default class AdhocFilterEditPopover extends React.Component { width: startingWidth, height: startingHeight, }; + + this.popoverContentRef = React.createRef(); } componentDidMount() { @@ -136,6 +142,7 @@ export default class AdhocFilterEditPopover extends React.Component { id="filter-edit-popover" {...popoverProps} data-test="filter-edit-popover" + ref={this.popoverContentRef} > {t('Save')} - ; } @@ -328,10 +299,11 @@ export default class AdhocFilterEditPopoverSimpleTabContent extends React.Compon }; return ( - + <> @@ -347,6 +320,7 @@ export default class AdhocFilterEditPopoverSimpleTabContent extends React.Compon {MULTI_OPERATORS.has(operator) || this.state.suggestions.length > 0 ? ( ) : ( @@ -373,7 +346,7 @@ export default class AdhocFilterEditPopoverSimpleTabContent extends React.Compon /> )} - + ); } } diff --git a/superset-frontend/src/explore/components/AdhocFilterEditPopoverSqlTabContent.jsx b/superset-frontend/src/explore/components/AdhocFilterEditPopoverSqlTabContent.jsx index 702c46d8476ae..2a982bacec978 100644 --- a/superset-frontend/src/explore/components/AdhocFilterEditPopoverSqlTabContent.jsx +++ b/superset-frontend/src/explore/components/AdhocFilterEditPopoverSqlTabContent.jsx @@ -132,7 +132,7 @@ export default class AdhocFilterEditPopoverSqlTabContent extends React.Component theme.gridUnit * 2}px; +`; + +const startingWidth = 320; const startingHeight = 240; export default class AdhocMetricEditPopover extends React.Component { @@ -65,17 +69,28 @@ export default class AdhocMetricEditPopover extends React.Component { this.onMouseUp = this.onMouseUp.bind(this); this.handleAceEditorRef = this.handleAceEditorRef.bind(this); this.refreshAceEditor = this.refreshAceEditor.bind(this); + + this.popoverRef = React.createRef(); + this.state = { adhocMetric: this.props.adhocMetric, width: startingWidth, height: startingHeight, }; + this.selectProps = { labelKey: 'label', isMulti: false, autosize: false, clearable: true, }; + + this.menuPortalProps = { + menuPosition: 'fixed', + menuPlacement: 'bottom', + menuPortalTarget: this.popoverRef.current, + }; + document.addEventListener('mouseup', this.onMouseUp); } @@ -215,6 +230,7 @@ export default class AdhocMetricEditPopover extends React.Component {
@@ -247,6 +264,7 @@ export default class AdhocMetricEditPopover extends React.Component {