Skip to content

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

feat(sdk,embed-js): Improve EntityPicker mobile UX (#71815)

Timofey Kachalov6078e48144b1
diff --git a/e2e/test/scenarios/organization/entity-picker.cy.spec.ts b/e2e/test/scenarios/organization/entity-picker.cy.spec.ts
index f3eb408b2d6..b532394e68b 100644
--- a/e2e/test/scenarios/organization/entity-picker.cy.spec.ts
+++ b/e2e/test/scenarios/organization/entity-picker.cy.spec.ts
@@ -943,6 +943,43 @@ describe("scenarios > organization > entity picker", () => {
.and("eq", "1198px");
});
+ it("should scroll to the left edge of the newly opened column", () => {
+ cy.viewport(375, 800);
+ cy.visit("/");
+
+ H.openNavigationSidebar();
+ H.startNewCollectionFromSidebar();
+ cy.findByTestId("new-collection-modal")
+ .findByLabelText(/Collection it's saved in/)
+ .click();
+
+ H.entityPickerModal().within(() => {
+ // After opening, the first column (level 0) should be visible
+ cy.findByTestId("item-picker-level-0").should("be.visible");
+
+ // Navigate into a collection
+ H.entityPickerModalItem(1, "First collection").click();
+
+ // The new column should be visible
+ cy.findByTestId("item-picker-level-2").should("be.visible");
+
+ // The scroll container should be scrolled so that the new column's
+ // left edge aligns with the container's left edge
+ cy.findByTestId("nested-item-picker").should(($container) => {
+ const container = $container[0];
+ const lastColumn = container.querySelector(
+ "[data-testid='item-picker-level-2']",
+ );
+
+ expect(lastColumn).to.not.be.null;
+
+ expect(container.scrollLeft).to.equal(
+ (lastColumn as HTMLElement).offsetLeft,
+ );
+ });
+ });
+ });
+
it("should restore previous path when clearing search from search results", () => {
cy.visit("/");
H.startNewQuestion();
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/AutoScrollBox.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/AutoScrollBox.tsx
index 9484e730e78..6ff07d319e7 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/AutoScrollBox.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/AutoScrollBox.tsx
@@ -6,15 +6,15 @@ import { Box } from "metabase/ui";
import S from "./EntityPicker.module.css";
-const scrollRight = (
+const scrollToLastColumn = (
container: HTMLDivElement | null,
behavior: "smooth" | "auto",
) => {
- if (!container) {
- return;
+ const lastColumn = container?.firstElementChild?.lastElementChild;
+
+ if (container && lastColumn instanceof HTMLElement) {
+ container.scrollTo({ left: lastColumn.offsetLeft, behavior });
}
- const diff = container.scrollWidth - container.clientWidth;
- container.scrollBy({ left: diff, behavior });
};
export const AutoScrollBox = ({
@@ -36,7 +36,7 @@ export const AutoScrollBox = ({
}
if (contentHash !== previousContentHash) {
- scrollRight(
+ scrollToLastColumn(
containerRef.current,
!previousContainerRef ? "auto" : "smooth",
);
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ButtonBar.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ButtonBar.tsx
index b007e72ffc0..a2770442d1c 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ButtonBar.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/ButtonBar.tsx
@@ -65,8 +65,10 @@ export const ButtonBar = ({
justify="space-between"
align="center"
p="md"
+ miw={0}
style={{
borderTop: "1px solid var(--mb-color-border)",
+ overflowX: "auto",
}}
>
<Flex gap="md">
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx
index 5d84268718c..b55aff35e93 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/EntityPickerModal.tsx
@@ -217,7 +217,7 @@ const SearchInput = ({
data-autofocus
type="search"
leftSection={<Icon name="search" size={16} />}
- miw={400}
+ miw="min(400px, 100%)"
placeholder={t`Search…`}
value={localValue}
onChange={(e) => {
diff --git a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx
index 120880618f1..0153ccb5f75 100644
--- a/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx
+++ b/frontend/src/metabase/common/components/Pickers/EntityPicker/components/NewCollectionDialog/NewCollectionDialog.tsx
@@ -108,7 +108,7 @@ export const NewCollectionDialog = () => {
return (
<>
- <Button onClick={open} disabled={!canCreateHere}>
+ <Button onClick={open} disabled={!canCreateHere} mr="md">
{lastCollection?.namespace === "transforms" ||
lastCollection?.namespace === "snippets"
? t`New folder`