Skip to content

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

Revert expandable data app contents collection in the sidebar (#84885)

Phoomparin Manoc1a330cf1e96
diff --git a/enterprise/backend/src/metabase_enterprise/data_apps/api.clj b/enterprise/backend/src/metabase_enterprise/data_apps/api.clj
index 1735cce9de4..b1ba40b5435 100644
--- a/enterprise/backend/src/metabase_enterprise/data_apps/api.clj
+++ b/enterprise/backend/src/metabase_enterprise/data_apps/api.clj
@@ -99,8 +99,7 @@
(def ^:private PublicDataAppResponse
[:map {:closed true}
[:name ms/NonBlankString]
- [:display_name ms/NonBlankString]
- [:resource_collection_id ms/PositiveInt]])
+ [:display_name ms/NonBlankString]])
(def ^:private RepoStatusResponse
[:map
@@ -164,7 +163,7 @@
[app]
(if api/*is-superuser?*
(assoc app :outdated (data-app.config/outdated? app))
- (select-keys app [:name :display_name :resource_collection_id])))
+ (select-keys app [:name :display_name])))
(defn- read-check-data-app
"Check whether the current user can access a data app. Viewing requires read access to the app's
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj
index d7617ec275b..2f1458210bc 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/api_test.clj
@@ -178,8 +178,7 @@
(with-redefs [data-app.config/supported-app-version 2]
(testing "a regular user is never told about the outdated app in a list"
(doseq [url ["apps" "apps?available=true"]]
- (is (= [{:name "current" :display_name "Current"
- :resource_collection_id (t2/select-one-fn :resource_collection_id :model/DataApp :name "current")}]
+ (is (= [{:name "current" :display_name "Current"}]
(mt/user-http-request :rasta :get 200 url)))))
(testing "for a regular user, opening an outdated app is a 409 that says what to do"
(doseq [url ["apps/old" "apps/old/bundle"]]
@@ -187,8 +186,7 @@
:message #"This app was built for version 1 of data apps.*"}
(mt/user-http-request :rasta :get 409 url)))))
(testing "the current app still opens"
- (is (= {:name "current" :display_name "Current"
- :resource_collection_id (t2/select-one-fn :resource_collection_id :model/DataApp :name "current")}
+ (is (= {:name "current" :display_name "Current"}
(mt/user-http-request :rasta :get 200 "apps/current")))
(is (str/includes?
(str (mt/user-real-request :crowberto :get 200 "apps/current/bundle"))
diff --git a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj
index 37fd9379663..f63d038603f 100644
--- a/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj
+++ b/enterprise/backend/test/metabase_enterprise/data_apps/group_access_test.clj
@@ -44,12 +44,9 @@
(let [list-apps (api.macros/find-route-fn 'metabase-enterprise.data-apps.api :get "/")]
(mt/with-current-user (mt/user->id :rasta)
(list-apps {} {})
- (doseq [[query expected] [[{} [{:name "birds" :display_name "Birds"
- :resource_collection_id (:resource_collection_id app)}
- {:name "disabled" :display_name "Disabled"
- :resource_collection_id (:resource_collection_id disabled)}]]
- [{:available true} [{:name "birds" :display_name "Birds"
- :resource_collection_id (:resource_collection_id app)}]]]]
+ (doseq [[query expected] [[{} [{:name "birds" :display_name "Birds"}
+ {:name "disabled" :display_name "Disabled"}]]
+ [{:available true} [{:name "birds" :display_name "Birds"}]]]]
(is (= expected (list-apps {} query))))))))
(deftest read-access-agrees-across-entry-points-test
@@ -296,7 +293,7 @@
(perms/revoke-collection-permissions! group-id collection-id)
(mt/user-http-request :rasta :get 403 "apps/birds")
(resources/ensure-resources! app)
- (is (= {:name "birds" :display_name "Birds" :resource_collection_id collection-id}
+ (is (= {:name "birds" :display_name "Birds"}
(mt/user-http-request :rasta :get 200 "apps/birds"))))))))
(deftest tenant-users-cannot-inherit-app-access-test
diff --git a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx
deleted file mode 100644
index 682ce13e294..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppNavbarLink.tsx
+++ /dev/null
@@ -1,71 +0,0 @@
-import { useId, useState } from "react";
-import { t } from "ttag";
-
-import { TreeNode } from "metabase/common/components/tree/TreeNode";
-import { SidebarLink } from "metabase/nav/containers/MainNavbar/SidebarItems";
-import { Box } from "metabase/ui";
-import * as Urls from "metabase/urls";
-import type { DataApp } from "metabase-types/api";
-
-interface Props {
- dataApp: DataApp;
- onItemSelect: () => void;
-}
-
-export function DataAppNavbarLink({ dataApp, onItemSelect }: Props) {
- const contentsId = useId();
- const [isContentsExpanded, setIsContentsExpanded] = useState(false);
-
- const { display_name: displayName, resource_collection_id: collectionId } =
- dataApp;
-
- const toggleButton = (
- <TreeNode.ExpandToggleButton
- c="core-brand"
- py="xxs"
- pl="xxxs"
- pr={0}
- aria-label={
- isContentsExpanded
- ? t`Collapse ${displayName}`
- : t`Expand ${displayName}`
- }
- aria-expanded={isContentsExpanded}
- aria-controls={contentsId}
- onClick={() => setIsContentsExpanded(!isContentsExpanded)}
- >
- <TreeNode.ExpandToggleIcon
- name="chevronright"
- isExpanded={isContentsExpanded}
- size={12}
- />
- </TreeNode.ExpandToggleButton>
- );
-
- return (
- <>
- <SidebarLink
- icon="app"
- onClick={onItemSelect}
- rel="noopener noreferrer"
- target="_blank"
- url={Urls.dataApp(dataApp.name)}
- left={toggleButton}
- >
- {displayName}
- </SidebarLink>
-
- {isContentsExpanded && (
- <Box id={contentsId} pl="1.5rem">
- <SidebarLink
- icon="folder"
- url={`/collection/${collectionId}`}
- onClick={onItemSelect}
- >
- {t`Contents`}
- </SidebarLink>
- </Box>
- )}
- </>
- );
-}
diff --git a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx
index c867e807dc5..e3261709dff 100644
--- a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.tsx
@@ -5,10 +5,10 @@ import {
SidebarHeading,
SidebarSection,
} from "metabase/nav/containers/MainNavbar/Sidebar";
+import { SidebarLink } from "metabase/nav/containers/MainNavbar/SidebarItems";
+import * as Urls from "metabase/urls";
import { useListDataAppsQuery } from "metabase-enterprise/api";
-import { DataAppNavbarLink } from "./DataAppNavbarLink";
-
export function DataAppsNavbarSection({
onItemSelect,
}: {
@@ -30,11 +30,16 @@ export function DataAppsNavbarSection({
aria-label={t`Data apps`}
>
{dataApps.map((dataApp) => (
- <DataAppNavbarLink
+ <SidebarLink
key={dataApp.name}
- dataApp={dataApp}
- onItemSelect={onItemSelect}
- />
+ icon="app"
+ onClick={onItemSelect}
+ rel="noopener noreferrer"
+ target="_blank"
+ url={Urls.dataApp(dataApp.name)}
+ >
+ {dataApp.display_name}
+ </SidebarLink>
))}
</CollapseSection>
</SidebarSection>
diff --git a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.unit.spec.tsx
index e82b48b4c70..90602b790af 100644
--- a/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data_apps/navbar/DataAppsNavbarSection.unit.spec.tsx
@@ -21,14 +21,16 @@ describe("DataAppsNavbarSection", () => {
it("shows every data app as a link", async () => {
fetchMock.get("path:/api/apps?available=true", [
- { name: "gizmo", display_name: "Gizmo", resource_collection_id: 42 },
- { name: "gadget", display_name: "Gadget", resource_collection_id: 43 },
+ { name: "gizmo", display_name: "Gizmo" },
+ { name: "gadget", display_name: "Gadget" },
]);
+ const onItemSelect = jest.fn();
+
renderWithProviders(
<Route
path="/"
- element={<DataAppsNavbarSection onItemSelect={jest.fn()} />}
+ element={<DataAppsNavbarSection onItemSelect={onItemSelect} />}
/>,
{ withRouter: true },
);
@@ -49,96 +51,13 @@ describe("DataAppsNavbarSection", () => {
"href",
"/apps/gadget",
);
- });
-
- it("expands contents when the chevron is clicked", async () => {
- fetchMock.get("path:/api/apps?available=true", [
- { name: "gizmo", display_name: "Gizmo", resource_collection_id: 42 },
- { name: "gadget", display_name: "Gadget", resource_collection_id: 43 },
- ]);
- const onItemSelect = jest.fn();
-
- renderWithProviders(
- <>
- <Route
- path="/"
- element={<DataAppsNavbarSection onItemSelect={onItemSelect} />}
- />
-
- <Route
- path="/collection/42"
- element={<div>Gizmo collection page</div>}
- />
- </>,
- { withRouter: true },
- );
+ await userEvent.click(gizmoLink);
- const gizmoToggle = await screen.findByRole("button", {
- name: "Expand Gizmo",
- });
-
- expect(
- screen.queryByRole("link", { name: /Contents/ }),
- ).not.toBeInTheDocument();
-
- await userEvent.click(gizmoToggle);
-
- // gizmo app should be expanded
- expect(gizmoToggle).toHaveAttribute("aria-expanded", "true");
- expect(onItemSelect).not.toHaveBeenCalled();
-
- // gadget app should not be expanded
- expect(
- screen.getByRole("button", { name: "Expand Gadget" }),
- ).toHaveAttribute("aria-expanded", "false");
-
- const contentsLink = screen.getByRole("link", { name: /Contents/ });
- expect(contentsLink).toHaveAttribute("href", "/collection/42");
- expect(contentsLink).not.toHaveAttribute("target", "_blank");
-
- await userEvent.click(screen.getByRole("link", { name: /Gizmo/ }));
expect(onItemSelect).toHaveBeenCalledTimes(1);
- expect(contentsLink).toBeInTheDocument();
-
- await userEvent.click(
- screen.getByRole("button", { name: "Collapse Gizmo" }),
- );
-
expect(
- screen.queryByRole("link", { name: /Contents/ }),
+ screen.queryByRole("button", { name: /Gizmo|Gadget/ }),
).not.toBeInTheDocument();
-
- await userEvent.click(screen.getByRole("button", { name: "Expand Gizmo" }));
- await userEvent.click(screen.getByRole("link", { name: /Contents/ }));
- expect(onItemSelect).toHaveBeenCalledTimes(2);
-
- expect(
- await screen.findByText("Gizmo collection page"),
- ).toBeInTheDocument();
- });
-
- it("expands contents when the chevron is activated with the keyboard", async () => {
- fetchMock.get("path:/api/apps?available=true", [
- { name: "gizmo", display_name: "Gizmo", resource_collection_id: 42 },
- ]);
-
- renderWithProviders(
- <Route
- path="/"
- element={<DataAppsNavbarSection onItemSelect={jest.fn()} />}
- />,
- { withRouter: true },
- );
-
- const toggle = await screen.findByRole("button", { name: "Expand Gizmo" });
- toggle.focus();
-
- await userEvent.keyboard("{Enter}");
- expect(screen.getByRole("link", { name: /Contents/ })).toBeInTheDocument();
-
- await userEvent.keyboard(" ");
-
expect(
screen.queryByRole("link", { name: /Contents/ }),
).not.toBeInTheDocument();