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

refactor(web): adopt TanStack Query for state management #1439

Merged
merged 39 commits into from
Jul 8, 2024
Merged

Conversation

imobachgs
Copy link
Contributor

@imobachgs imobachgs commented Jul 4, 2024

Trello: https://trello.com/c/8u1WOJz4/3723-8-agama-ui-adopt-a-state-management-solution

Agama's UI state management could be better. For that reason, and after evaluating a few alternatives (see the list of considered alternatives), we decided to adopt Tanstack Query (former React Query).

Why TanStack query

  • It offers a mechanism (based on promises) to fetch/update the state.
  • It is not limited to the client state: it works great with the server state, too.
  • It takes care of caching, re-fetching, error handling, etc.
  • It is a mature, well-documented and widely known project.
  • Plays nicely with React Router, although a TanStack Router project exits.

What is included in this PR

There is quite some work to do so let's consider this pull request as the first step in this path. It introduces the following changes:

  • Add TanStack query as a dependency.
  • Replace L10Provider with a queries-based approach, including data mutation. Check queries/l10n.js if you are curious.
  • Re-enable L10nPage tests (and add other tests).
  • Use React Router loaders to make sure data is loaded before the components are rendered.

Considered Alternatives

We had a look at others but did not consider them at all.

imobachgs and others added 30 commits July 2, 2024 09:09
Part of the code was accidentally sent as part of 179b65e.
* The label is not properly set yet.
* In case you need something really minimal, use
  the "render" function from React Testing Library.
@imobachgs imobachgs merged commit 05e7963 into master Jul 8, 2024
7 checks passed
@imobachgs imobachgs deleted the react-query branch July 8, 2024 12:33
jreidinger added a commit that referenced this pull request Jul 11, 2024
Use TanStack to replace `ProductProvider`. It is related to #1439 and
#1452.
imobachgs added a commit that referenced this pull request Jul 17, 2024
Use TanStack to replace IssuesProvider. It is related to #1439 and
#1452.
teclator added a commit that referenced this pull request Jul 23, 2024
Adapted the UI using TanStack query instead of route loaders and
useEffect hooks.


---

Related to #1439,
#1452,
#1470, and
#1483
imobachgs added a commit that referenced this pull request Jul 23, 2024
Adapt the users management code to use queries instead of `UsersClient`.
Related to #1439.
dgdavid added a commit that referenced this pull request Jul 23, 2024
Similar to #1439, #1452, and #1470, this set of changes aims to replace
the client/software with Tanstack queries.

Note that was not possible to fully drop the software client. It has to
wait until migration of
[`WithStatus`](https://github.com/openSUSE/agama/blob/bd2f35d0ead6d74931189f5619579f6c3ffa2770/web/src/client/mixins.js#L83)
and
[`WithProgress`](https://github.com/openSUSE/agama/blob/bd2f35d0ead6d74931189f5619579f6c3ffa2770/web/src/client/mixins.js#L147)
mixins too.
imobachgs added a commit that referenced this pull request Jul 25, 2024
At this moment, the code for working with product registration is not
used. Moreover, it has to be migrated to a TanStack Query approach
because reasons stated at #1439


Thus, we've agreed to drop it meanwhile in order to have less
dead/unused/pending to adapt code.

Please, note that changes were done on top of
#1498, reason why would be nice to
merge this after it. Additionally, it includes a removal of software
typedef comments that were forgotten at
#1483 and
#1496.
imobachgs added a commit that referenced this pull request Jul 29, 2024
Follow-up of #1439 the goal of this PR is to change the progress track
to use Tanstack Query.
imobachgs added a commit that referenced this pull request Aug 1, 2024
Follow-up of #1439. The goal of this PR is to change installer status
tracking to Tanstack Query. Additionally, it adjust the HTTP API a bit.

## Notes

The `WithStatus` mixin should not be relevant anymore. However, the
storage UI still uses it to detect when the proposal changes. We should
use a dedicated event instead.
dgdavid added a commit that referenced this pull request Aug 2, 2024
In the context of #1439, replace Questions client by its equivalent
using TanStack Query.

Additionally, it includes two commits with changes out of the scope of
the PBI we're working on. Namely:

* Migrates the _components/questions_ files to TypeScript,
560f953
* Stop re-exporting everything in _components/questions/index.ts_,
7c7b049

---

Related to https://trello.com/c/8u1WOJz4 (internal link)
teclator added a commit that referenced this pull request Aug 16, 2024
Adapt the network management code to use queries instead of
NetworkCient. Related to #1439.

Additionally, starts migrating the code to TypeScript and fixes bugs
found by the type system.

---

Reviewers, please note that this ended up being a rather long PR, reason
why is better to not only review the code but also to do manual testing
if possible. Take your time, but any issue out of the scope of state
management / queries migration should be reported as a new issue to be
addressed in a new PBI.

---

Notes for creating follow-up work, 

* Fix WifiConnectionForm to avoid `"error": "Network system error:
Network state error: Connection '<ssid>' already exists"` when
connecting to hidden network that previously failed. In short, we should
either, to drop the configuration created for a failed { hidden: true }
connection or to implement a mechanism to know that such a configuration
already exists and performs an _update_ instead of _add_.
* Review when it's possible to define a gateway and fix the UI
information accordingly
* Check if we can use the type Address from ipaddr package instead of
our own IPAddress type (most probably not)
* Add support for IPv6 since as @jreidinger
[said](#1519 (comment))
its usage is becoming more common. Look for `FIXME: IPv6 is not
supported yet.` comments
@imobachgs imobachgs mentioned this pull request Sep 20, 2024
imobachgs added a commit that referenced this pull request Sep 20, 2024
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.

3 participants