Skip to content
Snippets Groups Projects
Unverified Commit 344dba38 authored by Mahatthana (Kelvin) Nomsawadi's avatar Mahatthana (Kelvin) Nomsawadi Committed by GitHub
Browse files

Do not open sidesheets on SDK (#48630)

* Don't open sidesheet on SDK dashboards

* Add E2E test

* Fix `className` not passed

* Fix unit tests

* Fix E2E tests
parent 73d13e80
No related branches found
No related tags found
No related merge requests found
...@@ -48,7 +48,7 @@ export function expectSearchResultContent({ ...@@ -48,7 +48,7 @@ export function expectSearchResultContent({
}); });
} }
if (expectedSearchResult.timestamp) { if (expectedSearchResult.timestamp) {
cy.findByTestId("revision-history-button").findByText( cy.findByTestId("revision-history-text").findByText(
expectedSearchResult.timestamp, expectedSearchResult.timestamp,
); );
} }
......
import {
restore,
setTokenFeatures,
visitFullAppEmbeddingUrl,
} from "e2e/support/helpers";
import {
EMBEDDING_SDK_STORY_HOST,
describeSDK,
} from "e2e/support/helpers/e2e-embedding-sdk-helpers";
import {
JWT_SHARED_SECRET,
setupJwt,
} from "e2e/support/helpers/e2e-jwt-helpers";
describeSDK("scenarios > embedding-sdk > editable-dashboard", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
setTokenFeatures("all");
setupJwt();
cy.request("PUT", "/api/setting", {
"enable-embedding-sdk": true,
});
cy.createDashboard(
{
name: "Embedding SDK Test Dashboard",
},
{ wrapId: true },
);
cy.signOut();
cy.intercept("GET", "/api/dashboard/*").as("getDashboard");
cy.intercept("GET", "/api/user/current").as("getUser");
cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(
"dashcardQuery",
);
});
it("Should not open sidesheet when clicking last edit info (metabase#48354)", () => {
cy.get("@dashboardId").then(dashboardId => {
visitFullAppEmbeddingUrl({
url: EMBEDDING_SDK_STORY_HOST,
qs: {
id: "embeddingsdk-editabledashboard--default",
viewMode: "story",
},
onBeforeLoad: window => {
window.JWT_SHARED_SECRET = JWT_SHARED_SECRET;
window.METABASE_INSTANCE_URL = Cypress.config().baseUrl;
window.DASHBOARD_ID = dashboardId;
},
});
});
cy.get("#metabase-sdk-root")
.findByText("Edited a few seconds ago by Bobby Tables")
.click()
.should("be.visible");
cy.findByRole("heading", { name: "Info" }).should("not.exist");
cy.findByRole("tab", { name: "Overview" }).should("not.exist");
cy.findByRole("tab", { name: "History" }).should("not.exist");
});
});
...@@ -9,7 +9,7 @@ import type { NamedUser } from "metabase/lib/user"; ...@@ -9,7 +9,7 @@ import type { NamedUser } from "metabase/lib/user";
import { getFullName } from "metabase/lib/user"; import { getFullName } from "metabase/lib/user";
import { getUser } from "metabase/selectors/user"; import { getUser } from "metabase/selectors/user";
import type { TooltipProps } from "metabase/ui"; import type { TooltipProps } from "metabase/ui";
import { Tooltip } from "metabase/ui"; import { Text, Tooltip } from "metabase/ui";
import type { User } from "metabase-types/api"; import type { User } from "metabase-types/api";
export type ItemWithLastEditInfo = { export type ItemWithLastEditInfo = {
...@@ -93,14 +93,26 @@ function LastEditInfoLabel({ ...@@ -93,14 +93,26 @@ function LastEditInfoLabel({
return ( return (
<Tooltip disabled={!timeLabel} {...tooltipProps}> <Tooltip disabled={!timeLabel} {...tooltipProps}>
<TextButton {onClick ? (
size="small" <TextButton
className={className} className={className}
onClick={onClick} size="small"
data-testid="revision-history-button" onClick={onClick}
> data-testid="revision-history-button"
{children} >
</TextButton> {children}
</TextButton>
) : (
<Text
className={className}
size="sm"
fw="bold"
c="var(--mb-color-text-secondary)"
data-testid="revision-history-text"
>
{children}
</Text>
)}
</Tooltip> </Tooltip>
); );
} }
......
...@@ -20,7 +20,10 @@ describe("LastEditInfoLabel", () => { ...@@ -20,7 +20,10 @@ describe("LastEditInfoLabel", () => {
email: "john@metabase.test", email: "john@metabase.test",
}); });
function setup({ isLastEditedByCurrentUser = false } = {}) { function setup({
isLastEditedByCurrentUser = false,
onClick = jest.fn(),
} = {}) {
const testItem = { const testItem = {
"last-edit-info": { "last-edit-info": {
...TEST_USER, ...TEST_USER,
...@@ -32,11 +35,14 @@ describe("LastEditInfoLabel", () => { ...@@ -32,11 +35,14 @@ describe("LastEditInfoLabel", () => {
? TEST_USER ? TEST_USER
: { ...TEST_USER, id: TEST_USER.id + 1 }; : { ...TEST_USER, id: TEST_USER.id + 1 };
return renderWithProviders(<LastEditInfoLabel item={testItem} />, { return renderWithProviders(
storeInitialState: { <LastEditInfoLabel item={testItem} onClick={onClick} />,
currentUser, {
storeInitialState: {
currentUser,
},
}, },
}); );
} }
const A_FEW_SECONDS_AGO = moment().add(5, "seconds"); const A_FEW_SECONDS_AGO = moment().add(5, "seconds");
...@@ -93,4 +99,23 @@ describe("LastEditInfoLabel", () => { ...@@ -93,4 +99,23 @@ describe("LastEditInfoLabel", () => {
new RegExp(`Edited .* by you`), new RegExp(`Edited .* by you`),
); );
}); });
it("should not be clickable when `onClick` is not passed (currently only in SDK context) (metabase#48354)", () => {
setup({ onClick: null });
expect(screen.getByText(/Edited .* by .*/)).toBeInTheDocument();
expect(
screen.queryByRole("button", {
name: /Edited .* by .*/,
}),
).not.toBeInTheDocument();
});
it("should be clickable when `onClick` is passed (metabase#48354)", () => {
setup();
expect(
screen.getByRole("button", {
name: /Edited .* by .*/,
}),
).toBeInTheDocument();
});
}); });
...@@ -22,6 +22,7 @@ import type { ...@@ -22,6 +22,7 @@ import type {
DashboardNightModeControls, DashboardNightModeControls,
DashboardRefreshPeriodControls, DashboardRefreshPeriodControls,
} from "metabase/dashboard/types"; } from "metabase/dashboard/types";
import { isEmbeddingSdk } from "metabase/env";
import { useDispatch, useSelector } from "metabase/lib/redux"; import { useDispatch, useSelector } from "metabase/lib/redux";
import { fetchPulseFormInput } from "metabase/pulse/actions"; import { fetchPulseFormInput } from "metabase/pulse/actions";
import { getSetting } from "metabase/selectors/settings"; import { getSetting } from "metabase/selectors/settings";
...@@ -153,8 +154,12 @@ export const DashboardHeaderInner = ({ ...@@ -153,8 +154,12 @@ export const DashboardHeaderInner = ({
: "", : "",
)} )}
editingButtons={editingButtons} editingButtons={editingButtons}
onLastEditInfoClick={() => onLastEditInfoClick={
dispatch(setSidebar({ name: SIDEBAR_NAME.info })) isEmbeddingSdk
? undefined
: () => {
dispatch(setSidebar({ name: SIDEBAR_NAME.info }));
}
} }
refreshPeriod={refreshPeriod} refreshPeriod={refreshPeriod}
onRefreshPeriodChange={onRefreshPeriodChange} onRefreshPeriodChange={onRefreshPeriodChange}
......
...@@ -55,7 +55,7 @@ type DashboardHeaderViewProps = { ...@@ -55,7 +55,7 @@ type DashboardHeaderViewProps = {
collection: Collection; collection: Collection;
isBadgeVisible: boolean; isBadgeVisible: boolean;
isLastEditInfoVisible: boolean; isLastEditInfoVisible: boolean;
onLastEditInfoClick: () => void; onLastEditInfoClick?: () => void;
} & DashboardFullscreenControls & } & DashboardFullscreenControls &
DashboardRefreshPeriodControls & DashboardRefreshPeriodControls &
DashboardNightModeControls; DashboardNightModeControls;
......
...@@ -131,7 +131,7 @@ describe("InfoText", () => { ...@@ -131,7 +131,7 @@ describe("InfoText", () => {
`/collection/${MOCK_COLLECTION.id}-collection-name`, `/collection/${MOCK_COLLECTION.id}-collection-name`,
); );
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -143,7 +143,7 @@ describe("InfoText", () => { ...@@ -143,7 +143,7 @@ describe("InfoText", () => {
const collectionElement = screen.getByText("Collection"); const collectionElement = screen.getByText("Collection");
expect(collectionElement).toBeInTheDocument(); expect(collectionElement).toBeInTheDocument();
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -153,7 +153,7 @@ describe("InfoText", () => { ...@@ -153,7 +153,7 @@ describe("InfoText", () => {
model: "database", model: "database",
}); });
expect(screen.getByText("Database")).toBeInTheDocument(); expect(screen.getByText("Database")).toBeInTheDocument();
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -169,7 +169,7 @@ describe("InfoText", () => { ...@@ -169,7 +169,7 @@ describe("InfoText", () => {
`/question#?db=${MOCK_DATABASE.id}&table=${MOCK_TABLE.id}`, `/question#?db=${MOCK_DATABASE.id}&table=${MOCK_TABLE.id}`,
); );
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -186,7 +186,7 @@ describe("InfoText", () => { ...@@ -186,7 +186,7 @@ describe("InfoText", () => {
`/browse/databases/${MOCK_DATABASE.id}-database-name`, `/browse/databases/${MOCK_DATABASE.id}-database-name`,
); );
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -203,7 +203,7 @@ describe("InfoText", () => { ...@@ -203,7 +203,7 @@ describe("InfoText", () => {
`/collection/${MOCK_COLLECTION.id}-collection-name`, `/collection/${MOCK_COLLECTION.id}-collection-name`,
); );
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -213,7 +213,7 @@ describe("InfoText", () => { ...@@ -213,7 +213,7 @@ describe("InfoText", () => {
it("should show last_edited_by when available", async () => { it("should show last_edited_by when available", async () => {
await setup(); await setup();
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION} by ${MOCK_OTHER_USER.common_name}`, `Updated ${LAST_EDITED_DURATION} by ${MOCK_OTHER_USER.common_name}`,
); );
}); });
...@@ -227,7 +227,7 @@ describe("InfoText", () => { ...@@ -227,7 +227,7 @@ describe("InfoText", () => {
}, },
}); });
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Created by you`, `Created by you`,
); );
}); });
...@@ -241,7 +241,7 @@ describe("InfoText", () => { ...@@ -241,7 +241,7 @@ describe("InfoText", () => {
}, },
}); });
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Created ${CREATED_AT_DURATION}`, `Created ${CREATED_AT_DURATION}`,
); );
}); });
...@@ -254,7 +254,7 @@ describe("InfoText", () => { ...@@ -254,7 +254,7 @@ describe("InfoText", () => {
}, },
}); });
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -268,7 +268,7 @@ describe("InfoText", () => { ...@@ -268,7 +268,7 @@ describe("InfoText", () => {
}, },
}); });
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Updated ${LAST_EDITED_DURATION}`, `Updated ${LAST_EDITED_DURATION}`,
); );
}); });
...@@ -282,7 +282,7 @@ describe("InfoText", () => { ...@@ -282,7 +282,7 @@ describe("InfoText", () => {
}, },
}); });
expect(screen.getByTestId("revision-history-button")).toHaveTextContent( expect(screen.getByTestId("revision-history-text")).toHaveTextContent(
`Created ${CREATED_AT_DURATION}`, `Created ${CREATED_AT_DURATION}`,
); );
}); });
...@@ -299,7 +299,7 @@ describe("InfoText", () => { ...@@ -299,7 +299,7 @@ describe("InfoText", () => {
expect(screen.queryByText("")).not.toBeInTheDocument(); expect(screen.queryByText("")).not.toBeInTheDocument();
expect( expect(
screen.queryByTestId("revision-history-button"), screen.queryByTestId("revision-history-text"),
).not.toBeInTheDocument(); ).not.toBeInTheDocument();
}); });
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment