Skip to content

Commit

Permalink
Recents Picker Tab (#42079)
Browse files Browse the repository at this point in the history
* add recents tab

type updates

fix unit test

change where we filter recents

WIP Recents Tab

wip recents

design updates

update recents design to match search

use new recents format

initial recents implementation

fix types

* fix e2e tests

* update more e2e tests

* allow recents filters

* update test mocks

* add unit tests for recents tab

* update e2e tests

* add e2e tests for recents picker tab

* fix lost access test
  • Loading branch information
iethree committed May 14, 2024
1 parent 47b3f17 commit 52d32c1
Show file tree
Hide file tree
Showing 37 changed files with 612 additions and 46 deletions.
6 changes: 5 additions & 1 deletion e2e/support/helpers/e2e-collection-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,18 @@ export const moveOpenedCollectionTo = newParent => {
popover().within(() => cy.findByText("Move").click());

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText(newParent).click();
cy.button("Move").click();
});

entityPickerModal().should("not.exist");
};

export function pickEntity({ path, select }) {
export function pickEntity({ path, select, tab }) {
if (tab) {
cy.findByRole("tab", { name: tab }).click();
}
if (path) {
cy.findByTestId("nested-item-picker").within(() => {
for (const [index, name] of path.entries()) {
Expand Down
17 changes: 12 additions & 5 deletions e2e/test/scenarios/collections/collections.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe("scenarios > collection defaults", () => {
pickEntity({
path: ["Our analytics", `Collection ${COLLECTIONS_COUNT}`],
select: true,
tab: /Collections/,
});

cy.findByTestId("new-collection-modal").button("Create").click();
Expand Down Expand Up @@ -400,6 +401,7 @@ describe("scenarios > collection defaults", () => {
});

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText("Bobby Tables's Personal Collection").click();
cy.findByText(COLLECTION).click();
cy.button("Move").should("not.be.disabled");
Expand All @@ -425,13 +427,15 @@ describe("scenarios > collection defaults", () => {
popover().findByText("Move").click();

// we need to do this manually because we need to await the correct number of api requests to keep this from flaking
cy.wait([
"@getCollectionItems",
"@getCollectionItems",
"@getCollectionItems",
]);

entityPickerModal().within(() => {
cy.findByTestId("loading-spinner").should("not.exist");
cy.findByRole("tab", { name: /Collections/ }).click();
cy.wait([
"@getCollectionItems",
"@getCollectionItems",
"@getCollectionItems",
]);
// make sure the first collection (current parent) is selected
findPickerItem("First collection").should(
"have.attr",
Expand Down Expand Up @@ -577,6 +581,7 @@ describe("scenarios > collection defaults", () => {
popover().findByText("Move").click();

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.log("parent collection should be selected");
findPickerItem("First collection").should(
"have.attr",
Expand All @@ -599,6 +604,7 @@ describe("scenarios > collection defaults", () => {

entityPickerModal().within(() => {
cy.log("parent collection should be selected");
cy.findByRole("tab", { name: /Collections/ }).click();
findPickerItem("Second collection").should(
"have.attr",
"data-active",
Expand All @@ -623,6 +629,7 @@ describe("scenarios > collection defaults", () => {

entityPickerModal().within(() => {
cy.log("should disable all moving collections");
cy.findByRole("tab", { name: /Collections/ }).click();
findPickerItem("First collection").should("have.attr", "disabled");
findPickerItem("Another collection").should(
"have.attr",
Expand Down
12 changes: 10 additions & 2 deletions e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
visitDashboard,
visitEmbeddedPage,
visitIframe,
entityPickerModal,
} from "e2e/support/helpers";
import { b64hash_to_utf8 } from "metabase/lib/encoding";
import {
Expand Down Expand Up @@ -1311,6 +1312,7 @@ describe("scenarios > dashboard > dashboard cards > click behavior", () => {
cy.findAllByTestId("field-set")
.should("have.length", 2)
.should("contain.text", POINT_COUNT);

cy.get("@targetDashboardId").then(targetDashboardId => {
cy.location().should(({ pathname, search }) => {
expect(pathname).to.equal(`/dashboard/${targetDashboardId}`);
Expand Down Expand Up @@ -2148,7 +2150,10 @@ const clickLineChartPoint = () => {
const addDashboardDestination = () => {
cy.get("aside").findByText("Go to a custom destination").click();
cy.get("aside").findByText("Dashboard").click();
modal().findByText(TARGET_DASHBOARD.name).click();
entityPickerModal()
.findByRole("tab", { name: /Dashboards/ })
.click();
entityPickerModal().findByText(TARGET_DASHBOARD.name).click();
};

const addUrlDestination = () => {
Expand All @@ -2159,7 +2164,10 @@ const addUrlDestination = () => {
const addSavedQuestionDestination = () => {
cy.get("aside").findByText("Go to a custom destination").click();
cy.get("aside").findByText("Saved question").click();
modal().findByText(TARGET_QUESTION.name).click();
entityPickerModal()
.findByRole("tab", { name: /Questions/ })
.click();
entityPickerModal().findByText(TARGET_QUESTION.name).click();
};

const addSavedQuestionCreatedAtParameter = () => {
Expand Down
7 changes: 5 additions & 2 deletions e2e/test/scenarios/dashboard-cards/dashboard-drill.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
queryBuilderMain,
chartPathWithFillColor,
echartsContainer,
entityPickerModal,
} from "e2e/support/helpers";

const {
Expand Down Expand Up @@ -243,8 +244,10 @@ describe("scenarios > dashboard > dashboard drill", () => {
.parent()
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
.within(() => cy.findByText("Dashboard").click());
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
modal().within(() => cy.findByText("end dash").click());
entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Dashboards/ }).click();
cy.findByText("end dash").click();
});
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Available filters")
.parent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function selectQuestion(question) {
.findAllByText("Select question")
.first()
.click({ force: true });
entityPickerModal()
.findByRole("tab", { name: /Questions/ })
.click();
entityPickerModal().findByText(question).click();
cy.wait("@cardQuery");
dashboardGrid().findByText(question).should("exist");
Expand Down
8 changes: 8 additions & 0 deletions e2e/test/scenarios/dashboard/dashboard-management.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ describe("managing dashboard from the dashboard's edit menu", () => {
);
cy.findByTestId("collection-picker-button").click();
});

if (user === "admin") {
// admin has recents tab
entityPickerModal()
.findByRole("tab", { name: /Collections/ })
.click();
}

entityPickerModal()
.findByText("Create a new collection")
.click();
Expand Down
6 changes: 6 additions & 0 deletions e2e/test/scenarios/dashboard/dashboard.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe("scenarios > dashboard", () => {
});

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Dashboards/ }).click();
cy.findByText(dashboardName)
.closest("button")
.then($button => {
Expand Down Expand Up @@ -219,6 +220,9 @@ describe("scenarios > dashboard", () => {
cy.button("Yes please!").click();
});

entityPickerModal()
.findByRole("tab", { name: /Dashboards/ })
.click();
entityPickerModal().findByText("Create a new dashboard").click();
cy.findByTestId("create-dashboard-on-the-go").within(() => {
cy.findByPlaceholderText("My new dashboard").type("Foo");
Expand Down Expand Up @@ -323,6 +327,7 @@ describe("scenarios > dashboard", () => {
openDashboardMenu();
popover().findByText("Move").click();
entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText("Bobby Tables's Personal Collection").click();
cy.button("Move").click();
});
Expand All @@ -341,6 +346,7 @@ describe("scenarios > dashboard", () => {
openDashboardMenu();
popover().findByText("Move").click();
entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText("Our analytics").click();
cy.button("Move").click();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function moveModel(modelName, collectionName) {
popover().findByText("Move").click();

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText(collectionName).click();
cy.button("Move").click();
});
Expand Down
1 change: 1 addition & 0 deletions e2e/test/scenarios/native/data_ref.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe("scenarios > native question > data reference sidebar", () => {
popover().findByTestId("move-button").click();

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText("Bobby Tables's Personal Collection").click();
cy.button("Move").click();
});
Expand Down
1 change: 1 addition & 0 deletions e2e/test/scenarios/native/native_subquery.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe("scenarios > question > native subquery", () => {
openQuestionActions();
cy.findByTestId("move-button").click();
entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText("Bobby Tables's Personal Collection").click();
cy.button("Move").click();
});
Expand Down
52 changes: 52 additions & 0 deletions e2e/test/scenarios/onboarding/search/recently-viewed.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
openPeopleTable,
describeEE,
setTokenFeatures,
popover,
entityPickerModal,
} from "e2e/support/helpers";

describe("search > recently viewed", () => {
Expand Down Expand Up @@ -75,6 +77,56 @@ describe("search > recently viewed", () => {
});
});

describe("Recently Viewed > Entity Picker", () => {
beforeEach(() => {
restore();
cy.signInAsAdmin();
cy.visit("/");
});

it("shows recently created collection in entity picker", () => {
cy.createCollection({
name: "My Fresh Collection",
});

cy.findByTestId("app-bar").button(/New/).click();
popover().findByText("Dashboard").click();
cy.findByTestId("collection-picker-button").click();

entityPickerModal().within(() => {
cy.findByText("Select a collection").click();
cy.findByRole("tab", { name: /Recents/ });
cy.findByRole("tab", { name: /Collections/ });

cy.findByText("Today");
cy.findByText("My Fresh Collection");
});
});

it("shows recently visited dashboard in entity picker", () => {
visitDashboard(ORDERS_DASHBOARD_ID);
visitQuestion(ORDERS_QUESTION_ID);

cy.findByTestId("qb-header").icon("ellipsis").click();
popover().findByText("Add to dashboard").click();

entityPickerModal().within(() => {
cy.findByText("Add this question to a dashboard").click();
cy.findByRole("tab", { name: /Recents/ });
cy.findByRole("tab", { name: /Dashboards/ });

cy.findByText("Today");
cy.findByText("Orders in a dashboard").click();
cy.button("Select").click();
});

cy.url().should("contain", `/dashboard/${ORDERS_DASHBOARD_ID}-`);
cy.get("#Dashboard-Header-Container").findByText(
/You're editing this dashboard/,
);
});
});

describeEE("search > recently viewed > enterprise features", () => {
beforeEach(() => {
restore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ describe("scenarios > organization > timelines > collection", () => {
popover().findByText("Move timeline").click();

entityPickerModal().within(() => {
cy.findByRole("tab", { name: /Collections/ }).click();
cy.findByText("Bobby Tables's Personal Collection").click();
cy.button("Move").click();
cy.wait("@updateTimeline");
Expand Down
6 changes: 5 additions & 1 deletion e2e/test/scenarios/question/new.cy.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ describe("scenarios > question > new", () => {
.findByLabelText(/Which collection/)
.click();

pickEntity({ path: [myPersonalCollectionName], select: true });
pickEntity({
path: [myPersonalCollectionName],
select: true,
tab: /Collections/,
});

cy.findByTestId("save-question-modal").button("Save").click();
cy.wait("@createQuestion");
Expand Down

0 comments on commit 52d32c1

Please sign in to comment.