Skip to content

Commit

Permalink
Handle null people in pairing history
Browse files Browse the repository at this point in the history
- also try to prevent that from happening
  • Loading branch information
Pinwheeler committed Jan 8, 2025
1 parent 51f35a5 commit 07a2e44
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default async (
peopleSet.add(localPeople[r.person_id])
);

instance.people = Array.from(peopleSet);
instance.people = Array.from(peopleSet).filter((p) => p !== null);
snapshot.pairingInstances[idx] = instance;
snapshots[pairingTime] = snapshot;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
import { DateTime } from "luxon";
import React, { useContext } from "react";
import { ProjectPairingSnapshot } from "~/api/common/interfaces/parrit.interfaces";
import {
Person,
ProjectPairingSnapshot,
} from "~/api/common/interfaces/parrit.interfaces";
import { ProjectContext } from "../../contexts/ProjectContext";
import { TrashIcon } from "~/ui/TrashIcon";

interface Props {
pairingArrangement: ProjectPairingSnapshot;
}

const snip = (person?: Person): string => {
if (!person) {
return "null";
}
return person.name.slice(0, 3);
};

const PairingHistoryRecord: React.FC<Props> = (props) => {
const { pairingArrangement } = props;
const formattedDate = DateTime.fromISO(
Expand All @@ -20,7 +30,7 @@ const PairingHistoryRecord: React.FC<Props> = (props) => {
.map((instance) => {
const pbName = instance.pairingBoardName ?? "null";
// get the first 3 letters of each person's name
const names = instance.people.map((person) => person.name.slice(0, 3));
const names = instance.people.map(snip);
names.push(pbName.slice(0, 3));
// alphabetize the names
names.sort();
Expand Down
4 changes: 2 additions & 2 deletions app/routes/project.$projectId/hydrateProject.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export default async ({ request }: LoaderFunctionArgs): Promise<Project> => {
name: "Floating",
exempt: false,
},
people: Array.from(peopleMap.values()),
roles: Array.from(roleMap.values()),
people: Array.from(peopleMap.values()).filter((v) => v !== null),
roles: Array.from(roleMap.values()).filter((v) => v !== null),
};

return project;
Expand Down

0 comments on commit 07a2e44

Please sign in to comment.