Commit 70b6fe4c authored by Christos Tranoris's avatar Christos Tranoris
Browse files

change span button

parent 4ab92ec6
Loading
Loading
Loading
Loading
+49
Changes for docs/20260809_1452_remove_memberships_menu.md: 49 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Remove the Memberships nav entry

**Date:** 2026-08-09 14:52
**Scope:** `src/features/shell/Shell.tsx`, `src/features/shell/Shell.test.tsx`

## What changed

The sidebar no longer offers **Memberships** as a top-level destination. The
`/memberships` route, the `MembershipsListPage`, and the `canManageMemberships`
capability are all untouched.

## Why the route stays

Memberships is not a destination of its own — it is always reached *about a pool*:

- the Inventory detail panel's **View Memberships** link,
- the dangling-member links on the inventory and pool pages,
- direct deep links carrying a `poolId`.

Opened cold from the drawer, the page has no pool to talk about, so the nav entry
was the one way to reach it in a state where it could not show anything useful.
Removing the entry while keeping the route removes exactly that entry point and
breaks none of the links above.

## Changes

| File | Change |
|---|---|
| `src/features/shell/Shell.tsx` | Dropped the `{ label: 'Memberships', to: '/memberships', … }` item from `navItems` and the now-unused `PeopleAltIcon` import. |
| `src/features/shell/Shell.test.tsx` | Renamed the admin case to *"admin sees every nav link"* and removed its Memberships assertion; added the missing **Purge** assertion while there; dropped the vacuous Memberships queries from the requester/auditor cases; added a regression test asserting the link is absent even for an admin. |

The new test:

```ts
// Memberships is not a destination of its own: every route to it starts from a pool, and the
// page itself needs a poolId to show anything. The route stays for those links.
it('offers no Memberships nav link, even to an admin', () => {
  renderShell(['chronos.admin']);
  expect(screen.queryByRole('link', { name: 'Memberships' })).toBeNull();
});
```

## Verification

- `npx vitest run` — **1025/1025 passing**, 67 files.
- `npm run lint` — 106 errors, all pre-existing `no-explicit-any`; no change to the baseline.
- `npx tsc -b --force` — no new errors. The pre-existing `Shell.tsx` `TS2339: Property 'badge'
  does not exist` line reports a shorter union now that one nav item is gone; the error itself
  is unchanged and predates this work.
+84
Changes for docs/20260809_1455_pool_resource_availability_link.md: 84 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Search one resource's availability straight from the pool's member list

**Date:** 2026-08-09 14:55
**Scope:** `src/features/pools/PoolDetailPage.tsx`,
`src/features/availability/AvailabilitySearchPage.tsx`, plus their tests

## What changed

Each resource row on `/pools/{id}` now carries a **Search availability of _resource_**
action that opens the availability search already scoped to that pool *and* that
resource:

```
/availability?poolId=<poolId>&membershipId=<membership.id>
```

Previously "when is *this* resource free?" meant leaving the pool, opening the
availability page, re-picking the pool from a dropdown, and re-picking the resource
from a second dropdown — retyping information that was on screen a moment earlier.

## Design notes

**The parameter name is not new.** `membershipId` is the same parameter the
availability page already *writes* when it hands a chosen window on to the
reservation form (`bookingHandoff.ts`). The page now reads it as well, so the
handoff works in both directions and there is one name for one thing.

**The search wants a TMF639 id, the link carries a membership id.** The page keeps
resolving the selection through the loaded membership page
(`memberships.content.find(m => m.id === membershipId)`) and sends
`m.tmf639Id` on the wire. The link therefore carries the id the pool row already has,
and the codec boundary keeps owning the translation.

**One shared Actions column.** The members table previously showed the extract and
cleanup buttons only to an admin. Adding a second gate would have produced an empty
column for some users and none for others, so the column is now driven by

```ts
const showActions = caps.canSearchAvailability || caps.canManageMemberships;
```

with `colSpan = 6 + (showActions ? 1 : 0)` for the empty-state row. A requester —
who manages no memberships but does book — now gets exactly one action; an auditor,
who can do neither, gets no column at all rather than a blank one.

**Dangling members get no link.** A dangling membership's resource is gone from the
inventory, so a search about it would answer about something that is not there. The
button is gated on `caps.canSearchAvailability && expandable && !m.dangling`; the
admin's cleanup button still appears for those rows in the same column.

**The icon does not expand the row.** The member row is itself a toggle for the
per-resource reservations panel, so the button's `onClick` calls
`e.stopPropagation()` before navigating.

## Changes by file

