Skip to content

Add activity-asset mapping tracking to booking system#58

Merged
Ross1116 merged 2 commits into
mainfrom
staging
May 12, 2026
Merged

Add activity-asset mapping tracking to booking system#58
Ross1116 merged 2 commits into
mainfrom
staging

Conversation

@Ross1116

@Ross1116 Ross1116 commented May 12, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Upload review lets you correct both asset type and work pattern; per-row work-pattern selector added.
    • Activity mappings now show asset roles and estimated hours; “Role” badges appear where applicable.
  • Improvements

    • Activity selection and booking flows now respect asset-mapping identifiers for more reliable context.
    • Asset type and work-pattern option values and display formatting updated across forms and dialogs.
  • Tests

    • Added coverage for mapping identifiers and normalization of mapping metadata.

Review Change Stack

@vercel

vercel Bot commented May 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sitespace-app Ready Ready Preview, Comment May 12, 2026 6:45am

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 49c8c369-2b79-4a80-a615-1e108fcf73db

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa2819 and e28da64.

📒 Files selected for processing (4)
  • src/components/lookahead/ActivityDrilldownDialog.tsx
  • src/components/lookahead/LookaheadDashboard.tsx
  • src/components/lookahead/UploadReviewDialog.tsx
  • src/lib/formOptions.ts
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/components/lookahead/LookaheadDashboard.tsx
  • src/components/lookahead/ActivityDrilldownDialog.tsx
  • src/components/lookahead/UploadReviewDialog.tsx
  • src/lib/formOptions.ts

📝 Walkthrough

Walkthrough

This PR extends the booking and lookahead system to track activity-asset mappings throughout the data flow. It adds activity_asset_mapping_id to booking types and queries, updates form options to standardized values, enhances the upload review dialog to correct both asset type and work pattern, and derives stable activity identities for reliable drilling and state matching.

Changes

Activity-Asset Mapping and Booking Context Enhancement

Layer / File(s) Summary
Type definitions and booking payload contracts
src/types/index.ts, src/hooks/bookings/api.ts
ApiBooking, TransformedBooking, and lookahead response types gain optional activity_asset_mapping_id. BookingCreatePayload adds the field. ActivityMappingResponse expands with programme_activity_id, asset_role, estimated_total_hours, profile_shape, label_confidence, requirement_source, status flags, subcontractor_id, and created_at.
Asset type and work profile form options
src/lib/formOptions.ts
ASSET_TYPE_OPTIONS updated to snake_case keys (e.g., crane, hoist, loading_bay, ewp, concrete_pump, excavator, forklift, telehandler, compactor, other, none); WORK_PROFILE_SHAPE_OPTIONS extended to include staged.
API normalization and mapping expansion
src/hooks/lookahead/api.ts, src/lib/apiNormalization.ts
normalizeMappings maps additional ActivityMappingResponse fields; fetchLookaheadActivities returns activity_asset_mapping_id; updateProgrammeMapping accepts/returns profile_shape; toApiBooking preserves activity_asset_mapping_id.
Booking context query with asset-mapping filter
src/hooks/lookahead/api.ts, src/hooks/lookahead/keys.ts
fetchProgrammeActivityBookingContext accepts optional activityAssetMappingId, sends activity_asset_mapping_id in the request, and maps it onto top-level response and nested linked_booking_group. lookaheadKeys.activityBookingContext includes activity_asset_mapping_id when provided.
Hook parameter extension for asset-mapping context
src/hooks/lookahead/useLookaheadQueries.ts, src/components/lookahead/LookaheadDashboard.tsx
ActivityParams and useProgrammeActivityBookingContext accept activityAssetMappingId, include it in SWR cache key and fetcher call, and update useMemo dependencies; LookaheadDashboard forwards derived mapping id into the hook and to ActivityDrilldownDialog.
API integration tests
src/hooks/lookahead/api.test.ts
Tests verify lookaheadKeys.activityBookingContext query with activityAssetMappingId; fetchProgrammeActivityBookingContext normalizes activity_asset_mapping_id at top level and in linked_bookings; fetchLookaheadActivities and fetchProgrammeMappings normalization tests added/extended.
Booking creation with activity-asset mapping
src/components/forms/CreateBookingForm.tsx
CreateBookingForm includes activity_asset_mapping_id in booking payload, sourced from activityContext (or null).
Asset type label formatting in forms
src/components/forms/CreateAssetForm.tsx, src/components/forms/UpdateAssetForm.tsx
CreateAssetForm and UpdateAssetForm import and use formatAssetType() when rendering asset-type dropdown labels.
Activity identity derivation for drilling and booking
src/components/lookahead/ActivityDrilldownDialog.tsx, src/components/lookahead/LookaheadDashboard.tsx
ActivityDrilldownDialog adds getActivityRowKey() to prefer trimmed activity_asset_mapping_id over activity_id for stable keys and booking-context comparisons; LookaheadDashboard derives and forwards activityAssetMappingId.
Upload review dialog with asset type and work pattern correction
src/components/lookahead/UploadReviewDialog.tsx, src/components/lookahead/LookaheadDashboard.tsx
UploadReviewDialog extends onCorrectMapping to accept { asset_type, profile_shape }, adds helpers (formatOptionalHours, getMatchingOption), per-row profileShapeDrafts, search/filtering including asset_role and profile_shape, row meta for estimated hours and profile shape, conditional "Role" badge, and a "Work pattern" dropdown; submission includes both asset_type and profile_shape. LookaheadDashboard forwards the correction object directly to updateProgrammeMapping.
Booking normalization test coverage
src/lib/apiNormalization.test.ts, src/lib/apiNormalization.ts
Tests updated to ensure activity_asset_mapping_id is preserved when normalizing bookings from API responses.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Ross1116/sitespace-app#47: Related — earlier work expanding lookahead/programme API and types around activity-asset mappings and profile shapes.
  • Ross1116/sitespace-app#26: Related — touches booking normalization and CreateBookingForm/booking payloads that intersect with this PR.
  • Ross1116/sitespace-app#53: Related — overlapping changes to mapping normalization and ActivityMappingResponse fields.

