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

Sergei / 90221 / set right tab account for derivX when choose account from account switcher #7878

Merged

Conversation

sergei-deriv
Copy link
Contributor

@sergei-deriv sergei-deriv commented Mar 10, 2023

Changes:

Please include a summary of the change and which issue is fixed below:

  • add useEffect for checking window.location.hash

When you need to add unit test

  • If this change disrupt current flow
  • If this change is adding new flow

When you need to add integration test

  • If components from external libraries are being used to define the flow, e.g. @deriv/components
  • If it relies on a very specific set of props with no default behavior for the current component.

Test coverage checklist (for reviewer)

  • Ensure utility / function has a test case
  • Ensure all the tests are passing

Type of change

  • Bug fix
  • New feature
  • Update feature
  • Refactor code
  • Translation to code
  • Translation to crowdin
  • Script configuration
  • Improve performance
  • Style only
  • Dependency update
  • Documentation update
  • Release

@vercel
Copy link

vercel bot commented Mar 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
deriv-app ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 14, 2023 at 1:05PM (UTC)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2023

A production App ID was automatically generated for this PR. (log)

Click here to copy & paste above information.
- **PR**: [https://github.com/binary-com/deriv-app/pull/7878](https://github.com/binary-com/deriv-app/pull/7878)
- **URLs**:
    - **w/ App ID + Server**: https://deriv-app-git-fork-sergei-deriv-sergei-90221derivx-real-9f7481.binary.sx?qa_server=frontend.binaryws.com&app_id=32194
    - **Original**: https://deriv-app-git-fork-sergei-deriv-sergei-90221derivx-real-9f7481.binary.sx
- **App ID**: `32194`

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2023

🚨 Lighthouse report for the changes in this PR:

Category Score
🔺 Performance 18
🟧 Accessibility 75
🟢 Best practices 100
🟧 SEO 85
🟢 PWA 90

Lighthouse ran with https://deriv-app-git-fork-sergei-deriv-sergei-90221derivx-real-9f7481.binary.sx/

@codecov-commenter
Copy link

codecov-commenter commented Mar 10, 2023

Codecov Report

Merging #7878 (e820881) into master (c80dba7) will increase coverage by 0.01%.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##           master    #7878      +/-   ##
==========================================
+ Coverage   20.97%   20.98%   +0.01%     
==========================================
  Files        1502     1502              
  Lines       35177    35182       +5     
  Branches     6830     6832       +2     
==========================================
+ Hits         7379     7384       +5     
  Misses      27084    27084              
  Partials      714      714              
Impacted Files Coverage Δ
packages/cfd/src/Containers/cfd-dashboard.tsx 79.08% <100.00%> (+0.70%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

if (window.location.hash === '#demo-all' || window.location.hash === '#demo') {
setActiveIndex(1);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Copy link
Contributor

Choose a reason for hiding this comment

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

React Hook React.useEffect has an unnecessary dependency: 'window.location.hash'. Either exclude it or remove the dependency array. Outer scope values like 'window.location.hash' aren't valid dependencies because mutating them doesn't re-render the component.

The error message is very clear, I don't know why we always ignore react-hooks/exhaustive-deps instead of fixing it.


If you want to rerender to happen you should use useLocation() hook instead

const location = useLocation();

React.useEffect(() => {
    if (location.hash === '#real') {
        setActiveIndex(0);
    }
    if (location.hash === '#demo-all' || location.hash === '#demo') {
        setActiveIndex(1);
    }
}, [location.hash]);

Copy link
Contributor Author

@sergei-deriv sergei-deriv Mar 13, 2023

Choose a reason for hiding this comment

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

@farzin-deriv I think you are right, but in this file there are 2 more lines 'eslint-disable-next-line react-hooks/exhaustive-deps' so I didn't think it's a big problem :) Ok, in a future I'll try to avoid this error. Also, thanks for the advice about useLocation(), but I've noticed there is props.location and I've used it instead.

@eduard-deriv
Copy link
Contributor

LGTM!

@sonarcloud
Copy link

sonarcloud bot commented Mar 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

No Coverage information No Coverage information
3.0% 3.0% Duplication

@github-actions
Copy link
Contributor

Generating Lighthouse report...

@jim-deriv jim-deriv merged commit 5a34450 into deriv-com:master May 12, 2023
nijil-deriv pushed a commit to nijil-deriv/deriv-app that referenced this pull request May 24, 2023
… from account switcher (deriv-com#7878)

* feat: add useEffect for checking window.location.hash

* chore: empty

* feat: change window.location to hook useLocation()

* feat: change window.location to props.location

* feat: delete useLocation import
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.

6 participants