Skip to content

Commit

Permalink
Refactor code and enhance board link generation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
claygorman committed Jan 18, 2024
1 parent a3146e6 commit 7f0d11d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions backend/src/resolvers/board/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export const boards: Resolver<ResolverTypeWrapper<Partial<Board>>[], Project | u
}

const boards = await db.Board.findAll({
...additionalOptions,
include: [
{
model: db.BoardContainer,
Expand Down
24 changes: 14 additions & 10 deletions frontend/components/MainPage/RecentProjectsCards.tsx
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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(),
};
};
Expand Down

0 comments on commit 7f0d11d

Please sign in to comment.