Skip to content

feat: Update useSerialLogs to accept URL params#5674

Merged
steverydz merged 1 commit intomainfrom
WD-35798-serial-log-api-pagination
Apr 21, 2026
Merged

feat: Update useSerialLogs to accept URL params#5674
steverydz merged 1 commit intomainfrom
WD-35798-serial-log-api-pagination

Conversation

@steverydz
Copy link
Copy Markdown
Contributor

@steverydz steverydz commented Apr 17, 2026

Done

Updates the useSerialLogs hook so it accepts parameters for start time, end time and page size which will be passed to the backend API call

How to QA

Testing

  • This PR has tests
  • No testing required (explain why):

Security

  • Security considerations for review (list them):
    • Examples:
    • Access control: users can only access their own data
    • Input: user input is validated and sanitised
    • Sensitive data: secret or private data is not exposed in any way
    • ...
  • This PR has no security considerations (explain why): URL parameters are encoded

Issue / Card

Fixes https://warthogs.atlassian.net/browse/WD-36148

Screenshots

n/a

UX Approval

  • This PR does not require UX approval
  • This PR does require UX approval (add context):

Copilot AI review requested due to automatic review settings April 17, 2026 15:25
@webteam-app
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the serial logs fetch flow so consumers can request /serial-log with optional filtering/pagination query params, wiring the new params through the Flask endpoint and the React useSerialLogs hook.

Changes:

  • Add support for start-time, end-time, and page-size query params on the serial log API endpoint.
  • Update useSerialLogs to accept optional URL params and include them in the request URL / query cache key.
  • Add/extend Python and TS tests around the new parameters.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.

File Description
webapp/endpoints/models.py Reads start-time/end-time/page-size from the request and forwards them to the Store API call.
tests/endpoints/tests_models.py Adds new endpoint tests for serial-log requests that include query params.
static/js/publisher/hooks/useSerialLogs.ts Extends the hook signature to accept optional URL params and builds a URL with search params.
static/js/publisher/hooks/__tests__/useSerialLogs.test.tsx Adds hook tests for the new optional params.

Comment thread tests/endpoints/tests_models.py
Comment thread tests/endpoints/tests_models.py
Comment thread tests/endpoints/tests_models.py
Comment thread static/js/publisher/hooks/useSerialLogs.ts
Comment thread static/js/publisher/hooks/useSerialLogs.ts Outdated
Comment thread static/js/publisher/hooks/__tests__/useSerialLogs.test.tsx
Comment thread webapp/endpoints/models.py
@steverydz steverydz force-pushed the WD-35798-serial-log-api-pagination branch 2 times, most recently from 0fc2cc3 to 0251a4e Compare April 20, 2026 13:05
@edisile edisile requested review from Copilot and edisile April 20, 2026 14:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the serial log fetching flow to support pagination and time-range filtering by accepting URL query parameters in both the Flask endpoint and the React useSerialLogs hook.

Changes:

  • Extend /api/store/<id>/models/<model>/serial-log to forward start-time, end-time, page-size, and next-page query params to the Store API client.
  • Update useSerialLogs to construct a URL with optional query params and include them in the React Query cache key.
  • Add backend and frontend tests covering the new parameters.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
webapp/endpoints/models.py Reads new query params and forwards them to PublisherGW.get_store_model_serial_logs.
tests/endpoints/tests_models.py Adds endpoint tests verifying query params are passed through to the gateway call.
static/js/publisher/hooks/useSerialLogs.ts Adds optional URL params support and uses a constructed URL for fetch.
static/js/publisher/hooks/tests/useSerialLogs.test.tsx Adds MSW-based tests asserting the hook sends the correct query params.

Comment thread webapp/endpoints/models.py
Comment thread static/js/publisher/hooks/useSerialLogs.ts Outdated
Comment thread static/js/publisher/hooks/useSerialLogs.ts
Comment on lines +450 to +451
# Arguments are passed positionally:
# (session, store_id, model_name, start_time, end_time, page_size)
Comment on lines +516 to +523
mock_get_serial_log.assert_called_once()
# Arguments are passed positionally:
# session, store_id, model_name, start_time,
# end_time, page_size, cursor
self.assertEqual(
mock_get_serial_log.call_args.args[6],
"nextpage",
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

bad suggestion IMO, I feel like this would make the test more brittle and difficult to read

start_time = flask.request.args.get("start-time")
end_time = flask.request.args.get("end-time")
page_size = flask.request.args.get("page-size")
cursor = flask.request.args.get("next-page")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Any reason why we rename cursor to next-page param?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bartaz This is for clarity for the frontend as cursor isn't necessarily that obvious, although that is what it's called in the store API

if (urlSearchParams) {
const { startTime, endTime, pageSize, nextPage } = urlSearchParams;

if (startTime && endTime) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does the API only accept calls where both timestamps are present? in that case the urlSearchParams type could state this clearly

{
    pageSize?: number;
    nextPage?: string;
} | {
    startTime: string;
    endTime: string;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@edisile there's some nuance around it, but essentially yes. I'll update so it's clearer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes — the hook now uses an interval object ({ startTime, endTime }) for timestamp filtering, so the type enforces both values together. This is in 972b8e82.

@steverydz steverydz force-pushed the WD-35798-serial-log-api-pagination branch from 0251a4e to 972b8e8 Compare April 20, 2026 15:15
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 20, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /opt/hostedtoolcache/node/24.14.1/x64/bin/node /opt/hostedtoolcache/node/24.14.1/x64/bin/node dist/index.js --exec install (dns block)
  • login.ubuntu.com
    • Triggering command: /usr/bin/python3 python3 -m unittest discover tests (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@edisile edisile self-requested a review April 21, 2026 08:14
@steverydz steverydz merged commit 042ea5b into main Apr 21, 2026
23 of 24 checks passed
@steverydz steverydz deleted the WD-35798-serial-log-api-pagination branch April 21, 2026 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants