diff --git a/frontend/src/metabase/common/hooks/entity-framework/index.ts b/frontend/src/metabase/common/hooks/entity-framework/index.ts index b6141c46d1d926f30fa7060e8a56e81bdb25c878..b0d5f3a246fc08d2af60a22a3d674a5aca3202ee 100644 --- a/frontend/src/metabase/common/hooks/entity-framework/index.ts +++ b/frontend/src/metabase/common/hooks/entity-framework/index.ts @@ -12,7 +12,6 @@ export * from "./use-dashboard-query"; export * from "./use-database-list-query"; export * from "./use-database-query"; export * from "./use-group-list-query"; -export * from "./use-popular-item-list-query"; export * from "./use-question-list-query"; export * from "./use-question-query"; export * from "./use-revision-list-query"; diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/index.ts b/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/index.ts deleted file mode 100644 index 7ae5e4cc5d342e369bb6699fdf9a86cf484e0639..0000000000000000000000000000000000000000 --- a/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./use-popular-item-list-query"; diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/use-popular-item-list-query.ts b/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/use-popular-item-list-query.ts deleted file mode 100644 index 84d839d20c9f4ae6463915e8a7fa4fe435f09826..0000000000000000000000000000000000000000 --- a/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/use-popular-item-list-query.ts +++ /dev/null @@ -1,24 +0,0 @@ -import PopularItems from "metabase/entities/popular-items"; -import type { PopularItem } from "metabase-types/api"; - -import type { - UseEntityListQueryProps, - UseEntityListQueryResult, -} from "../use-entity-list-query"; -import { useEntityListQuery } from "../use-entity-list-query"; - -/** - * @deprecated use "metabase/api" instead - */ -export const usePopularItemListQuery = ( - props: UseEntityListQueryProps = {}, -): UseEntityListQueryResult<PopularItem> => { - return useEntityListQuery(props, { - fetchList: PopularItems.actions.fetchList, - getList: PopularItems.selectors.getList, - getLoading: PopularItems.selectors.getLoading, - getLoaded: PopularItems.selectors.getLoaded, - getError: PopularItems.selectors.getError, - getListMetadata: PopularItems.selectors.getListMetadata, - }); -}; diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/use-popular-item-list-query.unit.spec.tsx b/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/use-popular-item-list-query.unit.spec.tsx deleted file mode 100644 index 082aebf9be93045f6b67ee3ed70c8a3573a0e5b6..0000000000000000000000000000000000000000 --- a/frontend/src/metabase/common/hooks/entity-framework/use-popular-item-list-query/use-popular-item-list-query.unit.spec.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import { setupPopularItemsEndpoints } from "__support__/server-mocks"; -import { - renderWithProviders, - screen, - waitForLoaderToBeRemoved, - within, -} from "__support__/ui"; -import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper"; -import { createMockPopularItem } from "metabase-types/api/mocks"; - -import { usePopularItemListQuery } from "./use-popular-item-list-query"; - -const TEST_ITEM = createMockPopularItem(); - -const TestComponent = () => { - const { data = [], metadata, isLoading, error } = usePopularItemListQuery(); - - if (isLoading || error) { - return <LoadingAndErrorWrapper loading={isLoading} error={error} />; - } - - return ( - <div> - {data.map((item, index) => ( - <div key={index}>{item.model_object.name}</div> - ))} - - <div data-testid="metadata"> - {(!metadata || Object.keys(metadata).length === 0) && "No metadata"} - </div> - </div> - ); -}; - -const setup = () => { - setupPopularItemsEndpoints([TEST_ITEM]); - renderWithProviders(<TestComponent />); -}; - -describe("usePopularItemListQuery", () => { - it("should be initially loading", () => { - setup(); - expect(screen.getByTestId("loading-spinner")).toBeInTheDocument(); - }); - - it("should show data from the response", async () => { - setup(); - await waitForLoaderToBeRemoved(); - expect(screen.getByText(TEST_ITEM.model_object.name)).toBeInTheDocument(); - }); - it("should not have any metadata in the response", async () => { - setup(); - await waitForLoaderToBeRemoved(); - expect( - within(screen.getByTestId("metadata")).getByText("No metadata"), - ).toBeInTheDocument(); - }); -}); diff --git a/frontend/src/metabase/entities/index.js b/frontend/src/metabase/entities/index.js index c1001d93f1ee5fd85473c1f9b1ee391d32e67262..210241372e41543d9959b8eae7cc10d9399f2b2c 100644 --- a/frontend/src/metabase/entities/index.js +++ b/frontend/src/metabase/entities/index.js @@ -26,5 +26,4 @@ export { default as groups } from "./groups"; export { default as search } from "./search"; export { default as persistedModels } from "./persisted-models"; -export { default as popularItems } from "./popular-items"; export { default as snippets } from "./snippets"; diff --git a/frontend/src/metabase/entities/popular-items.js b/frontend/src/metabase/entities/popular-items.js deleted file mode 100644 index 8e2132ceb9aeba846fd43b948cec86261529ba60..0000000000000000000000000000000000000000 --- a/frontend/src/metabase/entities/popular-items.js +++ /dev/null @@ -1,50 +0,0 @@ -import { activityApi } from "metabase/api"; -import { createEntity, entityCompatibleQuery } from "metabase/lib/entities"; -import { entityTypeForObject } from "metabase/lib/schema"; -import { PopularItemSchema } from "metabase/schema"; - -export const getEntity = item => { - const entities = require("metabase/entities"); - return entities[entityTypeForObject(item)]; -}; - -export const getName = item => { - return item.model_object.display_name || item.model_object.name; -}; - -export const getIcon = item => { - const entity = getEntity(item); - const options = { variant: "secondary" }; - return entity.objectSelectors.getIcon(item.model_object, options); -}; - -/** - * @deprecated use "metabase/api" instead - */ -const PopularItems = createEntity({ - name: "popularItems", - nameOne: "popularItem", - path: "/api/activity/popular_items", - schema: PopularItemSchema, - - api: { - list: (entityQuery, dispatch) => - entityCompatibleQuery( - entityQuery, - dispatch, - activityApi.endpoints.listPopularItems, - ), - }, - - wrapEntity(item, dispatch = null) { - const entity = getEntity(item); - return entity.wrapEntity(item, dispatch); - }, - - objectSelectors: { - getName, - getIcon, - }, -}); - -export default PopularItems; diff --git a/frontend/src/metabase/home/components/HomeContent/HomeContent.tsx b/frontend/src/metabase/home/components/HomeContent/HomeContent.tsx index 4404e9533cc0675699cac74a18aa8acce870339f..c61813d15bc2d0600fd62972885c759be16e9ecc 100644 --- a/frontend/src/metabase/home/components/HomeContent/HomeContent.tsx +++ b/frontend/src/metabase/home/components/HomeContent/HomeContent.tsx @@ -1,9 +1,8 @@ -import { useListRecentItemsQuery } from "metabase/api"; import { - useDatabaseListQuery, - usePopularItemListQuery, - useSetting, -} from "metabase/common/hooks"; + useListRecentItemsQuery, + useListPopularItemsQuery, +} from "metabase/api"; +import { useDatabaseListQuery, useSetting } from "metabase/common/hooks"; import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper"; import { useSelector } from "metabase/lib/redux"; import { isSyncCompleted } from "metabase/lib/syncing"; @@ -26,7 +25,7 @@ export const HomeContent = (): JSX.Element | null => { const { data: recentItems, error: recentItemsError } = useListRecentItemsQuery(undefined, { refetchOnMountOrArgChange: true }); const { data: popularItems, error: popularItemsError } = - usePopularItemListQuery({ reload: true }); + useListPopularItemsQuery(undefined, { refetchOnMountOrArgChange: true }); const error = databasesError || recentItemsError || popularItemsError; if (error) { diff --git a/frontend/src/metabase/home/components/HomeModelCard/HomeModelCard.tsx b/frontend/src/metabase/home/components/HomeModelCard/HomeModelCard.tsx index 3395ec8b064d9464f31e6e61fb5ce1a32c48d753..a33adb13159de15dd823a1f0b112719e816d4fa5 100644 --- a/frontend/src/metabase/home/components/HomeModelCard/HomeModelCard.tsx +++ b/frontend/src/metabase/home/components/HomeModelCard/HomeModelCard.tsx @@ -12,6 +12,7 @@ interface HomeModelCardProps { export interface HomeModelIconProps { name: IconName; + variant?: "secondary"; } export const HomeModelCard = ({ diff --git a/frontend/src/metabase/home/components/HomePopularSection/HomePopularSection.tsx b/frontend/src/metabase/home/components/HomePopularSection/HomePopularSection.tsx index 629880e9b6720489efd35a6b9e67e3c5dae9490f..23da4ce1eef07b15bd5701ba63c3029fb538d035 100644 --- a/frontend/src/metabase/home/components/HomePopularSection/HomePopularSection.tsx +++ b/frontend/src/metabase/home/components/HomePopularSection/HomePopularSection.tsx @@ -1,9 +1,10 @@ import { t } from "ttag"; import _ from "underscore"; -import { usePopularItemListQuery } from "metabase/common/hooks"; +import { useListPopularItemsQuery } from "metabase/api"; import LoadingAndErrorWrapper from "metabase/components/LoadingAndErrorWrapper"; -import { getIcon, getName } from "metabase/entities/popular-items"; +import { getIcon } from "metabase/lib/icon"; +import { getName } from "metabase/lib/name"; import * as Urls from "metabase/lib/urls"; import type { PopularItem } from "metabase-types/api"; @@ -18,7 +19,7 @@ export const HomePopularSection = (): JSX.Element => { data: popularItems = [], isLoading, error, - } = usePopularItemListQuery(); + } = useListPopularItemsQuery(undefined, { refetchOnMountOrArgChange: true }); if (isLoading || error) { return <LoadingAndErrorWrapper loading={isLoading} error={error} />; @@ -31,8 +32,11 @@ export const HomePopularSection = (): JSX.Element => { {popularItems.map((item, index) => ( <HomeModelCard key={index} - title={getName(item)} - icon={getIcon(item)} + title={getName(item.model_object)} + icon={getIcon( + { ...item.model_object, model: item.model }, + { variant: "secondary" }, + )} url={Urls.modelToUrl(item) ?? ""} /> ))} diff --git a/frontend/src/metabase/schema.js b/frontend/src/metabase/schema.js index ba6d2ec19ba7e62072d2bfa5773acba044ddf894..8f2a867ceb8db0b44c6b355cc4b004acedcc19a9 100644 --- a/frontend/src/metabase/schema.js +++ b/frontend/src/metabase/schema.js @@ -140,7 +140,3 @@ export const ObjectUnionSchema = new schema.Union( CollectionSchema.define({ items: [ObjectUnionSchema], }); - -export const PopularItemSchema = new schema.Entity("popularItems", undefined, { - idAttribute: ({ model, model_id }) => `${model}:${model_id}`, -});