Skip to content
Open
101 changes: 101 additions & 0 deletions docs/decisions/TIG-337-compare-view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# TIG-337: side-by-side compare view (decision log)

Branch: `tig-337-tigerpath-side-by-side-parallel-view-for-comparing`. It's stacked on TIG-330
(`tig-330-tigerpath-implement-lucys-color-gradient-ui-on-the`), as the issue asks ("start it after TIG-330"),
so the compare boards use the gradient tokens.

## What ships

- **Backend:** `GET /api/v1/get_schedule/?planId=` and `GET /api/v1/get_requirements/?planId=` read any of
the user's own plans. Without `planId` they behave exactly as before (active plan). A plan id that is
missing, malformed or belongs to someone else returns 404. Neither read changes the active plan or writes anything.
- **`usePlanner`:** `comparePlanId` plus `compareSchedule`/`compareRequirements`, loaded through those
GETs only. Stale responses are dropped when the user switches quickly.
- **UI:** a **Compare** button next to the plan tabs opens a "Compare with" picker. The active plan is
editable on the left; the compared plan is read-only on the right. Each side shows a compact
requirement summary for every major and minor on that plan. Below 1100px it's one board at a time,
with a toggle between the two plans.

## Checks from the issue

| Check | How it's covered |
|---|---|
| Plans with different `additional_major_ids` each show their own requirements | `ComparePlanApiTest.test_each_plan_reports_its_own_majors`. Preview: plan b has two majors (SPI and POL). |
| Opening or closing compare never changes the active plan or writes a schedule | `test_compare_reads_never_change_active_plan_or_write` (plans' `schedule` and `updated_at` unchanged). Preview: zero non-GET requests across open, switch and close. |
| Selecting the same plan twice is blocked | The picker never lists the active plan (`compareOptions`, unit-tested); `setComparePlanId` refuses it as well. |
| Screenshots at 1440px and 1100px | In the PR. |

## Decisions

### D1. A read-only `planId` on the existing GETs, not a new endpoint

**Blocker:** both endpoints only ever returned the active plan (`get_active_plan`).
**Decision:** add an optional `planId` to the two existing GET views, scoped to `profile.schedule_plans`.
It's honored on GET only, so `update_schedule_and_get_requirements` (POST, which reuses
`get_requirements`) always answers for the active plan it just saved. Tested.
*Other option:* a separate `get_plan_snapshot` endpoint. That's more surface area for the same data.

### D2. The Figma has no finished side-by-side design

The file's only compare artifact is Angelina's low-fidelity grey "STEP 2: COMPARE" wireframe: two
halves, each with a majors/minors box. **Decision:** follow the issue's behavior spec and the existing new-planner
visual language (gradient tokens, plan-tab styling). Lucy should review the layout (see the PR).

### D3. Compare layout: two boards plus compact summaries; search and the full requirements panel are hidden

At 1440px a search column, two boards and two full `RequirementsPanel`s don't fit. Each board would be about 360px,
which truncates every course code. **Decision:** while comparing, the two boards take the full width (about 680px
each, close to the normal board), and each side gets a compact per-major/minor summary (the issue's
"compact per-major summary" fallback). Search, settling and external credits need the full panel,
so close compare to use them. Moving and removing courses on the left still works.
*Other option:* keep `RequirementsPanel` per side and drop the search column only. That's still too narrow at 1440px.

### D4. The read-only board renders without drag-and-drop