| File | Change |
|---|---|
| `src/features/pools/PoolDetailPage.tsx` | `MembersPanel` takes `useNavigate()`; new inline `AvailabilityIcon` (MUI `EventAvailable` path); shared `showActions` column with the new per-row `IconButton` (aria-label `Search availability of <tmf639Id>`, tooltip "Search this resource's availability"). |
| `src/features/availability/AvailabilitySearchPage.tsx` | Seeds `membershipId` state from `searchParams.get('membershipId')`, the same way `poolId` and the range are already seeded. |
| `src/features/pools/pools.test.tsx` | `makeMembersWrapper` now takes `{ listByResource, members, roles }` and mounts a `LocationProbe` inside the `MemoryRouter`, so the destination URL is asserted from the real router rather than a mocked `navigate`. Five new tests. |
| `src/features/availability/AvailabilitySearchPage.test.tsx` | Two new tests for arriving with `?poolId=…&membershipId=…`. |

## Tests added

`MembersPanel — search availability of one resource`:

- sends the row to `/availability?poolId=pool-1&membershipId=mem-1`;
- does not expand the row on its way there;
- offers nothing for a dangling member, while its cleanup button remains;
- is offered to a requester, who gets no membership actions;
- drops the Actions column entirely for an auditor.

`AvailabilitySearchPage — preselected resource from the URL`:

- preselects the resource named in the query string;
- searches that resource (`membershipId: 'res-1'` — the TMF639 id) rather than the pool.

## Verification

- `npx vitest run` — **1025/1025 passing**, 67 files (+7 from this change and the
  memberships-menu removal).
- `npm run lint` — 106 errors, all pre-existing `no-explicit-any`; baseline unchanged.
- `npx tsc -b --force` — no new errors versus the stored baseline.
+116
Changes for docs/20260809_1530_reservation_requires_membership.md: 116 added lines, 0 removed lines.
Original line number Diff line number Diff line
# "membershipId must not be null" — every reservation targets a resource

**Date:** 2026-08-09 15:30
**Reported as:** availability search → *Clip to calendar* → **Book whole span** → **Create Reservation**
returns

```json
{"status":400,"code":"VALIDATION",
 "detail":"Cannot construct instance of `FeasibilityRequest`, problem: membershipId must not be null"}
```

## What was actually wrong

Both booking forms labelled the resource **"Resource (optional)"** and offered an
**"— Any resource —"** entry, and the codec dropped the field when it was empty:

```ts
...(d.membershipId != null && { membershipId: d.membershipId }),
```

There is no such request. `FeasibilityRequest` lists `membershipId` in its
`required` set, and the contract spells it out: *"Membership row that binds the
target resource to the pool. **Required for every pool category, capacity pools
included.**"* "Any resource" was a UI invention — the server answers it with a 400,
and there is no pool-level booking to fall back to.

The span path is simply where it showed up most: a pool-level `CLIP_TO_CALENDAR`
search has no resource selected, so **Book whole span** handed the form nothing and
the 400 arrived on the *next* click, after the operator had already filled
everything in. The single-window **Book** path was luckier — it already fell back to
the window's `suggestedResource` — but a window without a suggestion failed the same way.

## The fix, per layer

**Domain — `FeasibilityDraft.membershipId` is required.** The type now says what the
contract says, so the unsendable request cannot be constructed at all. Making it
required immediately surfaced every construction site through `tsc -b`; each one is a
real caller that needed a resource.

```ts
export interface FeasibilityDraft {
  poolId: string;
  /**
   * The membership row binding the target resource to the pool. Required — the contract states it
   * for every pool category, capacity pools included, and a request without it is rejected with a
   * 400 rather than being read as "any resource". There is no pool-level booking to express.
   */
  membershipId: string;
```

**Codec — sent unconditionally.** `encodeFeasibilityDraft` no longer widens the wire
type to make the field optional; the `WireFeasibilityRequestOut` alias and its
rationale are gone, and the encoder returns the generated `WireFeasibilityRequest`
unchanged.

**Both booking forms — the resource is a required field.** `FirmReservationForm` and
`HoldRequestForm`:

- label it **"Resource"**, `required`, with the "— Any resource —" option removed;
- include it in `canSubmit`, so **Create Reservation** / **Request Hold** stays
  disabled until a resource is chosen instead of failing after the click;
- show `This pool has no resources to book.` as an error helper when the selected
  pool has no members — an empty dropdown and a dead button explain nothing;
