The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
UXW-804 Fix collection name & description character limits (#66380)
Gabriel Moreno36a0145de82a
diff --git a/frontend/src/metabase/collections/components/CollectionHeader/CollectionCaption.tsx b/frontend/src/metabase/collections/components/CollectionHeader/CollectionCaption.tsxindex b7c77033fe7..dbf261e0710 100644--- a/frontend/src/metabase/collections/components/CollectionHeader/CollectionCaption.tsx+++ b/frontend/src/metabase/collections/components/CollectionHeader/CollectionCaption.tsx@@ -57,6 +57,7 @@ export const CollectionCaption = ({isDisabled={!isEditable}data-testid="collection-name-heading"onChange={handleChangeName}+ maxLength={100}/></CaptionTitleContainer>{(isEditable || hasDescription) && (@@ -74,6 +75,7 @@ export const CollectionCaption = ({onChange={handleChangeDescription}data-testid="collection-description-in-caption"left={0}+ maxLength={255}/>)}</CaptionRoot>diff --git a/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsx b/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsxindex 0d07285026e..54c203002a4 100644--- a/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/collections/components/CollectionHeader/tests/common.unit.spec.tsx@@ -64,6 +64,26 @@ describe("CollectionHeader", () => {const input = screen.getByDisplayValue("Personal collection");expect(input).toBeDisabled();});++ it("should truncate name if it exceeds 100 characters", async () => {+ const collection = {+ name: "Name",+ can_write: true,+ };++ const { onUpdateCollection, collection: myCollection } = setup({+ collection,+ });++ const input = screen.getByDisplayValue("Name");+ await userEvent.clear(input);+ const longName = "a".repeat(110);+ await userEvent.type(input, `${longName}{Enter}`);++ expect(onUpdateCollection).toHaveBeenCalledWith(myCollection, {+ name: longName.slice(0, 100),+ });+ });});describe("collection description", () => {@@ -138,6 +158,31 @@ describe("CollectionHeader", () => {expect(input).toBeInTheDocument();expect(input).toBeDisabled();});++ it("should truncate description if it exceeds 255 characters", async () => {+ const collection = {+ description: "Description",+ can_write: true,+ };++ const { onUpdateCollection, collection: myCollection } = setup({+ collection,+ });++ // show input+ const editableText = screen.getByText("Description");+ await userEvent.click(editableText);++ const input = screen.getByDisplayValue("Description");+ await userEvent.clear(input);+ const longDescription = "a".repeat(256);+ await userEvent.type(input, longDescription);+ await userEvent.tab();++ expect(onUpdateCollection).toHaveBeenCalledWith(myCollection, {+ description: longDescription.slice(0, 255),+ });+ });});describe("collection timelines", () => {diff --git a/frontend/src/metabase/collections/components/CollectionInfoSidebar/CollectionInfoSidebar.tsx b/frontend/src/metabase/collections/components/CollectionInfoSidebar/CollectionInfoSidebar.tsxindex 13b7c21ec6e..1a3d388199c 100644--- a/frontend/src/metabase/collections/components/CollectionInfoSidebar/CollectionInfoSidebar.tsx+++ b/frontend/src/metabase/collections/components/CollectionInfoSidebar/CollectionInfoSidebar.tsx@@ -59,6 +59,7 @@ export const CollectionInfoSidebar = ({description={description}onChange={handleChangeDescription}canWrite={canWrite}+ maxLength={255}/></Stack><PLUGIN_COLLECTION_COMPONENTS.CollectionAuthorityLevelDisplaydiff --git a/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/common.unit.spec.tsx b/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/common.unit.spec.tsxindex 9fa69e0a4e0..667c08b2ec3 100644--- a/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/collections/components/CollectionInfoSidebar/tests/common.unit.spec.tsx@@ -1,3 +1,5 @@+import userEvent from "@testing-library/user-event";+import { screen } from "__support__/ui";import type { Collection } from "metabase-types/api";@@ -50,4 +52,25 @@ describe("CollectionInfoSidebar (OSS)", () => {screen.queryByText("entity_id_of_trusted_collection"),).not.toBeInTheDocument();});++ it("should truncate description if it exceeds 255 characters", async () => {+ setup({+ collection: {+ ...regularCollection,+ description: "Test Description",+ },+ });++ const editableText = screen.getByText("Test Description");+ await userEvent.click(editableText);++ const input = screen.getByDisplayValue("Test Description");+ await userEvent.clear(input);++ const longDescription = "a".repeat(256);+ await userEvent.type(input, longDescription);+ await userEvent.tab();++ expect(input).toHaveValue(longDescription.slice(0, 255));+ });});diff --git a/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.tsx b/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.tsxindex 1b1e575fb54..be41c5f8513 100644--- a/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.tsx+++ b/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.tsx@@ -1,4 +1,5 @@import { t } from "ttag";+import * as Yup from "yup";import { useCreateCollectionMutation } from "metabase/api";import { FormFooter } from "metabase/common/components/FormFooter";@@ -10,11 +11,19 @@ import {FormSubmitButton,FormTextInput,} from "metabase/forms";+import * as Errors from "metabase/lib/errors";import { Button, Flex, Modal } from "metabase/ui";import type { CollectionId } from "metabase-types/api";import type { CollectionPickerItem } from "../types";+const NEW_COLLECTION_SCHEMA = Yup.object({+ name: Yup.string()+ .required(Errors.required)+ .max(100, Errors.maxLength)+ .default(""),+});+interface NewCollectionDialogProps {isOpen: boolean;onClose: () => void;@@ -57,6 +66,7 @@ export const NewCollectionDialog = ({><FormProviderinitialValues={{ name: "" }}+ validationSchema={NEW_COLLECTION_SCHEMA}onSubmit={onCreateNewCollection}>{({ dirty }: { dirty: boolean }) => (diff --git a/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.unit.spec.tsx b/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.unit.spec.tsxindex 3712cbaeca3..cf1d747c557 100644--- a/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.unit.spec.tsx+++ b/frontend/src/metabase/common/components/Pickers/CollectionPicker/components/NewCollectionDialog.unit.spec.tsx@@ -76,4 +76,22 @@ describe("new collection dialog", () => {const body = JSON.parse(call.options?.body as string);expect(body.parent_id).toBe(null);});++ it("should show validation error when name exceeds 100 characters", async () => {+ setup({ parentCollectionId: "root" });+ const longName = "a".repeat(101);+ const input = screen.getByPlaceholderText("My new collection");+ await userEvent.type(input, longName);+ await userEvent.tab();++ expect(+ await screen.findByText(/must be 100 characters or less/),+ ).toBeInTheDocument();++ const createButton = screen.getByRole("button", { name: "Create" });+ expect(createButton).toBeDisabled();++ const apiCalls = fetchMock.callHistory.calls("path:/api/collection");+ expect(apiCalls).toHaveLength(0);+ });});