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-1784 add a loader to the lens tab (#75151)
Egor Grushin6edffa6fb4a9
diff --git a/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.tsindex c223d5a477c..aa939b376a1 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.ts@@ -329,6 +329,68 @@ describe("scenarios > data-studio > transforms > inspect", () => {});});+ describe("loading indicator", () => {+ it("shows the spinner only on the active tab and never leaves it stuck when switching tabs", () => {+ cy.intercept("POST", "/api/ee/transforms/*/inspect/*/query", (req) => {+ req.continue((res) => {+ res.setDelay(1000);+ });+ }).as("inspectorQuery");++ H.createAndRunMbqlTransform({+ sourceTable: SOURCE_TABLE,+ targetTable: "inspect_loading_table",+ targetSchema: TARGET_SCHEMA,+ name: "Loading indicator inspect transform",+ }).then(({ transformId }) => {+ H.DataStudio.Transforms.visitInspect(transformId);+ });++ cy.wait("@inspectorDiscovery");++ const summaryTab = () => cy.findByRole("tab", { name: /Summary/ });+ const colDistTab = () =>+ cy.findByRole("tab", { name: /Column Distributions/ });++ cy.log("the active Summary tab shows a spinner while its cards load");+ summaryTab().findByTestId("lens-tab-loader").should("be.visible");++ cy.log("switch away before Summary finishes loading");+ colDistTab().click();++ cy.log(+ "the previous tab does not get stuck — the fast Summary lens reverts to no indicator",+ );+ summaryTab().within(() => {+ cy.findByTestId("lens-tab-loader").should("not.exist");+ cy.findByLabelText(/clock icon/i).should("not.exist");+ });++ cy.log("the newly active tab now shows the spinner");+ colDistTab().findByTestId("lens-tab-loader").should("be.visible");++ cy.log("the spinner clears once the lens finishes loading");+ cy.findAllByTestId("visualization-root").should("have.length", 4);+ colDistTab().within(() => {+ cy.findByTestId("lens-tab-loader").should("not.exist");+ cy.findByLabelText(/clock icon/i).should("not.exist");+ });++ cy.log(+ "switch back: the loaded tab shows no indicator, active one re-loads cleanly",+ );+ summaryTab().click();++ colDistTab().within(() => {+ cy.findByTestId("lens-tab-loader").should("not.exist");+ cy.findByLabelText(/clock icon/i).should("not.exist");+ });++ cy.findByTestId("generic-summary-tables").should("be.visible");+ summaryTab().findByTestId("lens-tab-loader").should("not.exist");+ });+ });+describe("sql transforms", () => {it("should show Summary tab for a SQL transform", () => {H.createAndRunSqlTransform({diff --git a/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.tsx b/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.tsxindex 47ecfea5968..56952668ea8 100644--- a/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.tsx+++ b/enterprise/frontend/src/metabase-enterprise/transforms-inspector/pages/TransformInspectPage/components/LensNavigator/LensNavigator.tsx@@ -2,7 +2,17 @@ import type { PropsWithChildren } from "react";import { match } from "ts-pattern";import { t } from "ttag";-import { Box, Group, Icon, Stack, Tabs, Text, Tooltip, rem } from "metabase/ui";+import {+ Box,+ Group,+ Icon,+ Loader,+ Stack,+ Tabs,+ Text,+ Tooltip,+ rem,+} from "metabase/ui";import styles from "./LensNavigator.css";import type { LensTab } from "./types";@@ -14,80 +24,94 @@ type LensNavigatorProps = {onCloseTab: (tabKey: string) => void;};+type IndicatorProps = {+ tab: LensTab;+ activeTabKey: string | undefined;+};++const Indicator = ({ tab, activeTabKey }: IndicatorProps) => {+ if (!tab.isStatic || tab.isFullyLoaded) {+ return null;+ }+ // Only the active tab is mounted and actually loading, so an unvisited+ // inactive tab would otherwise show a spinner forever.+ if (tab.key === activeTabKey) {+ return <Loader size="xs" data-testid="lens-tab-loader" />;+ }+ if (!tab.complexity || tab.complexity.level === "fast") {+ return null;+ }+ return (+ <Tooltip+ label={match(tab.complexity.level)+ .with("slow", () => t`This analysis may take longer to load`)+ .with(+ "very-slow",+ () => t`This analysis may take significantly longer to load`,+ )+ .exhaustive()}+ >+ <Icon name="clock" size={12} c="text-tertiary" />+ </Tooltip>+ );+};+export const LensNavigator = ({tabs,activeTabKey,onSwitchTab,onCloseTab,children,-}: PropsWithChildren<LensNavigatorProps>) => (- <Stack- gap="0"- bd="1px solid border"- bdrs="sm"- bg="background-primary"- pt={rem(6)}- >- <Tabs- value={activeTabKey}- onChange={(value) => value && onSwitchTab(value)}- className={styles.tabs}+}: PropsWithChildren<LensNavigatorProps>) => {+ return (+ <Stack+ gap="0"+ bd="1px solid border"+ bdrs="sm"+ bg="background-primary"+ pt={rem(6)}>- <Tabs.List px="lg" className={styles.tabsList}>- {tabs.map((tab) => (- <Tabs.Tab key={tab.key} value={tab.key} className={styles.tab}>- <Group gap="xs" wrap="nowrap">- <Text- size="md"- fw={700}- c={tab.key === activeTabKey ? "text-brand" : "text-primary"}- truncate- miw={0}- >- {tab.title ?? t`Loading...`}- </Text>- {tab.isStatic &&- !tab.isFullyLoaded &&- match(tab.complexity?.level)- .with("slow", "very-slow", (level) => (- <Tooltip- label={match(level)- .with(- "slow",- () => t`This analysis may take longer to load`,- )- .with(- "very-slow",- () =>- t`This analysis may take significantly longer to load`,- )- .exhaustive()}- >- <Icon name="clock" size={12} c="text-tertiary" />- </Tooltip>- ))- .otherwise(() => null)}- {!tab.isStatic && (- <Box- component="span"- onClick={(e) => {- e.stopPropagation();- onCloseTab(tab.key);- }}- role="button"- aria-label={t`Close tab`}- ml={rem("2px")}- lh={1}- style={{ cursor: "pointer" }}+ <Tabs+ value={activeTabKey}+ onChange={(value) => value && onSwitchTab(value)}+ className={styles.tabs}+ >+ <Tabs.List px="lg" className={styles.tabsList}>+ {tabs.map((tab) => (+ <Tabs.Tab key={tab.key} value={tab.key} className={styles.tab}>+ <Group gap="xs" wrap="nowrap">+ <Text+ size="md"+ fw={700}+ c={tab.key === activeTabKey ? "text-brand" : "text-primary"}+ truncate+ miw={0}>- <Icon name="close" size={16} c="text-tertiary" />- </Box>- )}- </Group>- </Tabs.Tab>- ))}- </Tabs.List>- </Tabs>- <Box p="lg">{children}</Box>- </Stack>-);+ {tab.title ?? t`Loading...`}+ </Text>+ <Indicator tab={tab} activeTabKey={activeTabKey} />+ {!tab.isStatic && (+ <Box+ component="span"+ onClick={(e) => {+ e.stopPropagation();+ onCloseTab(tab.key);+ }}+ role="button"+ aria-label={t`Close tab`}+ ml={rem("2px")}+ lh={1}+ style={{ cursor: "pointer" }}+ >+ <Icon name="close" size={16} c="text-tertiary" />+ </Box>+ )}+ </Group>+ </Tabs.Tab>+ ))}+ </Tabs.List>+ </Tabs>+ <Box p="lg">{children}</Box>+ </Stack>+ );+};