Skip to content
Snippets Groups Projects
Unverified Commit 8daa8d51 authored by Alexander Lesnenko's avatar Alexander Lesnenko Committed by GitHub
Browse files

Fix metrics custom expression editor (#23045)

parent d975d759
No related branches found
No related tags found
No related merge requests found
...@@ -3,20 +3,21 @@ import React, { Component } from "react"; ...@@ -3,20 +3,21 @@ import React, { Component } from "react";
import ReactDOM from "react-dom"; import ReactDOM from "react-dom";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import { t } from "ttag"; import { t } from "ttag";
import _ from "underscore";
import Icon from "metabase/components/Icon"; import Icon from "metabase/components/Icon";
import Tooltip from "metabase/components/Tooltip"; import Tooltip from "metabase/components/Tooltip";
import AccordionList from "metabase/core/components/AccordionList"; import AccordionList from "metabase/core/components/AccordionList";
import FieldList from "./FieldList"; import FieldList from "../FieldList";
import QueryDefinitionTooltip from "./QueryDefinitionTooltip"; import QueryDefinitionTooltip from "../QueryDefinitionTooltip";
import ExpressionPopover from "./ExpressionPopover"; import ExpressionPopover from "../ExpressionPopover";
import * as AGGREGATION from "metabase/lib/query/aggregation"; import * as AGGREGATION from "metabase/lib/query/aggregation";
import Aggregation from "metabase-lib/lib/queries/structured/Aggregation"; import Aggregation from "metabase-lib/lib/queries/structured/Aggregation";
import _ from "underscore"; import { ExpressionPopoverRoot } from "./AggregationPopover.styled";
const COMMON_SECTION_NAME = t`Common Metrics`; const COMMON_SECTION_NAME = t`Common Metrics`;
const BASIC_SECTION_NAME = t`Basic Metrics`; const BASIC_SECTION_NAME = t`Basic Metrics`;
...@@ -301,31 +302,33 @@ export default class AggregationPopover extends Component { ...@@ -301,31 +302,33 @@ export default class AggregationPopover extends Component {
if (editingAggregation) { if (editingAggregation) {
return ( return (
<ExpressionPopover <ExpressionPopoverRoot>
title={CUSTOM_SECTION_NAME} <ExpressionPopover
query={query} title={CUSTOM_SECTION_NAME}
expression={aggregation} query={query}
startRule="aggregation" expression={aggregation}
onChange={parsedExpression => startRule="aggregation"
this.setState({ onChange={parsedExpression =>
aggregation: AGGREGATION.setContent( this.setState({
this.state.aggregation, aggregation: AGGREGATION.setContent(
parsedExpression, this.state.aggregation,
), parsedExpression,
error: null, ),
}) error: null,
} })
onBack={this.onClearAggregation} }
onDone={() => this.commitAggregation(this.state.aggregation)} onBack={this.onClearAggregation}
name={AGGREGATION.getName(this.state.aggregation)} onDone={() => this.commitAggregation(this.state.aggregation)}
onChangeName={name => name={AGGREGATION.getName(this.state.aggregation)}
this.setState({ onChangeName={name =>
aggregation: name this.setState({
? AGGREGATION.setName(aggregation, name) aggregation: name
: aggregation, ? AGGREGATION.setName(aggregation, name)
}) : aggregation,
} })
/> }
/>
</ExpressionPopoverRoot>
); );
} else if (choosingField) { } else if (choosingField) {
const [agg, fieldId] = aggregation; const [agg, fieldId] = aggregation;
......
import styled from "@emotion/styled";
export const ExpressionPopoverRoot = styled.div`
width: 350px;
`;
export { default } from "./AggregationPopover";
...@@ -5,7 +5,7 @@ import { t } from "ttag"; ...@@ -5,7 +5,7 @@ import { t } from "ttag";
import Clearable from "./Clearable"; import Clearable from "./Clearable";
import AggregationPopover from "./AggregationPopover"; import AggregationPopover from "./AggregationPopover";
import TippyPopover from "metabase/components/Popover/TippyPopover"; import ControlledPopoverWithTrigger from "metabase/components/PopoverWithTrigger/ControlledPopoverWithTrigger";
// NOTE: lots of duplication between AggregationWidget and BreakoutWidget // NOTE: lots of duplication between AggregationWidget and BreakoutWidget
...@@ -63,12 +63,20 @@ export default class AggregationWidget extends React.Component { ...@@ -63,12 +63,20 @@ export default class AggregationWidget extends React.Component {
) : ( ) : (
children children
); );
const popover = (
<TippyPopover if (!trigger) {
return null;
}
return (
<ControlledPopoverWithTrigger
disableContentSandbox
placement="bottom-start" placement="bottom-start"
visible={this.state.isOpen} visible={this.state.isOpen}
onClose={this.handleClose} onClose={this.handleClose}
content={ onOpen={this.handleOpen}
triggerContent={trigger}
popoverContent={
<AggregationPopover <AggregationPopover
query={query} query={query}
aggregation={aggregation} aggregation={aggregation}
...@@ -77,15 +85,9 @@ export default class AggregationWidget extends React.Component { ...@@ -77,15 +85,9 @@ export default class AggregationWidget extends React.Component {
/> />
} }
> >
<div>{trigger}</div> {trigger}
</TippyPopover> </ControlledPopoverWithTrigger>
); );
if (trigger) {
return <div onClick={this.handleOpen}>{popover}</div>;
} else {
return null;
}
} }
} }
......
...@@ -93,7 +93,7 @@ describe("scenarios > admin > datamodel > metrics", () => { ...@@ -93,7 +93,7 @@ describe("scenarios > admin > datamodel > metrics", () => {
cy.findByText("Learn how to create metrics"); cy.findByText("Learn how to create metrics");
}); });
it.skip("custom expression aggregation should work in metrics (metabase#22700)", () => { it("custom expression aggregation should work in metrics (metabase#22700)", () => {
cy.intercept("POST", "/api/dataset").as("dataset"); cy.intercept("POST", "/api/dataset").as("dataset");
const customExpression = "Count / Distinct([Product ID])"; const customExpression = "Count / Distinct([Product ID])";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment