Commit 0e4bd52e authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fix for pool resource reservations list

parent b93bef10
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+52
Changes for docs/20260806_1050_pool_resource_reservations.md: 52 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Pool detail — per-resource reservations

**Date:** 2026-08-06 10:50

## What & why

Operators on `/pools/{id}` had no way to see, per resource, what is booked against
it — they had to cross-reference the global Activity page. The backend added a new
endpoint that lists every reservation touching one TMF639 resource:

```
GET /api/v1/reservations/by-resource/{tmf639Id}
  ?activeOnly=<bool, default true>   # only capacity-holding states when true
  &type=<TENTATIVE_HOLD|FIRM>        # optional filter
  → 200: ReservationView[]           # plain array, server-sorted oldest booked-start first
```

The Members tab now makes each resource row **expandable**: clicking it reveals an
inline sub-table of that resource's reservations (firm bookings and tentative holds
alike), defaulting to `activeOnly=true` with an **Include past** checkbox to widen to
full history.

## Changes

- **Contract**: added the new path to `api-docs.json` (only delta vs the live spec;
  `ReservationView` unchanged) and regenerated `src/adapters/api/generated/schema.d.ts`
  via `npm run gen:types`.
- **Domain** (`domain/gateways.ts`): new `ResourceReservationQuery` type +
  `ActivityGateway.listReservationsByResource(tmf639Id, q?)` returning `Reservation[]`.
- **Adapter** (`adapters/api/gateways/activityGateway.ts`): implements the method —
  puts `tmf639Id` in the path, passes `activeOnly`/`type` as query params, maps the
  array through the existing `decodeReservation` codec.
- **App** (`app/queryKeys.ts`, `app/activity.ts`): `activity.byResource` query key +
  `useReservationsByResource(tmf639Id, q, enabled)` hook (fetches lazily).
- **UI** (`features/pools/PoolDetailPage.tsx`): expandable member rows (chevron +
  clickable row, copying the Calendars-tab pattern) and a new `ResourceReservationsPanel`
  rendering Type / State / Booked / Effective / Indicators, with the Include-past toggle.
- **Shared display** (`features/activity/reservationDisplay.tsx`): extracted
  `ReservationTypeChip`, `HoldExpiryChip`, `RowIndicators` out of `ActivityPage` so both
  the Activity page and the pool panel share one presentation vocabulary.
- **Tests**: MSW handler for the new endpoint; gateway tests (path/params/array-decode/
  empty); component tests for `ResourceReservationsPanel` (render, empty state, and the
  Include-past refetch with `activeOnly=false`).

## Verification

- `npx vitest run` — 717 tests pass (58 files).
- `npx vite build` — succeeds.
- `npm run lint` on all touched files — clean (the repo's pre-existing `no-explicit-any`
  errors in untouched files remain; this changeset adds none).
- Note: `tsc -b` / `npm run build` remain broken on the documented pre-existing MUI v9
  theme typing errors (`src/ui/theme.ts`), unrelated to this change.
+56
Changes for docs/20260806_1306_activate_reservation_promote_hold.md: 56 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Reservation detail — activate (promote a tentative hold to ACTIVE)

**Date:** 2026-08-06 13:06

## What & why

On `activity/reservations/{id}` the only lifecycle action was **Cancel**. The request
was to add, beside it, the ability to drive a reservation into the **ACTIVE** state.

### Finding: there is no "activate" endpoint — it's `promoteHold`

The live contract has no lifecycle/transition/`activate`/`provision` endpoint. A firm
reservation reaches ACTIVE on its own (`CREATED → PROVISIONING → ACTIVE`, backend-driven),
so the *only* operator-triggered path to ACTIVE is **promoting a tentative hold to a firm
reservation**:

```
POST /api/v1/reservations/holds/{holdId}/promote
  → 201 FeasibilityResponse (FEASIBLE — hold promoted to firm, now active)
  → 200 FeasibilityResponse (NOT_FEASIBLE / alternatives / conflict)
```

This was **already wired end-to-end** (`reservation.promoteHold` gateway method,
`usePromoteHold` hook with query invalidation) — it was just only surfaced in the
hold-request flow (`ActiveHoldsPanel`), never on the reservation detail page. So the new
"Activate" action only appears for reservations whose `type === 'TENTATIVE_HOLD'`; for a
firm reservation it renders nothing (there is nothing to promote).

## Changes

