Skip to content

Commit

Permalink
Skip 'orphaned' activities in the Schedule View component (thewca#9509)
Browse files Browse the repository at this point in the history
* Be more conservative about listing WCIF events

* Filter out orphaned activities

* Improve orphan detection
  • Loading branch information
gregorbg authored Jun 12, 2024
1 parent da07de0 commit 356c24d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
8 changes: 5 additions & 3 deletions app/webpacker/components/Schedule/CalendarView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React from 'react';
import {
earliestTimeOfDayWithBuffer,
getActivityEventId,
isOrphanedActivity,
latestTimeOfDayWithBuffer,
localizeActivityName,
} from '../../lib/utils/activities';
Expand All @@ -31,14 +32,15 @@ export default function CalendarView({
timeZone,
activeVenues,
activeRooms,
activeEvents,
activeEventIds,
calendarLocale,
wcifEvents,
}) {
const activeEventIds = activeEvents.map(({ id }) => id);
const fcActivities = activeRooms.flatMap((room) => room.activities
.filter((activity) => ['other', ...activeEventIds].includes(getActivityEventId(activity)))
.filter((activity) => !isOrphanedActivity(activity, wcifEvents))
.map((activity) => {
const eventName = activity.activityCode.startsWith('other') ? activity.name : localizeActivityName(activity, activeEvents);
const eventName = activity.activityCode.startsWith('other') ? activity.name : localizeActivityName(activity, wcifEvents);
const eventColor = activity.activityCode.startsWith('other') ? ACTIVITY_OTHER_GREY : room.color;

return ({
Expand Down
16 changes: 8 additions & 8 deletions app/webpacker/components/Schedule/TableView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
earliestWithLongestTieBreaker,
getActivityEventId,
getActivityRoundId,
groupActivities, localizeActivityName,
groupActivities,
isOrphanedActivity,
localizeActivityName,
} from '../../lib/utils/activities';
import { getSimpleTimeString } from '../../lib/utils/dates';
import { toDegrees } from '../../lib/utils/edit-schedule';
Expand Down Expand Up @@ -42,8 +44,10 @@ export default function TableView({
.flatMap((room) => room.activities)
.toSorted(earliestWithLongestTieBreaker);

const eventIds = activeEvents.map(({ id }) => id);
const visibleActivities = sortedActivities.filter((activity) => ['other', ...eventIds].includes(getActivityEventId(activity)));
const activeEventIds = activeEvents.map(({ id }) => id);
const visibleActivities = sortedActivities
.filter((activity) => ['other', ...activeEventIds].includes(getActivityEventId(activity)))
.filter((activity) => !isOrphanedActivity(activity, wcifEvents));

return (
<>
Expand All @@ -69,7 +73,6 @@ export default function TableView({
date={date}
timeZone={timeZone}
groupedActivities={groupedActivitiesForDay}
events={activeEvents}
rounds={activeRounds}
rooms={activeRooms}
isExpanded={isExpanded}
Expand All @@ -87,7 +90,6 @@ function SingleDayTable({
date,
timeZone,
groupedActivities,
events,
rounds,
rooms,
isExpanded,
Expand Down Expand Up @@ -137,7 +139,6 @@ function SingleDayTable({
key={representativeActivity.id}
isExpanded={isExpanded}
activityGroup={activityGroup}
events={events}
round={activityRound}
rooms={rooms}
timeZone={timeZone}
Expand Down Expand Up @@ -179,7 +180,6 @@ function HeaderRow({ isExpanded }) {
function ActivityRow({
isExpanded,
activityGroup,
events,
round,
rooms,
timeZone,
Expand All @@ -188,7 +188,7 @@ function ActivityRow({
const representativeActivity = activityGroup[0];
const { startTime, endTime } = representativeActivity;

const name = representativeActivity.activityCode.startsWith('other') ? representativeActivity.name : localizeActivityName(representativeActivity, events);
const name = representativeActivity.activityCode.startsWith('other') ? representativeActivity.name : localizeActivityName(representativeActivity, wcifEvents);
const eventId = representativeActivity.activityCode.startsWith('other') ? 'other' : parseActivityCode(representativeActivity.activityCode).eventId;

const activityIds = activityGroup.map((activity) => activity.id);
Expand Down
3 changes: 2 additions & 1 deletion app/webpacker/components/Schedule/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ export default function Schedule({
timeZone={activeTimeZone}
activeVenues={activeVenues}
activeRooms={activeRooms}
activeEvents={activeEvents}
activeEventIds={activeEventIds}
calendarLocale={calendarLocale}
wcifEvents={wcifEvents}
/>
) : (
<TableView
Expand Down
14 changes: 14 additions & 0 deletions app/webpacker/lib/utils/activities.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,17 @@ export const localizeActivityName = (activity, wcifEvents) => {

return localizeActivityCode(activity.activityCode, activityRound, activityEvent);
};

export const isOrphanedActivity = (activity, wcifEvents) => {
if (getActivityEventId(activity) === 'other') {
// 'other' activities are never matched to an event because by definition,
// they are not a standard WCA event.
return false;
}

const activityEvent = findActivityEvent(activity, wcifEvents);

return (
activityEvent === undefined || findActivityRound(activity, activityEvent.rounds) === undefined
);
};

0 comments on commit 356c24d

Please sign in to comment.