Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] refactor: Transition from useAsync to RTK Query (M2-8618) #2021

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

farmerpaul
Copy link
Contributor

@farmerpaul farmerpaul commented Jan 27, 2025

  • Tests for the changes have been added
  • Related documentation has been added / updated

📝 Description

Important

This is not quite ready for official review. I have a couple small tweaks left to add and plan to organize the commits more logically. Stay tuned!

🔗 Jira Ticket M2-8618

This PR begins the migration from useAsync and raw Axios mutation functions to RTK Query, which has been agreed upon as the new paradigm for making API calls in the Admin App.

See this Confluence doc for context:

In this PR, these endpoints have (mostly) been migrated over to RTK Query:

  • GET activities/applet/${appletId}
  • GET workspaces/${ownerId}/managers
  • GET workspaces/${ownerId}/applets/${appletId}/managers
  • GET workspaces/${ownerId}/respondents1
  • GET workspaces/${ownerId}/applets/${appletId}/respondents1
  • POST invitations/${appletId}/${url}
  • POST invitations/${appletId}/subject
  • POST invitations/${appletId}/shell-account
  • PUT subjects/${subjectId}
  • DELETE subjects/${subjectId}

Note

1 For now, preserved getWorkspaceRespondentsApi (which also calls these endpoints), as it is used in an async thunk. This and similar thunks should be deprecated, as they needlessly duplicate core RTK Query functionality.

As well, a custom base query function, axiosBaseQuery, has been written, allowing RTK Query to use axios instead of fetch for its HTTP requests (which it uses by default). Continuing to use axios for network requests allows unit tests to remain mostly unaffected by the migrated endpoints (preserving the use of jest-mock-axios), as well as the existing authentication stack to be used with no changes needed.

@farmerpaul farmerpaul added In Progress Some work in progress DO NOT MERGE labels Jan 27, 2025
Copy link

This pull request is automatically being deployed by Amplify Hosting (learn more).

Access this pull request here: https://pr-2021.d19gtpld8yi51u.amplifyapp.com

Piggypacking on auth token derived from existing axios auth logic.
`ParticipantsData` and `ManagersData` representing API response data
had been previously defined within component definitions rather than
`api.types.ts`. Removed these in favour of the api-defined types.
Async thunks that make API calls can't be converted to RTK Query due to
circular dependencies that introduces in unit tests. The correct
solution is to actually do away with some async thunks altogether, as
their role in most cases has been replaced by RTK Query.
Add `jest-fetch-mock` to support mocking HTTP GET requests that use
`fetch` to support RTK Query.

Update `mockGetRequestResponses` utility to seamlessly support both
Axios and `fetch`-based HTTP requests.

Update unit tests to use appropriate mocks for `fetch`-based requests.
Create RTK Query adapter to use Axios instead of `fetch`, allowing us to
reuse more existing auth and API infrastructure. This also allowed
reverting patches to unit tests and the `httpMocks` utility, which
were previously needed only because we had to support both Axios and
`fetch`.
@farmerpaul farmerpaul changed the title [WIP] refactor: PoC – transitioning to RTK Query [WIP] refactor: Transition from useAsync to RTK Query (M2-8618) Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Do not review In Progress Some work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant