The Coforge iNFINI frontend receives dashboard records in a raw API response. Transform the response into a display-ready structure by keeping the newest record for each id, grouping records by status, and sorting each group for consistent rendering.
Implement transform_response(raw_response). The input is a dictionary with an items key containing a list of record dictionaries. Each record contains:
id: a unique string identifying the record, although duplicate IDs may occurtitle: a display title stringstatus: one of failed, pending, or activepriority: an integer from 1 to 5updatedAt: an ISO 8601 UTC timestamp in YYYY-MM-DDTHH:MM:SSZ formatFor duplicate IDs, retain the record with the later updatedAt. If timestamps are equal, retain the record with the higher priority.
Return a dictionary with a sections key. It must contain one section for each status in this order: failed, pending, active. Each section has status and cards keys. A card contains only id, title, priority, and updatedAt.
Within each section, sort cards by descending priority, then descending updatedAt, then ascending id.
id has at most 100 duplicate recordsstatus is one of failed, pending, or activepriority is an integer from 1 through 5updatedAt is a valid ISO 8601 UTC timestamp in fixed-width formatdef transform_response(raw_response):