diff --git a/src/components/Dashboard/index.tsx b/src/components/Dashboard/index.tsx index ab24739..579d38f 100644 --- a/src/components/Dashboard/index.tsx +++ b/src/components/Dashboard/index.tsx @@ -1,14 +1,13 @@ -// src/app/dashboard/page.tsx -'use client'; - import * as React from 'react'; import { useSession } from 'next-auth/react'; import { Button } from '@patternfly/react-core/dist/dynamic/components/Button'; -import { useRouter } from 'next/navigation'; -import { Chip } from '@patternfly/react-core/dist/dynamic/components/Chip'; +import { Label } from '@patternfly/react-core/dist/dynamic/components/Label'; import { PageSection } from '@patternfly/react-core/dist/dynamic/components/Page'; import { Title } from '@patternfly/react-core/dist/dynamic/components/Title'; -import { Table, Thead, Tr, Th, Td, Tbody, ThProps } from '@patternfly/react-table'; +import { Card, CardTitle, CardBody } from '@patternfly/react-core/dist/dynamic/components/Card'; +import { Stack, StackItem } from '@patternfly/react-core/dist/dynamic/layouts/Stack'; +import { Flex, FlexItem } from '@patternfly/react-core/dist/dynamic/layouts/Flex'; +import { useRouter } from 'next/navigation'; import { fetchPullRequests, getGitHubUsername } from '../../utils/github'; import { PullRequest } from '../../types'; @@ -17,8 +16,6 @@ const Index: React.FunctionComponent = () => { const [pullRequests, setPullRequests] = React.useState([]); const [username, setUsername] = React.useState(null); const [error, setError] = React.useState(null); - const [activeSortIndex, setActiveSortIndex] = React.useState(undefined); - const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | undefined>(undefined); const router = useRouter(); const fetchAndSetPullRequests = React.useCallback(async () => { @@ -30,7 +27,11 @@ const Index: React.FunctionComponent = () => { const filteredPRs = data.filter( (pr: PullRequest) => pr.user.login === fetchedUsername && pr.labels.some((label) => label.name === 'skill' || label.name === 'knowledge') ); - setPullRequests(filteredPRs); + + // Sort by date (newest first) + const sortedPRs = filteredPRs.sort((a: PullRequest, b: PullRequest) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); + + setPullRequests(sortedPRs); } catch (error) { setError('Failed to fetch pull requests.'); } @@ -43,39 +44,6 @@ const Index: React.FunctionComponent = () => { return () => clearInterval(intervalId); }, [session, fetchAndSetPullRequests]); - const getSortableRowValues = (pr: PullRequest): (string | number)[] => { - const labels = pr.labels.map((label) => label.name).join(', '); - return [pr.title, pr.user.login, pr.state, new Date(pr.created_at).getTime(), new Date(pr.updated_at).getTime(), labels]; - }; - - let sortedPullRequests = pullRequests; - if (activeSortIndex !== undefined) { - sortedPullRequests = pullRequests.sort((a, b) => { - const aValue = getSortableRowValues(a)[activeSortIndex]; - const bValue = getSortableRowValues(b)[activeSortIndex]; - - if (typeof aValue === 'number' && typeof bValue === 'number') { - return activeSortDirection === 'asc' ? aValue - bValue : bValue - aValue; - } else if (typeof aValue === 'string' && typeof bValue === 'string') { - return activeSortDirection === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue); - } - - return 0; - }); - } - - const getSortParams = (columnIndex: number): ThProps['sort'] => ({ - sortBy: { - index: activeSortIndex, - direction: activeSortDirection - }, - onSort: (_event, index, direction) => { - setActiveSortIndex(index); - setActiveSortDirection(direction as 'asc' | 'desc'); - }, - columnIndex - }); - const handleEditClick = (pr: PullRequest) => { const hasKnowledgeLabel = pr.labels.some((label) => label.name === 'knowledge'); const hasSkillLabel = pr.labels.some((label) => label.name === 'skill'); @@ -98,50 +66,41 @@ const Index: React.FunctionComponent = () => {
{error &&
{error}
} - - - - - - - - - - - - - - - {sortedPullRequests.map((pr) => ( - - - - - - - - - - - ))} - -
TitleAuthorStateCreated AtUpdated AtLinkLabelsActions
{pr.title}{pr.user.login}{pr.state}{new Date(pr.created_at).toLocaleString()}{new Date(pr.updated_at).toLocaleString()} - - View PR - - - {pr.labels.map((label) => ( - - {label.name} - - ))} - - {pr.state === 'open' && ( - - )} -
+ + {pullRequests.map((pr) => ( + + + {pr.title} + + + State: {pr.state} + Created At: {new Date(pr.created_at).toLocaleString()} + Updated At: {new Date(pr.updated_at).toLocaleString()} + + {pr.labels.map((label) => ( + + ))} + + + + + + {pr.state === 'open' && ( + + )} + + + + + + ))} + ); };