Skip to content

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

Hide exploration error pages for unrequested query variants (#82450)

Kevin Kellehercfb8cbd6f9ce
diff --git a/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.ts b/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.ts
index 0e06fa42070..5bd0d156c84 100644
--- a/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.ts
+++ b/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.ts
@@ -255,6 +255,7 @@ export function getExplorationSidebarTree(
}
type PageKey = string;
+type MetricDimensionKey = string;
// every query in a page has the same card_id, dimension_id, and query_type
// we use this to identify the same shaped pages across threads
@@ -263,6 +264,29 @@ function getPageKey(query: ExplorationQuery): PageKey {
return `${card_id}-${dimension_id}-${query_type}`;
}
+function metricDimensionKey(query: ExplorationQuery): MetricDimensionKey {
+ return `${query.card_id}-${query.dimension_id}`;
+}
+
+// Variant pages (hour-of-day, top-n, etc.) are bonus charts, not research-plan
+// rows. If the planned default for the same metric+dimension exists, hide a
+// failed variant rather than showing an error the user didn't ask for.
+function shouldOmitFailedVariantPage(
+ queries: ExplorationQuery[],
+ status: ExplorationQueryStatus,
+ defaultCombos: Set<MetricDimensionKey>,
+): boolean {
+ if (status !== "error") {
+ return false;
+ }
+ const query = queries[0];
+ return (
+ query != null &&
+ query.query_type !== "default" &&
+ defaultCombos.has(metricDimensionKey(query))
+ );
+}
+
// max interestingness (contextual preferred) across all queries in a page
function getInterestingnessByPageKey(
queries: ExplorationQuery[],
@@ -367,6 +391,11 @@ function getExplorationQueryTree(
const queriesById = new Map<ExplorationQueryId, ExplorationQuery>(
(thread.queries ?? []).map((query) => [query.id, query]),
);
+ const defaultCombos = new Set(
+ (thread.queries ?? [])
+ .filter((query) => query.query_type === "default")
+ .map(metricDimensionKey),
+ );
const blocks = (thread.blocks ?? []).filter(
(block) => block.name != null, // don't show anything missing a name
@@ -382,6 +411,9 @@ function getExplorationQueryTree(
return null;
}
const status = getExplorationQueryGroupStatus(queries);
+ if (shouldOmitFailedVariantPage(queries, status, defaultCombos)) {
+ return null;
+ }
const pageKey = getPageKey(queries[0]);
return {
id: String(page.id),
diff --git a/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.unit.spec.ts b/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.unit.spec.ts
index 698f6e0082f..e81fb2dd38d 100644
--- a/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.unit.spec.ts
+++ b/frontend/src/metabase/explorations/components/ExplorationSidebar/utils.unit.spec.ts
@@ -825,6 +825,152 @@ describe("getExplorationSidebarTree inherits a heading status from its pages", (
});
});
+describe("getExplorationSidebarTree omits failed variant pages", () => {
+ const BLOCK_ID = 10;
+ const DEFAULT_PAGE_ID = 1;
+ const VARIANT_PAGE_ID = 2;
+
+ function treeWithDefaultAndVariant(
+ defaultQuery: ReturnType<typeof createQuery>,
+ variantQuery: ReturnType<typeof createQuery>,
+ ) {
+ return getAllTabExplorationSidebarTree({
+ queries: [defaultQuery, variantQuery],
+ blocks: [
+ createBlock({
+ id: BLOCK_ID,
+ name: "Revenue",
+ position: 0,
+ pages: [
+ createPage({
+ id: DEFAULT_PAGE_ID,
+ name: "Created At",
+ position: 0,
+ query_ids: [defaultQuery.id],
+ }),
+ createPage({
+ id: VARIANT_PAGE_ID,
+ name: "Created At (Hour of day)",
+ position: 1,
+ query_ids: [variantQuery.id],
+ }),
+ ],
+ }),
+ ],
+ });
+ }
+
+ it("omits an errored variant when a default query exists for the same metric and dimension", () => {
+ const tree = treeWithDefaultAndVariant(
+ createQuery({
+ id: 1,
+ name: "Created At",
+ status: "done",
+ card_id: 10,
+ dimension_id: "created_at",
+ }),
+ createQuery({
+ id: 2,
+ name: "Created At (Hour of day)",
+ status: "error",
+ error_message: "boom",
+ card_id: 10,
+ dimension_id: "created_at",
+ query_type: "temporal-pattern-hour",
+ }),
+ );
+
+ expect(getLeafIds(getMetricHeadings(tree)[0])).toEqual(["1"]);
+ });
+
+ it("omits a zero-row variant when a default query exists for the same combo", () => {
+ const tree = treeWithDefaultAndVariant(
+ createQuery({
+ id: 1,
+ name: "Created At",
+ status: "done",
+ card_id: 10,
+ dimension_id: "created_at",
+ row_count: 5,
+ }),
+ createQuery({
+ id: 2,
+ name: "Created At (Hour of day)",
+ status: "done",
+ card_id: 10,
+ dimension_id: "created_at",
+ query_type: "temporal-pattern-hour",
+ row_count: 0,
+ }),
+ );
+
+ expect(getLeafIds(getMetricHeadings(tree)[0])).toEqual(["1"]);
+ });
+
+ it("keeps an errored top-n-other page when there is no default for that combo", () => {
+ const variant = createQuery({
+ id: 2,
+ name: "User ID (Top values + Other)",
+ status: "error",
+ error_message: "boom",
+ card_id: 10,
+ dimension_id: "user_id",
+ query_type: "top-n-other",
+ });
+ const tree = getAllTabExplorationSidebarTree({
+ queries: [variant],
+ blocks: [
+ createBlock({
+ id: BLOCK_ID,
+ name: "Revenue",
+ position: 0,
+ pages: [
+ createPage({
+ id: VARIANT_PAGE_ID,
+ name: "User ID (Top values + Other)",
+ position: 0,
+ query_ids: [variant.id],
+ }),
+ ],
+ }),
+ ],
+ });
+
+ expect(getLeafIds(getMetricHeadings(tree)[0])).toEqual(["2"]);
+ });
+
+ it("keeps an errored default page", () => {
+ const erroredDefault = createQuery({
+ id: 1,
+ name: "Created At",
+ status: "error",
+ error_message: "boom",
+ card_id: 10,
+ dimension_id: "created_at",
+ });
+ const tree = getAllTabExplorationSidebarTree({
+ queries: [erroredDefault],
+ blocks: [
+ createBlock({
+ id: BLOCK_ID,
+ name: "Revenue",
+ position: 0,
+ pages: [
+ createPage({
+ id: DEFAULT_PAGE_ID,
+ name: "Created At",
+ position: 0,
+ query_ids: [erroredDefault.id],
+ }),
+ ],
+ }),
+ ],
+ });
+
+ expect(getLeafIds(getMetricHeadings(tree)[0])).toEqual(["1"]);
+ });
+});
+
describe("getExplorationSidebarTree last-activity timestamps", () => {
function headingData(node: ITreeNodeItem<ExplorationTreeNode> | undefined) {
return node?.data?.type === "heading" ? node.data : undefined;