Skip to content

Commit

Permalink
change where we filter recents
Browse files Browse the repository at this point in the history
  • Loading branch information
iethree committed May 10, 2024
1 parent 3f59a2c commit 2d23023
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useMemo } from "react";

import {
useListRecentItemsQuery,
useListPopularItemsQuery,
Expand All @@ -14,20 +16,25 @@ import { getIsXrayEnabled } from "../../selectors";
import { isWithinWeeks } from "../../utils";
import { EmbedHomepage } from "../EmbedHomepage";
import { HomePopularSection } from "../HomePopularSection";
import { HomeRecentSection } from "../HomeRecentSection";
import { HomeRecentSection, recentsFilter } from "../HomeRecentSection";
import { HomeXraySection } from "../HomeXraySection";

export const HomeContent = (): JSX.Element | null => {
const user = useSelector(getUser);
const embeddingHomepage = useSetting("embedding-homepage");
const isXrayEnabled = useSelector(getIsXrayEnabled);
const { data: databases, error: databasesError } = useDatabaseListQuery();
const { data: recentItems, error: recentItemsError } =
const { data: recentItemsRaw, error: recentItemsError } =
useListRecentItemsQuery(undefined, { refetchOnMountOrArgChange: true });
const { data: popularItems, error: popularItemsError } =
useListPopularItemsQuery(undefined, { refetchOnMountOrArgChange: true });
const error = databasesError || recentItemsError || popularItemsError;

const recentItems = useMemo(
() => (recentItemsRaw && recentsFilter(recentItemsRaw)) ?? [],
[recentItemsRaw],
);

if (error) {
return <LoadingAndErrorWrapper error={error} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const HomeRecentSection = () => {
<div>
<HomeCaption>{t`Pick up where you left off`}</HomeCaption>
<SectionBody>
{resultsFilter(recentItems).map((item, index) => (
{recentsFilter(recentItems).map((item, index) => (
<HomeModelCard
key={index}
title={getName(item)}
Expand All @@ -48,6 +48,6 @@ export const HomeRecentSection = () => {
);
};

export const resultsFilter = (results: RecentItem[]): RecentItem[] => {
export const recentsFilter = (results: RecentItem[]): RecentItem[] => {
return results.filter(item => item.model !== "collection").slice(0, 5);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { useListRecentItemsQuery } from "metabase/api";
import { getName } from "metabase/lib/name";
import { useDispatch } from "metabase/lib/redux";
import { RecentsListContent } from "metabase/nav/components/search/RecentsList/RecentsListContent";
import { getItemUrl } from "metabase/nav/components/search/RecentsList/util";
import { Paper } from "metabase/ui";
import type { RecentItem, UnrestrictedLinkEntity } from "metabase-types/api";

import { getItemUrl, recentsFilter } from "./util";

type RecentsListProps = {
onClick?: (elem: UnrestrictedLinkEntity) => void;
className?: string;
Expand All @@ -30,6 +31,7 @@ export const RecentsList = ({ onClick, className }: RecentsListProps) => {
if (onClick) {
onClick({
...item,
description: item.description ?? undefined,
name: getName(item),
});
} else {
Expand All @@ -41,7 +43,7 @@ export const RecentsList = ({ onClick, className }: RecentsListProps) => {
<Paper withBorder className={className}>
<RecentsListContent
isLoading={isRecentsListLoading}
results={data}
results={recentsFilter(data)}
onClick={onContainerClick}
/>
</Paper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { SearchResultLink } from "metabase/search/components/SearchResultLink";
import { Group, Loader, Stack, Title } from "metabase/ui";
import type { RecentItem } from "metabase-types/api";

import { getItemUrl, isItemActive, resultsFilter } from "./util";
import { getItemUrl, isItemActive } from "./util";

type RecentsListContentProps = {
isLoading: boolean;
Expand Down Expand Up @@ -67,7 +67,7 @@ export const RecentsListContent = ({
>
<Title order={4} px="sm">{t`Recently viewed`}</Title>
<Stack spacing={0}>
{resultsFilter(results).map((item, index) => {
{results.map((item, index) => {
const isActive = isItemActive(item);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export const getItemUrl = (item: RecentItem) => {
return url || undefined;
};

export const resultsFilter = (results: RecentItem[]): RecentItem[] => {
export const recentsFilter = (results: RecentItem[]): RecentItem[] => {
return results.filter(item => item.model !== "collection").slice(0, 5);
};

0 comments on commit 2d23023

Please sign in to comment.