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

CIF-1551 - [React Components] Refactor the NavigationContext #379

Merged
merged 14 commits into from
Sep 8, 2020

Conversation

dplaton
Copy link
Contributor

@dplaton dplaton commented Aug 19, 2020

Description

A React Context is a useful feature, allowing components to access context data without having the receive it via props. However, this comes with a cost - the components need to be wrapped in the context provider. We must always weigh the pros and cons of using a context and judge on a case by case basis.

In this particular case, the state of the "My Account Panel" (renamed it!) can be managed by the local state without the need of a "Context". I implemented a useNavigationState hook that manages all the states of the My Account panel and I removed the NavigationContext and the actions module. Also, I updated the AuthBar component so that it uses the new state management.

Related Issue

CIF-1551

Motivation and Context

Reduce code complexity.

How Has This Been Tested?

New unit tests, functional testing.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes and the overall coverage did not decrease.
  • All unit tests pass on CircleCi.
  • I ran all tests locally and they pass.

Daniel Platon added 2 commits August 19, 2020 21:09
Remove the NavigationContext and manage the navigation state lower in the tree, in the `AuthBar` component.
@dplaton dplaton marked this pull request as draft August 19, 2020 18:13
@codecov
Copy link

codecov bot commented Aug 19, 2020

Codecov Report

Merging #379 into master will decrease coverage by 0.34%.
The diff coverage is 75.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #379      +/-   ##
============================================
- Coverage     86.12%   85.77%   -0.35%     
  Complexity      924      924              
============================================
  Files           187      186       -1     
  Lines          4813     4780      -33     
  Branches        673      669       -4     
============================================
- Hits           4145     4100      -45     
- Misses          531      543      +12     
  Partials        137      137              
Flag Coverage Δ Complexity Δ
#integration 68.20% <ø> (ø) 687.00 <ø> (ø)
#jest 80.85% <75.00%> (-1.04%) 0.00 <0.00> (ø)
#karma 94.32% <ø> (ø) 0.00 <ø> (ø)
#unittests 86.07% <ø> (ø) 892.00 <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
react-components/src/context/ConfigContext.js 100.00% <ø> (ø) 0.00 <0.00> (ø)
...nents/src/components/AuthBar/useNavigationState.js 72.72% <72.72%> (ø) 0.00 <0.00> (?)
react-components/src/components/Portal/Portal.js 91.66% <100.00%> (+5.95%) 0.00 <0.00> (ø)
react-components/src/context/NavigationContext.js
react-components/src/actions/navigation/actions.js

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 68faa85...fbe8870. Read the comment docs.

@dplaton dplaton marked this pull request as ready for review August 20, 2020 08:14
const startAccMgEvent = new CustomEvent(events.START_ACC_MANAGEMENT);
const exitAccMgEvent = new CustomEvent(events.EXIT_ACC_MANAGEMENT);

const navigationPanel = document.querySelector('aside.navigation__root');
Copy link
Member

Choose a reason for hiding this comment

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

The selector should be taken from the ConfigContext, so it can be customized.

@@ -31,6 +31,7 @@ describe.each([
});

expect(files.length).toBeGreaterThan(0); // Ensures we read the right folder
// eslint-disable-next-line no-console
console.log(`Validating ${files.length} GraphQL requests against Magento schema ${version}`);
Copy link
Member

Choose a reason for hiding this comment

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

Please remove this line instead of setting an eslint exception.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was really useful to have that line in the tests, to see at least that something happens and that multiple versions are being processed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cjelger the Magento version information is already displayed as part of the test description

- read the navigation panel selector from the configuration context
- remove the log statement from the `validateQueries` test.
@herzog31 herzog31 added the enhancement New feature or request label Aug 25, 2020
alkim91 and others added 5 commits August 31, 2020 21:57
…anged when navigating the "My Account" feature.

The bug was caused by a clash of names between the OOTB `dispatchEvent` function and the custom one. Renaming the function and moving it in the same scope as the caller fixed the issue.
@LSantha LSantha merged commit 2103659 into master Sep 8, 2020
@LSantha LSantha deleted the tasks/CIF-1551 branch September 8, 2020 16:08
@LSantha LSantha removed the To Verify label Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants