Skip to content

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

Fix #54317: Object detail navigation state doesn't reset (#55238)

Duarte Laia0e247c2772c1
diff --git a/e2e/test/scenarios/visualizations-tabular/object_detail.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/object_detail.cy.spec.js
index 20c704aaa25..2779bbdbd28 100644
--- a/e2e/test/scenarios/visualizations-tabular/object_detail.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-tabular/object_detail.cy.spec.js
@@ -399,6 +399,48 @@ describe("scenarios > question > object details", { tags: "@slow" }, () => {
cy.get("@getActions").should("have.callCount", 0);
});
+ it("reset object detail navigation state on query change (metabase#54317)", () => {
+ const initialFilter = {
+ name: "Filter Orders ID < 15",
+ query: {
+ "source-table": ORDERS_ID,
+ filter: ["and", ["<", ["field", ORDERS.ID, null], 15]],
+ },
+ };
+
+ // Create the question with the initial filter and visit it
+ H.createQuestion(initialFilter, { visitQuestion: true });
+
+ // Click object display
+ cy.findByTestId("view-footer").within(() => {
+ cy.findByText("Visualization").click();
+ });
+
+ cy.findByTestId("display-options-sensible");
+ cy.icon("document").click();
+
+ // Verify "Item 14 of 14" in the pagination footer
+ cy.findByTestId("pagination-footer").within(() => {
+ for (let i = 1; i < 14; i++) {
+ cy.icon("chevronright").click(); // Click the right arrow
+ }
+ cy.findByText("Item 14 of 14").should("be.visible");
+ });
+
+ // Apply a new filter for order id < 10
+ cy.findByTestId("filters-visibility-control").click();
+ cy.findByTestId("filter-pill").click();
+ cy.findByTestId("number-filter-picker").within(() => {
+ cy.findByLabelText("Filter value").clear().type("10");
+ cy.findByRole("button", { name: "Update filter" }).click();
+ });
+
+ // Verify the pagination footer says "Item 1 of 9"
+ cy.findByTestId("pagination-footer").within(() => {
+ cy.findByText("Item 1 of 9").should("be.visible");
+ });
+ });
+
it("should respect 'view_as' column settings (VIZ-199)", () => {
cy.request("PUT", `/api/field/${REVIEWS.ID}`, {
settings: {
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailWrapper.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailWrapper.tsx
index eb43e43efc8..3c2967d135c 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailWrapper.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailWrapper.tsx
@@ -1,4 +1,4 @@
-import { useState } from "react";
+import { useEffect, useState } from "react";
import { skipToken, useListTableForeignKeysQuery } from "metabase/api";
import { DetailViewSidesheet } from "metabase/detail-view/components";
@@ -25,6 +25,12 @@ export function ObjectDetailWrapper({
}: ObjectDetailProps) {
const [currentObjectIndex, setCurrentObjectIndex] = useState(0);
+ useEffect(() => {
+ if (data.rows.length <= currentObjectIndex) {
+ setCurrentObjectIndex(0);
+ }
+ }, [data.rows, currentObjectIndex]);
+
// only show modal if this object detail was triggered via an object detail zoom action
const shouldShowModal = isObjectDetail;
const getFallbackQuestion = () =>