Commit 86e7ed20 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

Added SuggestedResource support from API contract through domain type, codec,...

Added SuggestedResource support from API contract through domain type, codec, and UI — the availability search table now shows
  the server's suggested resource per window and passes it to the reservation form on Book
parent 224fe704
Loading
Loading
Loading
Loading
+1 −4777

File changed.

Preview size limit exceeded, changes collapsed.

+25
Changes for docs/20260615_0042_availability_suggested_resource.md: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Availability Search: SuggestedResource Support

## What changed

The `POST /api/v1/availability/search` (and `/search/resource`) response now includes an optional `suggestedResource` field on each `AvailabilityWindow`. Implemented the full stack from domain type through codec to UI.

## Changes

### Domain (`src/domain/availability.ts`)
- Added `SuggestedResource` interface: `{ membershipId, tmf639Id, tmf639Name? }`
- Added optional `suggestedResource?: SuggestedResource` to `AvailabilityWindow`

### Codec (`src/adapters/api/mappers/pagination.ts`)
- Added `decodeSuggestedResource()` — returns `undefined` when `membershipId` or `tmf639Id` absent
- Updated `decodeAvailabilityWindow()` to decode `w.suggestedResource` and include it when present

### UI (`src/features/availability/AvailabilitySearchPage.tsx`)
- Added "Suggested Resource" column in the results table showing `tmf639Name ?? tmf639Id` or `—`
- `handleWindowSelect`: when no specific resource is selected in the dropdown, falls back to `w.suggestedResource?.membershipId` so the reservation form is pre-populated with the server's suggested resource

### Tests (`src/adapters/api/mappers/pagination.test.ts`)
- 3 new codec tests: absent → field omitted, full fields decoded, absent `tmf639Name` → field omitted

## Test results
- 683 tests, 57 files — all pass
+1
Changes for docs/index.md: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -65,3 +65,4 @@
| 2026-06-11 14:00 | [Availability search: pool and resource dropdowns](20260611_1400_availability_search_pool_resource_dropdowns.md) | Replaced free-text Pool ID/Membership ID fields and mode toggle in AvailabilitySearchPage with pool dropdown + conditional resource dropdown; mode implicit from selection; 7 tests pass |
| 2026-06-14 00:20 | [Blackouts page: pool and resource dropdowns](20260614_0020_blackouts_pool_resource_dropdowns.md) | Replaced free-text Scope Ref field with guided pool + conditional resource dropdowns in BlackoutsPage; New Blackout button disabled until scope selected; 675 tests passing |
| 2026-06-14 00:40 | [Pool Inventory page enhancements](20260614_0040_inventory_page_enhancements.md) | Added summary stat cards, utilization bars, pool category, StatusChip per resource, full resource list, and quick-nav buttons; 680 tests passing |
| 2026-06-15 00:42 | [Availability search: SuggestedResource support](20260615_0042_availability_suggested_resource.md) | Added SuggestedResource domain type; codec decodes it from AvailabilityWindow wire shape; UI shows Suggested Resource column and passes it to /reservations when no explicit resource is chosen; 683 tests passing |
+53
Changes for src/adapters/api/mappers/pagination.test.ts: 53 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -121,6 +121,59 @@ describe('decodeAvailabilityResult', () => {
    );
    expect(r.nextAvailability?.hour).toBe(6);
  });

  it('window without suggestedResource → field omitted', () => {
    const r = decodeAvailabilityResult(
      {
        windows: [
          { start: '2024-06-01T08:00:00Z', end: '2024-06-01T10:00:00Z', latestBookableStart: '2024-06-01T09:00:00Z' },
        ],
      },
      zone,
    );
    expect(r.windows[0].suggestedResource).toBeUndefined();
  });

  it('window with suggestedResource → decoded with all fields', () => {
    const r = decodeAvailabilityResult(
      {
        windows: [
          {
            start: '2024-06-01T08:00:00Z',
            end: '2024-06-01T10:00:00Z',
            latestBookableStart: '2024-06-01T09:00:00Z',
            suggestedResource: { membershipId: 'mem-1', tmf639Id: 'res-1', tmf639Name: 'My Resource' },
          },
        ],
      },
      zone,
    );
    expect(r.windows[0].suggestedResource).toEqual({
      membershipId: 'mem-1',
      tmf639Id: 'res-1',
      tmf639Name: 'My Resource',
    });
  });

  it('suggestedResource without tmf639Name → name field omitted', () => {
    const r = decodeAvailabilityResult(
      {
        windows: [
          {
            start: '2024-06-01T08:00:00Z',
            end: '2024-06-01T10:00:00Z',
            latestBookableStart: '2024-06-01T09:00:00Z',
            suggestedResource: { membershipId: 'mem-2', tmf639Id: 'res-2' },
          },
        ],
      },
      zone,
    );
    const sr = r.windows[0].suggestedResource;
    expect(sr?.membershipId).toBe('mem-2');
    expect(sr?.tmf639Id).toBe('res-2');
    expect(sr?.tmf639Name).toBeUndefined();
  });
});

// ─── buildActivityParams ──────────────────────────────────────────────────
+14
Changes for src/adapters/api/mappers/pagination.ts: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import type {
  LifecycleState,
  Page,
  ResourceSummary,
  SuggestedResource,
} from '@domain';
import type { DateTime } from 'luxon';
import { decodeDateTime, encodeDateTime } from './primitives';
@@ -53,11 +54,24 @@ export function decodeBrowsePage(

// ─── AvailabilityResult (bare, no pagination) ─────────────────────────────

function decodeSuggestedResource(
  w: WireAvailabilityWindow['suggestedResource'],
): SuggestedResource | undefined {
  if (!w?.membershipId || !w?.tmf639Id) return undefined;
  return {
    membershipId: w.membershipId,
    tmf639Id: w.tmf639Id,
    ...(w.tmf639Name != null && { tmf639Name: w.tmf639Name }),
  };
}

function decodeAvailabilityWindow(w: WireAvailabilityWindow, zone: string): AvailabilityWindow {
  const suggestedResource = decodeSuggestedResource(w.suggestedResource);
  return {
    start: decodeDateTime(w.start ?? '', zone),
    end: decodeDateTime(w.end ?? '', zone),
    latestBookableStart: decodeDateTime(w.latestBookableStart ?? '', zone),
    ...(suggestedResource != null && { suggestedResource }),
  };
}

Loading