Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/store/reducerHandlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ describe('reducer handlers', () => {
groupCount: 4,
});

const updatedActivity = (next.wcif as any)?.venues?.[0]?.rooms?.[0]?.activities?.[0];
expect(getActivityConfigExtensionData(updatedActivity)).toEqual({ groupCount: 4 });
const updatedActivity = next.wcif?.schedule.venues[0].rooms[0].activities[0];
expect(getActivityConfigExtensionData(updatedActivity!)).toEqual({ groupCount: 4 });
expect(next.wcif).not.toHaveProperty('venues');
expect(next.changedKeys.has('schedule')).toBe(true);
});

Expand Down
29 changes: 16 additions & 13 deletions src/store/reducerHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,21 +119,24 @@ export const reducers: Record<string, ReducerFunction> = {
changedKeys: new Set([...state.changedKeys, 'schedule']),
wcif: state.wcif && {
...state.wcif,
venues: state.wcif.schedule.venues.map((venue: Venue) => ({
...venue,
rooms: venue.rooms.map((room: Room) => ({
...room,
activities: room.activities.map((activity: Activity) => {
if (activity.id === action.activityId) {
return setActivityConfigExtensionData(activity, {
groupCount: action.groupCount,
});
}
schedule: {
...state.wcif.schedule,
venues: state.wcif.schedule.venues.map((venue: Venue) => ({
...venue,
rooms: venue.rooms.map((room: Room) => ({
...room,
activities: room.activities.map((activity: Activity) => {
if (activity.id === action.activityId) {
return setActivityConfigExtensionData(activity, {
groupCount: action.groupCount,
});
}

return activity;
}),
return activity;
}),
})),
})),
})),
},
},
};
},
Expand Down
20 changes: 20 additions & 0 deletions src/store/reducers/_tests_/competitorAssignments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,25 @@ describe('competitorAssignments reducers', () => {
expect(getGroupifierActivityConfig(updatedActivityTwo)?.featuredCompetitorWcaUserIds).toEqual([
10,
]);
expect(nextState.changedKeys.has('persons')).toBe(true);
expect(nextState.changedKeys.has('schedule')).toBe(true);
});

it('does not mark schedule when featured competitors do not change', () => {
const activity = buildActivity({ id: 1, activityCode: '333-r1' });
const person = buildPerson({
registrantId: 1,
assignments: [
{ activityId: 1, assignmentCode: 'competitor', stationNumber: null },
] as Assignment[],
});
const state = buildState(buildWcif([activity], [person]));

const nextState = bulkRemovePersonAssignments(state, {
assignments: [{ activityId: 1 }],
});

expect(nextState.changedKeys.has('persons')).toBe(true);
expect(nextState.changedKeys.has('schedule')).toBe(false);
});
});
2 changes: 2 additions & 0 deletions src/store/reducers/_tests_/roundActivities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('roundActivities reducers', () => {
const nextAssignments = nextState.wcif?.persons[0].assignments ?? [];
expect(nextState.needToSave).toBe(true);
expect(nextState.changedKeys.has('schedule')).toBe(true);
expect(nextState.changedKeys.has('persons')).toBe(false);
expect(nextActivities[0].childActivities).toEqual([childActivity]);
expect(nextAssignments[0]).toBe(unrelatedAssignment);
});
Expand Down Expand Up @@ -109,5 +110,6 @@ describe('roundActivities reducers', () => {
...matchingAssignment,
activityId: matchingChild.id,
});
expect(nextState.changedKeys.has('persons')).toBe(true);
});
});
30 changes: 26 additions & 4 deletions src/store/reducers/competitorAssignments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const fixFeaturedCompetitors = (wcif: Competition, registrantId: number): Compet
}

const wcaUserId = person.wcaUserId;
let scheduleChanged = false;

// Get all activity IDs where this person has a competitor assignment
const competitorActivityIds = new Set(
Expand All @@ -64,6 +65,7 @@ const fixFeaturedCompetitors = (wcif: Competition, registrantId: number): Compet
// Remove from featured if they're listed but don't have a competitor assignment
if (isFeatured && !hasCompetitorAssignment) {
const updatedIds = config.featuredCompetitorWcaUserIds.filter((id) => id !== wcaUserId);
scheduleChanged = true;

return setGroupifierActivityConfig(activity, {
...config,
Expand Down Expand Up @@ -93,6 +95,10 @@ const fixFeaturedCompetitors = (wcif: Competition, registrantId: number): Compet
)
);

if (!scheduleChanged) {
return wcif;
}

return {
...wcif,
schedule: newSchedule,
Expand Down Expand Up @@ -131,7 +137,11 @@ export const removePersonAssignments = (
return determineErrors({
...state,
needToSave: true,
changedKeys: new Set([...state.changedKeys, 'persons']),
changedKeys: new Set([
...state.changedKeys,
'persons',
...(updatedWcif.schedule !== state.wcif.schedule ? (['schedule'] as const) : []),
]),
wcif: updatedWcif,
});
};
Expand All @@ -153,7 +163,11 @@ export const upsertPersonAssignments = (
return determineErrors({
...state,
needToSave: true,
changedKeys: new Set([...state.changedKeys, 'persons']),
changedKeys: new Set([
...state.changedKeys,
'persons',
...(updatedWcif.schedule !== state.wcif.schedule ? (['schedule'] as const) : []),
]),
wcif: updatedWcif,
});
};
Expand Down Expand Up @@ -249,7 +263,11 @@ export const bulkRemovePersonAssignments = (
return determineErrors({
...state,
needToSave: true,
changedKeys: new Set([...state.changedKeys, 'persons']),
changedKeys: new Set([
...state.changedKeys,
'persons',
...(updatedWcif.schedule !== state.wcif.schedule ? (['schedule'] as const) : []),
]),
wcif: updatedWcif,
});
};
Expand Down Expand Up @@ -287,7 +305,11 @@ export const bulkUpsertPersonAssignments = (
return determineErrors({
...state,
needToSave: true,
changedKeys: new Set([...state.changedKeys, 'persons']),
changedKeys: new Set([
...state.changedKeys,
'persons',
...(updatedWcif.schedule !== state.wcif.schedule ? (['schedule'] as const) : []),
]),
wcif: updatedWcif,
});
};
14 changes: 13 additions & 1 deletion src/store/reducers/roundActivities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,23 @@ export const updateRoundChildActivities = (
] as const)
.filter((entry): entry is readonly [number, number] => entry[1] !== undefined)
);
const assignmentsChanged = state.wcif.persons.some((person) =>
person.assignments?.some((assignment) => {
const nextChildActivityId = replacementChildActivityIdsByPreviousId.get(
assignment.activityId
);
return nextChildActivityId !== undefined && nextChildActivityId !== assignment.activityId;
})
);

return {
...state,
needToSave: true,
changedKeys: new Set([...state.changedKeys, 'schedule']),
changedKeys: new Set([
...state.changedKeys,
'schedule',
...(assignmentsChanged ? ['persons' as const] : []),
]),
wcif: state.wcif && {
...state.wcif,
schedule: mapIn(state.wcif.schedule, 'venues', (venue) =>
Expand Down
Loading