Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Hide empty breakout step in readonly notebook (#63367)

Romeo Van Snick35f9175eb01a
diff --git a/e2e/test/scenarios/admin/transforms.cy.spec.ts b/e2e/test/scenarios/admin/transforms.cy.spec.ts
index c062a5beb0f..af002dff3b9 100644
--- a/e2e/test/scenarios/admin/transforms.cy.spec.ts
+++ b/e2e/test/scenarios/admin/transforms.cy.spec.ts
@@ -821,7 +821,6 @@ H.describeWithSnowplowEE("scenarios > admin > transforms", () => {
describe("queries", () => {
it("should render a readOnly preview of the MBQL query", () => {
cy.log("create a new transform that has all the steps");
- createMbqlTransform({ visitTransform: true });
H.getTableId({ name: "Animals" }).then((tableId) => {
H.getFieldId({ tableId, name: "score" }).then((ANIMAL_SCORE) => {
H.getFieldId({ tableId, name: "name" }).then((ANIMAL_NAME) => {
@@ -967,6 +966,42 @@ H.describeWithSnowplowEE("scenarios > admin > transforms", () => {
}
});
+ it("should hide empty sections in read-only mode", () => {
+ H.getTableId({ name: "Animals" }).then((tableId) => {
+ H.createTransform(
+ {
+ name: "MBQL transform",
+ source: {
+ type: "query",
+ query: {
+ database: WRITABLE_DB_ID,
+ type: "query",
+ query: {
+ "source-table": tableId,
+ aggregation: [["count"]],
+ },
+ },
+ },
+ target: {
+ type: "table",
+ name: TARGET_TABLE,
+ schema: TARGET_SCHEMA,
+ },
+ tag_ids: [],
+ },
+ { visitTransform: true },
+ );
+
+ H.getNotebookStep("summarize")
+ .scrollIntoView()
+ .should("be.visible")
+ .within(() => {
+ cy.findByText("by").should("not.exist");
+ cy.findByTestId("breakout-step").should("not.exist");
+ });
+ });
+ });
+
it("should be able to update a MBQL query", () => {
cy.log("create a new transform");
createMbqlTransform({ visitTransform: true });
diff --git a/frontend/src/metabase/querying/notebook/components/SummarizeStep/SummarizeStep.tsx b/frontend/src/metabase/querying/notebook/components/SummarizeStep/SummarizeStep.tsx
index 6e92eab38c2..87883f869e4 100644
--- a/frontend/src/metabase/querying/notebook/components/SummarizeStep/SummarizeStep.tsx
+++ b/frontend/src/metabase/querying/notebook/components/SummarizeStep/SummarizeStep.tsx
@@ -1,6 +1,7 @@
import { t } from "ttag";
import { Box, Flex } from "metabase/ui";
+import * as Lib from "metabase-lib";
import type { NotebookStepProps } from "../../types";
import { AggregateStep } from "../AggregateStep";
@@ -10,21 +11,26 @@ export function SummarizeStep({
step,
color,
isLastOpened,
+ readOnly,
...props
}: NotebookStepProps) {
const isMetric = step.question.type() === "metric";
+ const hasBreakouts = Lib.breakouts(step.query, step.stageIndex).length > 0;
+ const showBreakouts = !readOnly || hasBreakouts;
+
return (
<Flex
align={{ md: "center" }}
direction={{ base: "column", md: "row" }}
gap={{ base: "sm", md: isMetric ? "md" : "sm" }}
>
- <Box w={{ base: "100%", md: "50%" }}>
+ <Box w={{ base: "100%", md: "50%" }} flex="1 1 auto">
<AggregateStep
step={step}
color={color}
isLastOpened={isLastOpened}
+ readOnly={readOnly}
{...props}
/>
</Box>
@@ -33,16 +39,19 @@ export function SummarizeStep({
{t`Default time dimension`}
</Box>
) : (
- <Box c={color} fw="bold">{t`by`}</Box>
+ showBreakouts && <Box c={color} fw="bold">{t`by`}</Box>
+ )}
+ {showBreakouts && (
+ <Box w={{ base: "100%", md: "50%" }}>
+ <BreakoutStep
+ step={step}
+ color={color}
+ isLastOpened={false}
+ readOnly={readOnly}
+ {...props}
+ />
+ </Box>
)}
- <Box w={{ base: "100%", md: "50%" }}>
- <BreakoutStep
- step={step}
- color={color}
- isLastOpened={false}
- {...props}
- />
- </Box>
</Flex>
);
}