Skip to content

Usegetoptions and data lists to hooks using tanstack #1442

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

Merged

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Sep 8, 2023

Description

In this task @Magnusrm and I have collaborated to improve the functionality of two hooks, useGetOptions and useDataLists, in order to reduce their dependence on Redux states. Our primary objective was to implement Tanstack Queries for fetching data within components using these hooks. This change will also allow us to eliminate some redundant Saga code.

I would like to extend a special thanks to @olemartinorg for his invaluable contributions and significant involvement in realizing this project! ❤️

I’ve tried to summarized of what this PR introduces, but there’s a possibility I may have overlooked certain points. So, if there’s anything unclear in the code, feel free to point it out.

Changes to useGetOptions

  1. Eliminated the need for maintaining an options state in Redux.
  2. Introduced a new hook query, useGetOptionsQuery, solely responsible for fetching options.
  3. Integrated fileUploadWithTag with the useGetOptions hook, expanding its functionality to include support for static options and options (source) from repeating groups.
  4. Saga cleanup
  5. Leveraged Tanstack Query to initiate option fetching during component rendering. To ensure that options persist in such as summary, PDFs and expressions, we implemented a context (useAllOptions.ts) that provides a global map of all fetched options.
  6. Transferred the logic related to preselectedOptionIndex and options changes from the components to the reusable useGetOptions hook. We also introduced new functionality in useRemoveStaleValues to retain options that still exists when options have changed.
  7. Smaller refactors.

Changes to useDataLists

  1. Eliminated the need for maintaining datalists state in Redux by utilizing Tanstack Query and managing sorting state with useState hooks.
  2. Introduced a new hook query, useGetDataListQuery, solely responsible for fetching options.
  3. Saga cleanup
  4. Removed useDataLists hook as there is for now no need for an intermediate layer between the component and useDataListQuery.

These enhancements aim to streamline the use of these hooks and reduce their reliance on Redux states, ultimately improving the efficiency and maintainability of the codebase.

Unit and cypress tests
We’ve made significant updates to unit tests, addressing issues where they previously relied on options being available immediately without the need for fetching.

Furthermore, we have introduced new test cases to ensure everything works as planned, such as including handling options in dynamic scenarios (useRemoveStaleValues), resolved flakiness issues, and tested other behaviors that could result in failed tests following the implementation of Tanstack Query. These tests ensure the robustness of our code changes.

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

lassopicasso and others added 30 commits August 22, 2023 15:36
Ole Martin Handeland and others added 5 commits September 26, 2023 13:26
… global state not being available. This should clean up and simplify the state in useAllOptions.tsx and fixes the problem.
…d yet, we saved a list of no nodes, meaning all options were loaded every time. This should delay the 'nodesFound' event until we have actually found nodes.
Ole Martin Handeland added 7 commits September 27, 2023 13:44
…tanstack

# Conflicts:
#	src/queries/queries.ts
…ed mapped options after preselectedOptionIndex (so that they appear in summary)
…Type(). Only data tasks are expected to generate nodes, and for non-data tasks we should say we found no nodes, and there are thus no options to fetch.
…use infinite loading/spinner, as it just did (before we fixed it by checking the current task type)
@olemartinorg
Copy link
Contributor

@lassopicasso Tests pass! 🥳 Time to write a description here about the whole ordeal, and open up for review.. 😁

Ole Martin Handeland added 2 commits September 27, 2023 16:12
@lassopicasso lassopicasso added quality/debt kind/other Pull requests containing chores/repo structure/other changes fe-v4 Issues to be solved before v4 goes gold kind/product-feature Pull requests containing new features labels Sep 28, 2023
@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 2 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 15 Code Smells

83.5% 83.5% Coverage
0.5% 0.5% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@olemartinorg
Copy link
Contributor

Not sure what happened there with the Percy screenshots - the close button is now also shown on the receipt page for some reason, but it wasn't before. IMO, the close button should probably be shown there, so I think it's all OK.

@lassopicasso lassopicasso marked this pull request as ready for review September 29, 2023 07:19
Copy link
Member

@bjosttveit bjosttveit left a comment

Choose a reason for hiding this comment

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

Well done! 🥇

@lassopicasso lassopicasso merged commit 01585ee into main Oct 2, 2023
@lassopicasso lassopicasso deleted the usegetoptions-and-data-lists-to-hooks-using-tanstack branch October 2, 2023 13:57
@bjosttveit
Copy link
Member

PDF tests are still passing 🥳
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fe-v4 Issues to be solved before v4 goes gold kind/other Pull requests containing chores/repo structure/other changes kind/product-feature Pull requests containing new features quality/debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite useGetOptions() and data lists to hooks using Tanstack Query without Redux
4 participants