Poem

🐰 I hop with a mapping id tucked in my paw,

Fixing work patterns, adjusting with awe,
Asset types now snake_case and neat,
From upload to booking the data's complete,
A little rabbit clap for the mapping we saw.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 17.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title Check ✅ Passed Title check skipped as CodeRabbit has written the PR title.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch staging

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot changed the title @coderabbitai Add activity-asset mapping tracking to booking system May 12, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/lib/formOptions.ts (1)

1-23: ⚡ Quick win

Export derived union types from these option arrays.

This will prevent string drift in payload/types and catch invalid literals at compile time.

♻️ Proposed refactor
 export const ASSET_TYPE_OPTIONS = [
   "crane",
   "hoist",
   "loading_bay",
   "ewp",
   "concrete_pump",
   "excavator",
   "forklift",
   "telehandler",
   "compactor",
   "other",
   "none",
 ] as const;
+
+export type AssetTypeOption = (typeof ASSET_TYPE_OPTIONS)[number];

 export const WORK_PROFILE_SHAPE_OPTIONS = [
   "single_day",
   "flat",
   "front_loaded",
   "back_loaded",
   "bell",
   "inverse_bell",
   "staged",
 ] as const;
+
+export type WorkProfileShapeOption =
+  (typeof WORK_PROFILE_SHAPE_OPTIONS)[number];
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/formOptions.ts` around lines 1 - 23, The option arrays
ASSET_TYPE_OPTIONS and WORK_PROFILE_SHAPE_OPTIONS are fine but you should export
derived union types to prevent string drift; add exported type aliases (e.g.,
AssetType and WorkProfileShape) using the array literal types (typeof
ASSET_TYPE_OPTIONS[number] and typeof WORK_PROFILE_SHAPE_OPTIONS[number]) so
consumers and payload/types use the exact allowed literals derived from those
arrays rather than repeating raw strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/components/lookahead/ActivityDrilldownDialog.tsx`:
- Around line 31-32: The helper getActivityRowKey should treat
activity.activity_asset_mapping_id as empty when it is null, undefined, or a
string of only whitespace so React keys won't collide; change the logic in
getActivityRowKey to trim the mapping id and use it only if trimmed.length > 0,
otherwise return activity.activity_id (ensuring the return is a string). Apply
the same guard/trim-and-fallback pattern to the other locations that currently
use activity.activity_asset_mapping_id for keys/IDs (the similar usages near the
other getActivityRowKey occurrences) so every key/path uses the mapping id only
when nonblank and falls back to activity_id.

In `@src/components/lookahead/UploadReviewDialog.tsx`:
- Around line 328-340: The handler handleCorrect currently sends profile_shape:
profileShape || null which clears an existing mapping.profile_shape when
profileShape is undefined; change the payload so profile_shape is only changed
when the user explicitly provided a value: set profile_shape to
mapping.profile_shape (or null if absent) when profileShape is undefined,
otherwise use the provided profileShape (or null for an explicit empty value).
Apply the same fix to the other similar mapping-correction call sites in this
component that call onCorrectMapping so they preserve stored profile_shape
unless explicitly edited.

---

Nitpick comments:
In `@src/lib/formOptions.ts`:
- Around line 1-23: The option arrays ASSET_TYPE_OPTIONS and
WORK_PROFILE_SHAPE_OPTIONS are fine but you should export derived union types to
prevent string drift; add exported type aliases (e.g., AssetType and
WorkProfileShape) using the array literal types (typeof
ASSET_TYPE_OPTIONS[number] and typeof WORK_PROFILE_SHAPE_OPTIONS[number]) so
consumers and payload/types use the exact allowed literals derived from those
arrays rather than repeating raw strings.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 57e0ef41-14a9-441a-9337-cbc92a3107cf

📥 Commits

Reviewing files that changed from the base of the PR and between e768205 and 1fa2819.

📒 Files selected for processing (15)
  • src/components/forms/CreateAssetForm.tsx
  • src/components/forms/CreateBookingForm.tsx
  • src/components/forms/UpdateAssetForm.tsx
  • src/components/lookahead/ActivityDrilldownDialog.tsx
  • src/components/lookahead/LookaheadDashboard.tsx
  • src/components/lookahead/UploadReviewDialog.tsx
  • src/hooks/bookings/api.ts
  • src/hooks/lookahead/api.test.ts
  • src/hooks/lookahead/api.ts
  • src/hooks/lookahead/keys.ts
  • src/hooks/lookahead/useLookaheadQueries.ts
  • src/lib/apiNormalization.test.ts
  • src/lib/apiNormalization.ts
  • src/lib/formOptions.ts
  • src/types/index.ts

Comment thread src/components/lookahead/ActivityDrilldownDialog.tsx Outdated
Comment thread src/components/lookahead/UploadReviewDialog.tsx
@Ross1116 Ross1116 merged commit dbc9385 into main May 12, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant