All practice tasks

Coding (Platform)

Order History Pages

React · Medium · Pagination

An agent pages through checkout orders and searches for a customer’s order. In the supplied React screen, a slow response can overwrite a newer search and a new query can start on the previous query’s page. The API already owns tenant filtering and stable ordering; repair the browser-side request lifecycle.

Task

Show the current search page and its full matching total. Keep query changes, page navigation, retry, loading and out-of-order responses consistent.

Contract

  • Component props: HistoryApp receives api, tenantId and pageSize (default 2, allowed 1..50). These props stay stable during this mounted screen.
  • Provided API: api.list({tenantId,query,page,pageSize,signal}) returns a Promise of {items,total,nextPage}. page is a zero-based integer. query is trimmed before the request; no debounce is required. items contain {id,title,score}. The API already filters tenants and orders by score descending then ASCII ID ascending. total counts all matches before pagination. nextPage is page + 1 if another page exists, otherwise null. Promises can resolve or reject in any order and may finish even after their AbortSignal was aborted.

Acceptance criteria

  • Load query empty and page 0 at mount. Request a new page when the query or page changes.
  • A query change resets page to 0. Next page uses nextPage; Previous page subtracts one.
  • Keep page size and tenant in every request. Preserve the API row order and total.
  • On a new request clear previous rows and errors and show Loading orders. Disable both page buttons while loading or showing an error.
  • A successful current request shows N orders found and its rows. An empty successful page shows No orders found.
  • A failed current request shows Could not load orders and Retry. Retry sends the same query and page and clears the error.
  • Only the latest request can change rows, total, loading or error. Older successes and failures are ignored.
  • Abort the superseded request and all pending work on unmount; ignore any later completion.
  • Previous page is disabled on page 0; Next page is disabled when nextPage is null.

Constraints

  • At most 50 items per response, with unique ASCII IDs and titles of at most 120 characters. total is an integer 0..100000.
  • Search input is at most 80 characters. The fixture guarantees API shapes; malformed responses are not graded.
  • Do not implement the API, database, sorting or tenant authorization again in the browser. No real external network is required.

Editable files

  • src/HistoryApp.jsx — Repair search/page state and effect cleanup.
  • src/helpers.js — Optional helpers for this implementation.
  • tests/candidate.test.js — Add 3 new behavioral regressions; do not duplicate the supplied smoke test.

What this task practices

Order History Pages is a coding (platform) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as medium difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.