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/1508 rewrite page navigation #1682

Merged
merged 108 commits into from
Dec 7, 2023

Conversation

mikaelrss
Copy link
Contributor

@mikaelrss mikaelrss commented Dec 3, 2023

Description

This PR refactors the current page navigation to use react-router-dom based routing. Each step in the process is assigned a path in the url /:taskId and each page of a step is assigned a path /:pageKey. For stateless apps, we assign only the /:pageKey.

For pages on steps that are not the current process step, we allow the users to navigate here, but they will see a generic error message. The pages states that the current step is already completed, and provides a button for the user to navigate to the correct current step:

image

  • Add react-router-dom router for page navigation.
  • Add custom hooks for navigation, useNavigatePage and useNavigationParams.
  • Add a context PageNavigationContext which holds values that are related to component focus Id, scroll position, and hidden pages.
  • Add a context UiConfigContext which holds values that were previously stored in redux. This highlighed a new problem. The current way of fetching these values uses the layout settings, which mean that for instance showLanguageSelector can only be specified in a layout set. This means that for instance selection and receipt pages, there is no way of showing the language selector. This worked previously because the settings of the last page was stored in redux and subsequently used in the receipt page. This is also why the Percy screenshot tests are failing.
  • Update fetch query cache in ProcessContext. Instead of storing the data from tanstack/react-query in a useState and passing along the setState function to other components, I refactored this to instead update the query cache wherever the data was being updated. I discovered that this was necessary after unmounting ProcessContext and remounting it, by navigating back from a form to instance selection and forward to the form again. Then all state about process was lost, and replaced by the cached query in tanstack, which thought the initial process request was the applicable state.
  • I have skipped all cypress tests that rely on triggering validation on page navigation with a // TODO(1508) comment. These tests need to be addressed in combination with Rewrite validation sagas to hooks/Tanstack query #1506 @bjosttveit.
  • Add issue about a proper place for config hideCloseButton, showLanguageSelector. Layout settings for receipt pages and instance selection #1686

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

Ole Martin Handeland added 30 commits November 15, 2023 11:18
…tputting to use DisplayError.tsx. Committing this knowing that much of the code does not currently pass type-checks.
…ontext/createLaxQueryContext into unified (and simplified + improved) variants
… ValidPartyProvider. There's still some inconsistencies around having a valid party. The InstantiationButton (for example) does not check to see if the current party is valid to instantiate before performing instantiation.
…ta is not yet fetched, mocking fetchTextResources() most places
…t, so that they work before app texts have been fetched
…o slow that this request halts, so the test should no longer assume it
# Conflicts:
#	src/components/altinnAppHeader.tsx
#	src/hooks/queries/useGetTextResourcesQuery.ts
- Removing ValidPartyProvider.tsx, as validating the current party is done implicitly by checking if the party is in the list of valid parties we already fetch. We must have a valid party to proceed to instantiation.
- Introducing a LanguageProvider that keeps tabs on which language is currently selected in the app. Loading a Profile will automatically select the language given in the profile.
- Renaming reportee-selection.ts to party-selection.ts and adjusting the tests after minor (non-functional) changes
@@ -15,12 +15,12 @@ export function mergeAndSort(...args: IAttachments[]) {
}

// Sort all attachments by name
for (const nodeId in Object.keys(result)) {
Object.keys(result).forEach((nodeId) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code produced a bug with the attachments-in-groups.ts cypress test. It iterated over the indices of the array instead of the keys. i.e [0,1,2,3] vs ["key-1", "key2"].

I guess it appeared because the state previousy was stored in a sorted order, and this now might not be the case. I am unsure why this has changed, but since the result always is sorted when we extract it, I don't see an issue here.

Copy link
Member

Choose a reason for hiding this comment

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

It should probably have been a for ... of instead of a for ... in loop

@mikaelrss mikaelrss force-pushed the refactor/1508-rewrite-page-navigation branch from 8b5b090 to 53c1932 Compare December 5, 2023 09:50
@mikaelrss mikaelrss marked this pull request as ready for review December 5, 2023 10:54
@mikaelrss mikaelrss added the kind/breaking-change Issue/pull request containing a breaking change label Dec 6, 2023
Copy link
Contributor

@olemartinorg olemartinorg left a comment

Choose a reason for hiding this comment

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

Great work!!

@mikaelrss mikaelrss marked this pull request as draft December 6, 2023 16:45
@mikaelrss mikaelrss marked this pull request as ready for review December 6, 2023 16:45
Copy link

sonarqubecloud bot commented Dec 6, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 23 Code Smells

65.2% 65.2% Coverage
0.6% 0.6% Duplication

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

@mikaelrss mikaelrss merged commit b11facd into main Dec 7, 2023
@mikaelrss mikaelrss deleted the refactor/1508-rewrite-page-navigation branch December 7, 2023 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/breaking-change Issue/pull request containing a breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rewrite page navigation using hooks
3 participants