Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
standardDeviation,
} from 'utils/mathFunctions';
import useDataApiWithFeedback from 'utils/useDataApiWithFeedback';
import { getFullUserName } from 'utils/user';
import withConfirm, { WithConfirmType } from 'utils/withConfirm';

type FapProposalsAndAssignmentsTableProps = {
Expand Down Expand Up @@ -82,6 +83,18 @@ const FapProposalColumns: Column<FapProposalType>[] = [
title: 'Title',
field: 'proposal.title',
},
{
title: 'Principal Investigator',
render: (rowData) => {
return getFullUserName(rowData.proposal.proposer);
},
customSort(a, b) {
const name1 = getFullUserName(a.proposal.proposer);
const name2 = getFullUserName(b.proposal.proposer);

return name1 < name2 ? -1 : 1;
},
},
{
title: 'Status',
field: 'proposal.status.name',
Expand All @@ -93,6 +106,8 @@ const FapProposalColumns: Column<FapProposalType>[] = [
{
title: 'Reviewers',
render: (data) => data.assignments?.length,
customSort: (a, b) =>
(a.assignments?.length || 0) - (b.assignments?.length || 0),
},
{
title: 'Reviews',
Expand All @@ -106,6 +121,29 @@ const FapProposalColumns: Column<FapProposalType>[] = [

return totalReviews === 0 ? '-' : `${countReviews} / ${totalReviews}`;
},
customSort: (a, b) => {
const totalReviewsA = a.assignments?.length || 0;
const totalReviewsB = b.assignments?.length || 0;
const gradedProposalsA =
a.assignments?.filter(
(assignment) =>
assignment.review !== null && assignment.review.grade !== null
).length || 0;
const gradedProposalsB =
b.assignments?.filter(
(assignment) =>
assignment.review !== null && assignment.review.grade !== null
).length || 0;

const incompleteReviewsA = totalReviewsA - gradedProposalsA;
const incompleteReviewsB = totalReviewsB - gradedProposalsB;

if (incompleteReviewsA === incompleteReviewsB) {
return totalReviewsB - totalReviewsA;
}

return incompleteReviewsA - incompleteReviewsB;
},
},
{
title: 'Average grade',
Expand Down Expand Up @@ -459,6 +497,7 @@ const FapProposalsAndAssignmentsTable = ({
]}
actions={tableActions}
options={{
columnsButton: true,
search: true,
selection: true,
pageSize: pageSize ? +pageSize : Math.min(10, maxPageLength),
Expand Down
3 changes: 3 additions & 0 deletions apps/frontend/src/graphql/fap/getFapProposals.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ query getFapProposals($fapId: Int!, $callId: Int, $instrumentId: Int, $legacy: B
proposalId
proposer {
id
firstname
lastname
preferredname
institutionId
}
status {
Expand Down
Loading