Both boards sit inside one `DragDropContext`. Reusing `Droppable`/`Draggable` on the right would duplicate the
`sem0`…`sem7` droppable ids. `Board readOnly` renders static markup instead: no remove button, no
grab cursor, no hover gradient, and no `#semesters` id (the tutorial targets the left board's).

### D5. Clicking the compared plan's tab swaps the sides

Making the compared plan active would otherwise put the same plan on both sides. **Decision:** the
previously active plan moves to the compare side. This is the only compare-related flow that writes,
because the user explicitly chose a new active plan (`set_active_plan`). It's the same request as clicking any tab.

### D6. Compare state isn't persisted

Compare closes on reload. Persisting it would mean a write (`user_state`) when opening compare, and
the issue says opening and closing compare must not write.

### D7. Summary text stays at WCAG AA

The summary's "x/y complete" count and the "not supported yet" label use the text color, because the existing
muted grey (4.31:1) and incomplete red (4.06:1) fall just under 4.5:1 on the tinted requirement card. Colored
dots carry each requirement's done/incomplete status.
*Not changed:* the existing full requirements panel still shows its red count on white (4.27:1). Flagged for follow-up.

### D8. The tutorial closes compare first

The tour highlights the search pane and requirements panel, which compare mode hides.

### D9. Print shows the active plan only

The compare side and the summaries are `dont-print`. The printout stays "My Four Year Schedule: <active plan>".

### D10. "By year" is the default compare layout; "Boards" stays as an option

Requested in review: line the two plans up year by year so each semester can be compared at a glance.
**Decision:** compare mode opens in **By year**: Freshman to Senior run top to bottom, each with a Fall row
and a Spring row. Each row holds one plan's courses on a single line, active plan on the left and compared plan
on the right, so the same semester sits side by side.
- **Differences** are shown by outline shape, not color alone. A solid outline means the course is only in this
plan; a dashed outline means it's in a different semester in the other plan (the chip's tooltip says which).
Courses in the same semester in both plans stay plain. A one-line summary counts each kind, and screen readers
get the same wording. Matching uses the catalog id (external credits match by name), over the eight board
semesters (`diffSchedules`, unit-tested).
- **The left plan stays editable:** each row is a horizontal drop target, so courses can be reordered, moved
between semesters (including by keyboard) or removed. Chips shrink and truncate to keep one line per semester;
the hover card shows the full name.
- **Below 1100px** the existing toggle shows one plan's column, still aligned by semester with the markers.
- **Printing** while comparing prints the active plan as a normal board.
- **Boards** (two four-year grids, the issue's literal ask) is one click away, so reviewers can choose.
197 changes: 173 additions & 24 deletions frontend/src/new/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import Board from './components/Board';
import RequirementsPanel from './components/RequirementsPanel';
import CourseDrawer from './components/CourseDrawer';
import SettingsModal from './components/SettingsModal';
import ComparePicker from './components/ComparePicker';
import CompareSummary from './components/CompareSummary';
import CompareByYear from './components/CompareByYear';
import './styles.css';

const semesterIndexOf = (droppableId) => parseInt(droppableId.replace('sem', ''), 10);

export default function App() {
const planner = usePlanner();
const { profile, plans, activePlan, schedule, requirements } = planner;
const { profile, plans, activePlan, schedule, requirements, comparePlan } = planner;
const comparing = Boolean(comparePlan);

const [searchQuery, setSearchQuery] = useState('');
const [searchResults, setSearchResults] = useState([]);
Expand All @@ -28,6 +32,10 @@ export default function App() {
const [pathModal, setPathModal] = useState(null); // {mode: 'create'|'edit', plan}
const [settingsOpen, setSettingsOpen] = useState(false);
const [creditPath, setCreditPath] = useState(null);
// Below 1100px compare mode shows one board at a time; this picks which.
const [compareView, setCompareView] = useState('active');
// 'year': semesters lined up across both plans (default); 'boards': two four-year boards.
const [compareLayout, setCompareLayout] = useState('year');

// main.jsx already applied the last-used theme before the first paint. Only apply (and remember)
// a theme once the profile says which one, so there is no flash to purple while it loads and a
Expand Down Expand Up @@ -101,12 +109,52 @@ export default function App() {

const switchToClassic = () => setUiVersion('classic').then(() => window.location.reload());

const centerTop = (
<div className="tp-center-top">
<PlanTabs
plans={plans}
activePlanId={activePlan?.id}
onSelect={planner.selectPlan}
onEdit={(plan) => setPathModal({ mode: 'edit', plan })}
onCreate={() => setPathModal({ mode: 'create' })}
/>
<ComparePicker
plans={plans}
activePlanId={activePlan?.id}
comparePlanId={comparePlan?.id ?? null}
onChange={(id) => {
setCompareView('active');
planner.setComparePlanId(id);
}}
/>
<span className="tp-save-state dont-print" aria-live="polite">
{planner.saving ? 'Saving…' : ''}
</span>
</div>
);

const activeBoard = schedule ? (
<Board
schedule={schedule}
classYear={profile?.classYear}
draggingSeason={draggingSeason}
onRemove={planner.removeCourse}
/>
) : (
<p className="tp-empty">Loading your plan...</p>
);

return (
<div className="tp-app" data-theme={themeName}>
<Header
onOpenSettings={() => setSettingsOpen(true)}
onSwitchToClassic={switchToClassic}
onStartTutorial={startTutorial}
onStartTutorial={() => {
// The tour points at the search pane and requirements panel, which compare mode hides.
if (!comparing) return startTutorial();
planner.setComparePlanId(null);
return requestAnimationFrame(() => requestAnimationFrame(startTutorial));
}}
/>

<div className="print-only tp-print-header">
Expand All @@ -118,6 +166,126 @@ export default function App() {
</div>

<DragDropContext onDragStart={onDragStart} onDragEnd={onDragEnd}>
{comparing ? (
<main className="tp-main comparing">
<div className="tp-compare" data-show={compareView}>
{centerTop}
{planner.notice && (
<div className={`tp-notice ${planner.notice.tone}`} role="status">
{planner.notice.text}
</div>
)}
<div className="tp-compare-controls dont-print">
<div className="tp-compare-layout" role="tablist" aria-label="Compare layout">
<button
type="button"
role="tab"
aria-selected={compareLayout === 'year'}
className={compareLayout === 'year' ? 'active' : ''}
onClick={() => setCompareLayout('year')}
>
By year
</button>
<button
type="button"
role="tab"
aria-selected={compareLayout === 'boards'}
className={compareLayout === 'boards' ? 'active' : ''}
onClick={() => setCompareLayout('boards')}
>
Boards
</button>
</div>
<div className="tp-compare-toggle" role="tablist" aria-label="Plan shown">
<button
type="button"
role="tab"
aria-selected={compareView === 'active'}
className={compareView === 'active' ? 'active' : ''}
onClick={() => setCompareView('active')}
>
{activePlan?.name || 'Active plan'}
</button>
<button
type="button"
role="tab"
aria-selected={compareView === 'compare'}
className={compareView === 'compare' ? 'active' : ''}
onClick={() => setCompareView('compare')}
>
{comparePlan.name}
</button>
</div>
</div>
{planner.compareError ? (
<div className="tp-notice error tp-compare-error" role="alert">
<p>Couldn&apos;t load {comparePlan.name} to compare. Your own plan is unaffected.</p>
<div className="tp-confirm-actions">
<button type="button" className="tp-btn tp-btn-save tp-btn-sm" onClick={planner.retryCompare}>
Try again
</button>
<button
type="button"
className="tp-btn tp-btn-neutral tp-btn-sm"
onClick={() => planner.setComparePlanId(null)}
>
Close compare
</button>
</div>
</div>
) : compareLayout === 'year' ? (
<>
<div className="dont-print tp-byyear-wrap">
<CompareByYear
activePlan={activePlan}
comparePlan={comparePlan}
schedule={schedule}
compareSchedule={planner.compareSchedule}
requirements={requirements}
compareRequirements={planner.compareRequirements}
draggingSeason={draggingSeason}
onRemove={planner.removeCourse}
/>
</div>
{/* Printing while comparing prints the active plan as a normal board. */}
<div className="print-only">
{schedule && <Board readOnly schedule={schedule} classYear={profile?.classYear} />}
</div>
</>
) : (
<div className="tp-compare-sides">
<section className="tp-compare-side active-side" aria-label={`${activePlan?.name || 'Active plan'} (editable)`}>
<header className="tp-compare-head">
<h2>{activePlan?.name || 'Active plan'}</h2>
<span className="tp-compare-tag editable">Editing</span>
</header>
<div className="dont-print">
<CompareSummary requirements={requirements} />
</div>
{activeBoard}
</section>
<section className="tp-compare-side compare-side dont-print" aria-label={`${comparePlan.name} (read-only)`}>
<header className="tp-compare-head">
<h2>{comparePlan.name}</h2>
<span className="tp-compare-tag">Read-only</span>
</header>
<CompareSummary requirements={planner.compareRequirements} />
{planner.compareSchedule ? (
<Board
readOnly
schedule={planner.compareSchedule}
classYear={profile?.classYear}
label={`${comparePlan.name} four-year plan (read-only)`}
/>
) : (
<p className="tp-empty">Loading {comparePlan.name}...</p>
)}
</section>
</div>
)}
</div>
</main>
) : (
<main className="tp-main">
<SearchPanel
query={searchQuery}
Expand All @@ -131,33 +299,13 @@ export default function App() {
/>

<div className="tp-center">
<div className="tp-center-top">
<PlanTabs
plans={plans}
activePlanId={activePlan?.id}
onSelect={planner.selectPlan}
onEdit={(plan) => setPathModal({ mode: 'edit', plan })}
onCreate={() => setPathModal({ mode: 'create' })}
/>
<span className="tp-save-state dont-print" aria-live="polite">
{planner.saving ? 'Saving…' : ''}
</span>
</div>
{centerTop}
{planner.notice && (
<div className={`tp-notice ${planner.notice.tone}`} role="status">
{planner.notice.text}
</div>
)}
{schedule ? (
<Board
schedule={schedule}
classYear={profile?.classYear}
draggingSeason={draggingSeason}
onRemove={planner.removeCourse}
/>
) : (
<p className="tp-empty">Loading your plan...</p>
)}
{activeBoard}
</div>

<RequirementsPanel
Expand All @@ -167,6 +315,7 @@ export default function App() {
onEditPlan={() => activePlan && setPathModal({ mode: 'edit', plan: activePlan })}
/>
</main>
)}
</DragDropContext>

<CourseDrawer
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/new/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@ export const updatePlanSettings = ({ planId, name, majorIds, minorCodes }) =>
minorCodes: JSON.stringify(minorCodes || []),
});

export const getSchedule = () => apiFetch('/api/v1/get_schedule/');
// Without a planId these read the active plan. With one (compare mode) they read that plan
// read-only; the server never changes the active plan for these GETs.
export const getSchedule = (planId) =>
apiFetch(planId == null ? '/api/v1/get_schedule/' : `/api/v1/get_schedule/?planId=${encodeURIComponent(planId)}`);
// "grouped" returns {majors, degrees, minors} covering every major on the plan.
export const getRequirements = () => apiFetch('/api/v1/get_requirements/?layout=grouped');
export const getRequirements = (planId) =>
apiFetch(
`/api/v1/get_requirements/?layout=grouped${planId == null ? '' : `&planId=${encodeURIComponent(planId)}`}`
);
export const saveScheduleAndGetRequirements = (strippedSchedule) =>
apiPost('/api/v1/update_schedule_and_get_requirements/?layout=grouped', {
schedule: JSON.stringify(strippedSchedule),
Expand Down
Loading
Loading