The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
GDGT-1581: Add Python preview disclaimer (#68789)
Stas Gavrylove22e0e5fb174
diff --git a/e2e/support/helpers/e2e-data-studio-helpers.ts b/e2e/support/helpers/e2e-data-studio-helpers.tsindex 2efac53c22b..00fde9dcb91 100644--- a/e2e/support/helpers/e2e-data-studio-helpers.ts+++ b/e2e/support/helpers/e2e-data-studio-helpers.ts@@ -23,6 +23,7 @@ export const DataStudio = {settingsTab: () => DataStudio.Transforms.header().findByText("Settings"),dependenciesTab: () =>DataStudio.Transforms.header().findByText("Dependencies"),+ pythonResults: () => cy.findByTestId("python-results"),},Jobs: {header: () => cy.findByTestId("jobs-header"),diff --git a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.tsindex 8de01b2d36c..7e2903264b2 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts@@ -1729,7 +1729,7 @@ LIMITcy.findByTestId("python-data-picker").should("not.exist");cy.log("results panel should be hidden in read-only mode");- cy.findByTestId("python-results").should("not.exist");+ H.DataStudio.Transforms.pythonResults().should("not.exist");cy.log("library buttons should be hidden in read-only mode");cy.findByLabelText("Import common library").should("not.exist");@@ -1766,7 +1766,7 @@ LIMITcy.findByTestId("python-data-picker").should("be.visible");cy.log("results panel should be visible in edit mode");- cy.findByTestId("python-results").should("be.visible");+ H.DataStudio.Transforms.pythonResults().should("be.visible");cy.log("Edit definition button should be hidden in edit mode");H.DataStudio.Transforms.editDefinition().should("not.exist");@@ -1809,7 +1809,7 @@ LIMITcy.url().should("not.include", "/edit");H.DataStudio.Transforms.editDefinition().should("be.visible");cy.findByTestId("python-data-picker").should("not.exist");- cy.findByTestId("python-results").should("not.exist");+ H.DataStudio.Transforms.pythonResults().should("not.exist");},);@@ -3669,6 +3669,42 @@ describe(firstRows: [["43"]],});});++ it("should display preview notice message", () => {+ H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(+ (id) => {+ createPythonTransform({+ body: dedent`+ import pandas as pd++ def transform(foo):+ return pd.DataFrame([{"foo": 42}])+ `,+ sourceTables: { foo: id },+ visitTransform: true,+ });+ },+ );++ H.DataStudio.Transforms.editDefinition().click();++ H.DataStudio.Transforms.pythonResults()+ .findByText("Done")+ .should("not.exist");+ H.DataStudio.Transforms.pythonResults()+ .findByText("Preview based on the first 100 rows from each table.")+ .should("not.exist");++ runPythonScriptAndWaitForSuccess();++ cy.log("Preview disclaimer should appear");+ H.DataStudio.Transforms.pythonResults()+ .findByText("Done")+ .should("be.visible");+ H.DataStudio.Transforms.pythonResults()+ .findByText("Preview based on the first 100 rows from each table.")+ .should("be.visible");+ });},);@@ -4002,7 +4038,7 @@ function runPythonScriptAndWaitForSuccess() {.findByTestId("loading-indicator", { timeout: 60000 }).should("not.exist");- cy.findByTestId("python-results").should("be.visible");+ H.DataStudio.Transforms.pythonResults().should("be.visible");}function getRowNames(): Cypress.Chainable<string[]> {diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.cssindex c609ede35db..696f8941f16 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.module.css@@ -48,3 +48,12 @@font-family: var(--mb-default-monospace-font-family);overflow: auto;}++.content {+ overflow: auto;+}++.footer {+ border-top: 1px solid var(--mb-color-border);+ flex-shrink: 0;+}diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsxindex 9d1a1e98e3b..69ef03d42f8 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms-python/components/PythonTransformEditor/PythonEditorResults/PythonEditorResults.tsx@@ -1,4 +1,4 @@-import { useState } from "react";+import { useEffect, useState } from "react";import { c, t } from "ttag";import EmptyCodeResult from "assets/img/empty-states/code.svg";@@ -6,7 +6,16 @@ import { AnsiLogs } from "metabase/common/components/AnsiLogs";import { DebouncedFrame } from "metabase/common/components/DebouncedFrame";import { LoadingSpinner } from "metabase/common/components/MetadataInfo/MetadataInfo.styled";import { isMac } from "metabase/lib/browser";-import { Box, Flex, Group, Icon, Stack, Tabs, Text } from "metabase/ui";+import {+ ActionIcon,+ Box,+ Flex,+ Group,+ Icon,+ Stack,+ Tabs,+ Text,+} from "metabase/ui";import type { TestPythonTransformResponse } from "metabase-types/api";import { ExecutionOutputTable } from "./ExecutionOutputTable";@@ -24,25 +33,35 @@ export function PythonEditorResults({isRunning,}: PythonEditorProps) {const [tab, setTab] = useState<ResultsTab>("results");+ const [footerDismissed, setFooterDismissed] = useState(false);const hasDataOrError = executionResult?.output || executionResult?.error;++ useEffect(() => {+ setFooterDismissed(false);+ }, [executionResult]);+return (<DebouncedFrame className={S.visualization}><Stack data-testid="python-results" gap={0} h="100%">- <ExecutionResultHeader- executionResult={executionResult}- tab={tab}- onTabChange={setTab}- />- {!hasDataOrError && <EmptyState />}- {hasDataOrError &&- tab === "results" &&- (executionResult?.error ? (- <ErrorState error={executionResult.error.message} />- ) : (- <ExecutionOutputTable output={executionResult?.output} />- ))}- {executionResult && tab === "output" && (- <ExecutionOutputLogs executionResult={executionResult} />+ <ExecutionResultTabs tab={tab} onTabChange={setTab} />+ <Box className={S.content} flex={1} mih={0}>+ {!hasDataOrError && <EmptyState />}+ {hasDataOrError &&+ tab === "results" &&+ (executionResult?.error ? (+ <ErrorState error={executionResult.error.message} />+ ) : (+ <ExecutionOutputTable output={executionResult?.output} />+ ))}+ {executionResult && tab === "output" && (+ <ExecutionOutputLogs executionResult={executionResult} />+ )}+ </Box>+ {!footerDismissed && (+ <ResultsFooter+ executionResult={executionResult}+ onDismiss={() => setFooterDismissed(true)}+ />)}{isRunning && <LoadingState />}</Stack>@@ -50,17 +69,13 @@ export function PythonEditorResults({);}-function ExecutionResultHeader({- executionResult,+function ExecutionResultTabs({tab,onTabChange,}: {- executionResult?: TestPythonTransformResponse | null;tab: ResultsTab;onTabChange: (tab: ResultsTab) => void;}) {- const message = getMessageForExecutionResult(executionResult);-return (<Group className={S.header} justify="space-between"><Box mt="xs">@@ -73,12 +88,11 @@ function ExecutionResultHeader({}}><Tabs.List>- <Tabs.Tab value="results">{t`Results`}</Tabs.Tab>+ <Tabs.Tab value="results">{t`Results preview`}</Tabs.Tab><Tabs.Tab value="output">{t`Output`}</Tabs.Tab></Tabs.List></Tabs></Box>- {message}</Group>);}@@ -129,30 +143,69 @@ function ErrorState({ error }: { error: string }) {);}-function getMessageForExecutionResult(- executionResult?: TestPythonTransformResponse | null,-) {+function ResultsFooter({+ executionResult,+ onDismiss,+}: {+ executionResult?: TestPythonTransformResponse | null;+ onDismiss: () => void;+}) {if (!executionResult) {return null;}if (executionResult.error) {return (- <Flex gap="sm" align="center" pr="md" c="error">- <Icon name="warning" />- {t`An error occurred while executing your Python script`}+ <Flex className={S.footer} gap="xs" align="center" px="md" py="md">+ <Icon size="1rem" style={{ flexShrink: 0 }} name="warning" c="error" />+ <Text+ c="text-primary"+ ml="xs"+ >{t`An error occurred while executing your Python script.`}</Text>+ <DismissButton onDismiss={onDismiss} /></Flex>);}+ if (!executionResult.output) {+ return null;+ }+return (- <Flex gap="sm" align="center" pr="md" c="success">- <Icon name="check_filled" />- {t`Script executed successfully`}+ <Flex className={S.footer} gap="xs" align="center" px="md" py="md">+ <Icon+ size="1rem"+ style={{ flexShrink: 0 }}+ name="check_filled"+ c="success"+ />+ <Text fw="bold" c="text-primary" lh="xs">{t`Done`}</Text>+ <Text+ c="text-tertiary"+ ml="xs"+ lh="xs"+ >{t`Preview based on the first 100 rows from each table.`}</Text>+ <DismissButton onDismiss={onDismiss} /></Flex>);}+function DismissButton({ onDismiss }: { onDismiss: () => void }) {+ return (+ <ActionIcon+ ml="auto"+ size="1.5rem"+ radius="xl"+ variant="subtle"+ c="text-tertiary"+ onClick={onDismiss}+ aria-label={t`Dismiss`}+ >+ <Icon name="close" size={12} />+ </ActionIcon>+ );+}+function ExecutionOutputLogs({executionResult,}: {