- **New** `features/activity/ActivateReservationButton.tsx` — mirrors
  `CancelReservationButton`:
  - Capability-gated on `canCreateReservations` (promotion creates a firm reservation).
  - Renders only for `TENTATIVE_HOLD`; disabled (with tooltip) when the hold has expired,
    when a cancellation is pending, or when the state isn't promotable
    (`PROMOTABLE_STATES = CREATED, PROVISIONING, PROVISIONING_FAILED`).
  - `ConfirmDialog` → `usePromoteHold().mutateAsync(reservation.id)`; the returned
    `FeasibilityResult` is shown via `OutcomePanel` (FEASIBLE / alternatives / conflict),
    and thrown `ProblemDetail`s via `ProblemDetailAlert`. On FEASIBLE the invalidated
    activity query refetches and the lifecycle chip flips to ACTIVE.
  - `variant` `'button'` (detail page) | `'icon'` (future table reuse), like the cancel button.
- **`features/activity/ReservationDetailPage.tsx`**: renders `<ActivateReservationButton>`
  above `<CancelReservationButton>` in the Actions section (siblings of the detail column so
  each keeps full width for its result/error panel).
- **Tests**: new `ActivateReservationButton.test.tsx` (promote call + id, type gating, capability
  gating, disabled-by-state / expired / cancel-pending, outcome render, error surfacing).
  `ReservationDetailPage.test.tsx` mock extended with `usePromoteHold`.

## Verification

- `npx vitest run` — **729 tests pass** (59 files).
- Touched-file ESLint — clean; the 2 `no-explicit-any` errors in `ReservationDetailPage.test.tsx`
  (lines 57/81) are **pre-existing at HEAD** (verified via `git stash`), untouched by this change.
- No contract/type regeneration needed — `promoteHold` was already in the committed schema.
- Note: `tsc -b` / `npm run build` remain broken on the documented pre-existing MUI v9 theme
  typing errors (`src/ui/theme.ts`), unrelated to this change.
+2
Changes for docs/index.md: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

| Date | File | Description |
|---|---|---|
| 2026-08-06 13:06 | [Reservation detail — activate (promote hold to ACTIVE)](20260806_1306_activate_reservation_promote_hold.md) | Added an Activate action beside Cancel on `activity/reservations/{id}`; the only operator path to ACTIVE is promoting a tentative hold (`POST /reservations/holds/{id}/promote`, already wired via `usePromoteHold`); new capability-gated, state-aware `ActivateReservationButton` shown only for holds, surfacing the FeasibilityResult via OutcomePanel; 729 tests passing |
| 2026-08-06 10:50 | [Pool detail — per-resource reservations](20260806_1050_pool_resource_reservations.md) | New `GET /reservations/by-resource/{tmf639Id}` endpoint surfaced on the Members tab: each resource row expands to an inline sub-table of its reservations (firm + tentative holds), defaulting to active-only with an Include-past toggle; extracted shared reservation-display chips |
| 2026-06-16 01:00 | [Dockerization with runtime config injection](20260616_0100_docker_runtime_config.md) | Added Dockerfile, docker-compose, nginx.conf, and entrypoint; app reads runtime window.__CHRONOS_CONFIG__ overlaid on build-time env so one image runs anywhere; found pre-existing `tsc -b`/`npm run build` breakage (MUI v9 theme types) |
| 2026-06-16 00:30 | [Documentation set (README hub + guides)](20260616_0030_documentation_set.md) | Rewrote README as a hub and added docs/guides/: developer, REST API, administrator, requester, auditor, and operations guides — grounded in capabilities.ts, api-docs.json, and the requirements spec |
| 2026-06-16 00:10 | [Reconcile MUI version in docs](20260616_0010_reconcile_mui_version_docs.md) | Updated v6 → v9 references across design v1.2, implementation plan v0.2, requirements, and README to match the installed MUI v9; left dated task logs as historical record |
+16
Changes for src/adapters/api/gateways/activityGateway.ts: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import type {
  Page,
  Reservation,
  ReservationQuery,
  ResourceReservationQuery,
} from '@domain';
import type { Transport } from '../transport';
import { decodeInconsistencyFlag } from '../mappers/entities';
@@ -36,6 +37,21 @@ export function createActivityGateway(transport: Transport, zone: string): Activ
      return decodePage(raw as WireResPage, w => decodeReservation(w, zone));
    },

    async listReservationsByResource(
      tmf639Id: string,
      q: ResourceReservationQuery = {},
    ): Promise<Reservation[]> {
      const params: Record<string, unknown> = {
        ...(q.activeOnly != null && { activeOnly: q.activeOnly }),
        ...(q.type != null && { type: q.type }),
      };
      const raw = await transport.request(
        `/api/v1/reservations/by-resource/${encodeURIComponent(tmf639Id)}`,
        { params },
      );
      return ((raw as WireReservation[] | null) ?? []).map(w => decodeReservation(w, zone));
    },

    async getReservation(id: string): Promise<Reservation> {
      const raw = await transport.request(`/api/v1/activity/reservations/${id}`);
      const activity = raw as { reservation?: WireReservation };
Loading