- **keep** the chosen resource when an alternative is taken. Both forms used to clear
  it; the alternative kinds are all start/end moves (`EARLIEST_FEASIBLE_START`,
  `LATEST_FEASIBLE_END`, `EARLIEST_FEASIBLE_END`), so the target never changed — and
  clearing it now would leave the form unsubmittable.

**Availability search — the span handoff carries a resource when it can.**

```ts
function spanSuggestedMembershipId(): string {
  const ids = (results?.windows ?? []).map(w => w.suggestedResource?.membershipId);
  const [first] = ids;
  return first && ids.every(id => id === first) ? first : '';
}
```

A span is booked against one membership, so a server suggestion only carries over
when **every** window of the preview names the same resource. Windows that disagree
(or a window with no suggestion) would make the choice arbitrary; the form asks for
one instead — and now refuses to submit without it. The search page's own
"Resource (optional)" filter is untouched: pool-level *searching* is supported, it is
only pool-level *booking* that is not.

## Changed files

| File | Change |
|---|---|
| `src/domain/gateways.ts` | `FeasibilityDraft.membershipId` required, with the contract quote as its comment. |
| `src/adapters/api/mappers/entities.ts` | `encodeFeasibilityDraft` sends `membershipId` unconditionally; `WireFeasibilityRequestOut` removed. |
| `src/features/reservations/FirmReservationForm.tsx` | Required Resource select, `canSubmit` gate, empty-pool helper, alternative keeps the resource. |
| `src/features/reservations/HoldRequestForm.tsx` | Same. |
| `src/features/availability/AvailabilitySearchPage.tsx` | `spanSuggestedMembershipId()`; `handleBookSpan` carries an agreed suggestion. |
| Test fixtures (`gateways.test.ts`, `app/reservations.test.ts`, `test/integration.test.tsx`, `mappers/entities.test.ts`) | Drafts carry a `membershipId`. |

## Tests

- `entities.test.ts`: *"omits membershipId for a pool-level request instead of sending null"* —
  which pinned the bug — replaced by **"always sends membershipId"**.
- `FirmReservationForm.test.tsx`: Submit stays disabled until a resource is chosen;
  the empty-pool message; the alternative keeps the resource. `fillValidForm()` now
  picks a resource, and the default membership mock is a populated page.
- `HoldRequestForm.test.tsx`: the same three, plus *"calls useRequestHold with the
  draft (no membershipId when no resource selected)"* rewritten to assert the
  membership is **always** present.
- `AvailabilitySearchPage.test.tsx`: **Book whole span** carries the suggested
  resource when every window agrees; carries none when the windows disagree; carries
  none when a window has no suggestion.

## Verification

- `npx vitest run` — **1033/1033 passing**, 67 files (+8).
- `npm run lint` — 104 errors, all pre-existing `no-explicit-any` (two fewer than the
  106 baseline; the rewritten mocks needed fewer casts).
- `npx tsc -b --force` — no new errors versus the baseline.
+59
Changes for docs/20260809_1545_nav_availability_after_pools.md: 59 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Nav: Availability moves next to Pools, Assessment leaves the drawer

**Date:** 2026-08-09 15:45
**Asked for:** *"move availability menu after pools and remove menu Assessment"*

## Availability, second

```ts
{ label: 'Pools',        to: '/pools',        icon: <StorageIcon />,          show: caps.canManagePools },
// Next to Pools: "when is this free?" is asked about a pool, and the pool pages link into it.
{ label: 'Availability', to: '/availability', icon: <CalendarViewWeekIcon />, show: caps.canSearchAvailability },
{ label: 'Reservations', to: '/reservations', icon: <EventNoteIcon />,        show: caps.canCreateReservations },
```

It used to sit below Reservations, three entries away from the page that hands work
to it. Availability is asked *about a pool* — `/pools/{id}` now links straight into
it per resource (`20260809_1455`), and the search page's first field is the pool —
so the drawer reads in the order the work happens: pick a pool, ask when it is free,
book it.

## Assessment, gone from the drawer

The **Assessment** entry and its `AssignmentIcon` import are removed. The
`/assessment` route, `AssessmentPage` and the capability all stay — this is the same
call made for Memberships (`20260809_1452`): assessment answers a question *about a
service order*, and opened cold from the drawer there is no order to assess. The
route remains for the links and deep links that carry one.

## Changed files

| File | Change |
|---|---|
| `src/features/shell/Shell.tsx` | `navItems` reordered; Assessment entry and `AssignmentIcon` import deleted. |
| `src/features/shell/Shell.test.tsx` | Assessment dropped from the admin nav test; two regression tests added. |

## Tests

