From ccf090c847237b57aeb419690124b123d173f551 Mon Sep 17 00:00:00 2001 From: Delilah <23665803+goplayoutside3@users.noreply.github.com> Date: Mon, 21 Oct 2024 13:53:23 -0500 Subject: [PATCH] filter out private or deleted projects --- .../RecentProjects/RecentProjects.js | 34 +++++++++---------- .../RecentProjects/RecentProjectsContainer.js | 29 ++++++++++------ 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjects.js b/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjects.js index 12a5053614..04d860ace3 100644 --- a/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjects.js +++ b/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjects.js @@ -7,10 +7,11 @@ import { ContentBox } from '@components/shared' export default function RecentProjects({ isLoading = false, - recentProjectsStats = [], + recentProjects = [], error = undefined }) { const size = useContext(ResponsiveContext) + return ( {isLoading ? ( @@ -23,7 +24,7 @@ export default function RecentProjects({ There was an error fetching your recent projects - ) : !recentProjectsStats.length ? ( + ) : !recentProjects.length ? ( No Recent Projects found @@ -44,14 +45,14 @@ export default function RecentProjects({ style={{ listStyle: 'none' }} margin='0' > - {recentProjectsStats.map(stat => ( -
  • + {recentProjects.map(project => ( +
  • @@ -64,17 +65,14 @@ export default function RecentProjects({ RecentProjects.propTypes = { isLoading: bool, - recentProjectsStats: arrayOf( + recentProjects: arrayOf( shape({ + avatar_src: string, count: number, - project_id: number, - projectInfo: shape({ - avatar_src: string, - description: string, - display_name: string, - id: string, - slug: string - }) + description: string, + display_name: string, + id: string, + slug: string }) ) } diff --git a/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjectsContainer.js b/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjectsContainer.js index 04bc727fa2..a19b75656a 100644 --- a/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjectsContainer.js +++ b/packages/lib-user/src/components/UserHome/components/RecentProjects/RecentProjectsContainer.js @@ -16,8 +16,8 @@ function RecentProjectsContainer({ authUser }) { } = useStats({ sourceId: authUser?.id, query: recentProjectsQuery }) // limit to 20 projects fetched from panoptes - const contributionStats = stats?.project_contributions.slice(0, 20) - const projectIds = contributionStats?.map(project => project.project_id) + const contributions = stats?.project_contributions.slice(0, 20) + const projectIds = contributions?.map(project => project.project_id) // Get more info about each project const { @@ -29,21 +29,28 @@ function RecentProjectsContainer({ authUser }) { id: projectIds?.join(',') }) - // Attach project info to each contribution stat - if (projects?.length && contributionStats?.length) { - contributionStats.forEach(stat => { - const projectObj = projects.find( - project => parseInt(project.id) === stat.project_id - ) - stat.projectInfo = projectObj - }) + // Attach project info to each contribution stat (see similar behavior in TopProjects) + let recentProjects = [] + + if (projects?.length && contributions?.length) { + recentProjects = contributions + .map(projectContribution => { + const projectData = projects?.find( + project => project.id === projectContribution.project_id.toString() + ) + return { + count: projectContribution.count, + ...projectData + } + }) + .filter(project => project?.id) // exclude private or deleted projects } return ( ) }