Skip to content

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

Uxw 2736 improve transitions between main app data studio and admin (#68508)

Nick Fitzpatrickeb0a8d4900a5
diff --git a/e2e/support/helpers/e2e-ui-elements-helpers.js b/e2e/support/helpers/e2e-ui-elements-helpers.js
index 955d1b022f6..6e206048d0d 100644
--- a/e2e/support/helpers/e2e-ui-elements-helpers.js
+++ b/e2e/support/helpers/e2e-ui-elements-helpers.js
@@ -667,3 +667,35 @@ export function ensureParameterColumnValue({ columnName, columnValue }) {
});
});
}
+
+export function getProfileLink() {
+ return cy.findByTestId("app-switcher-target");
+}
+
+export const mainAppLinkText = "Main app";
+export const dataStudioAppLinkText = "Data studio";
+export const adminAppLinkText = "Admin";
+
+export function goToMainApp() {
+ getProfileLink().click();
+ popover().findByText(mainAppLinkText).click();
+}
+
+export function goToAdmin() {
+ getProfileLink().click();
+ popover().findByText(adminAppLinkText).click();
+}
+
+export function goToDataStudio() {
+ getProfileLink().click();
+ popover().findByText(dataStudioAppLinkText).click();
+}
+
+export function goToProfile() {
+ getProfileLink().click();
+ popover().findByTestId("mode-switcher-profile-link").click();
+}
+
+export function getHelpSubmenu() {
+ return cy.findByTestId("help-submenu");
+}
diff --git a/e2e/test/scenarios/admin-2/people.cy.spec.js b/e2e/test/scenarios/admin-2/people.cy.spec.js
index 04fd22bcca1..4dadd5fc18f 100644
--- a/e2e/test/scenarios/admin-2/people.cy.spec.js
+++ b/e2e/test/scenarios/admin-2/people.cy.spec.js
@@ -681,7 +681,7 @@ describe("scenarios > admin > people > group managers", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
+ H.activateToken("bleeding-edge");
cy.visit("/admin/people");
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
@@ -694,9 +694,7 @@ describe("scenarios > admin > people > group managers", () => {
cy.signInAsNormalUser();
cy.visit("/");
- cy.icon("gear").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Admin settings").click();
+ H.goToAdmin();
});
describe("group managers", () => {
diff --git a/e2e/test/scenarios/admin-2/whitelabel.cy.spec.js b/e2e/test/scenarios/admin-2/whitelabel.cy.spec.js
index 2d2e7af3297..572dea077f1 100644
--- a/e2e/test/scenarios/admin-2/whitelabel.cy.spec.js
+++ b/e2e/test/scenarios/admin-2/whitelabel.cy.spec.js
@@ -76,8 +76,9 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
it("should show the new name in the main app", () => {
cy.visit("/");
- cy.icon("gear").click();
- H.popover().findByText(`About ${NEW_COMPANY_NAME}`).click();
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
+ H.getHelpSubmenu().findByText(`About ${NEW_COMPANY_NAME}`).click();
H.modal()
.findByText(`Thanks for using ${NEW_COMPANY_NAME}!`)
.should("be.visible");
@@ -461,7 +462,7 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
cy.log("test custom illustration");
- cy.findByTestId("admin-navbar").findByText("Exit admin").click();
+ H.goToMainApp();
H.appBar().findByText("New").click();
H.popover().findByText("Dashboard").click();
H.modal().findByTestId("collection-picker-button").click();
@@ -494,7 +495,7 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
}).click();
H.selectDropdown().findByText("No illustration").click();
- cy.findByTestId("admin-navbar").findByText("Exit admin").click();
+ H.goToMainApp();
H.appBar().findByText("New").click();
H.popover().findByText("Dashboard").click();
H.modal().findByTestId("collection-picker-button").click();
@@ -606,7 +607,8 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
cy.signInAsNormalUser();
cy.visit("/");
- openSettingsMenu();
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
helpLink().should("not.exist");
cy.log("Set custom Help link");
@@ -635,7 +637,8 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
cy.signInAsNormalUser();
cy.visit("/");
- openSettingsMenu();
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
helpLink().should(
"have.attr",
"href",
@@ -654,7 +657,8 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
cy.wait("@putHelpLink");
cy.visit("/");
- openSettingsMenu();
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
helpLink()
.should("have.attr", "href")
@@ -662,7 +666,8 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
cy.signInAsNormalUser();
cy.visit("/");
- openSettingsMenu();
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
helpLink()
.should("have.attr", "href")
@@ -674,8 +679,8 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
cy.signInAsNormalUser();
cy.visit("/");
- openSettingsMenu();
-
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
helpLink()
.should("have.attr", "href")
.and("include", "https://www.metabase.com/help?");
@@ -733,7 +738,7 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
.blur();
H.undoToast().findByText("Changes saved").should("be.visible");
- cy.findByTestId("admin-navbar").findByText("Exit admin").click();
+ H.goToMainApp();
cy.url().should("include", "/test-1");
});
@@ -755,7 +760,7 @@ describe("formatting > whitelabel", { tags: "@EE" }, () => {
.findByText("This field must be a relative URL.")
.should("be.visible");
- cy.findByTestId("admin-navbar").findByText("Exit admin").click();
+ H.goToMainApp();
cy.url().should("include", "/test-2");
});
});
@@ -772,10 +777,8 @@ function setApplicationFontTo(font) {
H.updateSetting("application-font", font);
}
-const openSettingsMenu = () =>
- H.appBar().findByRole("button", { name: "Settings" }).click();
-
-const helpLink = () => H.popover().findByRole("menuitem", { name: "Help" });
+const helpLink = () =>
+ H.getHelpSubmenu().findByRole("menuitem", { name: "Get help" });
const getHelpLinkCustomDestinationInput = () =>
cy.findByPlaceholderText("Enter a URL it should go to");
diff --git a/e2e/test/scenarios/admin/admin-reproductions.cy.spec.js b/e2e/test/scenarios/admin/admin-reproductions.cy.spec.js
index baa7fddd33c..ae01f9d05be 100644
--- a/e2e/test/scenarios/admin/admin-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/admin/admin-reproductions.cy.spec.js
@@ -1,5 +1,6 @@
const { H } = cy;
import { SAMPLE_DB_ID, WRITABLE_DB_ID } from "e2e/support/cypress_data";
+import { mainAppLinkText } from "e2e/support/helpers";
describe("issue 26470", { tags: "@external" }, () => {
beforeEach(() => {
@@ -60,8 +61,7 @@ describe("issue 21532", () => {
it("should allow navigating back from admin settings (metabase#21532)", () => {
cy.visit("/");
- cy.icon("gear").click();
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
cy.findByTestId("admin-layout-content");
cy.go("back");
@@ -94,15 +94,6 @@ describe("issue 41765", { tags: "@external" }, () => {
});
});
- function enterAdmin() {
- H.appBar().icon("gear").click();
- H.popover().findByText("Admin settings").click();
- }
-
- function exitAdmin() {
- H.appBar().findByText("Exit admin").click();
- }
-
function openWritableDatabaseQuestion() {
// start new question without navigating
H.appBar().findByText("New").click();
@@ -123,7 +114,7 @@ describe("issue 41765", { tags: "@external" }, () => {
H.getNotebookStep("data").button("Pick columns").click();
H.popover().findByText(COLUMN_DISPLAY_NAME).should("not.exist");
- enterAdmin();
+ H.goToAdmin();
H.appBar().findByText("Databases").click();
cy.findAllByRole("link").contains(WRITABLE_DB_DISPLAY_NAME).click();
@@ -140,7 +131,7 @@ describe("issue 41765", { tags: "@external" }, () => {
tableName: TEST_TABLE,
});
- exitAdmin();
+ H.goToMainApp();
openWritableDatabaseQuestion();
H.getNotebookStep("data").button("Pick columns").click();
@@ -160,7 +151,7 @@ describe("(metabase#45042)", () => {
//Ensure tabs are present in normal view
cy.findByTestId("admin-navbar").within(() => {
cy.findByRole("link", { name: "Settings" }).should("exist");
- cy.findByRole("link", { name: "Exit admin" }).should("exist");
+ H.getProfileLink().should("exist");
});
//Shrink viewport
@@ -173,7 +164,6 @@ describe("(metabase#45042)", () => {
.click();
cy.findByRole("list", { name: "Navigation links" }).should("exist");
cy.findByRole("link", { name: "Settings" }).should("exist");
- cy.findByRole("link", { name: "Exit admin" }).should("exist");
});
// dismiss nav list
@@ -181,6 +171,10 @@ describe("(metabase#45042)", () => {
.should("be.visible")
.click();
cy.findByRole("list", { name: "Navigation links" }).should("not.exist");
+
+ //ensure that app switcher is visible and functional
+ H.getProfileLink().click();
+ H.popover().findByText(mainAppLinkText).should("exist");
});
});
diff --git a/e2e/test/scenarios/admin/databases.cy.spec.js b/e2e/test/scenarios/admin/databases.cy.spec.js
index 8f4fdf8634d..a5739b43d5f 100644
--- a/e2e/test/scenarios/admin/databases.cy.spec.js
+++ b/e2e/test/scenarios/admin/databases.cy.spec.js
@@ -953,7 +953,7 @@ describe("scenarios > admin > databases > sample database", () => {
cy.findByText("Sample Database").should("not.exist");
});
- cy.findByTestId("exit-admin").click();
+ H.goToMainApp();
cy.wait("@loadDatabases");
cy.findByTestId("main-navbar-root").within(() => {
@@ -970,7 +970,7 @@ describe("scenarios > admin > databases > sample database", () => {
cy.findByText("Sample Database").should("exist");
});
- cy.findByTestId("exit-admin").click();
+ H.goToMainApp();
cy.wait("@loadDatabases");
cy.findByTestId("main-navbar-root").within(() => {
diff --git a/e2e/test/scenarios/admin/datamodel/reproductions.cy.spec.ts b/e2e/test/scenarios/admin/datamodel/reproductions.cy.spec.ts
index c6e9cf10fd9..ff7479bde1f 100644
--- a/e2e/test/scenarios/admin/datamodel/reproductions.cy.spec.ts
+++ b/e2e/test/scenarios/admin/datamodel/reproductions.cy.spec.ts
@@ -133,8 +133,7 @@ describe("issue 15542", () => {
function openOrdersProductIdSettings() {
// Navigate without reloading the page
- H.appBar().icon("gear").click();
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
H.appBar().findByText("Table Metadata").click();
H.DataModel.TablePicker.getTable("Orders").click();
@@ -161,7 +160,7 @@ describe("issue 15542", () => {
cy.wait("@fieldDimensionUpdate");
- cy.findByRole("link", { name: "Exit admin" }).click();
+ H.goToMainApp();
openOrdersTable();
H.tableHeaderClick("Product ID");
@@ -177,7 +176,7 @@ describe("issue 15542", () => {
H.DataModel.FieldSection.getDisplayValuesInput().click();
H.popover().findByText("Use original value").click();
- cy.findByRole("link", { name: "Exit admin" }).click();
+ H.goToMainApp();
openOrdersTable();
H.tableHeaderClick("Product ID");
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
index 025bd176d66..71087df00eb 100644
--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
@@ -454,7 +454,7 @@ describe("Remote Sync", () => {
.should("exist");
H.modal().should("not.exist");
- cy.findByTestId("exit-admin").click();
+ H.goToMainApp();
// Branch picker should appear in the app bar (doesn't require import)
H.getGitSyncControls().should("contain.text", "main");
@@ -482,7 +482,7 @@ describe("Remote Sync", () => {
.should("exist");
H.modal().should("not.exist", { timeout: 10000 });
- cy.findByTestId("exit-admin").click();
+ H.goToMainApp();
// In read-only mode, git sync controls should not be visible in app bar
H.getGitSyncControls().should("not.exist");
@@ -569,7 +569,7 @@ describe("Remote Sync", () => {
.findByText("Enabled")
.should("not.exist");
- cy.findByTestId("exit-admin").click();
+ H.goToMainApp();
ensureSyncedCollectionIsVisible();
});
diff --git a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
index 7543d8a571f..0990beb1a3b 100644
--- a/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
+++ b/e2e/test/scenarios/collections/instance-analytics.cy.spec.js
@@ -229,8 +229,7 @@ describe("scenarios > Metabase Analytics Collection (AuditV2) ", () => {
});
// it's important that we do this manually, as this will only reproduce if theres no page load
- cy.findByTestId("app-bar").icon("gear").click();
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
cy.findByLabelText("Navigation bar").findByText("Permissions").click();
H.sidebar().findByText("Administrators").click();
cy.findByTestId("permission-table")
diff --git a/e2e/test/scenarios/collections/uploads.cy.spec.js b/e2e/test/scenarios/collections/uploads.cy.spec.js
index 3f4f0fa7f96..804fafa23ec 100644
--- a/e2e/test/scenarios/collections/uploads.cy.spec.js
+++ b/e2e/test/scenarios/collections/uploads.cy.spec.js
@@ -74,10 +74,7 @@ describe("CSV Uploading", { tags: ["@external", "@actions"] }, () => {
"Ensure that table is visible in admin without refreshing (metabase#38041)",
);
- cy.findByTestId("app-bar")
- .findByRole("button", { name: "Settings" })
- .click();
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
cy.findByRole("link", { name: "Table Metadata" }).click();
diff --git a/e2e/test/scenarios/data-studio/snippets.cy.spec.ts b/e2e/test/scenarios/data-studio/snippets.cy.spec.ts
index 55edd6db756..21742f74476 100644
--- a/e2e/test/scenarios/data-studio/snippets.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/snippets.cy.spec.ts
@@ -188,7 +188,9 @@ describe("scenarios > data studio > snippets", () => {
H.DataStudio.Library.libraryPage().findByText("Test snippet").click();
- cy.findByTestId("snippet-header").findByRole("button").click();
+ cy.findByTestId("snippet-header")
+ .findByRole("button", { name: /Snippet menu options/ })
+ .click();
H.popover().findByText("Delete").click();
H.modal().within(() => {
diff --git a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts
index 7e2903264b2..ab6ad573939 100644
--- a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts
@@ -120,7 +120,7 @@ describe("scenarios > admin > transforms", () => {
cy.findByText("Data").should("not.exist");
});
- cy.findByRole("link", { name: "Exit" }).click();
+ H.goToMainApp();
H.modal().button("Discard changes").click();
H.newButton("Question").click();
diff --git a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.js b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.js
index 5aecf8518f4..36e9e6c9139 100644
--- a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.js
@@ -1160,8 +1160,7 @@ describe("issue 21528", () => {
cy.log("The following scenario breaks on 46");
// Navigating to another page via JavaScript is faster than using `cy.visit("/admin/datamodel")` to load the whole page again.
- H.appBar().findByRole("button", { name: "Settings" }).click();
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
H.appBar().findByText("Table Metadata").click();
cy.findByRole("main")
.findByText("Start by selecting data to model")
@@ -1170,7 +1169,7 @@ describe("issue 21528", () => {
"eq",
`/admin/datamodel/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}`,
);
- cy.findByTestId("admin-navbar").findByText("Exit admin").click();
+ H.goToMainApp();
H.openNavigationSidebar();
H.navigationSidebar().findByText("Our analytics").click();
diff --git a/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts b/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts
index 6d78eed4e1a..65f9ce6269d 100644
--- a/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts
+++ b/e2e/test/scenarios/onboarding/add-initial-data.cy.spec.ts
@@ -243,7 +243,7 @@ describe("Add data modal", () => {
cy.button("Enable uploads").click();
cy.wait("@enableUploads");
- cy.findByLabelText("Navigation bar").contains("Exit admin").click();
+ H.goToMainApp();
H.navigationSidebar()
.findByRole("section", { name: "Data" })
.findByLabelText("Add data")
diff --git a/e2e/test/scenarios/onboarding/auth/signin.cy.spec.js b/e2e/test/scenarios/onboarding/auth/signin.cy.spec.js
index a6f557994fb..d60a20a02ca 100644
--- a/e2e/test/scenarios/onboarding/auth/signin.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/auth/signin.cy.spec.js
@@ -23,7 +23,7 @@ describe("scenarios > auth > signin", () => {
cy.signInAsAdmin();
cy.visit("/auth/login");
cy.url().should("not.contain", "auth/login");
- cy.icon("gear").should("exist");
+ H.getProfileLink().should("exist");
});
it("should display an error for incorrect passwords", () => {
diff --git a/e2e/test/scenarios/onboarding/command-palette.cy.spec.js b/e2e/test/scenarios/onboarding/command-palette.cy.spec.js
index 8ed4d7c4935..778056410f9 100644
--- a/e2e/test/scenarios/onboarding/command-palette.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/command-palette.cy.spec.js
@@ -497,8 +497,9 @@ describe("shortcuts", { tags: ["@actions"] }, () => {
cy.realPress("?");
H.shortcutModal().should("not.exist");
- H.appBar().findByRole("img", { name: /gear/ }).click();
- H.popover().findByText("Keyboard shortcuts").click();
+ H.getProfileLink().click();
+ H.popover().findByText("Help").click();
+ H.getHelpSubmenu().findByText("Keyboard shortcuts").click();
H.shortcutModal().should("exist");
cy.realPress("Escape");
H.shortcutModal().should("not.exist");
@@ -607,8 +608,7 @@ describe("shortcuts", { tags: ["@actions"] }, () => {
cy.realPress("[");
H.navigationSidebar().should("not.visible");
- cy.findByLabelText("Settings menu").click();
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
cy.findByTestId("site-name-setting").should("exist");
cy.location("pathname").should("contain", "/admin/settings");
diff --git a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
index cc9a6a38334..b10e5e2ed9a 100644
--- a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
@@ -389,7 +389,7 @@ describe("scenarios > home > custom homepage", () => {
"Orders in a dashboard",
);
- cy.findByTestId("admin-navbar").findByText("Exit admin").click();
+ H.goToMainApp();
cy.location("pathname").should(
"equal",
`/dashboard/${ORDERS_DASHBOARD_ID}`,
diff --git a/e2e/test/scenarios/onboarding/onboarding-checklist.cy.spec.ts b/e2e/test/scenarios/onboarding/onboarding-checklist.cy.spec.ts
index 05ddf8d6a36..959c6ef0908 100644
--- a/e2e/test/scenarios/onboarding/onboarding-checklist.cy.spec.ts
+++ b/e2e/test/scenarios/onboarding/onboarding-checklist.cy.spec.ts
@@ -66,7 +66,9 @@ describe("Inaccessible Onboarding checklist", () => {
cy.log("The link should not exist in the main settings menu either");
cy.findByLabelText("Settings menu").click();
- H.popover()
+ H.popover().findByText("Help").click();
+
+ cy.findByTestId("help-submenu")
.should("contain", "About Acme, corp.")
.and("not.contain", "How to use Metabase");
});
diff --git a/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js b/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js
index 2498e129ff8..aaa521638fa 100644
--- a/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js
@@ -81,9 +81,8 @@ describe("user > settings", () => {
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("Success");
- cy.findByLabelText("gear icon").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Sign out").click();
+ H.getProfileLink().click();
+ H.popover().findByText("Sign out").click();
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("Sign in to Metabase");
});
@@ -131,8 +130,8 @@ describe("user > settings", () => {
// Assert that the page reloaded with the new language
cy.findByLabelText("Nama depan").should("exist");
- // We need some UI element other than a string
- cy.icon("gear").should("exist");
+ // We need some UI element other than a string, and cannot get by labels as they could be translated
+ H.getProfileLink().should("exist");
});
it("should be able to open the app with every locale from the available locales (metabase#22192)", () => {
@@ -146,7 +145,7 @@ describe("user > settings", () => {
cy.request("PUT", `/api/user/${user.id}`, { locale });
cy.visit("/");
cy.wait("@getUser");
- cy.icon("gear").should("exist");
+ H.getProfileLink().should("exist");
});
},
);
@@ -302,8 +301,8 @@ describe("user > settings", () => {
cy.findByTestId("table-body").should("be.visible"); // wait for table to be rendered
cy.window().then((win) => {
- H.appBar()
- .findByLabelText("Settings")
+ H.getProfileLink()
+ .findByText("RT")
.should("exist")
.then(($button) => {
cy.wrap(win.getComputedStyle($button[0]).color).should(
@@ -323,8 +322,7 @@ describe("user > settings", () => {
});
});
- H.appBar().findByLabelText("Settings").click();
- H.popover().findByText("Account settings").click();
+ H.goToProfile();
cy.findByDisplayValue("Light").click();
H.popover().findByText("Dark").click();
@@ -335,8 +333,8 @@ describe("user > settings", () => {
cy.findByTestId("table-body").should("be.visible"); // wait for table to be rendered
cy.window().then((win) => {
- H.appBar()
- .findByLabelText("Settings")
+ H.getProfileLink()
+ .findByText("RT")
.should("exist")
.then(($button) => {
cy.wrap(win.getComputedStyle($button[0]).color).should(
diff --git a/e2e/test/scenarios/permissions/application-permissions.cy.spec.js b/e2e/test/scenarios/permissions/application-permissions.cy.spec.js
index 4b828374738..1676ceff266 100644
--- a/e2e/test/scenarios/permissions/application-permissions.cy.spec.js
+++ b/e2e/test/scenarios/permissions/application-permissions.cy.spec.js
@@ -4,6 +4,7 @@ import {
ORDERS_DASHBOARD_ID,
ORDERS_QUESTION_ID,
} from "e2e/support/cypress_sample_instance_data";
+import { adminAppLinkText } from "e2e/support/helpers";
const { ORDERS_ID } = SAMPLE_DATABASE;
@@ -17,7 +18,8 @@ describe("scenarios > admin > permissions > application", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- H.activateToken("pro-self-hosted");
+ // H.activateToken("pro-self-hosted");
+ H.activateToken("bleeding-edge");
});
it("shows permissions help", () => {
@@ -123,9 +125,7 @@ describe("scenarios > admin > permissions > application", () => {
it("allows accessing tools for non-admins", () => {
cy.visit("/");
- cy.icon("gear").click();
-
- H.popover().findByText("Admin settings").click();
+ H.goToAdmin();
cy.log("Tools smoke test");
cy.location("pathname").should("eq", "/admin/tools/help");
@@ -147,9 +147,9 @@ describe("scenarios > admin > permissions > application", () => {
it("does not allow accessing admin tools for non-admins", () => {
cy.signInAsNormalUser();
cy.visit("/");
- cy.icon("gear").click();
+ H.getProfileLink().click();
- H.popover().findByText("Admin settings").should("not.exist");
+ H.popover().findByText(adminAppLinkText).should("not.exist");
cy.visit("/admin/tools/errors");
H.main().findByText("Sorry, you don’t have permission to see that.");
diff --git a/e2e/test/scenarios/permissions/data-model-permissions.cy.spec.js b/e2e/test/scenarios/permissions/data-model-permissions.cy.spec.js
index 434d22776f2..c034907611d 100644
--- a/e2e/test/scenarios/permissions/data-model-permissions.cy.spec.js
+++ b/e2e/test/scenarios/permissions/data-model-permissions.cy.spec.js
@@ -37,9 +37,7 @@ describe("scenarios > admin > permissions", () => {
cy.visit("/");
// Go to the admin settings
- cy.icon("gear").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Admin settings").click();
+ H.goToAdmin();
// Assert the Data Model page state
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
@@ -86,9 +84,7 @@ describe("scenarios > admin > permissions", () => {
cy.visit("/");
// Go to the admin settings
- cy.icon("gear").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Admin settings").click();
+ H.goToAdmin();
// Assert the Data Model page state
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
diff --git a/e2e/test/scenarios/permissions/database-details-permissions.cy.spec.js b/e2e/test/scenarios/permissions/database-details-permissions.cy.spec.js
index ca171adfc7b..5d953a04c35 100644
--- a/e2e/test/scenarios/permissions/database-details-permissions.cy.spec.js
+++ b/e2e/test/scenarios/permissions/database-details-permissions.cy.spec.js
@@ -29,9 +29,7 @@ describe("scenarios > admin > permissions > database details permissions", () =>
cy.signInAsNormalUser();
cy.visit("/");
- cy.icon("gear").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Admin settings").should("be.visible").click();
+ H.goToAdmin();
cy.location("pathname").should("eq", "/admin/databases");
diff --git a/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js
index ad5fe260dd9..a6dd711a842 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js
+++ b/e2e/test/scenarios/question-reproductions/reproductions-1.cy.spec.js
@@ -1019,14 +1019,13 @@ describe("issue 19742", () => {
});
H.openNavigationSidebar();
- cy.icon("gear").click();
- selectFromDropdown("Admin settings");
+ H.goToAdmin();
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("Table Metadata").click();
H.DataModel.TablePicker.getTable("Orders").button("Hide table").click();
- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
- cy.findByText("Exit admin").click();
+
+ H.goToMainApp();
// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage
cy.findByText("New").click();
@@ -1044,10 +1043,6 @@ describe("issue 19742", () => {
});
});
-function selectFromDropdown(optionName) {
- H.popover().findByText(optionName).click();
-}
-
const QUESTION_1 = {
name: "Q1",
query: {
diff --git a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
index ce2d3d39152..d3dc230041a 100644
--- a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
+++ b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js
@@ -2620,7 +2620,7 @@ describe("issue 23449", () => {
cy.button("Save").click();
cy.log("make a model on Reviews");
- cy.findByRole("link", { name: "Exit admin" }).click();
+ H.goToMainApp();
H.navigationSidebar().findByLabelText("Browse models").click();
cy.findByLabelText("Create a new model").click();
cy.findByRole("link", { name: /Use the notebook editor/ }).click();
diff --git a/e2e/test/scenarios/question/notebook.cy.spec.js b/e2e/test/scenarios/question/notebook.cy.spec.js
index 235c704d772..36d1f96ff85 100644
--- a/e2e/test/scenarios/question/notebook.cy.spec.js
+++ b/e2e/test/scenarios/question/notebook.cy.spec.js
@@ -247,7 +247,7 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {
H.popover().isRenderedWithinViewport();
// Click anywhere outside this popover to close it because the issue with rendering happens when popover opens for the second time
- cy.icon("gear").click();
+ H.getProfileLink().click();
H.getNotebookStep("filter")
.findByText("Add filters to narrow your answer")
.click();
@@ -259,7 +259,7 @@ describe("scenarios > question > notebook", { tags: "@slow" }, () => {
.findByText("Pick a function or metric")
.click();
// Click outside to close this popover
- cy.icon("gear").click();
+ H.getProfileLink().click();
// Popover invoked again blocks the button making it impossible to click the button for the third time
H.getNotebookStep("summarize")
.findByText("Pick a function or metric")
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.unit.spec.tsx
index 5d5b177b990..e0a63f18d9d 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.unit.spec.tsx
@@ -120,7 +120,6 @@ describe("DataStudioLayout", () => {
});
expect(screen.getByText("Library")).toBeInTheDocument();
- expect(screen.getByText("Exit")).toBeInTheDocument();
});
it("should render GitSyncAppBarControls when sidebar is expanded", async () => {
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.module.css b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.module.css
new file mode 100644
index 00000000000..1e9076eb625
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.module.css
@@ -0,0 +1,10 @@
+.ProfileLink {
+ /* This is to keep the app switcher position a consistent space away
+ from the right when the window is smaller than the data studio
+ typically allows. Once we have a more responsive data studio layout
+ this can be removed. */
+ @media screen and (max-width: calc(50rem + 300px)) {
+ position: fixed;
+ right: 3.5rem;
+ }
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.tsx
index 8832f211a33..e9ea7940594 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/common/components/PaneHeader/PaneHeader.tsx
@@ -4,6 +4,7 @@ import { t } from "ttag";
import { EditableText } from "metabase/common/components/EditableText";
import { useSelector } from "metabase/lib/redux";
+import { AppSwitcher } from "metabase/nav/components/AppSwitcher";
import { PLUGIN_METABOT } from "metabase/plugins";
import { getLocation } from "metabase/selectors/routing";
import {
@@ -18,6 +19,7 @@ import {
Tooltip,
} from "metabase/ui";
+import S from "./PaneHeader.module.css";
import type { PaneHeaderTab } from "./types";
export interface PaneHeaderProps extends Omit<StackProps, "title"> {
@@ -26,7 +28,7 @@ export interface PaneHeaderProps extends Omit<StackProps, "title"> {
menu?: ReactNode;
tabs?: ReactNode;
actions?: ReactNode;
- breadcrumbs?: ReactNode;
+ breadcrumbs: ReactNode;
showMetabotButton?: boolean;
}
@@ -43,16 +45,14 @@ export const PaneHeader = ({
}: PaneHeaderProps) => {
return (
<Stack gap={0} pt="xs" {...rest}>
- {(breadcrumbs || showMetabotButton) && (
- <Flex mb="lg" mt="md" h="2rem" w="100%">
- {breadcrumbs}
- {showMetabotButton && (
- <Box ml="auto">
- <PLUGIN_METABOT.MetabotDataStudioButton />
- </Box>
- )}
- </Flex>
- )}
+ <Flex mb="lg" mt="md" w="100%">
+ {breadcrumbs}
+
+ <Group ml="auto" gap="md">
+ {showMetabotButton && <PLUGIN_METABOT.MetabotDataStudioButton />}
+ <AppSwitcher className={S.ProfileLink} />
+ </Group>
+ </Flex>
<Group
className={className}
gap="sm"
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/measures/components/MeasureHeader/MeasureHeader.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/measures/components/MeasureHeader/MeasureHeader.unit.spec.tsx
index cc649e994cc..f1f6cefd899 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/measures/components/MeasureHeader/MeasureHeader.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/measures/components/MeasureHeader/MeasureHeader.unit.spec.tsx
@@ -1,4 +1,5 @@
import userEvent from "@testing-library/user-event";
+import { Route } from "react-router";
import { renderWithProviders, screen } from "__support__/ui";
import { createMockMeasure } from "metabase-types/api/mocks";
@@ -18,13 +19,19 @@ const setup = ({ readOnly }: SetupOpts = {}) => {
const measure = createMockMeasure({ name: "Order count" });
renderWithProviders(
- <MeasureHeader
- measure={measure}
- onRemove={jest.fn()}
- readOnly={readOnly}
- tabUrls={tabUrls}
- previewUrl="/measures/1/preview"
+ <Route
+ path="/"
+ component={() => (
+ <MeasureHeader
+ measure={measure}
+ onRemove={jest.fn()}
+ readOnly={readOnly}
+ tabUrls={tabUrls}
+ previewUrl="/measures/1/preview"
+ />
+ )}
/>,
+ { withRouter: true },
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.tsx
index befdcaf5c89..001b690c818 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.tsx
@@ -34,7 +34,7 @@ export function SnippetHeader({
snippet,
actions,
...rest
-}: SnippetHeaderProps & PaneHeaderProps) {
+}: SnippetHeaderProps & Omit<PaneHeaderProps, "breadcrumbs">) {
const dispatch = useDispatch();
const remoteSyncReadOnly = useSelector(getIsRemoteSyncReadOnly);
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.unit.spec.tsx
index f27e4435e46..a33e781a3a9 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/snippets/components/SnippetHeader/SnippetHeader.unit.spec.tsx
@@ -1,3 +1,5 @@
+import { Route } from "react-router";
+
import { mockSettings } from "__support__/settings";
import { renderWithProviders, screen } from "__support__/ui";
import type {
@@ -18,9 +20,14 @@ const setup = ({ snippet = {}, remoteSyncType }: SetupOps) => {
const mockSnippet = createMockNativeQuerySnippet(snippet);
renderWithProviders(
- <SnippetHeader
- snippet={mockSnippet}
- actions={<div data-testid="custom-actions" />}
+ <Route
+ path="/"
+ component={() => (
+ <SnippetHeader
+ snippet={mockSnippet}
+ actions={<div data-testid="custom-actions" />}
+ />
+ )}
/>,
{
storeInitialState: createMockState({
@@ -29,6 +36,7 @@ const setup = ({ snippet = {}, remoteSyncType }: SetupOps) => {
"remote-sync-enabled": !!remoteSyncType,
}),
}),
+ withRouter: true,
},
);
};
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/tables/components/TableHeader/TableHeader.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/tables/components/TableHeader/TableHeader.tsx
index 7a6e0a271f3..a2141bab219 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/tables/components/TableHeader/TableHeader.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/tables/components/TableHeader/TableHeader.tsx
@@ -15,7 +15,7 @@ import { TableTabs } from "./TableTabs";
type TableHeaderProps = {
table: Table;
-} & PaneHeaderProps;
+} & Omit<PaneHeaderProps, "breadcrumbs">;
export function TableHeader({ table, ...rest }: TableHeaderProps) {
const { path, isLoadingPath } = useCollectionPath({
@@ -28,6 +28,7 @@ export function TableHeader({ table, ...rest }: TableHeaderProps) {
icon="table"
menu={<TableMoreMenu table={table} />}
tabs={<TableTabs table={table} />}
+ {...rest}
breadcrumbs={
<DataStudioBreadcrumbs loading={isLoadingPath}>
{path?.map((collection, i) => (
@@ -43,7 +44,6 @@ export function TableHeader({ table, ...rest }: TableHeaderProps) {
<span>{table.display_name}</span>
</DataStudioBreadcrumbs>
}
- {...rest}
/>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.module.css b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.module.css
new file mode 100644
index 00000000000..701aadb5949
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.module.css
@@ -0,0 +1,6 @@
+.ProfileLink {
+ position: absolute;
+ top: 1.25rem;
+ right: 3.5rem;
+ background-color: var(--mb-color-background-secondary);
+}
diff --git a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx
index d0e93bf8213..15addd26f42 100644
--- a/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/dependencies/pages/DependencyGraphPage/DependencyGraphPage.tsx
@@ -2,12 +2,14 @@ import type { Location } from "history";
import { useContext } from "react";
import * as Urls from "metabase/lib/urls";
+import { AppSwitcher } from "metabase/nav/components/AppSwitcher";
import { PLUGIN_DEPENDENCIES } from "metabase/plugins";
import { Stack } from "metabase/ui";
import { DependencyGraph } from "../../components/DependencyGraph";
import { isSameNode } from "../../utils";
+import S from "./DependencyGraphPage.module.css";
import { parseDependencyEntry } from "./utils";
export type DependencyGraphPageQuery = {
@@ -34,6 +36,7 @@ export function DependencyGraphPage({ location }: DependencyGraphPageProps) {
getGraphUrl={(entry) => Urls.dependencyGraph({ entry, baseUrl })}
withEntryPicker={withEntryPicker}
/>
+ <AppSwitcher className={S.ProfileLink} />
</Stack>
);
}
diff --git a/frontend/src/metabase/admin/people/components/GroupsListing.tsx b/frontend/src/metabase/admin/people/components/GroupsListing.tsx
index adba7fe7044..d9786173d93 100644
--- a/frontend/src/metabase/admin/people/components/GroupsListing.tsx
+++ b/frontend/src/metabase/admin/people/components/GroupsListing.tsx
@@ -269,7 +269,7 @@ function GroupRow({
gap="md"
>
<UserAvatar
- user={{ first_name: getGroupNameLocalized(group) }}
+ user={{ name: getGroupNameLocalized(group) }}
bg={backgroundColor}
/>
<Box component="span" fw={700} c="brand">
diff --git a/frontend/src/metabase/common/components/UserAvatar/UserAvatar.tsx b/frontend/src/metabase/common/components/UserAvatar/UserAvatar.tsx
index c78a2ef496e..7eeb7bb708b 100644
--- a/frontend/src/metabase/common/components/UserAvatar/UserAvatar.tsx
+++ b/frontend/src/metabase/common/components/UserAvatar/UserAvatar.tsx
@@ -1,25 +1,19 @@
-import { isEmail } from "metabase/lib/email";
+import {
+ type PartialGroup,
+ type PartialUser,
+ initial,
+ userInitials,
+} from "metabase/common/utils/user";
import type { AvatarProps } from "./UserAvatar.styled";
import { Avatar as StyledAvatar } from "./UserAvatar.styled";
interface UserAvatarProps extends AvatarProps {
- user: User;
+ user: PartialUser;
}
interface GroupProps {
- user: Group;
-}
-
-interface User {
- first_name: string | null;
- last_name: string | null;
- common_name: string;
- email?: string;
-}
-
-interface Group {
- first_name: string;
+ user: PartialGroup;
}
export function UserAvatar({ user, ...props }: UserAvatarProps | GroupProps) {
@@ -29,36 +23,3 @@ export function UserAvatar({ user, ...props }: UserAvatarProps | GroupProps) {
export function Avatar({ children, ...props }: { children: string }) {
return <StyledAvatar {...props}>{initial(children) ?? "?"}</StyledAvatar>;
}
-
-function initial(name?: string | null) {
- return name ? name.charAt(0).toUpperCase() : "";
-}
-
-function userInitials(user: User | Group) {
- if (user) {
- return nameInitials(user) || emailInitials(user as User);
- }
-
- return null;
-}
-
-function nameInitials(user: User | Group) {
- if ("common_name" in user) {
- return initial(user.first_name) + initial(user.last_name);
- }
-
- // render group
- return initial(user.first_name);
-}
-
-function emailInitials(user: User) {
- const email = [user.email, user.common_name].find((maybeEmail) =>
- isEmail(maybeEmail),
- );
- if (email) {
- const emailUsername = email.split("@")[0];
- return emailUsername.slice(0, 2).toUpperCase();
- }
-
- return null;
-}
diff --git a/frontend/src/metabase/common/components/UserAvatar/UserAvatar.unit.spec.tsx b/frontend/src/metabase/common/components/UserAvatar/UserAvatar.unit.spec.tsx
index 33c8de0776e..b9db49d3ec7 100644
--- a/frontend/src/metabase/common/components/UserAvatar/UserAvatar.unit.spec.tsx
+++ b/frontend/src/metabase/common/components/UserAvatar/UserAvatar.unit.spec.tsx
@@ -1,16 +1,17 @@
import { render, screen } from "__support__/ui";
+import { createMockUser } from "metabase-types/api/mocks";
import { UserAvatar } from "./UserAvatar";
describe("UserAvatar", () => {
describe("Users", () => {
test("render user with name", async () => {
- const revisionUser = {
+ const revisionUser = createMockUser({
first_name: "Testy",
last_name: "Tableton",
common_name: "Testy Tableton",
- };
+ });
render(<UserAvatar user={revisionUser} />);
@@ -18,12 +19,12 @@ describe("UserAvatar", () => {
});
test("render user without name", async () => {
- const revisionUser = {
+ const revisionUser = createMockUser({
first_name: null,
last_name: null,
common_name: "[email protected]",
- };
+ });
render(<UserAvatar user={revisionUser} />);
@@ -33,11 +34,11 @@ describe("UserAvatar", () => {
describe("Revision history", () => {
test("render user with name", async () => {
- const revisionUser = {
+ const revisionUser = createMockUser({
first_name: "Testy",
last_name: "Tableton",
common_name: "Testy Tableton",
- };
+ });
render(<UserAvatar user={revisionUser} />);
@@ -45,11 +46,11 @@ describe("UserAvatar", () => {
});
test("render user without name", async () => {
- const revisionUser = {
+ const revisionUser = createMockUser({
first_name: null,
last_name: null,
common_name: "[email protected]",
- };
+ });
render(<UserAvatar user={revisionUser} />);
@@ -59,9 +60,10 @@ describe("UserAvatar", () => {
describe("Admin > Groups", () => {
test("render group name", async () => {
- const revisionUser = {
+ const revisionUser = createMockUser({
first_name: "Admin",
- };
+ last_name: null,
+ });
render(<UserAvatar user={revisionUser} />);
diff --git a/frontend/src/metabase/common/utils/user.ts b/frontend/src/metabase/common/utils/user.ts
new file mode 100644
index 00000000000..2ebd6cb511a
--- /dev/null
+++ b/frontend/src/metabase/common/utils/user.ts
@@ -0,0 +1,47 @@
+import { isEmail } from "metabase/lib/email";
+import type { BaseUser, Group } from "metabase-types/api";
+
+export type PartialUser = Partial<
+ Pick<BaseUser, "first_name" | "last_name" | "email" | "common_name">
+>;
+export type PartialGroup = Pick<Group, "name">;
+
+const isUser = (user: PartialUser | PartialGroup): user is PartialUser => {
+ return "common_name" in user || "email" in user;
+};
+
+export function userInitials(user: PartialGroup | PartialUser) {
+ const initials = nameInitials(user);
+
+ if (initials) {
+ return initials;
+ } else if (isUser(user)) {
+ return emailInitials(user);
+ }
+
+ return null;
+}
+
+function nameInitials(user: PartialUser | PartialGroup) {
+ if (isUser(user)) {
+ return initial(user.first_name) + initial(user.last_name);
+ } else {
+ // render group
+ return initial(user.name);
+ }
+}
+export function initial(name?: string | null) {
+ return name ? name.charAt(0).toUpperCase() : "";
+}
+
+function emailInitials(user: PartialUser) {
+ const email = [user.email, user.common_name].find((maybeEmail) =>
+ isEmail(maybeEmail),
+ );
+ if (email) {
+ const emailUsername = email.split("@")[0];
+ return emailUsername.slice(0, 2).toUpperCase();
+ }
+
+ return null;
+}
diff --git a/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx b/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx
index 9e6c371785d..a2488004960 100644
--- a/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx
+++ b/frontend/src/metabase/home/components/Onboarding/Onboarding.tsx
@@ -17,7 +17,7 @@ import CS from "metabase/css/core/index.css";
import { getIsXrayEnabled } from "metabase/home/selectors";
import { useSelector } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
-import { useHelpLink } from "metabase/nav/components/ProfileLink/useHelpLink";
+import { useHelpLink } from "metabase/nav/components/AppSwitcher/useHelpLink";
import {
getDocsUrl,
getIsPaidPlan,
diff --git a/frontend/src/metabase/nav/components/AboutModal/AboutModal.tsx b/frontend/src/metabase/nav/components/AboutModal/AboutModal.tsx
new file mode 100644
index 00000000000..434a7f14461
--- /dev/null
+++ b/frontend/src/metabase/nav/components/AboutModal/AboutModal.tsx
@@ -0,0 +1,78 @@
+import { t } from "ttag";
+import _ from "underscore";
+
+import { LogoIcon } from "metabase/common/components/LogoIcon";
+import { useSetting } from "metabase/common/hooks";
+import { capitalize } from "metabase/lib/formatting";
+import { useSelector } from "metabase/lib/redux";
+import {
+ getApplicationName,
+ getIsWhiteLabeling,
+} from "metabase/selectors/whitelabel";
+import {
+ Box,
+ Divider,
+ Flex,
+ Modal,
+ type ModalProps,
+ Stack,
+ Text,
+ Title,
+} from "metabase/ui";
+import type { MetabaseInfo } from "metabase-types/api";
+
+export const AboutModal = ({
+ onClose,
+ opened,
+}: Pick<ModalProps, "onClose" | "opened">) => {
+ const version = useSetting("version") as MetabaseInfo["version"];
+ const applicationName = useSelector(getApplicationName);
+ const { tag, date, ...versionExtra } = version;
+
+ const isWhiteLabeling = useSelector(getIsWhiteLabeling);
+ const showTrademark = !isWhiteLabeling;
+
+ return (
+ <Modal opened={opened} onClose={onClose} withCloseButton={false} size={475}>
+ <Flex direction="column" align="center" pb="lg">
+ <Box c="brand" pb="md">
+ <LogoIcon height={48} />
+ </Box>
+ <Stack gap={14} align="center">
+ <Title order={2}>{t`Thanks for using ${applicationName}!`}</Title>
+ <Title order={4}>
+ {t`You're on version`} {tag}
+ </Title>
+ <Text c="text-secondary" fw="bold">
+ {t`Built on`} {date}
+ </Text>
+ {tag &&
+ !/^v\d+\.\d+\.\d+$/.test(tag) &&
+ _.map(versionExtra, (value, key) => (
+ <Text key={key} c="text-secondary" fw="bold">
+ {capitalize(key)}: {String(value)}
+ </Text>
+ ))}
+
+ {showTrademark && (
+ <>
+ <Divider size={2} w="100%" />
+ <Stack align="center" gap={0}>
+ <Text fz="sm" fw="bold" c="text-secondary" lh="sm">
+ {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- This only shows on OSS instance */}
+ {t`Metabase is a Trademark of Metabase, Inc`}
+ </Text>
+ <Text
+ fz="sm"
+ fw="bold"
+ c="text-secondary"
+ lh="sm"
+ >{t`and is built with care by a team from all across this pale blue dot.`}</Text>
+ </Stack>
+ </>
+ )}
+ </Stack>
+ </Flex>
+ </Modal>
+ );
+};
diff --git a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.styled.tsx b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.styled.tsx
index be49541e116..82ecf3ada99 100644
--- a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.styled.tsx
+++ b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.styled.tsx
@@ -46,7 +46,9 @@ export const MobileHide = styled.div`
export const AdminMobileNavbar = styled.div`
${breakpointMaxMedium} {
- display: block;
+ display: flex;
+ align-items: center;
+ gap: 0.5rem;
}
display: none;
diff --git a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx
index 44b05797e39..d2b37ded152 100644
--- a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx
+++ b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.tsx
@@ -13,6 +13,7 @@ import { getUserIsAdmin } from "metabase/selectors/user";
import { Button, Icon } from "metabase/ui";
import type { AdminPath } from "metabase-types/store";
+import { AppSwitcher } from "../AppSwitcher";
import StoreLink from "../StoreLink";
import { AdminNavItem } from "./AdminNavItem";
@@ -20,7 +21,6 @@ import { AdminNavLink } from "./AdminNavItem.styled";
import AdminNavCS from "./AdminNavbar.module.css";
import {
AdminButtons,
- AdminExitLink,
AdminLogoContainer,
AdminLogoLink,
AdminLogoText,
@@ -78,8 +78,6 @@ export const AdminNavbar = ({
</AdminLogoContainer>
</AdminLogoLink>
- <MobileNavbar adminPaths={adminPaths} currentPath={currentPath} />
-
<MobileHide>
<AdminNavbarItems data-testid="admin-navbar-items">
{adminPaths.map(({ name, key, path }) => (
@@ -93,14 +91,11 @@ export const AdminNavbar = ({
</AdminNavbarItems>
{!isPaidPlan && isAdmin && <StoreLink />}
-
- <AdminButtons>
- <AdminExitLink
- to="/"
- data-testid="exit-admin"
- >{t`Exit admin`}</AdminExitLink>
- </AdminButtons>
</MobileHide>
+ <AdminButtons>
+ <MobileNavbar adminPaths={adminPaths} currentPath={currentPath} />
+ <AppSwitcher />
+ </AdminButtons>
</AdminNavbarRoot>
);
};
@@ -121,13 +116,15 @@ const MobileNavbar = ({ adminPaths, currentPath }: AdminMobileNavbarProps) => {
onClick={() => setMobileNavOpen((prev) => !prev)}
variant="subtle"
p="0.25rem"
- >
- <Icon
- name="burger"
- size={32}
- className={AdminNavCS.MobileHamburgerIcon}
- />
- </Button>
+ leftSection={
+ <Icon
+ name="burger"
+ size={32}
+ className={AdminNavCS.MobileHamburgerIcon}
+ />
+ }
+ />
+
{mobileNavOpen && (
<AdminMobileNavBarItems aria-label={t`Navigation links`}>
{adminPaths.map(({ name, key, path }) => (
@@ -140,7 +137,6 @@ const MobileNavbar = ({ adminPaths, currentPath }: AdminMobileNavbarProps) => {
{name}
</AdminNavLink>
))}
- <AdminExitLink to="/">{t`Exit admin`}</AdminExitLink>
</AdminMobileNavBarItems>
)}
</AdminMobileNavbar>
diff --git a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx
index 0d719bdec6b..07fbd012302 100644
--- a/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx
+++ b/frontend/src/metabase/nav/components/AdminNavbar/AdminNavbar.unit.spec.tsx
@@ -1,3 +1,6 @@
+import { Route } from "react-router";
+
+import { setupBugReportingDetailsEndpoint } from "__support__/server-mocks";
import { mockSettings } from "__support__/settings";
import { renderWithProviders, screen } from "__support__/ui";
import {
@@ -10,6 +13,7 @@ import { createMockState } from "metabase-types/store/mocks";
import { AdminNavbar } from "./AdminNavbar";
const setup = ({ isAdmin = false, isPaidPlan = false }) => {
+ setupBugReportingDetailsEndpoint();
const state = createMockState({
currentUser: createMockUser({ is_superuser: isAdmin }),
settings: mockSettings(
@@ -19,9 +23,16 @@ const setup = ({ isAdmin = false, isPaidPlan = false }) => {
),
});
- return renderWithProviders(<AdminNavbar path="/admin" adminPaths={[]} />, {
- storeInitialState: state,
- });
+ return renderWithProviders(
+ <Route
+ path="/"
+ component={() => <AdminNavbar path="/admin" adminPaths={[]} />}
+ />,
+ {
+ storeInitialState: state,
+ withRouter: true,
+ },
+ );
};
describe("AdminNavbar", () => {
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
index a6c15397f62..f06cf22489f 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBar.tsx
@@ -22,7 +22,7 @@ export interface AppBarProps {
isSearchVisible?: boolean;
isEmbeddingIframe?: boolean;
isNewButtonVisible?: boolean;
- isProfileLinkVisible?: boolean;
+ isAppSwitcherVisible?: boolean;
isCollectionPathVisible?: boolean;
isQuestionLineageVisible?: boolean;
onToggleNavbar: () => void;
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
index 3a282d0a486..e8bc13ff709 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarLarge.tsx
@@ -9,8 +9,8 @@ import type { DetailViewState } from "metabase-types/store";
import CollectionBreadcrumbs from "../../containers/CollectionBreadcrumbs";
import QuestionLineage from "../../containers/QuestionLineage";
+import { AppSwitcher } from "../AppSwitcher";
import NewItemButton from "../NewItemButton";
-import { ProfileLink } from "../ProfileLink";
import { SearchBar } from "../search/SearchBar";
import { SearchButton } from "../search/SearchButton/SearchButton";
@@ -30,7 +30,7 @@ export interface AppBarLargeProps {
isSearchVisible?: boolean;
isEmbeddingIframe?: boolean;
isNewButtonVisible?: boolean;
- isProfileLinkVisible?: boolean;
+ isAppSwitcherVisible?: boolean;
isCollectionPathVisible?: boolean;
isQuestionLineageVisible?: boolean;
onToggleNavbar: () => void;
@@ -48,7 +48,7 @@ const AppBarLarge = ({
isSearchVisible,
isEmbeddingIframe,
isNewButtonVisible,
- isProfileLinkVisible,
+ isAppSwitcherVisible,
isCollectionPathVisible,
isQuestionLineageVisible,
onToggleNavbar,
@@ -94,7 +94,7 @@ const AppBarLarge = ({
) : null}
</AppBarInfoContainer>
</Flex>
- {(isSearchVisible || isNewButtonVisible || isProfileLinkVisible) && (
+ {(isSearchVisible || isNewButtonVisible || isAppSwitcherVisible) && (
<Flex
align="center"
gap="sm"
@@ -106,9 +106,9 @@ const AppBarLarge = ({
(isEmbeddingIframe ? <SearchBar /> : <SearchButton mr="md" />)}
{isNewButtonVisible && <NewItemButton collectionId={collectionId} />}
{!isEmbeddingIframe && <PLUGIN_METABOT.MetabotAppBarButton />}
- {isProfileLinkVisible && (
+ {isAppSwitcherVisible && (
<Box c="text-primary" aria-label={t`Settings menu`}>
- <ProfileLink />
+ <AppSwitcher />
</Box>
)}
</Flex>
diff --git a/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx b/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx
index 27d89ee6b8e..84a1206f816 100644
--- a/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx
+++ b/frontend/src/metabase/nav/components/AppBar/AppBarSmall.tsx
@@ -8,14 +8,13 @@ import type { DetailViewState } from "metabase-types/store";
import CollectionBreadcrumbs from "../../containers/CollectionBreadcrumbs";
import QuestionLineage from "../../containers/QuestionLineage";
-import { ProfileLink } from "../ProfileLink";
+import { AppSwitcher } from "../AppSwitcher";
import { SearchButton } from "../search/SearchButton/SearchButton";
import { AppBarLogo } from "./AppBarLogo";
import {
AppBarHeader,
AppBarLogoContainer,
- AppBarProfileLinkContainer,
AppBarSearchContainer,
AppBarSubheader,
AppBarToggleContainer,
@@ -29,7 +28,7 @@ export interface AppBarSmallProps {
isLogoVisible?: boolean;
isSearchVisible?: boolean;
isEmbeddingIframe?: boolean;
- isProfileLinkVisible?: boolean;
+ isAppSwitcherVisible?: boolean;
isCollectionPathVisible?: boolean;
isQuestionLineageVisible?: boolean;
onToggleNavbar: () => void;
@@ -43,7 +42,7 @@ const AppBarSmall = ({
isLogoVisible,
isSearchVisible,
isEmbeddingIframe,
- isProfileLinkVisible,
+ isAppSwitcherVisible,
isCollectionPathVisible,
isQuestionLineageVisible,
onToggleNavbar,
@@ -54,7 +53,7 @@ const AppBarSmall = ({
const [isSearchActive, setSearchActive] = useState(false);
const isInfoVisible = isQuestionLineageVisible || isCollectionPathVisible;
const isHeaderVisible =
- isLogoVisible || isNavBarEnabled || isSearchVisible || isProfileLinkVisible;
+ isLogoVisible || isNavBarEnabled || isSearchVisible || isAppSwitcherVisible;
const isSubheaderVisible = !isNavBarVisible && isInfoVisible;
const handleSearchActive = useCallback(() => {
@@ -93,11 +92,7 @@ const AppBarSmall = ({
))}
</AppBarSearchContainer>
{!isEmbeddingIframe && <PLUGIN_METABOT.MetabotAppBarButton />}
- {isProfileLinkVisible && (
- <AppBarProfileLinkContainer>
- <ProfileLink />
- </AppBarProfileLinkContainer>
- )}
+ {isAppSwitcherVisible && <AppSwitcher />}
</Flex>
<AppBarLogoContainer isVisible={isLogoVisible && !isSearchActive}>
<AppBarLogo
diff --git a/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.module.css b/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.module.css
new file mode 100644
index 00000000000..3a93af0b86c
--- /dev/null
+++ b/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.module.css
@@ -0,0 +1,6 @@
+.Avatar {
+ --avatar-bg: var(--mb-color-background-secondary) !important;
+ --avatar-color: var(--mb-color-text-primary) !important;
+
+ cursor: pointer;
+}
diff --git a/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.tsx b/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.tsx
new file mode 100644
index 00000000000..d5c585b8e92
--- /dev/null
+++ b/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.tsx
@@ -0,0 +1,256 @@
+import { useMemo, useState } from "react";
+import { t } from "ttag";
+
+import { getAdminPaths } from "metabase/admin/app/selectors";
+import { logout } from "metabase/auth/actions";
+import { ErrorDiagnosticModalWrapper } from "metabase/common/components/ErrorPages/ErrorDiagnosticModal";
+import { trackErrorDiagnosticModalOpened } from "metabase/common/components/ErrorPages/analytics";
+import { ExternalLink } from "metabase/common/components/ExternalLink";
+import { ForwardRefLink } from "metabase/common/components/Link";
+import { userInitials } from "metabase/common/utils/user";
+import {
+ getCanAccessOnboardingPage,
+ getIsNewInstance,
+} from "metabase/home/selectors";
+import type { ColorName } from "metabase/lib/colors/types";
+import { useDispatch, useSelector } from "metabase/lib/redux";
+import * as Urls from "metabase/lib/urls";
+import { PLUGIN_DATA_STUDIO } from "metabase/plugins";
+import { openDiagnostics } from "metabase/redux/app";
+import { setOpenModal } from "metabase/redux/ui";
+import { getUser } from "metabase/selectors/user";
+import { getApplicationName } from "metabase/selectors/whitelabel";
+import {
+ ActionIcon,
+ Avatar,
+ Box,
+ Divider,
+ Group,
+ Icon,
+ type IconName,
+ Menu,
+ Stack,
+ Text,
+} from "metabase/ui";
+
+import { AboutModal } from "../AboutModal/AboutModal";
+
+import S from "./AppSwitcher.module.css";
+import { useGetCurrentApp } from "./useGetCurrentApp";
+import { useHelpLink } from "./useHelpLink";
+
+const CURRENT_APP_ICON_OVERRIDES: {
+ name: IconName;
+ c: ColorName;
+} = { name: "check_filled", c: "brand" };
+
+export const AppSwitcher = ({ className }: { className?: string }) => {
+ const [modalOpen, setModalOpen] = useState<string | null>(null);
+
+ const dispatch = useDispatch();
+
+ const user = useSelector(getUser);
+ const applicationName = useSelector(getApplicationName);
+
+ // generate the proper set of list items for the current user
+ // based on whether they're an admin or not
+ const adminItems = useSelector(getAdminPaths);
+ const canAccessOnboardingPage = useSelector(getCanAccessOnboardingPage);
+ const canAccessDataStudio = useSelector(
+ PLUGIN_DATA_STUDIO.canAccessDataStudio,
+ );
+ const isNewInstance = useSelector(getIsNewInstance);
+ const helpLink = useHelpLink();
+
+ const openModal = (modalName: string) => {
+ setModalOpen(modalName);
+ };
+
+ const closeModal = () => {
+ setModalOpen(null);
+ };
+
+ const currentApp = useGetCurrentApp();
+
+ const appsSection = useMemo(() => {
+ const showAdminSettingsItem = adminItems?.length > 0;
+
+ if (!canAccessDataStudio && !showAdminSettingsItem) {
+ return null;
+ }
+
+ const items: React.ReactNode[] = [
+ <Menu.Item
+ key="main-app-link"
+ component={ForwardRefLink}
+ to="/"
+ leftSection={
+ <Icon
+ name="dashboard"
+ {...(currentApp === "main" ? CURRENT_APP_ICON_OVERRIDES : null)}
+ />
+ }
+ >
+ {t`Main app`}
+ </Menu.Item>,
+ ];
+
+ if (canAccessDataStudio) {
+ items.push(
+ <Menu.Item
+ key="data-studio-app-link"
+ component={ForwardRefLink}
+ to={Urls.dataStudio()}
+ leftSection={
+ <Icon
+ name="table"
+ {...(currentApp === "data-studio"
+ ? CURRENT_APP_ICON_OVERRIDES
+ : null)}
+ />
+ }
+ >
+ {t`Data studio`}
+ </Menu.Item>,
+ );
+ }
+ if (showAdminSettingsItem) {
+ items.push(
+ <Menu.Item
+ key="admin-app-link"
+ component={ForwardRefLink}
+ to={"/admin"}
+ leftSection={
+ <Icon
+ name="io"
+ {...(currentApp === "admin" ? CURRENT_APP_ICON_OVERRIDES : null)}
+ />
+ }
+ >{t`Admin`}</Menu.Item>,
+ );
+ }
+
+ return (
+ <>
+ <Divider key="app-sectiondivider" w="100%" my="sm" />
+ <Box px="md">{items}</Box>
+ </>
+ );
+ }, [canAccessDataStudio, adminItems, currentApp]);
+
+ // If the instance is not new, we remove the link from the sidebar automatically and show it here instead!
+ const showOnboardingLink = !isNewInstance && canAccessOnboardingPage;
+
+ return (
+ <>
+ <Menu position="bottom-end" shadow="md" width={200} offset={9}>
+ <Menu.Target>
+ {appsSection ? (
+ <ActionIcon
+ size="2.25rem"
+ p="sm"
+ variant="outline"
+ bd="1px solid var(--mb-color-border)"
+ aria-label={t`Settings`}
+ bdrs="50%"
+ className={className}
+ data-testid="app-switcher-target"
+ >
+ <Icon
+ name="mode"
+ // Need an escape hatch here for the white color in admin settings
+ style={{
+ color:
+ currentApp === "admin"
+ ? "var(--mantine-color-white)"
+ : "var(--mb-color-text-primary)",
+ }}
+ size={16}
+ />
+ </ActionIcon>
+ ) : (
+ <Avatar
+ radius="lg"
+ size={32}
+ className={S.Avatar}
+ bd="1px solid var(--mb-color-border)"
+ data-testid="app-switcher-target"
+ >
+ {user ? userInitials(user) : "?"}
+ </Avatar>
+ )}
+ </Menu.Target>
+ <Menu.Dropdown w={320} px="0">
+ {/* Avatar Stuff */}
+ <Box px="md">
+ <Menu.Item
+ component={ForwardRefLink}
+ to={Urls.accountSettings()}
+ data-testid="mode-switcher-profile-link"
+ >
+ <Group wrap="nowrap">
+ <Avatar color="brand" radius="lg" size={32}>
+ {user ? userInitials(user) : "?"}
+ </Avatar>
+ <Stack gap="xs">
+ <Text lh="xs">{user?.first_name}</Text>
+ <Text c="text-tertiary" fz="md" lh="xs">
+ {user?.email}
+ </Text>
+ </Stack>
+ </Group>
+ </Menu.Item>
+ </Box>
+
+ {/* Apps */}
+ {appsSection}
+
+ {/* Logout and Help */}
+ <Divider w="100%" my="sm" />
+ <Box px="md">
+ <Menu.Sub position="left-start" offset={20} closeDelay={350}>
+ <Menu.Sub.Target>
+ <Menu.Sub.Item>{t`Help`}</Menu.Sub.Item>
+ </Menu.Sub.Target>
+ <Menu.Sub.Dropdown data-testid="help-submenu">
+ {helpLink.visible && (
+ <Menu.Item component={ExternalLink} href={helpLink.href}>
+ {t`Get help`}
+ </Menu.Item>
+ )}
+ {showOnboardingLink && (
+ <Menu.Item component={ForwardRefLink} to="/getting-started">
+ {/* eslint-disable-next-line metabase/no-literal-metabase-strings -- This string only shows for non-whitelabeled instances */}
+ {t`How to use Metabase`}
+ </Menu.Item>
+ )}
+
+ <Menu.Item
+ onClick={() => dispatch(setOpenModal("help"))}
+ >{t`Keyboard shortcuts`}</Menu.Item>
+
+ <Menu.Item
+ onClick={() => {
+ trackErrorDiagnosticModalOpened("profile-menu");
+ dispatch(openDiagnostics());
+ }}
+ >{t`Download diagnostics`}</Menu.Item>
+ <Menu.Item onClick={() => openModal("about")}>
+ {t`About ${applicationName}`}
+ </Menu.Item>
+ </Menu.Sub.Dropdown>
+ </Menu.Sub>
+ <Menu.Item
+ onClick={() => dispatch(logout())}
+ >{t`Sign out`}</Menu.Item>
+ </Box>
+ </Menu.Dropdown>
+ </Menu>
+
+ <AboutModal onClose={closeModal} opened={modalOpen === "about"} />
+ {modalOpen === "diagnostic" && (
+ <ErrorDiagnosticModalWrapper isModalOpen={true} onClose={closeModal} />
+ )}
+ </>
+ );
+};
diff --git a/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.unit.spec.tsx b/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.unit.spec.tsx
new file mode 100644
index 00000000000..d0f4a20c69a
--- /dev/null
+++ b/frontend/src/metabase/nav/components/AppSwitcher/AppSwitcher.unit.spec.tsx
@@ -0,0 +1,340 @@
+import userEvent from "@testing-library/user-event";
+import dayjs from "dayjs";
+import { Route } from "react-router";
+
+import { setupEnterpriseOnlyPlugin } from "__support__/enterprise";
+import { setupBugReportingDetailsEndpoint } from "__support__/server-mocks";
+import { mockSettings } from "__support__/settings";
+import { renderWithProviders, screen, waitFor, within } from "__support__/ui";
+import type { HelpLinkSetting } from "metabase-types/api";
+import {
+ createMockMetabaseInfo,
+ createMockTokenFeatures,
+ createMockTokenStatus,
+ createMockUser,
+} from "metabase-types/api/mocks";
+import {
+ createMockAdminAppState,
+ createMockAdminState,
+} from "metabase-types/store/mocks";
+
+import { AppSwitcher } from "./AppSwitcher";
+
+const USER = createMockUser();
+
+const REGULAR_ITEMS = [
+ USER.first_name as string,
+ USER.email,
+ "Help",
+ "Sign out",
+];
+const ADMIN_ITEMS = [...REGULAR_ITEMS, "Main app", "Admin"];
+const HOSTED_ITEMS = [...ADMIN_ITEMS];
+
+const WITH_DATA_STUDIO = [...ADMIN_ITEMS, "Data studio"];
+
+const adminNavItem = {
+ name: `People`,
+ path: "/admin/people",
+ key: "people",
+} as const;
+
+async function setup({
+ isAdmin = false,
+ isHosted = false,
+ isPaidPlan = true,
+ hasDataStudio = false,
+ helpLinkSetting = "metabase",
+ helpLinkCustomDestinationSetting = "https://custom-destination.com/help",
+ instanceCreationDate = dayjs().toISOString(),
+}: {
+ isAdmin?: boolean;
+ isHosted?: boolean;
+ isPaidPlan?: boolean;
+ hasDataStudio?: boolean;
+ helpLinkSetting?: HelpLinkSetting;
+ helpLinkCustomDestinationSetting?: string;
+ instanceCreationDate?: string;
+} = {}) {
+ setupBugReportingDetailsEndpoint();
+
+ const settings = mockSettings({
+ "is-hosted?": isHosted,
+ "token-status": createMockTokenStatus({ valid: isPaidPlan }),
+ "help-link": helpLinkSetting,
+ "help-link-custom-destination": helpLinkCustomDestinationSetting,
+ "instance-creation": instanceCreationDate,
+ "token-features": createMockTokenFeatures({
+ data_studio: hasDataStudio,
+ }),
+ });
+
+ if (hasDataStudio) {
+ setupEnterpriseOnlyPlugin("data-studio");
+ }
+
+ const admin = createMockAdminState({
+ app: createMockAdminAppState({
+ paths: isAdmin ? [adminNavItem] : [],
+ }),
+ });
+
+ renderWithProviders(
+ <>
+ <Route path="/" component={AppSwitcher} />
+ <Route path="/admin" component={AppSwitcher} />
+ <Route path="/data-studio" component={AppSwitcher} />
+ </>,
+ {
+ withRouter: true,
+ storeInitialState: {
+ admin,
+ settings,
+ currentUser: { ...USER, is_superuser: isAdmin },
+ },
+ },
+ );
+
+ await openProfileLink();
+}
+
+async function setupHosted(opts = {}) {
+ return setup({ ...opts, isHosted: true });
+}
+
+describe("ProfileLink", () => {
+ it("should render standard links", async () => {
+ await setup();
+
+ // Should always render a profile link
+ expect(
+ await screen.findByText(USER.first_name as string),
+ ).toBeInTheDocument();
+ expect(await screen.findByText(USER.email)).toBeInTheDocument();
+
+ //Should render a help submenu
+ expect(
+ await screen.findByRole("menuitem", { name: "Help" }),
+ ).toBeInTheDocument();
+
+ // Should render logout
+ expect(
+ await screen.findByRole("menuitem", { name: "Sign out" }),
+ ).toBeInTheDocument();
+ });
+
+ describe("self-hosted", () => {
+ it("should show the proper set of items for normal users", async () => {
+ await setup({ isAdmin: false });
+
+ REGULAR_ITEMS.forEach((title) => {
+ expect(screen.getByText(title)).toBeInTheDocument();
+ });
+ expect(screen.queryByText("Admin settings")).not.toBeInTheDocument();
+ expect(
+ screen.queryByRole("img", { name: /mode/i }),
+ ).not.toBeInTheDocument();
+
+ expect(screen.getByTestId("app-switcher-target")).toHaveTextContent("TT");
+ });
+
+ it("should show the proper set of items for admin users", async () => {
+ await setup({ isAdmin: true });
+
+ ADMIN_ITEMS.forEach((title) => {
+ expect(screen.getByText(title)).toBeInTheDocument();
+ });
+
+ expect(
+ await within(screen.getByTestId("app-switcher-target")).findByRole(
+ "img",
+ { name: /mode/ },
+ ),
+ ).toBeInTheDocument();
+ });
+ });
+
+ describe("current app", () => {
+ it("should update it's apps section as you navigate", async () => {
+ await setup({ isAdmin: true, hasDataStudio: true });
+
+ await assertActiveApp("main");
+
+ await userEvent.click(await getAdminMenuItem());
+ await openProfileLink();
+ await waitFor(() => assertActiveApp("admin"));
+
+ await userEvent.click(await getDataStudioMenuItem());
+ await openProfileLink();
+ await assertActiveApp("data-studio");
+
+ await userEvent.click(await getMainAppMenuItem());
+ await openProfileLink();
+ await assertActiveApp("main");
+ });
+ });
+
+ describe("hosted", () => {
+ it("should show the proper set of items for normal users", async () => {
+ await setupHosted({ isAdmin: false });
+
+ REGULAR_ITEMS.forEach((title) => {
+ expect(screen.getByText(title)).toBeInTheDocument();
+ });
+ expect(screen.queryByText("Admin settings")).not.toBeInTheDocument();
+ });
+
+ it("should show the proper set of items for admin users", async () => {
+ await setupHosted({ isAdmin: true });
+
+ HOSTED_ITEMS.forEach((title) => {
+ expect(screen.getByText(title)).toBeInTheDocument();
+ });
+ });
+ });
+
+ describe("with data studio", () => {
+ it("should show data studio app when apropriate", async () => {
+ await setup({ isAdmin: true, hasDataStudio: true });
+
+ WITH_DATA_STUDIO.forEach((title) => {
+ expect(screen.getByText(title)).toBeInTheDocument();
+ });
+ });
+ });
+
+ describe("help submenu", () => {
+ describe("'How to use Metabase' link", () => {
+ it("should render if the instance was created more than 30 days ago", async () => {
+ await setup({
+ instanceCreationDate: dayjs().subtract(42, "days").toISOString(),
+ });
+ await openHelpSubmenu();
+
+ expect(screen.getByText("How to use Metabase")).toBeInTheDocument();
+ });
+
+ it("should not render for new instances (younger than 30 days)", async () => {
+ await setup({
+ instanceCreationDate: dayjs().subtract(14, "days").toISOString(),
+ });
+ await openHelpSubmenu();
+
+ expect(
+ screen.queryByText("How to use Metabase"),
+ ).not.toBeInTheDocument();
+ });
+ });
+
+ describe("help link", () => {
+ describe("when the setting is set to hidden", () => {
+ it("should return not be visible", async () => {
+ await setup({
+ helpLinkSetting: "hidden",
+ });
+ await openHelpSubmenu();
+
+ const link = screen.queryByRole("menuitem", { name: /get help/i });
+
+ expect(link).not.toBeInTheDocument();
+ });
+ });
+
+ describe("when the setting is `custom`", () => {
+ it("should return the custom destination", async () => {
+ await setup({
+ helpLinkSetting: "custom",
+ helpLinkCustomDestinationSetting: "https://custom.example.org/help",
+ });
+ await openHelpSubmenu();
+
+ const link = screen.getByRole("menuitem", { name: /get help/i });
+
+ expect(link).toBeInTheDocument();
+ expect(link).toHaveProperty(
+ "href",
+ "https://custom.example.org/help",
+ );
+ });
+ });
+
+ describe("when the setting is `metabase`", () => {
+ describe("when admin on paid plan", () => {
+ it("should return the default /help-premium link", async () => {
+ await setup({
+ isAdmin: true,
+ isPaidPlan: true,
+ helpLinkSetting: "metabase",
+ });
+
+ await openHelpSubmenu();
+
+ const link = screen.getByRole("menuitem", { name: /get help/i });
+
+ expect(link).toBeInTheDocument();
+ const mockBugReportDetails = encodeURIComponent(
+ JSON.stringify(createMockMetabaseInfo()),
+ );
+ const expected = `https://www.metabase.com/help-premium?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v1&diag=${mockBugReportDetails}`;
+ await waitFor(() => expect(link).toHaveProperty("href", expected));
+
+ expect(link).toHaveProperty("href", expected);
+ });
+ });
+
+ describe("when non admin", () => {
+ it("should return the default /help link", async () => {
+ await setup({
+ isAdmin: false,
+ isPaidPlan: true,
+ helpLinkSetting: "metabase",
+ });
+
+ await openHelpSubmenu();
+
+ const link = screen.getByRole("menuitem", { name: /get help/i });
+
+ expect(link).toBeInTheDocument();
+ expect(link).toHaveProperty(
+ "href",
+ "https://www.metabase.com/help?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v1",
+ );
+ });
+ });
+ });
+ });
+ });
+});
+
+const openProfileLink = async () => {
+ await userEvent.click(screen.getByTestId("app-switcher-target"));
+ await screen.findByRole("menu");
+};
+
+const openHelpSubmenu = async () =>
+ await userEvent.click(await screen.findByRole("menuitem", { name: "Help" }));
+
+const assertActiveApp = async (current: "main" | "admin" | "data-studio") => {
+ expect(
+ await within(await getMainAppMenuItem()).findByRole("img", {
+ name: current === "main" ? /check_filled/i : /dashboard/i,
+ }),
+ ).toBeInTheDocument();
+ expect(
+ await within(await getAdminMenuItem()).findByRole("img", {
+ name: current === "admin" ? /check_filled/i : /io/i,
+ }),
+ ).toBeInTheDocument();
+ expect(
+ await within(await getDataStudioMenuItem()).findByRole("img", {
+ name: current === "data-studio" ? /check_filled/i : /table/i,
+ }),
+ ).toBeInTheDocument();
+};
+
+const getMainAppMenuItem = () =>
+ screen.findByRole("menuitem", { name: /main app/i });
+const getAdminMenuItem = () =>
+ screen.findByRole("menuitem", { name: /admin/i });
+const getDataStudioMenuItem = () =>
+ screen.findByRole("menuitem", { name: /data studio/i });
diff --git a/frontend/src/metabase/nav/components/AppSwitcher/index.ts b/frontend/src/metabase/nav/components/AppSwitcher/index.ts
new file mode 100644
index 00000000000..5a9f03b4db0
--- /dev/null
+++ b/frontend/src/metabase/nav/components/AppSwitcher/index.ts
@@ -0,0 +1 @@
+export * from "./AppSwitcher";
diff --git a/frontend/src/metabase/nav/components/AppSwitcher/useGetCurrentApp.tsx b/frontend/src/metabase/nav/components/AppSwitcher/useGetCurrentApp.tsx
new file mode 100644
index 00000000000..d6ebd94d6c8
--- /dev/null
+++ b/frontend/src/metabase/nav/components/AppSwitcher/useGetCurrentApp.tsx
@@ -0,0 +1,17 @@
+import { match } from "ts-pattern";
+
+import { useRouter } from "metabase/router";
+
+export const useGetCurrentApp = () => {
+ const { location } = useRouter();
+ return match(location.pathname)
+ .when(
+ (path) => path.startsWith("/admin"),
+ () => "admin",
+ )
+ .when(
+ (path) => path.startsWith("/data-studio"),
+ () => "data-studio",
+ )
+ .otherwise(() => "main");
+};
diff --git a/frontend/src/metabase/nav/components/ProfileLink/useHelpLink.ts b/frontend/src/metabase/nav/components/AppSwitcher/useHelpLink.ts
similarity index 100%
rename from frontend/src/metabase/nav/components/ProfileLink/useHelpLink.ts
rename to frontend/src/metabase/nav/components/AppSwitcher/useHelpLink.ts
diff --git a/frontend/src/metabase/nav/components/ProfileLink/useHelpLink.unit.spec.ts b/frontend/src/metabase/nav/components/AppSwitcher/useHelpLink.unit.spec.ts
similarity index 100%
rename from frontend/src/metabase/nav/components/ProfileLink/useHelpLink.unit.spec.ts
rename to frontend/src/metabase/nav/components/AppSwitcher/useHelpLink.unit.spec.ts
diff --git a/frontend/src/metabase/nav/components/ProfileLink/ProfileLink.tsx b/frontend/src/metabase/nav/components/ProfileLink/ProfileLink.tsx
deleted file mode 100644
index c4eaee308a7..00000000000
--- a/frontend/src/metabase/nav/components/ProfileLink/ProfileLink.tsx
+++ /dev/null
@@ -1,313 +0,0 @@
-import cx from "classnames";
-import { useState } from "react";
-import { t } from "ttag";
-import _ from "underscore";
-
-import { getAdminPaths } from "metabase/admin/app/selectors";
-import { logout } from "metabase/auth/actions";
-import { ErrorDiagnosticModalWrapper } from "metabase/common/components/ErrorPages/ErrorDiagnosticModal";
-import { trackErrorDiagnosticModalOpened } from "metabase/common/components/ErrorPages/analytics";
-import { ForwardRefLink } from "metabase/common/components/Link";
-import { LogoIcon } from "metabase/common/components/LogoIcon";
-import { Modal } from "metabase/common/components/Modal";
-import { useSetting } from "metabase/common/hooks";
-import CS from "metabase/css/core/index.css";
-import {
- getCanAccessOnboardingPage,
- getIsNewInstance,
-} from "metabase/home/selectors";
-import { capitalize } from "metabase/lib/formatting";
-import { connect, useDispatch, useSelector } from "metabase/lib/redux";
-import * as Urls from "metabase/lib/urls";
-import { PLUGIN_DATA_STUDIO } from "metabase/plugins";
-import { openDiagnostics } from "metabase/redux/app";
-import { setOpenModal } from "metabase/redux/ui";
-import {
- getApplicationName,
- getIsWhiteLabeling,
-} from "metabase/selectors/whitelabel";
-import { ActionIcon, Icon, type IconName, Menu, Tooltip } from "metabase/ui";
-import type { MetabaseInfo } from "metabase-types/api";
-import type { AdminPath, State } from "metabase-types/store";
-
-import { useHelpLink } from "./useHelpLink";
-
-// generate the proper set of list items for the current user
-// based on whether they're an admin or not
-const mapStateToProps = (state: State) => ({
- adminItems: getAdminPaths(state),
- canAccessOnboardingPage: getCanAccessOnboardingPage(state),
- canAccessDataStudio: PLUGIN_DATA_STUDIO.canAccessDataStudio(state),
- isNewInstance: getIsNewInstance(state),
-});
-
-const mapDispatchToProps = {
- onOpenDiagnostics: openDiagnostics,
- onLogout: logout,
-};
-
-interface ProfileLinkProps {
- adminItems: AdminPath[];
- canAccessOnboardingPage: boolean;
- canAccessDataStudio: boolean;
- isNewInstance: boolean;
- onOpenDiagnostics: () => void;
- onLogout: () => void;
-}
-
-interface MenuItem {
- title?: string;
- icon?: IconName | null;
- externalLink?: boolean;
- link?: string;
- action?: () => void;
- separator?: boolean;
-}
-
-function ProfileLinkInner({
- adminItems,
- canAccessOnboardingPage,
- canAccessDataStudio,
- isNewInstance,
- onLogout,
- onOpenDiagnostics,
-}: ProfileLinkProps) {
- const [modalOpen, setModalOpen] = useState<string | null>(null);
- const version = useSetting("version") as MetabaseInfo["version"];
- const applicationName = useSelector(getApplicationName);
- const { tag, date, ...versionExtra } = version;
- const helpLink = useHelpLink();
- const dispatch = useDispatch();
-
- const openModal = (modalName: string) => {
- setModalOpen(modalName);
- };
-
- const closeModal = () => {
- setModalOpen(null);
- };
-
- const generateOptionsForUser = (): MenuItem[] => {
- const showAdminSettingsItem = adminItems?.length > 0;
- // If the instance is not new, we remove the link from the sidebar automatically and show it here instead!
- const showOnboardingLink = !isNewInstance && canAccessOnboardingPage;
-
- const menuItems: MenuItem[] = [];
- menuItems.push({
- title: t`Account settings`,
- icon: null,
- link: Urls.accountSettings(),
- });
- if (showAdminSettingsItem) {
- menuItems.push({
- title: t`Admin settings`,
- icon: null,
- link: "/admin",
- });
- }
- if (canAccessDataStudio) {
- menuItems.push({
- title: t`Data studio`,
- icon: null,
- link: Urls.dataStudio(),
- });
- }
- menuItems.push({ separator: true });
- if (helpLink.visible) {
- menuItems.push({
- title: t`Help`,
- icon: null,
- link: helpLink.href,
- externalLink: true,
- });
- }
- if (showOnboardingLink) {
- menuItems.push({
- // eslint-disable-next-line metabase/no-literal-metabase-strings -- This string only shows for non-whitelabeled instances
- title: t`How to use Metabase`,
- icon: null,
- link: "/getting-started",
- });
- }
- menuItems.push(
- {
- title: t`Keyboard shortcuts`,
- icon: null,
- action: () => dispatch(setOpenModal("help")),
- },
- {
- title: t`Download diagnostics`,
- icon: null,
- action: () => {
- trackErrorDiagnosticModalOpened("profile-menu");
- onOpenDiagnostics();
- },
- },
- {
- title: t`About ${applicationName}`,
- icon: null,
- action: () => openModal("about"),
- },
- {
- separator: true,
- },
- {
- title: t`Sign out`,
- icon: null,
- action: () => onLogout(),
- },
- );
-
- return menuItems;
- };
-
- // show trademark if application name is not whitelabeled
- const isWhiteLabeling = useSelector(getIsWhiteLabeling);
- const showTrademark = !isWhiteLabeling;
- const menuItems = generateOptionsForUser();
-
- return (
- <>
- <Menu position="bottom-end" shadow="md" width={200}>
- <Menu.Target>
- <Tooltip label={t`Settings`}>
- <ActionIcon
- size="2.25rem"
- p="sm"
- variant="outline"
- color="text-primary"
- bd="1px solid var(--mb-color-border)"
- aria-label={t`Settings`}
- >
- <Icon name="gear" size={16} />
- </ActionIcon>
- </Tooltip>
- </Menu.Target>
- <Menu.Dropdown>
- {menuItems.map((item, index) => {
- if (!item) {
- return null;
- }
-
- if (item.separator) {
- return <Menu.Divider key={index} />;
- }
-
- const component = item.externalLink
- ? "a"
- : item.link
- ? ForwardRefLink
- : "button";
-
- const commonProps = {
- leftSection: item.icon && <Icon name={item.icon} />,
- onClick: () => {
- if (item.action) {
- item.action();
- }
- },
- };
-
- if (component === ForwardRefLink && item.link) {
- return (
- <Menu.Item<typeof ForwardRefLink>
- key={item.title}
- {...commonProps}
- component={ForwardRefLink}
- to={item.link}
- >
- {item.title}
- </Menu.Item>
- );
- }
-
- if (component === "a" && item.link) {
- return (
- <Menu.Item<"a">
- key={item.title}
- {...commonProps}
- component="a"
- href={item.link}
- target="_blank"
- rel="noopener noreferrer"
- >
- {item.title}
- </Menu.Item>
- );
- }
-
- return (
- <Menu.Item<"button">
- key={item.title}
- {...commonProps}
- component="button"
- >
- {item.title}
- </Menu.Item>
- );
- })}
- </Menu.Dropdown>
- </Menu>
-
- {modalOpen === "about" ? (
- <Modal small onClose={closeModal}>
- <div
- className={cx(CS.px4, CS.pt4, CS.pb2, CS.textCentered, CS.relative)}
- >
- <div className={cx(CS.textBrand, CS.pb2)}>
- <LogoIcon height={48} />
- </div>
- <h2
- style={{ fontSize: "1.75em" }}
- className={CS.textDark}
- >{t`Thanks for using ${applicationName}!`}</h2>
- <div className={CS.pt2}>
- <h3 className={cx(CS.textDark, CS.mb1)}>
- {t`You're on version`} {tag}
- </h3>
- <p className={cx(CS.textMedium, CS.textBold)}>
- {t`Built on`} {date}
- </p>
- {tag && !/^v\d+\.\d+\.\d+$/.test(tag) && (
- <div>
- {_.map(versionExtra, (value, key) => (
- <p key={key} className={cx(CS.textMedium, CS.textBold)}>
- {capitalize(key)}: {String(value)}
- </p>
- ))}
- </div>
- )}
- </div>
- </div>
- {showTrademark && (
- <div
- style={{ borderWidth: "2px" }}
- className={cx(
- CS.p2,
- CS.h5,
- CS.textCentered,
- CS.textMedium,
- CS.borderTop,
- )}
- >
- <span className={CS.block}>
- {/* eslint-disable-next-line i18next/no-literal-string, metabase/no-literal-metabase-strings -- This only shows on OSS instance */}
- <span className={CS.textBold}>Metabase</span>{" "}
- {/* eslint-disable-next-line i18next/no-literal-string, metabase/no-literal-metabase-strings -- This only shows on OSS instance */}
- {t`is a Trademark of`} Metabase, Inc
- </span>
- <span>{t`and is built with care by a team from all across this pale blue dot.`}</span>
- </div>
- )}
- </Modal>
- ) : null}
- {modalOpen === "diagnostic" && (
- <ErrorDiagnosticModalWrapper isModalOpen={true} onClose={closeModal} />
- )}
- </>
- );
-}
-
-const connector = connect(mapStateToProps, mapDispatchToProps);
-
-export const ProfileLink = connector(ProfileLinkInner);
diff --git a/frontend/src/metabase/nav/components/ProfileLink/ProfileLink.unit.spec.tsx b/frontend/src/metabase/nav/components/ProfileLink/ProfileLink.unit.spec.tsx
deleted file mode 100644
index f7c64bf0c75..00000000000
--- a/frontend/src/metabase/nav/components/ProfileLink/ProfileLink.unit.spec.tsx
+++ /dev/null
@@ -1,222 +0,0 @@
-import userEvent from "@testing-library/user-event";
-import dayjs from "dayjs";
-
-import { setupBugReportingDetailsEndpoint } from "__support__/server-mocks";
-import { mockSettings } from "__support__/settings";
-import { renderWithProviders, screen, waitFor } from "__support__/ui";
-import { ProfileLink } from "metabase/nav/components/ProfileLink";
-import type { HelpLinkSetting } from "metabase-types/api";
-import {
- createMockMetabaseInfo,
- createMockTokenStatus,
- createMockUser,
-} from "metabase-types/api/mocks";
-import {
- createMockAdminAppState,
- createMockAdminState,
-} from "metabase-types/store/mocks";
-
-const REGULAR_ITEMS = [
- "Account settings",
- "Help",
- "About Metabase",
- "Sign out",
-];
-const ADMIN_ITEMS = [...REGULAR_ITEMS, "Admin settings"];
-const HOSTED_ITEMS = [...ADMIN_ITEMS];
-
-const adminNavItem = {
- name: `People`,
- path: "/admin/people",
- key: "people",
-} as const;
-
-function setup({
- isAdmin = false,
- isHosted = false,
- isPaidPlan = true,
- helpLinkSetting = "metabase",
- helpLinkCustomDestinationSetting = "https://custom-destination.com/help",
- instanceCreationDate = dayjs().toISOString(),
-}: {
- isAdmin?: boolean;
- isHosted?: boolean;
- isPaidPlan?: boolean;
- helpLinkSetting?: HelpLinkSetting;
- helpLinkCustomDestinationSetting?: string;
- instanceCreationDate?: string;
-}) {
- const settings = mockSettings({
- "is-hosted?": isHosted,
- "token-status": createMockTokenStatus({ valid: isPaidPlan }),
- "help-link": helpLinkSetting,
- "help-link-custom-destination": helpLinkCustomDestinationSetting,
- "instance-creation": instanceCreationDate,
- });
-
- const admin = createMockAdminState({
- app: createMockAdminAppState({
- paths: isAdmin ? [adminNavItem] : [],
- }),
- });
-
- return renderWithProviders(<ProfileLink />, {
- storeInitialState: {
- admin,
- settings,
- currentUser: createMockUser({ is_superuser: isAdmin }),
- },
- });
-}
-
-function setupHosted(opts = {}) {
- return setup({ ...opts, isHosted: true });
-}
-
-describe("ProfileLink", () => {
- beforeEach(() => {
- setupBugReportingDetailsEndpoint();
- });
-
- describe("self-hosted", () => {
- it("should show the proper set of items for normal users", async () => {
- setup({ isAdmin: false });
-
- await openMenu();
-
- REGULAR_ITEMS.forEach((title) => {
- expect(screen.getByText(title)).toBeInTheDocument();
- });
- expect(screen.queryByText("Admin settings")).not.toBeInTheDocument();
- });
-
- it("should show the proper set of items for admin users", async () => {
- setup({ isAdmin: true });
-
- await openMenu();
-
- ADMIN_ITEMS.forEach((title) => {
- expect(screen.getByText(title)).toBeInTheDocument();
- });
- });
- });
-
- describe("hosted", () => {
- it("should show the proper set of items for normal users", async () => {
- setupHosted({ isAdmin: false });
-
- await openMenu();
-
- REGULAR_ITEMS.forEach((title) => {
- expect(screen.getByText(title)).toBeInTheDocument();
- });
- expect(screen.queryByText("Admin settings")).not.toBeInTheDocument();
- });
-
- it("should show the proper set of items for admin users", async () => {
- setupHosted({ isAdmin: true });
-
- await openMenu();
-
- HOSTED_ITEMS.forEach((title) => {
- expect(screen.getByText(title)).toBeInTheDocument();
- });
- });
- });
-
- describe("'How to use Metabase' link", () => {
- it("should render if the instance was created more than 30 days ago", async () => {
- setup({
- instanceCreationDate: dayjs().subtract(42, "days").toISOString(),
- });
-
- await openMenu();
- expect(screen.getByText("How to use Metabase")).toBeInTheDocument();
- });
-
- it("should not render for new instances (younger than 30 days)", async () => {
- setup({
- instanceCreationDate: dayjs().subtract(14, "days").toISOString(),
- });
-
- await openMenu();
- expect(screen.queryByText("How to use Metabase")).not.toBeInTheDocument();
- });
- });
-
- describe("help link", () => {
- describe("when the setting is set to hidden", () => {
- it("should return not be visible", async () => {
- setup({
- helpLinkSetting: "hidden",
- });
- await openMenu();
-
- const link = screen.queryByRole("menuitem", { name: /help/i });
-
- expect(link).not.toBeInTheDocument();
- });
- });
-
- describe("when the setting is `custom`", () => {
- it("should return the custom destination", async () => {
- setup({
- helpLinkSetting: "custom",
- helpLinkCustomDestinationSetting: "https://custom.example.org/help",
- });
- await openMenu();
-
- const link = screen.getByRole("menuitem", { name: /help/i });
-
- expect(link).toBeInTheDocument();
- expect(link).toHaveProperty("href", "https://custom.example.org/help");
- });
- });
-
- describe("when the setting is `metabase`", () => {
- describe("when admin on paid plan", () => {
- it("should return the default /help-premium link", async () => {
- setup({
- isAdmin: true,
- isPaidPlan: true,
- helpLinkSetting: "metabase",
- });
- await openMenu();
- const link = screen.getByRole("menuitem", { name: /help/i });
-
- expect(link).toBeInTheDocument();
- const mockBugReportDetails = encodeURIComponent(
- JSON.stringify(createMockMetabaseInfo()),
- );
- const expected = `https://www.metabase.com/help-premium?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v1&diag=${mockBugReportDetails}`;
- await waitFor(() => expect(link).toHaveProperty("href", expected));
-
- expect(link).toHaveProperty("href", expected);
- });
- });
-
- describe("when non admin", () => {
- it("should return the default /help link", async () => {
- setup({
- isAdmin: false,
- isPaidPlan: true,
- helpLinkSetting: "metabase",
- });
- await openMenu();
- const link = screen.getByRole("menuitem", { name: /help/i });
-
- expect(link).toBeInTheDocument();
- expect(link).toHaveProperty(
- "href",
- "https://www.metabase.com/help?utm_source=in-product&utm_medium=menu&utm_campaign=help&instance_version=v1",
- );
- });
- });
- });
- });
-});
-
-const openMenu = async () => {
- await userEvent.click(screen.getByRole("img", { name: /gear/i }));
- await screen.findByRole("menu");
-};
diff --git a/frontend/src/metabase/nav/components/ProfileLink/index.ts b/frontend/src/metabase/nav/components/ProfileLink/index.ts
deleted file mode 100644
index 77459b2f2a7..00000000000
--- a/frontend/src/metabase/nav/components/ProfileLink/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export { ProfileLink } from "./ProfileLink";
diff --git a/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx b/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx
index 82c8b918154..0a9cd1cae21 100644
--- a/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx
+++ b/frontend/src/metabase/nav/containers/AppBar/AppBar.tsx
@@ -12,12 +12,12 @@ import { closeNavbar, toggleNavbar } from "metabase/redux/app";
import type { RouterProps } from "metabase/selectors/app";
import {
getDetailViewState,
+ getIsAppSwitcherVisible,
getIsCollectionPathVisible,
getIsLogoVisible,
getIsNavBarEnabled,
getIsNavbarOpen,
getIsNewButtonVisible,
- getIsProfileLinkVisible,
getIsQuestionLineageVisible,
getIsSearchVisible,
} from "metabase/selectors/app";
@@ -39,7 +39,7 @@ const mapStateToProps = (state: State, props: RouterProps) => ({
isSearchVisible: getIsSearchVisible(state),
isEmbeddingIframe: getIsEmbeddingIframe(state),
isNewButtonVisible: getIsNewButtonVisible(state),
- isProfileLinkVisible: getIsProfileLinkVisible(state),
+ isAppSwitcherVisible: getIsAppSwitcherVisible(state),
isCollectionPathVisible: getIsCollectionPathVisible(state, props),
isQuestionLineageVisible: getIsQuestionLineageVisible(state, props),
detailView: getDetailViewState(state),
diff --git a/frontend/src/metabase/public/containers/PublicApp/PublicApp.tsx b/frontend/src/metabase/public/containers/PublicApp/PublicApp.tsx
index dbaea1856bd..3bdf303e1be 100644
--- a/frontend/src/metabase/public/containers/PublicApp/PublicApp.tsx
+++ b/frontend/src/metabase/public/containers/PublicApp/PublicApp.tsx
@@ -28,6 +28,7 @@ function mapStateToProps(state: State) {
function PublicApp({ errorPage, children }: Props) {
const applicationName = useSelector(getApplicationName);
+
usePageTitle(applicationName, { titleIndex: 0 });
useLayoutEffect(() => {
diff --git a/frontend/src/metabase/public/containers/PublicApp/PublicApp.unit.spec.tsx b/frontend/src/metabase/public/containers/PublicApp/PublicApp.unit.spec.tsx
index a7a9968a3b3..db7a853d3d3 100644
--- a/frontend/src/metabase/public/containers/PublicApp/PublicApp.unit.spec.tsx
+++ b/frontend/src/metabase/public/containers/PublicApp/PublicApp.unit.spec.tsx
@@ -80,9 +80,9 @@ describe("PublicApp", () => {
expect(screen.getByText("Powered by")).toBeInTheDocument();
});
- it("renders not found page on error", () => {
+ it("renders not found page on error", async () => {
setup({ error: { status: 404 } });
- expect(screen.getByText("Not found")).toBeInTheDocument();
+ expect(await screen.findByText("Not found")).toBeInTheDocument();
expect(screen.queryByTestId("test-content")).not.toBeInTheDocument();
});
diff --git a/frontend/src/metabase/selectors/app.ts b/frontend/src/metabase/selectors/app.ts
index 9406c7261c5..266ef0c5cee 100644
--- a/frontend/src/metabase/selectors/app.ts
+++ b/frontend/src/metabase/selectors/app.ts
@@ -204,7 +204,7 @@ export const getIsNewButtonVisible = createSelector(
},
);
-export const getIsProfileLinkVisible = createSelector(
+export const getIsAppSwitcherVisible = createSelector(
[getIsEmbeddingIframe],
(isEmbeddingIframe) => !isEmbeddingIframe,
);
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
index f32771b12f6..8668b6cc390 100644
--- a/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/index.ts
@@ -308,6 +308,8 @@ import metabot_sad_component from "./metabot_sad.svg?component";
import metabot_sad_source from "./metabot_sad.svg?source";
import metric_component from "./metric.svg?component";
import metric_source from "./metric.svg?source";
+import mode_component from "./mode.svg?component";
+import mode_source from "./mode.svg?source";
import model_component from "./model.svg?component";
import model_source from "./model.svg?source";
import model_with_badge_component from "./model_with_badge.svg?component";
@@ -1145,6 +1147,10 @@ export const Icons: Record<IconName, { component: React.VFC; source: string }> =
component: metric_component,
source: metric_source,
},
+ mode: {
+ component: mode_component,
+ source: mode_source,
+ },
model: {
component: model_component,
source: model_source,
@@ -1812,6 +1818,7 @@ export type IconName =
| "metabot"
| "metabot_sad"
| "metric"
+ | "mode"
| "model"
| "model_with_badge"
| "moon"
diff --git a/frontend/src/metabase/ui/components/icons/Icon/icons/mode.svg b/frontend/src/metabase/ui/components/icons/Icon/icons/mode.svg
new file mode 100644
index 00000000000..d64b25fac2b
--- /dev/null
+++ b/frontend/src/metabase/ui/components/icons/Icon/icons/mode.svg
@@ -0,0 +1,7 @@
+
+<svg viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M6 2H2.66667C2.29848 2 2 2.29848 2 2.66667V6C2 6.36819 2.29848 6.66667 2.66667 6.66667H6C6.36819 6.66667 6.66667 6.36819 6.66667 6V2.66667C6.66667 2.29848 6.36819 2 6 2Z" stroke="currentcolor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M13.333 2H9.99967C9.63148 2 9.33301 2.29848 9.33301 2.66667V6C9.33301 6.36819 9.63148 6.66667 9.99967 6.66667H13.333C13.7012 6.66667 13.9997 6.36819 13.9997 6V2.66667C13.9997 2.29848 13.7012 2 13.333 2Z" stroke="currentcolor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M13.333 9.33337H9.99967C9.63148 9.33337 9.33301 9.63185 9.33301 10V13.3334C9.33301 13.7016 9.63148 14 9.99967 14H13.333C13.7012 14 13.9997 13.7016 13.9997 13.3334V10C13.9997 9.63185 13.7012 9.33337 13.333 9.33337Z" stroke="currentcolor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/>
+<path d="M6 9.33337H2.66667C2.29848 9.33337 2 9.63185 2 10V13.3334C2 13.7016 2.29848 14 2.66667 14H6C6.36819 14 6.66667 13.7016 6.66667 13.3334V10C6.66667 9.63185 6.36819 9.33337 6 9.33337Z" stroke="currentcolor" stroke-width="1.33333" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>