```ts
it('offers no Assessment nav link, even to an admin', …)

it('places Availability directly after Pools', () => {
  renderShell(['chronos.admin']);
  const labels = screen.getAllByRole('link').map(l => l.textContent);
  expect(labels.indexOf('Availability')).toBe(labels.indexOf('Pools') + 1);
});
```

The order test reads the rendered link list rather than the `navItems` array, so it
fails if the drawer is reordered *or* if a capability hides Pools from under it.
The requester test was renamed to match what it actually asserts
(`'requester sees Reservations and Activity; does not see Pools or Statistics'`).

## Verification

- `npx vitest run` — **1035/1035 passing**, 67 files.
- `npm run lint` — 104 errors, all pre-existing `no-explicit-any`.
- `npx tsc -b --force` — no new errors. The one pre-existing `Shell.tsx`
  `Property 'badge' does not exist` error changes only its *message* text, because
  the union it prints now lists `Availability` second.
+98
Changes for docs/20260809_1605_availability_book_span_button.md: 98 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Availability results — "Book whole span" is a button, and the row action says "Book separate"

**Date:** 2026-08-09 16:05
**Asked for:** *"in availability page make the Book whole span a button, since within the info box
does not look good. better write Book separate all book whole span"*

## What was there

In `CLIP_TO_CALENDAR` mode the span action lived in the `action` slot of an info
`Alert` above the table:

```tsx
<Alert severity="info" action={<Button size="small" onClick={handleBookSpan}>Book whole span</Button>}>
  Booking this span reserves all {results.windows.length} windows as one group.
</Alert>
```

Two things were wrong with it. An info box is where an operator reads a notice, not
where they look for something to click, and the alert's `action` slot renders a
low-emphasis text button — the *primary* way to use a clipped preview looked like a
footnote. And each table row's button still read **Book**, so the page offered two
differently-scoped bookings under the same word.

## What it is now

The count line became the results' header row: the count on the left, the span
button on the right as a `contained` button of its own, with one caption naming both
actions.

```tsx
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2, flexWrap: 'wrap', mb: 1 }}>
  <Typography variant="subtitle2">
    {results?.windows.length} available window{results?.windows.length === 1 ? '' : 's'}
  </Typography>

  {spanBookable && (
    <>
      {/* Two ways to book the same preview, so each says which windows it takes */}
      <Typography variant="caption" color="text.secondary">
        <strong>Book separate</strong> reserves one window;{' '}
        <strong>Book whole span</strong> reserves all {results!.windows.length} as one group.
      </Typography>
      <Button variant="contained" size="small" onClick={handleBookSpan}
              sx={{ ml: { xs: 0, sm: 'auto' }, whiteSpace: 'nowrap' }}>
        Book whole span
      </Button>
    </>
  )}
</Box>
```

The row action is renamed only while both are on screen, so nothing changes for a
plain `STRICT` search or for the embedded picker:

```tsx
{onWindowSelect ? 'Select' : spanBookable ? 'Book separate' : 'Book'}
```

The condition that gated the alert is now a named flag, since three places read it:

```ts
// Only a clipped preview describes a span, and only the routed page can navigate to the form —
// embedded in a picker there is nothing to hand the span to.
const spanBookable = isClipped && !onWindowSelect && !noWindows;
```

Behaviour is untouched: `handleBookSpan` and `handleWindowSelect` are the same
functions with the same query strings, including the agreed-suggestion resource
handoff from `20260809_1530`. `Alert` is no longer imported by this page.

## Changed files

| File | Change |
|---|---|
| `src/features/availability/AvailabilitySearchPage.tsx` | Span action lifted out of the `Alert` into a header row beside the count; `spanBookable` flag; row label becomes "Book separate" alongside it; `Alert` import removed. |
| `src/features/availability/AvailabilitySearchPage.test.tsx` | Two tests added. |

## Tests

```ts
it('offers the span action as a button of its own, not inside an info alert', …)
  // asserts no role="alert" on the page and span.closest('.MuiAlert-root') === null

it('names the per-window action "Book separate" while the span button is offered', …)
  // "Book" in STRICT; "Book separate" once Clip to calendar is picked
```

The existing `getByRole('button', { name: /book whole span/i })` queries — the
clipped-mode test and the three suggested-resource span tests — all still resolve:
the caption mentions the same words but is a `Typography`, not a button. The row's
`aria-label="select window {i}"` is unchanged, so the row queries were unaffected by
the rename.

## Verification

- `npx vitest run` — **1037/1037 passing**, 67 files (+2).
- `npm run lint` — 104 errors, all pre-existing `no-explicit-any`.
- `npx tsc -b --force` — no new errors versus the baseline.
Loading