Skip to content

Commit

Permalink
Added review, approved and declined count (#4779)
Browse files Browse the repository at this point in the history
  • Loading branch information
Devorein authored Oct 10, 2024
1 parent 5102941 commit 85ea427
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ThumbUpOutlined as ApprovedIcon, HighlightOff as RejectedIcon } from '@mui/icons-material';
import ProposalIcon from '@mui/icons-material/TaskOutlined';
import { Box, Button, Card, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material';
import { Stack } from '@mui/system';
import type { UserProposal } from '@root/lib/proposals/getUserProposals';
import { relativeTime } from '@root/lib/utils/dates';
import { useRouter } from 'next/router';

import Link from 'components/common/Link';
import { evaluationIcons } from 'components/settings/proposals/constants';

import { StyledTable, OpenButton, StyledTableRow } from './ProposalsTable';
import { OpenButton, StyledTable, StyledTableRow } from './ProposalsTable';

export function ActionableProposalsTable({ proposals }: { proposals: UserProposal[] }) {
const router = useRouter();
Expand All @@ -32,14 +32,24 @@ export function ActionableProposalsTable({ proposals }: { proposals: UserProposa
Due date
</Typography>
</TableCell>
<TableCell align='left'>
<Typography variant='body2' fontWeight='bold'>
Current step
</Typography>
</TableCell>
<TableCell align='center'>
<Typography variant='body2' fontWeight='bold'>
Last updated
Your review
</Typography>
</TableCell>
<TableCell align='left'>
<TableCell align='center'>
<Typography variant='body2' fontWeight='bold'>
Current step
Approved
</Typography>
</TableCell>
<TableCell align='center'>
<Typography variant='body2' fontWeight='bold'>
Declined
</Typography>
</TableCell>
<TableCell align='right'>
Expand Down Expand Up @@ -88,7 +98,7 @@ export function ActionableProposalsTable({ proposals }: { proposals: UserProposa
router.push(`/${router.query.domain}/${proposal.path}`);
}}
>
<TableCell width={400}>
<TableCell width={250}>
<Typography>{proposal.title || 'Untitled'}</Typography>
<Link href={`/${proposal.path}`} onClick={(e) => e.stopPropagation()}>
<OpenButton />
Expand All @@ -97,18 +107,36 @@ export function ActionableProposalsTable({ proposals }: { proposals: UserProposa
<TableCell align='center' width={200}>
<Typography color={isOverdue ? 'error' : 'initial'}>{dueDateText}</Typography>
</TableCell>
<TableCell align='center' width={250}>
<Typography>{relativeTime(proposal.updatedAt)}</Typography>
</TableCell>
<TableCell width={250}>
<TableCell width={150}>
<Stack direction='row' alignItems='center' justifyContent='flex-start' gap={1}>
{proposal.currentEvaluation && evaluationIcons[proposal.currentEvaluation.type]()}
<Typography>
{proposal.status === 'draft' ? 'Draft' : proposal.currentEvaluation?.title || 'Evaluation'}
</Typography>
</Stack>
</TableCell>
<TableCell align='right' width={250}>
<TableCell align='center' width={150}>
<Typography>
{proposal.userReviewResult === 'pass' ? (
<ApprovedIcon fontSize='small' color='success' />
) : proposal.userReviewResult === 'fail' ? (
<RejectedIcon fontSize='small' color='error' />
) : (
'-'
)}
</Typography>
</TableCell>
<TableCell align='center' width={150}>
<Typography color={proposal.totalPassedReviewResults ? 'success' : undefined}>
{proposal.totalPassedReviewResults || '-'}
</Typography>
</TableCell>
<TableCell align='center' width={150}>
<Typography color={proposal.totalFailedReviewResults ? 'error' : undefined}>
{proposal.totalFailedReviewResults || '-'}
</Typography>
</TableCell>
<TableCell align='right' width={150}>
<Button
color='primary'
size='small'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import styled from '@emotion/styled';
import { ThumbUpOutlined as ApprovedIcon, HighlightOff as RejectedIcon } from '@mui/icons-material';
import ProposalIcon from '@mui/icons-material/TaskOutlined';
import { Box, Card, Chip, Table, TableBody, TableCell, TableHead, TableRow, Typography } from '@mui/material';
import { Stack } from '@mui/system';
Expand Down Expand Up @@ -88,14 +89,25 @@ export function ProposalsTable({
Status
</Typography>
</TableCell>
<TableCell align='left'>
<Typography variant='body2' fontWeight='bold'>
Current step
</Typography>
</TableCell>

<TableCell align='center'>
<Typography variant='body2' fontWeight='bold'>
Last updated
Your review
</Typography>
</TableCell>
<TableCell align='left'>
<TableCell align='center'>
<Typography variant='body2' fontWeight='bold'>
Current step
Approved
</Typography>
</TableCell>
<TableCell align='center'>
<Typography variant='body2' fontWeight='bold'>
Declined
</Typography>
</TableCell>
<TableCell align='center'>
Expand Down Expand Up @@ -123,7 +135,7 @@ export function ProposalsTable({
}}
>
<TableCell
width={400}
width={250}
sx={{
pl: 0
}}
Expand All @@ -141,18 +153,37 @@ export function ProposalsTable({
size='small'
/>
</TableCell>
<TableCell align='center' width={250}>
<Typography>{relativeTime(proposal.updatedAt)}</Typography>
</TableCell>
<TableCell align='left' width={250}>
<TableCell align='left' width={150}>
<Stack direction='row' alignItems='center' justifyContent='flex-start' gap={1}>
{proposal.currentEvaluation && evaluationIcons[proposal.currentEvaluation.type]()}
<Typography>
{proposal.status === 'draft' ? 'Draft' : proposal.currentEvaluation?.title || 'Evaluation'}
</Typography>
</Stack>
</TableCell>
<TableCell width={250} align='center'>

<TableCell align='center' width={150}>
<Typography>
{proposal.userReviewResult === 'pass' ? (
<ApprovedIcon fontSize='small' color='success' />
) : proposal.userReviewResult === 'fail' ? (
<RejectedIcon fontSize='small' color='error' />
) : (
'-'
)}
</Typography>
</TableCell>
<TableCell align='center' width={150}>
<Typography color={proposal.totalPassedReviewResults ? 'success' : undefined}>
{proposal.totalPassedReviewResults || '-'}
</Typography>
</TableCell>
<TableCell align='center' width={150}>
<Typography color={proposal.totalFailedReviewResults ? 'error' : undefined}>
{proposal.totalFailedReviewResults || '-'}
</Typography>
</TableCell>
<TableCell width={150} align='center'>
{assigned ? (proposal.reviewedAt ? relativeTime(proposal.reviewedAt) : '-') : null}
</TableCell>
</StyledTableRow>
Expand Down
15 changes: 13 additions & 2 deletions lib/proposals/getUserProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export type UserProposal = {
currentEvaluation?: CurrentEvaluation;
viewable: boolean;
reviewedAt?: Date | null;
userReviewResult?: ProposalEvaluationResult | null;
totalPassedReviewResults?: number;
totalFailedReviewResults?: number;
};

export type GetUserProposalsResponse = {
Expand Down Expand Up @@ -181,7 +184,8 @@ export async function getUserProposals({
reviews: {
select: {
reviewerId: true,
completedAt: true
completedAt: true,
result: true
}
},
vote: {
Expand Down Expand Up @@ -263,6 +267,10 @@ export async function getUserProposals({
(reviewer.roleId && userRoles.includes(reviewer.roleId)) ||
reviewer.systemRole === 'space_member'
);
const userReviewResult = currentEvaluation?.reviews.find((review) => review.reviewerId === userId)?.result;
const totalPassedReviewResults = currentEvaluation?.reviews.filter((review) => review.result === 'pass').length;
const totalFailedReviewResults = currentEvaluation?.reviews.filter((review) => review.result === 'fail').length;

const isVoter = currentEvaluation?.type === 'vote' && isReviewer;
const isAppealReviewer = currentEvaluation?.appealReviewers.some(
(reviewer) => reviewer.userId === userId || (reviewer.roleId && userRoles.includes(reviewer.roleId))
Expand Down Expand Up @@ -330,7 +338,10 @@ export async function getUserProposals({
path: proposal.page.path,
status: proposal.status,
viewable: accessibleProposalIds.includes(proposal.id),
reviewedAt
reviewedAt,
userReviewResult,
totalPassedReviewResults,
totalFailedReviewResults
};

// needs review/vote
Expand Down

0 comments on commit 85ea427

Please sign in to comment.