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
Closes EMB-990 add description to columns in CollectionBrowser (#66305)
Sébastienfb303ccd82f0
diff --git a/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsx b/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsxindex 2922d44862a..6b93561401d 100644--- a/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.tsx@@ -36,6 +36,7 @@ type UserFacingEntityName = (typeof USER_FACING_ENTITY_NAMES)[number];export type CollectionBrowserListColumns =| "type"| "name"+ | "description"| "lastEditedBy"| "lastEditedAt"| "archive";diff --git a/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.unit.spec.tsx b/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.unit.spec.tsxindex 377a5f8ac78..f5d373742f2 100644--- a/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.unit.spec.tsx+++ b/frontend/src/embedding-sdk-bundle/components/public/CollectionBrowser/CollectionBrowser.unit.spec.tsx@@ -93,6 +93,64 @@ describe("CollectionBrowser", () => {expect(columnNames).toStrictEqual(["Type", "Name"]);});++ it("should NOT include description column by default", async () => {+ await setup();++ await waitFor(() => {+ expect(screen.getByTestId("items-table-head")).toBeInTheDocument();+ });++ const columnNames: (string | null)[] = [];++ within(screen.getByTestId("items-table-head"))+ .getAllByRole("button")+ .forEach((el) => {+ columnNames.push(el.textContent);+ });++ expect(columnNames).not.toContain("Description");+ });++ it("should show description column when explicitly included", async () => {+ await setup({+ props: {+ visibleColumns: ["type", "name", "description"],+ },+ });++ await waitFor(() => {+ expect(screen.getByTestId("items-table-head")).toBeInTheDocument();+ });++ const columnNames: (string | null)[] = [];++ within(screen.getByTestId("items-table-head"))+ .getAllByRole("button")+ .forEach((el) => {+ columnNames.push(el.textContent);+ });++ expect(columnNames).toStrictEqual(["Type", "Name", "Description"]);+ });++ it("should display description column as configured", async () => {+ await setup({+ props: {+ visibleColumns: ["type", "name", "description"],+ },+ });++ await waitFor(() => {+ expect(screen.getByTestId("items-table-head")).toBeInTheDocument();+ });++ const headerRow = screen.getByTestId("items-table-head");+ const columnHeaders = within(headerRow).getAllByRole("button");+ const columnTexts = columnHeaders.map((header) => header.textContent);++ expect(columnTexts).toContain("Description");+ });});async function setup({diff --git a/frontend/src/metabase-types/api/collection.ts b/frontend/src/metabase-types/api/collection.tsindex 6e5db05eeec..2bb573b8de7 100644--- a/frontend/src/metabase-types/api/collection.ts+++ b/frontend/src/metabase-types/api/collection.ts@@ -175,6 +175,7 @@ export type getCollectionRequest = {export type ListCollectionItemsSortColumn =| "name"+ | "description"| "last_edited_at"| "last_edited_by"| "model";diff --git a/frontend/src/metabase/collections/components/CollectionContent/constants.ts b/frontend/src/metabase/collections/components/CollectionContent/constants.tsindex 1685a12213e..05845ea15d9 100644--- a/frontend/src/metabase/collections/components/CollectionContent/constants.ts+++ b/frontend/src/metabase/collections/components/CollectionContent/constants.ts@@ -5,6 +5,7 @@ export const COLLECTION_PAGE_SIZE = 25;const COLLECTION_CONTENT_COLUMNS = ["type","name",+ "description","lastEditedBy","lastEditedAt","actionMenu",diff --git a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsxindex 55c44879b72..568879ba978 100644--- a/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx+++ b/frontend/src/metabase/common/components/ItemsTable/BaseItemsTable/BaseItemsTable.tsx@@ -172,6 +172,7 @@ export const BaseItemsTable = ({{visibleColumnsMap["name"] && (<Columns.Name.Col isInDragLayer={isInDragLayer} />)}+ {visibleColumnsMap["description"] && <Columns.Description.Col />}{visibleColumnsMap["lastEditedBy"] && <Columns.LastEditedBy.Col />}{visibleColumnsMap["lastEditedAt"] && <Columns.LastEditedAt.Col />}{visibleColumnsMap["actionMenu"] && <Columns.ActionMenu.Col />}@@ -206,6 +207,12 @@ export const BaseItemsTable = ({onSortingOptionsChange={onSortingOptionsChange}/>)}+ {visibleColumnsMap["description"] && (+ <Columns.Description.Header+ sortingOptions={sortingOptions}+ onSortingOptionsChange={onSortingOptionsChange}+ />+ )}{visibleColumnsMap["lastEditedBy"] && (<Columns.LastEditedBy.HeadersortingOptions={sortingOptions}diff --git a/frontend/src/metabase/common/components/ItemsTable/Columns.tsx b/frontend/src/metabase/common/components/ItemsTable/Columns.tsxindex ba50cd480c8..eb0c4d8ccf4 100644--- a/frontend/src/metabase/common/components/ItemsTable/Columns.tsx+++ b/frontend/src/metabase/common/components/ItemsTable/Columns.tsx@@ -189,6 +189,38 @@ export const Columns = {);},},+ Description: {+ Col: () => (+ <TableColumn+ hideAtContainerBreakpoint="sm"+ containerName="ItemsTableContainer"+ />+ ),+ Header: ({ sortingOptions, onSortingOptionsChange }: HeaderProps) => (+ <SortableColumnHeader+ name="description"+ sortingOptions={sortingOptions}+ hideAtContainerBreakpoint="sm"+ onSortingOptionsChange={onSortingOptionsChange}+ >+ {t`Description`}+ </SortableColumnHeader>+ ),+ Cell: ({+ item,+ testIdPrefix = "table",+ }: {+ item: CollectionItem;+ testIdPrefix?: string;+ onClick?: (item: CollectionItem) => void;+ }) => {+ return (+ <ItemCell data-testid={`${testIdPrefix}-description`}>+ <Ellipsified>{item.description ?? ""}</Ellipsified>+ </ItemCell>+ );+ },+ },LastEditedBy: {Col: () => (<TableColumndiff --git a/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx b/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsxindex 5049e606e3f..33e10e44dc9 100644--- a/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx+++ b/frontend/src/metabase/common/components/ItemsTable/DefaultItemRenderer.tsx@@ -74,8 +74,12 @@ export const DefaultItemRenderer = ({item={item}testIdPrefix={testIdPrefix}onClick={onClick}+ includeDescription={!visibleColumnsMap["description"]}/>)}+ {visibleColumnsMap["description"] && (+ <Columns.Description.Cell item={item} testIdPrefix={testIdPrefix} />+ )}{visibleColumnsMap["lastEditedBy"] && (<Columns.LastEditedBy.Cell item={item} testIdPrefix={testIdPrefix} />)}diff --git a/src/metabase/collections_rest/api.clj b/src/metabase/collections_rest/api.cljindex ce472efdaa6..192689bf383 100644--- a/src/metabase/collections_rest/api.clj+++ b/src/metabase/collections_rest/api.clj@@ -281,7 +281,7 @@"Valid values for the `?pinned_state` param accepted by endpoints in this namespace."#{"all" "is_pinned" "is_not_pinned"})-(def ^:private valid-sort-columns #{"name" "last_edited_at" "last_edited_by" "model"})+(def ^:private valid-sort-columns #{"name" "last_edited_at" "last_edited_by" "model" "description"})(def ^:private valid-sort-directions #{"asc" "desc"})(defn- normalize-sort-choice [w] (when w (keyword (str/replace w #"_" "-"))))@@ -979,7 +979,9 @@[:last_edit_first_name :desc][:%lower.name :asc]][:model :asc] [[:model_ranking :asc] [:%lower.name :asc]]- [:model :desc] [[:model_ranking :desc] [:%lower.name :asc]])+ [:model :desc] [[:model_ranking :desc] [:%lower.name :asc]]+ [:description :asc] [[:%lower.description :asc :nulls-last] [:%lower.name :asc]]+ [:description :desc] [[:%lower.description :desc :nulls-last] [:%lower.name :asc]]);; add a fallback sort order so paging is still deterministic even if collection have the same name or;; whatever[[:id :asc]]]))diff --git a/test/metabase/collections_rest/api_test.clj b/test/metabase/collections_rest/api_test.cljindex a420f39a208..d7d69f3e000 100644--- a/test/metabase/collections_rest/api_test.clj+++ b/test/metabase/collections_rest/api_test.clj@@ -1289,6 +1289,27 @@:sort-direction :desc:official-collections-first? true} :mysql)))))+(deftest ^:parallel children-sort-clause-description-test+ (testing "Sorting by description"+ (testing "ascending"+ (is (= [[:authority_level :asc :nulls-last]+ [:type :asc :nulls-first]+ [:%lower.description :asc :nulls-last]+ [:%lower.name :asc]+ [:id :asc]]+ (api.collection/children-sort-clause {:sort-column :description+ :sort-direction :asc+ :official-collections-first? true} :postgres))))+ (testing "descending"+ (is (= [[:authority_level :asc :nulls-last]+ [:type :asc :nulls-first]+ [:%lower.description :desc :nulls-last]+ [:%lower.name :asc]+ [:id :asc]]+ (api.collection/children-sort-clause {:sort-column :description+ :sort-direction :desc+ :official-collections-first? true} :postgres))))))+(deftest ^:parallel snippet-collection-items-test(testing "GET /api/collection/:id/items";; EE behavior is tested