From 7f0d11d8396d7634304be4d05d4f437f28b5fb8a Mon Sep 17 00:00:00 2001 From: claygorman Date: Wed, 17 Jan 2024 16:18:48 -0800 Subject: [PATCH] Refactor code and enhance board link generation The existing code in RecentProjectsCards.tsx has been refactored for more efficient project card data formatting. This was achieved by restructuring and resorting the imports and destructuring the project object. A significant enhancement has been made to the way in which the board link is generated, using `boardId` instead of the hard-coded value of '1'. An option for additional querying options has also been added in the board resolver. --- backend/src/resolvers/board/index.ts | 1 + .../MainPage/RecentProjectsCards.tsx | 24 +++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend/src/resolvers/board/index.ts b/backend/src/resolvers/board/index.ts index d452d81..5584b3d 100644 --- a/backend/src/resolvers/board/index.ts +++ b/backend/src/resolvers/board/index.ts @@ -94,6 +94,7 @@ export const boards: Resolver>[], Project | u } const boards = await db.Board.findAll({ + ...additionalOptions, include: [ { model: db.BoardContainer, diff --git a/frontend/components/MainPage/RecentProjectsCards.tsx b/frontend/components/MainPage/RecentProjectsCards.tsx index 0f16a5d..d5e63b3 100644 --- a/frontend/components/MainPage/RecentProjectsCards.tsx +++ b/frontend/components/MainPage/RecentProjectsCards.tsx @@ -1,13 +1,14 @@ -import { EllipsisVerticalIcon } from '@heroicons/react/20/solid'; -import { classNames } from '@/services/utils'; import { useSuspenseQuery } from '@apollo/client'; -import { GetProjectsQuery, Project } from '@/gql/__generated__/graphql'; -import { GET_PROJECTS } from '@/gql/gql-queries-mutations'; +import { EllipsisVerticalIcon } from '@heroicons/react/20/solid'; import { sample } from 'lodash'; -import Link from 'next/link'; import type { Route } from 'next'; +import Link from 'next/link'; import { Suspense } from 'react'; +import { GetProjectsQuery, Project } from '@/gql/__generated__/graphql'; +import { GET_PROJECTS } from '@/gql/gql-queries-mutations'; +import { classNames } from '@/services/utils'; + const baseColors = [ 'bg-pink-600', 'bg-purple-600', @@ -33,12 +34,15 @@ const getUniqueColor = () => { }; const formatProjectCard = (project: Project) => { + const { id, name, key: initials, issueCount, boards } = project; + const boardId = boards?.[0]?.id ?? 1; + return { - id: project.id, - name: project.name, - initials: project.key, - href: `projects/${project.id}/boards/1`, - issueCount: project.issueCount, + id, + name, + initials, + href: `projects/${id}/boards/${boardId}`, + issueCount, bgColor: getUniqueColor(), }; };