Skip to content

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

Fix drilling Metabot quesitons hides drilled questions (#72233)

Mahatthana (Kelvin) Nomsawadia57cff4dd487
diff --git a/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx
index e5542f05f26..4bc2292f5ab 100644
--- a/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx
+++ b/e2e/test-component/scenarios/embedding-sdk/metabot-question.cy.spec.tsx
@@ -71,6 +71,30 @@ describe("scenarios > embedding-sdk > metabot-question", () => {
mockAuthProviderAndJwtSignIn();
};
+ it("should show drill-through results after drilling from a metabot question", () => {
+ setup(metabotResponseWithNavigateTo);
+
+ mountSdkContent(<MetabotQuestion />);
+
+ getSdkRoot().within(() => {
+ cy.findByTestId("metabot-chat-input").type("Show orders {enter}");
+ cy.findByTestId("visualization-root").should("exist");
+
+ H.tableInteractiveBody().findAllByRole("gridcell", { name: "2" }).click();
+ });
+
+ H.popover().findByText("View this Product's Orders").click();
+
+ getSdkRoot().within(() => {
+ cy.findByTestId("visualization-root").should("be.visible");
+
+ H.assertTableData({
+ columns: ["Product ID", "Max of Quantity"],
+ firstRows: [["2", "18"]],
+ });
+ });
+ });
+
it("should automatically show the ad-hoc question for the last agent message containing ad-hoc question link", () => {
setup(metabotResponseWithNavigateTo);
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkInternalNavigation/context.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkInternalNavigation/context.tsx
index fa8b2850eeb..685118377a9 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkInternalNavigation/context.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkInternalNavigation/context.tsx
@@ -23,7 +23,7 @@ export type SdkInternalNavigationEntry =
})
| (BaseEntry & {
type: "question";
- id: SdkQuestionId;
+ id: SdkQuestionId | null;
name: string;
virtual?: true;
parameters?: ParameterValues;
diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx
index ef247ab47c6..7bfc6b0e351 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkQuestion/context/SdkQuestionProvider.tsx
@@ -264,15 +264,10 @@ export const SdkQuestionProvider = ({
// Push the question name to the stack if the stack is empty (ie: this is the root question)
// We need to wait for the question to load to have the name
useEffect(() => {
- if (
- question &&
- !!questionId &&
- navigation &&
- navigation.stack.length === 0
- ) {
+ if (question && navigation && navigation.stack.length === 0) {
navigation.push({
type: "question",
- id: questionId,
+ id: questionId ?? null,
name: question.displayName() || t`Question`,
});
}
diff --git a/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx
index 5a036ac0c17..0c0c064cc74 100644
--- a/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/public/SdkQuestion/SdkQuestion.unit.spec.tsx
@@ -21,6 +21,10 @@ import {
waitForLoaderToBeRemoved,
within,
} from "__support__/ui";
+import {
+ SdkInternalNavigationContext,
+ type SdkInternalNavigationContextValue,
+} from "embedding-sdk-bundle/components/private/SdkInternalNavigation/context";
import {
SdkQuestionDefaultView,
type SdkQuestionDefaultViewProps,
@@ -97,6 +101,21 @@ const TEST_CARD = createMockCard({
parameters: [TEST_PARAM],
});
+function makeMockNavigation(
+ overrides: Partial<SdkInternalNavigationContextValue> = {},
+): SdkInternalNavigationContextValue {
+ return {
+ stack: [],
+ push: jest.fn(),
+ pop: jest.fn(),
+ canGoBack: false,
+ currentEntry: undefined,
+ previousEntry: undefined,
+ initWithDashboard: jest.fn(),
+ ...overrides,
+ };
+}
+
const setup = async ({
isValidCard = true,
title,
@@ -105,12 +124,16 @@ const setup = async ({
initialSqlParameters,
cardId = TEST_CARD_ID,
preventWaitForLoader = false,
+ mockNavigation,
}: Partial<
Pick<BaseSdkQuestionProps, "initialSqlParameters"> &
Pick<SdkQuestionDefaultViewProps, "withChartTypeSelector" | "title"> & {
isValidCard?: boolean;
withCustomLayout?: boolean;
- } & { cardId: BaseEntityId | CardId; preventWaitForLoader?: boolean }
+ cardId: BaseEntityId | CardId | null;
+ preventWaitForLoader?: boolean;
+ mockNavigation?: SdkInternalNavigationContextValue;
+ }
> = {}) => {
const { state } = setupSdkState({
currentUser: TEST_USER,
@@ -151,14 +174,16 @@ const setup = async ({
});
renderWithSDKProviders(
- <SdkQuestion
- questionId={cardId}
- title={title}
- withChartTypeSelector={withChartTypeSelector}
- initialSqlParameters={initialSqlParameters}
- >
- {withCustomLayout ? <InteractiveQuestionCustomLayout /> : undefined}
- </SdkQuestion>,
+ <SdkInternalNavigationContext.Provider value={mockNavigation ?? null}>
+ <SdkQuestion
+ questionId={cardId}
+ title={title}
+ withChartTypeSelector={withChartTypeSelector}
+ initialSqlParameters={initialSqlParameters}
+ >
+ {withCustomLayout ? <InteractiveQuestionCustomLayout /> : undefined}
+ </SdkQuestion>
+ </SdkInternalNavigationContext.Provider>,
{
componentProviderProps: {
authConfig: createMockSdkConfig(),
@@ -357,4 +382,29 @@ describe("InteractiveQuestion", () => {
).not.toBeInTheDocument();
expect(screen.getByTestId("query-visualization-root")).toBeInTheDocument();
});
+
+ describe("navigation stack initialization", () => {
+ it("should push a question entry with id=null for an ad-hoc question (questionId is null)", async () => {
+ const mockNavigation = makeMockNavigation();
+ await setup({ cardId: null, mockNavigation });
+
+ expect(mockNavigation.push).toHaveBeenCalledWith({
+ type: "question",
+ id: null,
+ name: expect.any(String),
+ });
+ });
+
+ it("should not push to the navigation stack when the stack is already populated", async () => {
+ const existingEntry = {
+ type: "dashboard" as const,
+ id: 1,
+ name: "Sales Dashboard",
+ };
+ const mockNavigation = makeMockNavigation({ stack: [existingEntry] });
+ await setup({ mockNavigation });
+
+ expect(mockNavigation.push).not.toHaveBeenCalled();
+ });
+ });
});