Skip to content

Commit

Permalink
Get all assignments in statistics (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland authored Nov 21, 2022
1 parent 94c8bd6 commit 3407fe2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useContext } from 'react';
import { useContext, useState } from 'react';
import { Modal, Label, Header } from 'semantic-ui-react';
import { UserContext } from 'contexts';
import { api } from 'utils/api';
import { statusColor, statusDisplay } from 'utils/assignment-utils';
import { useGetAssignments } from 'hooks';

const statuses = [
'active',
Expand All @@ -27,12 +27,23 @@ const reviewDisplay = {


export const StatsContainer = ({ trigger }) => {
const [{ user, assignments }] = useContext(UserContext);
const getAssignments = useGetAssignments();
const [{ user }] = useContext(UserContext);
const [assignments, setAssignments] = useState([]);

const onOpen = () => {
getAssignments(user._id, user.reviewer);
}
const getAssignments = async () => {
try {
const { assignments } = await api.getAssignments(user._id, false, true);

setAssignments(assignments);
}
catch (error) {
console.warn(error);
}
};

getAssignments();
};

const regular = assignments ? assignments.filter(({ annotator }) => annotator.login === user.login) : [];
const review = assignments ? assignments.filter(({ reviewer }) => reviewer.login === user.login) : [];
Expand Down
5 changes: 3 additions & 2 deletions client/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,18 @@ export const api = {

return volumes;
},
getAssignments: async (userId, reviewer) => {
getAssignments: async (userId, reviewer, getAll = false) => {
const assignments = [];

// Get user's assignments
const assignmentResponse = await axios.get(`/user/${ userId }/assignment`);

// Filter out duplicates and by status
const filtered = Object.values(assignmentResponse.data.reduce((assignments, assignment) => {
const filtered = Object.values(assignmentResponse.data.reduce((assignments, assignment, getAll) => {
assignments[assignment.item_id] = assignment;
return assignments;
}, {})).filter(({ status }) =>
getAll ? true :
status === 'awaiting review' || status === 'active' || status === 'under review'
);

Expand Down

0 comments on commit 3407fe2

Please sign in to comment.