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
Keep the main navbar open until the user toggles it, or creates something (#83033)
Maz Amelidcb19a825845
diff --git a/e2e/support/helpers/e2e-ad-hoc-question-helpers.js b/e2e/support/helpers/e2e-ad-hoc-question-helpers.jsindex f14e90d4ba7..19803c9d39c 100644--- a/e2e/support/helpers/e2e-ad-hoc-question-helpers.js+++ b/e2e/support/helpers/e2e-ad-hoc-question-helpers.js@@ -2,6 +2,7 @@ import { SAMPLE_DB_ID, SAMPLE_DB_TABLES } from "e2e/support/cypress_data";import { runNativeQuery } from "./e2e-misc-helpers";import { NativeEditor } from "./e2e-native-editor-helpers";+import { closeNavigationSidebar } from "./e2e-ui-elements-helpers";const {STATIC_ORDERS_ID,@@ -44,6 +45,7 @@ function newCardHash(type) {export function startNewQuestion() {const hash = newCardHash("question");cy.visit(`/question/notebook#${hash}`);+ closeNavigationSidebar();}/**@@ -109,6 +111,7 @@ function newNativeCardHash(export function startNewNativeQuestion(config) {const hash = newNativeCardHash("question", config);cy.visit("/question#" + hash);+ closeNavigationSidebar();}/**@@ -141,6 +144,7 @@ export function visitQuestionAdhoc(cy.intercept(url).as(alias);cy.visit(`/question${questionMode}#` + adhocQuestionHash(question));+ closeNavigationSidebar();runQueryIfNeeded(question, autorun);diff --git a/e2e/support/helpers/e2e-detail-view-helpers.ts b/e2e/support/helpers/e2e-detail-view-helpers.tsindex cdaac3e3f39..b402cfdc204 100644--- a/e2e/support/helpers/e2e-detail-view-helpers.ts+++ b/e2e/support/helpers/e2e-detail-view-helpers.ts@@ -1,5 +1,7 @@import type { CardId, TableId } from "metabase-types/api";+import { closeNavigationSidebar } from "./e2e-ui-elements-helpers";+export const DetailView = {visitModel,visitTable,@@ -22,6 +24,7 @@ function visitModel(modelIdOrSlug: CardId | string, rowId: string | number) {"modelDetailTableMetadata",);cy.visit(`/model/${modelIdOrSlug}/detail/${rowId}`);+ closeNavigationSidebar();cy.wait("@modelDetailTableMetadata");}@@ -30,6 +33,7 @@ function visitTable(tableId: TableId, rowId: string | number) {"tableDetailTableMetadata",);cy.visit(`/table/${tableId}/detail/${rowId}`);+ closeNavigationSidebar();cy.wait("@tableDetailTableMetadata");}diff --git a/e2e/support/helpers/e2e-document-helpers.ts b/e2e/support/helpers/e2e-document-helpers.tsindex 118cba50979..8ba31428725 100644--- a/e2e/support/helpers/e2e-document-helpers.ts+++ b/e2e/support/helpers/e2e-document-helpers.ts@@ -1,5 +1,7 @@import type { CommentId, DocumentId } from "metabase-types/api";+import { closeNavigationSidebar } from "./e2e-ui-elements-helpers";+export const documentContent = () => cy.findByTestId("document-content");export const documentSaveButton = () =>@@ -96,6 +98,7 @@ function visitDocumentCommentById(const hash = commentId == null ? "" : `#comment-${commentId}`;cy.visit(`/document/${documentId}/comments/${nodeId}${hash}`);+ closeNavigationSidebar();cy.wait(`@${alias}`);}@@ -105,6 +108,7 @@ const visitDocumentById = (id: DocumentId) => {cy.intercept("GET", `/api/document/${id}`).as(alias);cy.visit(`/document/${id}`);+ closeNavigationSidebar();cy.wait(`@${alias}`);};diff --git a/e2e/support/helpers/e2e-explorations-helpers.ts b/e2e/support/helpers/e2e-explorations-helpers.tsindex 245cfdad60a..cebd9c64663 100644--- a/e2e/support/helpers/e2e-explorations-helpers.ts+++ b/e2e/support/helpers/e2e-explorations-helpers.ts@@ -5,6 +5,7 @@ import type { GetExplorationDataResponse } from "metabase-types/api";import { updateSetting } from "./api";import { setupAnthropicLlmProvider } from "./e2e-metabot-helpers";import { activateToken } from "./e2e-token-helpers";+import { closeNavigationSidebar } from "./e2e-ui-elements-helpers";const MOCK_LLM_PORT = 6125;const MOCK_LLM_RESPONSE = "Hello from Explorations!";@@ -31,6 +32,7 @@ export function explorationsMetabotPromptInput(): Cypress.Chainable<export function visitNewExploration(): void {cy.visit("/question/research");+ closeNavigationSidebar();cy.findByRole("button", { name: /Manual setup/i }).should("be.visible");}@@ -279,5 +281,6 @@ export function createExplorationViaApi({export function visitExploration(id: number): void {cy.visit(`/question/research/${id}`);+ closeNavigationSidebar();cy.findAllByRole("treeitem").first().should("be.visible");}diff --git a/e2e/support/helpers/e2e-metrics-viewer-helpers.ts b/e2e/support/helpers/e2e-metrics-viewer-helpers.tsindex 3c22b913259..74f5b04cdd9 100644--- a/e2e/support/helpers/e2e-metrics-viewer-helpers.ts+++ b/e2e/support/helpers/e2e-metrics-viewer-helpers.ts@@ -1,5 +1,10 @@+import { closeNavigationSidebar } from "./e2e-ui-elements-helpers";+export const MetricsViewer = {- goToViewer: () => cy.visit("/explore"),+ goToViewer: () => {+ cy.visit("/explore");+ closeNavigationSidebar();+ },formulaInput: () => cy.findByTestId("metrics-formula-input"),searchInput: () => {// Click the right edge of the container to focus the CodeMirror inputdiff --git a/e2e/support/helpers/e2e-misc-helpers.js b/e2e/support/helpers/e2e-misc-helpers.jsindex 886d307443c..68c0210908c 100644--- a/e2e/support/helpers/e2e-misc-helpers.js+++ b/e2e/support/helpers/e2e-misc-helpers.js@@ -1,5 +1,9 @@import { pickEntity } from "./e2e-collection-helpers";-import { modal, undoToast } from "./e2e-ui-elements-helpers";+import {+ closeNavigationSidebar,+ modal,+ undoToast,+} from "./e2e-ui-elements-helpers";// Find a text field by label text, type it in, then blur the field.// Commonly used in our Admin section as we auto-save settings.@@ -130,6 +134,7 @@ function visitQuestionById(id, { onBeforeLoad } = {}) {url: `/question/${id}`,onBeforeLoad,});+ closeNavigationSidebar();cy.wait("@" + metadataAlias);cy.wait("@" + alias);@@ -152,6 +157,7 @@ export function visitModel(id, { hasDataAccess = true } = {}) {}cy.visit(`/model/${id}`);+ closeNavigationSidebar();cy.wait("@" + alias);}@@ -240,6 +246,7 @@ function visitDashboardById(dashboard_id, config) {url: `/dashboard/${dashboard_id}`,qs: config.params,});+ closeNavigationSidebar();// dashcardTimeout lets callers widen the per-query wait window for dashboards with// many cards, whose tail queries stagger past cy.wait's 5s default under CPU load@@ -253,6 +260,7 @@ function visitDashboardById(dashboard_id, config) {// - the one which user doesn't have access to// the last request will always be `GET /api/dashboard/:dashboard_id`cy.visit(`/dashboard/${dashboard_id}`);+ closeNavigationSidebar();cy.wait(`@${dashboardAlias}`);}diff --git a/e2e/support/helpers/e2e-ui-elements-helpers.js b/e2e/support/helpers/e2e-ui-elements-helpers.jsindex 50c99166972..a5b61666001 100644--- a/e2e/support/helpers/e2e-ui-elements-helpers.js+++ b/e2e/support/helpers/e2e-ui-elements-helpers.js@@ -151,39 +151,41 @@ export function appBar() {}export function openNavigationSidebar() {- // Opening the sidebar is racy. The toggle flips the sidebar, so blindly- // clicking it closes an already-open one. But a single non-retrying read of- // its open state isn't safe either: navigating to a dashboard/question- // collapses the navbar, and that collapse can land a beat after the page- // content renders. The old code could read a lingering-open navbar, skip the- // toggle click, then watch it collapse out from under the assertion below.- // Re-check after acting and re-open if it collapsed, so the helper self-heals- // regardless of a pending collapse.- ensureNavigationSidebarOpen();+ setNavigationSidebarOpen(true);navigationSidebar().should("be.visible");}-function ensureNavigationSidebarOpen(attempt = 0) {+/**+ * Close the main navigation sidebar by clicking the app bar toggle, if it's open.+ *+ * The navbar stays open until the user closes it, but most specs were written+ * for the full-width layout of questions, dashboards and documents, so the+ * shared `visit*` helpers call this after loading those pages.+ */+export function closeNavigationSidebar() {+ setNavigationSidebarOpen(false);+ navigationSidebar().should("not.be.visible");+}++// The toggle flips the navbar, so only click it when the navbar is in the+// wrong state. Re-check after acting in case the state changed under us (small+// screens collapse the navbar on navigation) and try again if it did.+function setNavigationSidebarOpen(isOpen, attempt = 0) {const MAX_ATTEMPTS = 5;navigationSidebar().then(($nav) => {- if (!$nav.is(":visible")) {- appBar().findByTestId("sidebar-toggle").click();+ if ($nav.is(":visible") !== isOpen) {+ // Not `appBar()`: its "Navigation bar" label is translated, and the+ // visit helpers call this in specs that run in other locales.+ cy.findByTestId("app-bar").findByTestId("sidebar-toggle").click();}});- // Each Cypress command yields a tick, giving a pending collapse time to- // flush; if the navbar closed after our first read, try again.navigationSidebar().then(($nav) => {- if (!$nav.is(":visible") && attempt < MAX_ATTEMPTS) {- ensureNavigationSidebarOpen(attempt + 1);+ if ($nav.is(":visible") !== isOpen && attempt < MAX_ATTEMPTS) {+ setNavigationSidebarOpen(isOpen, attempt + 1);}});}-export function closeNavigationSidebar() {- appBar().findByTestId("sidebar-toggle").click();- navigationSidebar().should("not.be.visible");-}-export function browseDatabases() {return navigationSidebar().findByLabelText("Browse databases");}diff --git a/e2e/test/scenarios/actions/table-editing.cy.spec.ts b/e2e/test/scenarios/actions/table-editing.cy.spec.tsindex e2dc9b33d04..2d29cafd59c 100644--- a/e2e/test/scenarios/actions/table-editing.cy.spec.ts+++ b/e2e/test/scenarios/actions/table-editing.cy.spec.ts@@ -172,6 +172,7 @@ describe("scenarios > actions > table editing", () => {);cy.visit(`/browse/databases/${WRITABLE_DB_ID}/tables/${tableId}/edit`);+ H.closeNavigationSidebar();});cy.log("wait for the grid to be interactive");diff --git a/e2e/test/scenarios/admin/datamodel/segments.cy.spec.ts b/e2e/test/scenarios/admin/datamodel/segments.cy.spec.tsindex 1f5c9981eca..37c004b62f6 100644--- a/e2e/test/scenarios/admin/datamodel/segments.cy.spec.ts+++ b/e2e/test/scenarios/admin/datamodel/segments.cy.spec.ts@@ -353,6 +353,7 @@ describe("scenarios > admin > datamodel > segments", () => {},}).then(({ body: { id } }) => {cy.visit(`/reference/segments/${id}`);+ H.closeNavigationSidebar();cy.findAllByRole("listitem").filter(":contains(X-ray this segment)").click();diff --git a/e2e/test/scenarios/dashboard-filters/dashboard-filters-reproductions-1.cy.spec.js b/e2e/test/scenarios/dashboard-filters/dashboard-filters-reproductions-1.cy.spec.jsindex 5a51e492a8a..d620075fc7e 100644--- a/e2e/test/scenarios/dashboard-filters/dashboard-filters-reproductions-1.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/dashboard-filters-reproductions-1.cy.spec.js@@ -1553,7 +1553,7 @@ describe("issue 26230, issue 27356", () => {// Switching from the parameterized dashboard to the non-parameterized one// via the navigation sidebar should load cleanly, without erroring// (metabase#27356).- cy.button("Toggle sidebar").click();+ H.openNavigationSidebar();cy.findByRole("listitem", { name: REGULAR_DASHBOARD }).click();cy.wait("@loadDashboard");diff --git a/e2e/test/scenarios/dashboard/dashboard-questions.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard-questions.cy.spec.jsindex e9c2754c9e5..6e8cfbfc7b8 100644--- a/e2e/test/scenarios/dashboard/dashboard-questions.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashboard-questions.cy.spec.js@@ -480,7 +480,7 @@ describe("Dashboard > Dashboard Questions", () => {// unbookmark itH.queryBuilderHeader().icon("bookmark_filled").click();- cy.findByTestId("sidebar-toggle").click();+ H.openNavigationSidebar();H.navigationSidebar().findByText("Collections").should("be.visible");H.navigationSidebar().findByText("Orders").should("not.exist");@@ -1221,6 +1221,7 @@ describe("Dashboard > Dashboard Questions", () => {H.editDashboard();H.removeDashboardCard(1); // removes card for QUESTION_THREEH.saveDashboard();+ H.closeNavigationSidebar(); // breadcrumbs are hidden while the navbar is openH.appBar().findByText("First collection").click(); // navigate via breadcrumbs to avoid page refreshH.openCollectionMenu();H.popover().within(() => {diff --git a/e2e/test/scenarios/dashboard/dashboard.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard.cy.spec.jsindex a9453527ae8..5c653864088 100644--- a/e2e/test/scenarios/dashboard/dashboard.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashboard.cy.spec.js@@ -1804,7 +1804,6 @@ describe("issue 47170", () => {it("should not show error when dashboard fetch request is cancelled (metabase#47170)", () => {cy.visit(`/dashboard/${ORDERS_DASHBOARD_ID}`);- H.appBar().button("Toggle sidebar").click();H.navigationSidebar().findByText("Dashboard A").should("be.visible");H.main().findByTestId("dashboard-header-skeleton").should("be.visible");H.navigationSidebar().findByText("Dashboard A").click();diff --git a/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.jsindex fa8f2de4af7..2f5e885b7dc 100644--- a/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js@@ -484,6 +484,7 @@ describe("issue 29304", () => {window.Cypress = undefined;},});+ H.closeNavigationSidebar();};beforeEach(() => {diff --git a/e2e/test/scenarios/documents/documents.cy.spec.ts b/e2e/test/scenarios/documents/documents.cy.spec.tsindex c0c1e5d0553..cfad59941c9 100644--- a/e2e/test/scenarios/documents/documents.cy.spec.ts+++ b/e2e/test/scenarios/documents/documents.cy.spec.ts@@ -269,6 +269,8 @@ describe("documents", () => {cy.location("pathname").should("equal", "/document/1-test-document");H.documentContent().should("contain.text", "This is a paragraph");+ // breadcrumbs are hidden while the navbar is open+ H.closeNavigationSidebar();H.appBar().findByRole("link", { name: /Our analytics/ }).click();diff --git a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts b/e2e/test/scenarios/documents/supporting-text.cy.spec.tsindex e0dda9986a3..c7a247ae0c6 100644--- a/e2e/test/scenarios/documents/supporting-text.cy.spec.ts+++ b/e2e/test/scenarios/documents/supporting-text.cy.spec.ts@@ -251,6 +251,7 @@ describe("documents supporting text", () => {path: "/api/document/*",}).as("documentGet");cy.reload();+ H.closeNavigationSidebar();cy.wait("@documentGet");diff --git a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.jsindex 372bbabe610..9f3c25b8a24 100644--- a/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js+++ b/e2e/test/scenarios/embedding/interactive-embedding.cy.spec.js@@ -172,6 +172,8 @@ describe("scenarios > embedding > full app", () => {url: "/question/" + ORDERS_QUESTION_ID,qs: { additional_info: false },});+ // the app bar only shows breadcrumbs while the navbar is closed+ H.closeNavigationSidebar();cy.findByTestId("app-bar").findByText("Our analytics")@@ -1075,6 +1077,8 @@ describe("scenarios > embedding > full app", () => {url: `/dashboard/${ORDERS_DASHBOARD_ID}`,qs: { additional_info: false },});+ // the app bar only shows breadcrumbs while the navbar is closed+ H.closeNavigationSidebar();cy.findByTestId("dashboard-header").findByText("Orders in a dashboard")@@ -1189,9 +1193,8 @@ describe("scenarios > embedding > full app", () => {cy.log("Navigate to a dashboard via in-app navigation");H.navigationSidebar().findByText("Our analytics").click();cy.findByRole("main").findByText(dashboardDetails.name).click();- H.navigationSidebar()- .findByText("Our analytics")- .should("not.be.visible");+ H.navigationSidebar().should("be.visible");+ H.closeNavigationSidebar();cy.get("main header").findByText(dashboardDetails.name)@@ -1299,6 +1302,34 @@ describe("scenarios > embedding > full app", () => {});});+ it("should keep the navbar open when navigating, and only close it when the user toggles it", () => {+ const dashboardName = "Navbar dashboard";+ H.createDashboard({ name: dashboardName });++ H.visitFullAppEmbeddingUrl({ url: "/" });+ H.navigationSidebar().should("be.visible");++ cy.log("navigating to a dashboard keeps the navbar open");+ H.navigationSidebar().findByText("Our analytics").click();+ cy.findByRole("main").findByText(dashboardName).click();+ cy.findByTestId("dashboard-name-heading").should(+ "have.value",+ dashboardName,+ );+ H.navigationSidebar().should("be.visible");+ H.appBar().findByText("Our analytics").should("not.be.visible");++ cy.log("the toggle closes the navbar, and it stays closed on navigation");+ H.appBar().findByTestId("sidebar-toggle").click();+ H.navigationSidebar().should("not.be.visible");+ H.appBar().findByText("Our analytics").click();+ cy.findByTestId("collection-name-heading").should(+ "have.text",+ "Our analytics",+ );+ H.navigationSidebar().should("not.be.visible");+ });+it("should send `frame` message with dashboard height when the dashboard is resized (metabase#37437)", () => {const TAB_1 = { id: 1, name: "Tab 1" };const TAB_2 = { id: 2, name: "Tab 2" };@@ -1345,6 +1376,8 @@ describe("scenarios > embedding > full app", () => {},});+ // the app bar only shows breadcrumbs while the navbar is closed+ H.closeNavigationSidebar();cy.get("@postMessage").invoke("resetHistory");cy.findByTestId("app-bar").findByText("Our analytics").click();diff --git a/e2e/test/scenarios/explorations/explorations.cy.spec.ts b/e2e/test/scenarios/explorations/explorations.cy.spec.tsindex b3c62d284cc..4c8bee2840b 100644--- a/e2e/test/scenarios/explorations/explorations.cy.spec.ts+++ b/e2e/test/scenarios/explorations/explorations.cy.spec.ts@@ -632,6 +632,7 @@ describe("scenarios > explorations", () => {filterToggle().should("have.attr", "aria-pressed", "false");cy.reload();+ H.closeNavigationSidebar();cy.findAllByRole("treeitem", { timeout: 15000 }).first().should("be.visible");@@ -707,6 +708,7 @@ describe("scenarios > explorations", () => {cy.log("Hidden state is persisted server-side across a reload");cy.reload();+ H.closeNavigationSidebar();cy.findAllByRole("treeitem").should("have.length", 1);cy.log("Show hidden items + the group Show action restore the pages");diff --git a/e2e/test/scenarios/metrics/metrics-explorer.cy.spec.ts b/e2e/test/scenarios/metrics/metrics-explorer.cy.spec.tsindex bfc9a641a69..a23755b7ae9 100644--- a/e2e/test/scenarios/metrics/metrics-explorer.cy.spec.ts+++ b/e2e/test/scenarios/metrics/metrics-explorer.cy.spec.ts@@ -1860,10 +1860,6 @@ describe("scenarios > metrics > explorer", () => {});describe("Segments", () => {- beforeEach(() => {- H.MetricsViewer.goToViewer();- });-it("should apply a segment as a filter to a metric", () => {const SEGMENT_NAME = "Big orders";@@ -1879,6 +1875,9 @@ describe("scenarios > metrics > explorer", () => {},},});+ // Open the viewer only once the segment exists, so it can't load and+ // cache the segment list before the segment is created.+ H.MetricsViewer.goToViewer();addMetric("Count of orders");@@ -2309,6 +2308,7 @@ describe("scenarios > metrics > explorer > shared dimensions", () => {// changed hash would hand the new state to the previous test's stale app.viewerVisitCount += 1;cy.visit(`/explore?visit=${viewerVisitCount}#${hash}`);+ H.closeNavigationSidebar();H.MetricsViewer.searchBarPills().should("have.length", names.length);H.MetricsViewer.getAllMetricVisualizations().should("have.length.at.least",diff --git a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.jsindex 9351dedc040..a555b4bca92 100644--- a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js+++ b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js@@ -32,6 +32,7 @@ describe("scenarios > home > homepage", () => {it("should display x-rays for the Sample Database", () => {cy.visit("/");+ H.closeNavigationSidebar();cy.wait("@getXrayCandidates");cy.findByTestId("home-page").within(() => {cy.findByText(diff --git a/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js b/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.jsindex 7eb385eab55..0187577dda8 100644--- a/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js+++ b/e2e/test/scenarios/onboarding/navbar/navbar.cy.spec.js@@ -41,6 +41,8 @@ describe("scenarios > navigation > navbar", () => {H.popover().findByText(/SQL query/).click();+ // creating new content collapses the navbar+ H.navigationSidebar().should("not.be.visible");H.openNavigationSidebar();H.assertNavigationSidebarItemSelected(/Third collection/, "false");@@ -52,13 +54,18 @@ describe("scenarios > navigation > navbar", () => {cy.location("pathname").should("eq", "/");cy.findByTestId("home-page").should("be.visible");H.navigationSidebar().should("be.visible");- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.navigationSidebar().should("not.be.visible");+ // navigating to a dashboard doesn't collapse the navbar+ cy.visit(`/dashboard/${ORDERS_DASHBOARD_ID}`);+ H.dashboardGrid().should("be.visible");+ H.navigationSidebar().should("be.visible");++ // clicking the logo reopens a closed navbar+ H.closeNavigationSidebar();cy.findByTestId("main-logo-link").click();cy.location("pathname").should("eq", "/");cy.findByTestId("home-page").should("be.visible");- H.navigationSidebar().should("not.be.visible");+ H.navigationSidebar().should("be.visible");H.visitDashboard(ORDERS_DASHBOARD_ID);H.navigationSidebar().should("not.be.visible");@@ -111,7 +118,8 @@ describe("scenarios > navigation > navbar", () => {new RegExp(`^/question/${ORDERS_QUESTION_ID}\\b`),);H.queryBuilderHeader().findByText("Orders").should("be.visible");- H.navigationSidebar().should("not.be.visible");+ // clicking the logo reopens the navbar, and the redirect keeps it open+ H.navigationSidebar().should("be.visible");});});});diff --git a/e2e/test/scenarios/organization/official-collections.cy.spec.js b/e2e/test/scenarios/organization/official-collections.cy.spec.jsindex d36c4fced9d..05ace411b68 100644--- a/e2e/test/scenarios/organization/official-collections.cy.spec.js+++ b/e2e/test/scenarios/organization/official-collections.cy.spec.js@@ -165,6 +165,8 @@ function testOfficialBadgePresence(expectBadge = true) {H.deleteToken();}cy.visit(`/collection/${collectionId}`);+ // the app bar only shows collection breadcrumbs while the navbar is closed+ H.closeNavigationSidebar();});// Dashboard Pagediff --git a/e2e/test/scenarios/organization/timelines-sharing.cy.spec.ts b/e2e/test/scenarios/organization/timelines-sharing.cy.spec.tsindex c9255a8a0bc..a7605fb15d8 100644--- a/e2e/test/scenarios/organization/timelines-sharing.cy.spec.ts+++ b/e2e/test/scenarios/organization/timelines-sharing.cy.spec.ts@@ -129,9 +129,10 @@ describe("scenarios > organization > timelines > public links and embeds", () =>it("should show saved events read-only on an interactively embedded dashboard but keep the events panel on the question", () => {// without the token this runs in plain-app mode and asserts the wrong surfaceH.activateToken("pro-self-hosted");- cy.get<DashboardId>("@dashboardId").then((id) =>- H.visitFullAppEmbeddingUrl({ url: `/dashboard/${id}`, qs: {} }),- );+ cy.get<DashboardId>("@dashboardId").then((id) => {+ H.visitFullAppEmbeddingUrl({ url: `/dashboard/${id}`, qs: {} });+ H.closeNavigationSidebar();+ });expectReadOnlyDashboardEvents();expectDashCardMenuWithoutEvents();diff --git a/e2e/test/scenarios/visualizations/drillthroughs/column_extract_drill.cy.spec.js b/e2e/test/scenarios/visualizations/drillthroughs/column_extract_drill.cy.spec.jsindex 172756626bc..dc6c6fd799a 100644--- a/e2e/test/scenarios/visualizations/drillthroughs/column_extract_drill.cy.spec.js+++ b/e2e/test/scenarios/visualizations/drillthroughs/column_extract_drill.cy.spec.js@@ -161,6 +161,8 @@ describe("extract action", { viewportWidth: 1600 }, () => {// this is the way to open model definition with columnscy.visit(`/model/${modelId}/query`);cy.findByTestId("dataset-edit-bar").findByText("Cancel").click();+ // the model editor has no navbar; close it once we're back on the model+ H.closeNavigationSidebar();});cy.findByTestId("table-scroll-container").scrollTo("right");diff --git a/e2e/test/scenarios/visualizations/tabular/table.cy.spec.js b/e2e/test/scenarios/visualizations/tabular/table.cy.spec.jsindex 25de5fb7e2a..1aa7d328609 100644--- a/e2e/test/scenarios/visualizations/tabular/table.cy.spec.js+++ b/e2e/test/scenarios/visualizations/tabular/table.cy.spec.js@@ -931,6 +931,7 @@ describe("scenarios > visualizations > table > dashboards context", () => {// Ensure resizing did not permanently changed the row heightcy.reload();+ H.closeNavigationSidebar();H.assertRowHeight(0, wrappedRowInitialHeight);// Disable text wrapping from dashcard settingsdiff --git a/enterprise/frontend/src/metabase-enterprise/table-editing/table-edit/EditTableDataContainer.tsx b/enterprise/frontend/src/metabase-enterprise/table-editing/table-edit/EditTableDataContainer.tsxindex b5ac4708982..7fe9eb00e0c 100644--- a/enterprise/frontend/src/metabase-enterprise/table-editing/table-edit/EditTableDataContainer.tsx+++ b/enterprise/frontend/src/metabase-enterprise/table-editing/table-edit/EditTableDataContainer.tsx@@ -8,7 +8,6 @@ import {BulkActionButton,} from "metabase/common/components/BulkActionBar";import { GenericError } from "metabase/common/components/ErrorPages";-import { useCloseNavbarOnMount } from "metabase/common/hooks/use-close-navbar-on-mount";import { getUserIsAdmin } from "metabase/current-user";import { useSelector } from "metabase/redux";import { useLocation, useParams } from "metabase/router";@@ -49,8 +48,6 @@ export const EditTableDataContainer = () => {const { dbId: dbIdParam, tableId: tableIdParam } =useParams<EditTableDataContainerParams>();- useCloseNavbarOnMount();-const databaseId = parseInt(dbIdParam ?? "", 10);const tableId = parseInt(tableIdParam ?? "", 10);diff --git a/frontend/src/metabase/app/nav/AppBar.tsx b/frontend/src/metabase/app/nav/AppBar.tsxindex 6371e78fa1d..77c84304f8b 100644--- a/frontend/src/metabase/app/nav/AppBar.tsx+++ b/frontend/src/metabase/app/nav/AppBar.tsx@@ -20,7 +20,7 @@ import { CollectionBreadcrumbs } from "metabase/nav/containers/CollectionBreadcrimport { isQuestionPath } from "metabase/nav/containers/MainNavbar/getSelectedItems";import { getOriginalQuestion, getQuestion } from "metabase/query_builder";import { useDispatch, useSelector } from "metabase/redux";-import { closeNavbar, toggleNavbar } from "metabase/redux/app";+import { closeNavbar, openNavbar, toggleNavbar } from "metabase/redux/app";import { useLocation, useNavigate, useParams } from "metabase/router";import { getDetailViewState, getIsNavbarOpen } from "metabase/selectors/app";import { modelToUrl } from "metabase/urls";@@ -132,6 +132,7 @@ export function AppBarContainer() {detailView={detailView}isMetricsViewer={isMetricsViewer}onToggleNavbar={() => dispatch(toggleNavbar())}+ onOpenNavbar={() => dispatch(openNavbar())}onCloseNavbar={() => dispatch(closeNavbar())}collectionId={collectionId}collectionBreadcrumbs={diff --git a/frontend/src/metabase/app/nav/Navbar.unit.spec.tsx b/frontend/src/metabase/app/nav/Navbar.unit.spec.tsxindex 12123e353a1..39759e4bff6 100644--- a/frontend/src/metabase/app/nav/Navbar.unit.spec.tsx+++ b/frontend/src/metabase/app/nav/Navbar.unit.spec.tsx@@ -22,11 +22,7 @@ import {waitForLoaderToBeRemoved,} from "__support__/ui";import { ROOT_COLLECTION } from "metabase/common/collections/constants";-import {- CLOSE_NAVBAR,- OPEN_NAVBAR,- isNavbarOpenForPathname,-} from "metabase/redux/app";+import { CLOSE_NAVBAR, OPEN_NAVBAR } from "metabase/redux/app";import type { State } from "metabase/redux/store";import { Route } from "metabase/router";import * as iframeUtils from "metabase/utils/iframe";@@ -71,7 +67,7 @@ async function setup({const storeInitialState = createMockState({app: createMockAppState({- isNavbarOpen: isOpen ?? isNavbarOpenForPathname(pathname, true),+ isNavbarOpen: isOpen ?? true,}),embed: createMockEmbedState({options: createMockEmbedOptions(embedOptions),@@ -119,35 +115,23 @@ describe("nav > containers > Navbar > Core App", () => {});["question/1", "model/1", "dashboard/1"].forEach((pathname) => {- it(`should be hidden on initial load for a ${pathname}`, async () => {+ it(`should be open on initial load for a ${pathname}`, async () => {await setup({ pathname: `/${pathname}` });- await expectNavbarClosed();+ await expectNavbarOpen();});});- it("should hide when visiting a question", async () => {+ it("should stay open when visiting a question", async () => {const store = await setup({ pathname: "/" });await expectNavbarOpen();dispatchLocationChange({ store, pathname: "/question/1" });- await expectNavbarClosed();- });-- it("should stay open when navigating to the database reference questions page (metabase#72001)", async () => {- const store = await setup({ pathname: "/reference/databases/1" });- await expectNavbarOpen();- dispatchLocationChange({- store,- pathname: "/reference/databases/1/tables/2/questions",- });await expectNavbarOpen();});- it("should hide when visiting a question and stay hidden when returning to collection", async () => {- const store = await setup({ pathname: "/collection/1" });- await expectNavbarOpen();- dispatchLocationChange({ store, pathname: "/question/1" });+ it("should stay closed when visiting a question after being closed manually", async () => {+ const store = await setup({ isOpen: false, pathname: "/collection/1" });await expectNavbarClosed();- dispatchLocationChange({ store, pathname: "/collection/1" });+ dispatchLocationChange({ store, pathname: "/question/1" });await expectNavbarClosed();});@@ -167,29 +151,30 @@ describe("nav > containers > Navbar > Core App", () => {await expectNavbarOpen();});- it("should preserve state when navigating collections", async () => {+ it("should only change state on explicit open/close actions, not navigation", async () => {const store = await setup({ pathname: "/collection/1" });await expectNavbarOpen();dispatchLocationChange({ store, pathname: "/collection/2" });await expectNavbarOpen();dispatchLocationChange({ store, pathname: "/question/1" });+ await expectNavbarOpen();+ dispatchLocationChange({ store, pathname: "/dashboard/1" });+ await expectNavbarOpen();+ // act(...) flushes the connected Navbar re-render caused by the dispatch+ act(() => {+ store.dispatch({ type: CLOSE_NAVBAR });+ });await expectNavbarClosed();dispatchLocationChange({ store, pathname: "/collection/3" });await expectNavbarClosed();- dispatchLocationChange({ store, pathname: "/collection/4" });+ dispatchLocationChange({ store, pathname: "/question/2" });await expectNavbarClosed();- // act(...) flushes the connected Navbar re-render caused by the dispatchact(() => {store.dispatch({ type: OPEN_NAVBAR });});await expectNavbarOpen();- dispatchLocationChange({ store, pathname: "/collection/5" });+ dispatchLocationChange({ store, pathname: "/collection/4" });await expectNavbarOpen();- act(() => {- store.dispatch({ type: CLOSE_NAVBAR });- });- dispatchLocationChange({ store, pathname: "/collection/6" });- await expectNavbarClosed();});describe("embedded", () => {diff --git a/frontend/src/metabase/common/hooks/use-close-navbar-on-mount.tsx b/frontend/src/metabase/common/hooks/use-close-navbar-on-mount.tsxdeleted file mode 100644index 0c2ab1b26ef..00000000000--- a/frontend/src/metabase/common/hooks/use-close-navbar-on-mount.tsx+++ /dev/null@@ -1,12 +0,0 @@-import { useMount } from "react-use";--import { useDispatch } from "metabase/redux";-import { closeNavbar } from "metabase/redux/app";--export function useCloseNavbarOnMount() {- const dispatch = useDispatch();-- useMount(() => {- dispatch(closeNavbar());- });-}diff --git a/frontend/src/metabase/detail-view/pages/ModelDetailPage/ModelDetailPage.tsx b/frontend/src/metabase/detail-view/pages/ModelDetailPage/ModelDetailPage.tsxindex bbd484385bf..9425a835a57 100644--- a/frontend/src/metabase/detail-view/pages/ModelDetailPage/ModelDetailPage.tsx+++ b/frontend/src/metabase/detail-view/pages/ModelDetailPage/ModelDetailPage.tsx@@ -13,7 +13,7 @@ import {getTableQuery,} from "metabase/detail-view/utils";import { useDispatch, useSelector } from "metabase/redux";-import { closeNavbar, setDetailView } from "metabase/redux/app";+import { setDetailView } from "metabase/redux/app";import { useParams } from "metabase/router";import { getIsNavbarOpen } from "metabase/selectors/app";import * as Urls from "metabase/urls";@@ -78,10 +78,6 @@ export function ModelDetailPage() {const dispatch = useDispatch();const isNavBarOpen = useSelector(getIsNavbarOpen);- useEffect(() => {- dispatch(closeNavbar());- }, [dispatch]);-useEffect(() => {if (table) {dispatch(setDetailView({ rowName, table, collectionId }));diff --git a/frontend/src/metabase/detail-view/pages/TableDetailPage/TableDetailPage.tsx b/frontend/src/metabase/detail-view/pages/TableDetailPage/TableDetailPage.tsxindex 49f1c3efd72..232e2b129f5 100644--- a/frontend/src/metabase/detail-view/pages/TableDetailPage/TableDetailPage.tsx+++ b/frontend/src/metabase/detail-view/pages/TableDetailPage/TableDetailPage.tsx@@ -16,7 +16,7 @@ import {getTableQuery,} from "metabase/detail-view/utils";import { useDispatch, useSelector } from "metabase/redux";-import { closeNavbar, setDetailView } from "metabase/redux/app";+import { setDetailView } from "metabase/redux/app";import { useParams } from "metabase/router";import { getIsNavbarOpen } from "metabase/selectors/app";import { extractRemappedColumns } from "metabase/viz-core";@@ -65,10 +65,6 @@ export function TableDetailPage() {const dispatch = useDispatch();const isNavBarOpen = useSelector(getIsNavbarOpen);- useEffect(() => {- dispatch(closeNavbar());- }, [dispatch]);-useEffect(() => {if (table) {dispatch(setDetailView({ rowName, table, collectionId: null }));diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx b/frontend/src/metabase/nav/components/AppBar/AppBar.tsxindex 57b17e170c5..627f917d6c4 100644--- a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx@@ -30,6 +30,7 @@ export interface AppBarProps {questionLineage?: ReactNode;onSearchItemSelect?: (result: SearchResult) => void;onToggleNavbar: () => void;+ onOpenNavbar: () => void;onCloseNavbar: () => void;}diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsx b/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsxindex bf91f1c1f07..490950d5b66 100644--- a/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsx+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.unit.spec.tsx@@ -1,3 +1,5 @@+import userEvent from "@testing-library/user-event";+import { setupUserMetabotPermissionsEndpoint } from "__support__/server-mocks";import {createMockMediaQueryList,@@ -68,6 +70,19 @@ describe("AppBar", () => {expect(screen.getByTestId("new-button")).toBeInTheDocument();});+ it("should open the navbar when the logo is clicked", async () => {+ const props = getProps({+ isNavBarEnabled: true,+ isNavBarOpen: false,+ isLogoVisible: true,+ });++ renderWithProviders(<AppBar {...props} />);+ await userEvent.click(screen.getByTestId("main-logo-link"));++ expect(props.onOpenNavbar).toHaveBeenCalledTimes(1);+ });+it("should render the desktop app bar for saved questions and dashboards", () => {const props = getProps({isCollectionPathVisible: true,@@ -179,6 +194,7 @@ const getProps = (opts?: Partial<AppBarProps>): AppBarProps => ({collectionBreadcrumbs: <BreadcrumbsMock />,questionLineage: <QuestionLineageMock />,onToggleNavbar: jest.fn(),+ onOpenNavbar: jest.fn(),onCloseNavbar: jest.fn(),...opts,});diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsxindex 57957a312f2..cd7d3a43da4 100644--- a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx+++ b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx@@ -39,6 +39,7 @@ export interface AppBarLargeProps {questionLineage?: ReactNode;onSearchItemSelect?: (result: SearchResult) => void;onToggleNavbar: () => void;+ onOpenNavbar: () => void;}export const AppBarLarge = ({@@ -60,6 +61,7 @@ export const AppBarLarge = ({questionLineage,onSearchItemSelect,onToggleNavbar,+ onOpenNavbar,}: AppBarLargeProps): JSX.Element => {const isNavBarVisible = isNavBarOpen && isNavBarEnabled;const isInfoVisible = !isNavBarVisible || isQuestionLineageVisible;@@ -95,6 +97,7 @@ export const AppBarLarge = ({isLogoVisible={isLogoVisible}isNavBarEnabled={isNavBarEnabled}isGitSyncVisible={isGitSyncVisible}+ onLogoClick={onOpenNavbar}/><PLUGIN_REMOTE_SYNC.GitSyncAppBarControls /><Flexdiff --git a/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenu.tsx b/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenu.tsxindex eac6a0d7b03..8f93ea8e200 100644--- a/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenu.tsx+++ b/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenu.tsx@@ -1,3 +1,5 @@+import { useCallback } from "react";+import { useListDatabasesQuery } from "metabase/api";import {canUserCreateNativeQueries,@@ -24,6 +26,10 @@ export const NewItemMenu = (props: NewItemMenuProps) => {const hasNativeWrite = useSelector(canUserCreateNativeQueries);const hasDatabaseWithJsonEngine = getHasDatabaseWithJsonEngine(databases);const dispatch = useDispatch();+ const handleCloseNavbar = useCallback(+ () => dispatch(closeNavbar()),+ [dispatch],+ );return (<NewItemMenuView@@ -31,7 +37,7 @@ export const NewItemMenu = (props: NewItemMenuProps) => {hasDataAccess={hasDataAccess}hasNativeWrite={hasNativeWrite}hasDatabaseWithJsonEngine={hasDatabaseWithJsonEngine}- onCloseNavbar={() => dispatch(closeNavbar())}+ onCloseNavbar={handleCloseNavbar}/>);};diff --git a/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenuView.tsx b/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenuView.tsxindex bd4d7e36654..7bda0c4dbf0 100644--- a/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenuView.tsx+++ b/frontend/src/metabase/nav/components/NewItemMenu/NewItemMenuView.tsx@@ -33,6 +33,7 @@ export const NewItemMenuView = ({hasDataAccess,hasNativeWrite,hasDatabaseWithJsonEngine,+ onCloseNavbar,}: NewItemMenuProps) => {const dispatch = useDispatch();@@ -71,6 +72,7 @@ export const NewItemMenuView = ({collectionId,cardType: "question",})}+ onClick={onCloseNavbar}leftSection={<Icon name="insight" />}>{t`Question`}@@ -90,6 +92,7 @@ export const NewItemMenuView = ({cardType: "question",DEPRECATED_RAW_MBQL_databaseId: lastUsedDatabaseId || undefined,})}+ onClick={onCloseNavbar}leftSection={<Icon name="sql" />}>{hasDatabaseWithJsonEngine ? t`Native query` : t`SQL query`}@@ -117,6 +120,7 @@ export const NewItemMenuView = ({key="document"component={ForwardRefLink}to="/document/new"+ onClick={onCloseNavbar}leftSection={<Icon name="document" />}>{t`Document`}@@ -134,6 +138,7 @@ export const NewItemMenuView = ({dispatch,canWriteToCollections,hasNlqAccess,+ onCloseNavbar,]);if (menuItems.length === 0) {diff --git a/frontend/src/metabase/new/components/NewModals/NewItemMenu.unit.spec.tsx b/frontend/src/metabase/new/components/NewModals/NewItemMenu.unit.spec.tsxindex 980aeade72b..27859257e7c 100644--- a/frontend/src/metabase/new/components/NewModals/NewItemMenu.unit.spec.tsx+++ b/frontend/src/metabase/new/components/NewModals/NewItemMenu.unit.spec.tsx@@ -1,19 +1,22 @@import userEvent from "@testing-library/user-event";+import fetchMock from "fetch-mock";import { setupEnterprisePlugins } from "__support__/enterprise";import {setupCollectionByIdEndpoint,+ setupCollectionsEndpoints,setupDatabasesEndpoints,setupUserMetabotPermissionsEndpoint,} from "__support__/server-mocks";import { mockSettings } from "__support__/settings";import { createMockState } from "__support__/state";-import { renderWithProviders, screen } from "__support__/ui";+import { renderWithProviders, screen, waitFor } from "__support__/ui";import { NewItemMenu } from "metabase/nav/components/NewItemMenu";import { Route } from "metabase/router";import type { Database } from "metabase-types/api";import {createMockCollection,+ createMockDashboard,createMockUser,createMockUserPermissions,} from "metabase-types/api/mocks";@@ -54,7 +57,7 @@ async function setup({});setupEnterprisePlugins();- renderWithProviders(+ const { store } = renderWithProviders(<Routepath="/"element={@@ -79,6 +82,8 @@ async function setup({},);await userEvent.click(await screen.findByText("New"));++ return { store };}describe("NewItemMenu", () => {@@ -139,6 +144,46 @@ describe("NewItemMenu", () => {).toBeInTheDocument();});+ describe("navbar collapsing", () => {+ it.each(["Question", "SQL query", "Document"])(+ "should collapse the navbar when creating a new %s",+ async (itemName) => {+ const { store } = await setup();+ expect(store.getState().app.isNavbarOpen).toBe(true);++ await userEvent.click(await screen.findByText(itemName));++ expect(store.getState().app.isNavbarOpen).toBe(false);+ },+ );++ it("should not collapse the navbar when the new dashboard modal is opened and cancelled", async () => {+ const { store } = await setup();+ await userEvent.click(await screen.findByText("Dashboard"));+ await userEvent.click(+ await screen.findByRole("button", { name: "Cancel" }),+ );++ expect(store.getState().app.isNavbarOpen).toBe(true);+ });++ it("should collapse the navbar once a new dashboard is created", async () => {+ setupCollectionsEndpoints({ collections: [COLLECTION] });+ fetchMock.post("path:/api/dashboard", createMockDashboard({ id: 42 }));+ const { store } = await setup();++ await userEvent.click(await screen.findByText("Dashboard"));+ expect(store.getState().app.isNavbarOpen).toBe(true);++ await userEvent.type(await screen.findByLabelText("Name"), "Sales");+ await userEvent.click(screen.getByRole("button", { name: "Create" }));++ await waitFor(() =>+ expect(store.getState().app.isNavbarOpen).toBe(false),+ );+ });+ });+describe("New Dashboard", () => {it("should open new dashboard modal on click", async () => {await setup();diff --git a/frontend/src/metabase/new/components/NewModals/NewModals.tsx b/frontend/src/metabase/new/components/NewModals/NewModals.tsxindex b267f53db39..315abd95509 100644--- a/frontend/src/metabase/new/components/NewModals/NewModals.tsx+++ b/frontend/src/metabase/new/components/NewModals/NewModals.tsx@@ -10,13 +10,14 @@ import { PaletteShortcutsModal } from "metabase/palette/components/PaletteShortcimport { useRegisterShortcut } from "metabase/palette/hooks/useRegisterShortcut";import { ActionCreator } from "metabase/querying/action-creator";import { useDispatch, useSelector } from "metabase/redux";+import { closeNavbar } from "metabase/redux/app";import type { State } from "metabase/redux/store";import type { ModalState } from "metabase/redux/store/modal";import { closeModal, setOpenModal } from "metabase/redux/ui";import { useLocation, useNavigate, useParams } from "metabase/router";import { Modal, PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS } from "metabase/ui";import * as Urls from "metabase/urls";-import type { WritebackAction } from "metabase-types/api";+import type { Dashboard, WritebackAction } from "metabase-types/api";const getCurrentOpenModalState = <TProps,>(state: State) =>// Unjustified type cast. FIXME@@ -49,6 +50,15 @@ export const NewModals = () => {dispatch(closeModal());}, [dispatch]);+ const handleDashboardCreated = useCallback(+ (dashboard: Dashboard) => {+ dispatch(closeModal());+ dispatch(closeNavbar());+ navigate(Urls.dashboard(dashboard, { editMode: true }));+ },+ [dispatch, navigate],+ );+useEffect(() => {// Hide the modals on location changehandleModalClose();@@ -88,6 +98,7 @@ export const NewModals = () => {<CreateDashboardModalopenedonClose={handleModalClose}+ onCreate={handleDashboardCreated}collectionId={collectionId}/>);diff --git a/frontend/src/metabase/palette/components/Palette.unit.spec.tsx b/frontend/src/metabase/palette/components/Palette.unit.spec.tsxindex 9239e520694..7386e9caea1 100644--- a/frontend/src/metabase/palette/components/Palette.unit.spec.tsx+++ b/frontend/src/metabase/palette/components/Palette.unit.spec.tsx@@ -41,7 +41,7 @@ const setup = ({setupCollectionByIdEndpoint({collections: [createMockCollection({ id: "root", can_write: true })],});- renderWithProviders(+ return renderWithProviders(<Route path={initialRoute ? "*" : "/"} element={<Palette />} />,{withKBar: true,@@ -108,6 +108,21 @@ describe("command palette", () => {});});+ it.each(["New question", "New document"])(+ "should collapse the navbar when running the %s action",+ async (actionName) => {+ const { store } = setup();+ expect(store.getState().app.isNavbarOpen).toBe(true);++ await userEvent.keyboard("[ControlLeft>]k");+ const input = await screen.findByPlaceholderText(/search for anything/i);+ await userEvent.type(input, actionName);+ await userEvent.click(await screen.findByText(actionName));++ expect(store.getState().app.isNavbarOpen).toBe(false);+ },+ );+it("should match the action with alias when typing original name", async () => {setup();await userEvent.keyboard("[ControlLeft>]k");diff --git a/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx b/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsxindex adc01fdc736..0b5c3f60d36 100644--- a/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx+++ b/frontend/src/metabase/palette/hooks/useCommandPaletteBasicActions.tsx@@ -17,7 +17,7 @@ import {import { getHasDatabaseWithActionsEnabled } from "metabase/databases/utils/predicates";import { openEmbedJsWizard } from "metabase/embedding/store/embed-setup-modal";import { useDispatch, useSelector } from "metabase/redux";-import { openDiagnostics } from "metabase/redux/app";+import { closeNavbar, openDiagnostics } from "metabase/redux/app";import type { ModalName } from "metabase/redux/store/modal";import { closeModal, setOpenModal } from "metabase/redux/ui";import { useNavigate } from "metabase/router";@@ -117,6 +117,7 @@ export const useCommandPaletteBasicActions = ({icon: "insight",perform: () => {dispatch(closeModal());+ dispatch(closeNavbar());navigate(Urls.newQuestion({mode: "notebook",@@ -137,6 +138,7 @@ export const useCommandPaletteBasicActions = ({icon: "sql",perform: () => {dispatch(closeModal());+ dispatch(closeNavbar());navigate(Urls.newQuestion({DEPRECATED_RAW_MBQL_type: "native",@@ -177,6 +179,7 @@ export const useCommandPaletteBasicActions = ({section: "basic",icon: "document",perform: () => {+ dispatch(closeNavbar());navigate(Urls.newDocument());},});diff --git a/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx b/frontend/src/metabase/query_builder/containers/QueryBuilder.tsxindex 46925d839cb..d0311037faf 100644--- a/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx+++ b/frontend/src/metabase/query_builder/containers/QueryBuilder.tsx@@ -25,7 +25,6 @@ import {import { usePageTitleWithLoadingTime } from "metabase/hooks/use-page-title";import { VISUALIZATION_SLOW_TIMEOUT } from "metabase/querying/constants";import { connect, useSelector } from "metabase/redux";-import { closeNavbar } from "metabase/redux/app";import {editSummary,setIsNativeEditorOpen,@@ -125,12 +124,10 @@ import {getFirstQueryResult,getIsActionListVisible,getIsAdditionalInfoVisible,- getIsAnySidebarOpen,getIsDirty,getIsHeaderVisible,getIsLiveResizable,getIsLoadingComplete,- getIsNativeEditorOpen,getIsResultDirty,getIsRunnable,getIsTimeseries,@@ -190,11 +187,9 @@ const mapStateToProps = (state: State) => {uiControls: getUiControls(state),...state.qb.uiControls,dataReferenceStack: getDataReferenceStack(state),- isAnySidebarOpen: getIsAnySidebarOpen(state),isDirty: getIsDirty(state),isObjectDetail: getIsObjectDetail(state),- isNativeEditorOpen: getIsNativeEditorOpen(state),isNavBarOpen: getIsNavbarOpen(state),isLiveResizable: getIsLiveResizable(state),isTimeseries: getIsTimeseries(state),@@ -303,9 +298,6 @@ const mapDispatchToProps = {viewNextObjectDetail,viewPreviousObjectDetail,zoomInRow,-- // other- closeNavbar,};const connector = connect(mapStateToProps, mapDispatchToProps);@@ -329,9 +321,6 @@ function QueryBuilderInner(props: QueryBuilderInnerProps) {question,originalQuestion,uiControls,- isNativeEditorOpen,- isAnySidebarOpen,- closeNavbar,initializeQB,locationChanged,setUIControls,@@ -393,8 +382,6 @@ function QueryBuilderInner(props: QueryBuilderInnerProps) {const previousUIControls = usePrevious(uiControls);const previousLocation = usePrevious(location);- const wasShowingAnySidebar = usePrevious(isAnySidebarOpen);- const wasNativeEditorOpen = usePrevious(isNativeEditorOpen);const openModal = useCallback((modal: QueryBuilderUIControls["modal"]) => setUIControls({ modal }),@@ -458,21 +445,6 @@ function QueryBuilderInner(props: QueryBuilderInnerProps) {clearTimeout(timeout.current);});- useEffect(() => {- if (- (isAnySidebarOpen && !wasShowingAnySidebar) ||- (isNativeEditorOpen && !wasNativeEditorOpen)- ) {- closeNavbar();- }- }, [- isAnySidebarOpen,- wasShowingAnySidebar,- isNativeEditorOpen,- wasNativeEditorOpen,- closeNavbar,- ]);-useEffect(() => {const { isShowingDataReference, isShowingTemplateTagsEditor } = uiControls;const {diff --git a/frontend/src/metabase/redux/app.ts b/frontend/src/metabase/redux/app.tsindex de28e98758c..9dbb1d4aa3e 100644--- a/frontend/src/metabase/redux/app.ts+++ b/frontend/src/metabase/redux/app.ts@@ -61,18 +61,6 @@ const errorPage = handleActions(null,);-// regexr.com/7r89i-// Word boundaries are added so partial matches don't collapse the navbar-// e.g. /model shouldn't match /browse/models, /question shouldn't match /reference/.../questions-const PATH_WITH_COLLAPSED_NAVBAR =- /\/(model\b|question\b|dashboard|metabot|document|explore).*/;--export function isNavbarOpenForPathname(pathname: string, prevState: boolean) {- return (- !isSmallScreen() && !PATH_WITH_COLLAPSED_NAVBAR.test(pathname) && prevState- );-}-export const OPEN_NAVBAR = "metabase/app/OPEN_NAVBAR";export const CLOSE_NAVBAR = "metabase/app/CLOSE_NAVBAR";export const TOGGLE_NAVBAR = "metabase/app/TOGGLE_NAVBAR";@@ -86,6 +74,9 @@ const isNavbarOpen = handleActions([OPEN_NAVBAR]: () => true,[TOGGLE_NAVBAR]: (isOpen) => !isOpen,[CLOSE_NAVBAR]: () => false,+ // The navbar only opens or closes on explicit user action, so navigation+ // keeps whatever state the user last chose. The one exception is small+ // screens, where an open navbar would cover the whole page.[LOCATION_CHANGE]: (prevState: boolean,{ payload }: LocationChangeAction,@@ -94,7 +85,7 @@ const isNavbarOpen = handleActions(return prevState;}- return isNavbarOpenForPathname(payload.pathname, prevState);+ return isSmallScreen() ? false : prevState;},},true,diff --git a/frontend/src/metabase/redux/app.unit.spec.ts b/frontend/src/metabase/redux/app.unit.spec.tsindex 51aa4c50a10..1f5bb069864 100644--- a/frontend/src/metabase/redux/app.unit.spec.ts+++ b/frontend/src/metabase/redux/app.unit.spec.ts@@ -1,6 +1,5 @@import appReducer, {closeNavbar,- isNavbarOpenForPathname,openNavbar,resetErrorPage,setErrorPage,@@ -8,11 +7,9 @@ import appReducer, {} from "metabase/redux/app";// Characterization tests for the two reducers that react to navigation via the-// `@@router/LOCATION_CHANGE` action (`isNavbarOpen` collapse-by-pathname and-// `errorPage` clear-on-navigate). The router migration re-owns this action with-// a byte-identical type string and payload shape, so these tests must keep-// passing through the migration — they lock the subtle behaviour most likely to-// drift.+// `@@router/LOCATION_CHANGE` action (`isNavbarOpen` preserve-across-navigation+// and `errorPage` clear-on-navigate). The navbar only changes on explicit user+// action, so navigation must never collapse it on a regular (non-small) screen.const LOCATION_CHANGE = "@@router/LOCATION_CHANGE";@@ -29,19 +26,19 @@ describe("app reducer — navigation reactions", () => {});describe("isNavbarOpen on LOCATION_CHANGE", () => {- it("collapses when navigating to a path in the collapse list", () => {- const state = appReducer(- initialState(),- locationChange({ pathname: "/question/1" }),- );- expect(state.isNavbarOpen).toBe(false);- });-- it("stays open when navigating to a non-collapsing path", () => {- const state = appReducer(- initialState(),- locationChange({ pathname: "/collection/1" }),- );+ // The navbar no longer collapses based on the destination pathname; it+ // stays open unless the user closed it themselves.+ it.each([+ "/question/1",+ "/model/1",+ "/dashboard/1",+ "/metabot",+ "/document/1",+ "/explore",+ "/collection/1",+ "/browse/models",+ ])("stays open when navigating to %s", (pathname) => {+ const state = appReducer(initialState(), locationChange({ pathname }));expect(state.isNavbarOpen).toBe(true);});@@ -56,29 +53,11 @@ describe("app reducer — navigation reactions", () => {expect(state.isNavbarOpen).toBe(true);});- // Word-boundary cases pinned by the regex comment in app.ts: a partial match- // must not collapse the navbar.- it.each([- ["/model/1", false], // a model — collapses- ["/browse/models", true], // listing — must NOT collapse- ["/question/1", false], // a question — collapses- ["/reference/segments/1/questions", true], // listing — must NOT collapse- ["/dashboard/1", false],- ["/metabot", false],- ["/document/1", false],- ["/explore", false],- ["/collection/root", true],- ["/browse/databases", true],- ])("pathname %s => isNavbarOpen %s", (pathname, expected) => {- const state = appReducer(initialState(), locationChange({ pathname }));- expect(state.isNavbarOpen).toBe(expected);- });-- it("does not reopen a closed navbar just because the path is non-collapsing", () => {+ it("keeps a manually-closed navbar closed across navigation", () => {const closed = appReducer(initialState(), closeNavbar());const state = appReducer(closed,- locationChange({ pathname: "/collection/1" }),+ locationChange({ pathname: "/question/1" }),);expect(state.isNavbarOpen).toBe(false);});@@ -124,16 +103,3 @@ describe("app reducer — navigation reactions", () => {});});});--describe("isNavbarOpenForPathname", () => {- it.each([- ["/question/1", true, false],- ["/collection/1", true, true],- ["/browse/models", true, true],- ["/model/1", true, false],- // a collapsing path can never force the navbar open when it was closed- ["/collection/1", false, false],- ])("pathname %s with prevState %s => %s", (pathname, prevState, expected) => {- expect(isNavbarOpenForPathname(pathname, prevState)).toBe(expected);- });-});