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

UINV-522: display the exchanged calculated total amount when invoice in foreign currency #757

Merged
merged 19 commits into from
Feb 14, 2024

Conversation

alisher-epam
Copy link
Contributor

@alisher-epam alisher-epam commented Feb 5, 2024

Purpose

https://folio-org.atlassian.net/browse/UINV-522 -Display the exchanged calculated total amount when invoice in foreign currency

Approach

Screen.Recording.2024-02-05.at.19.47.04.mp4

Screenshots

Pre-Merge Checklist

Before merging this PR, please go through the following list and take appropriate actions.

  • I've added appropriate record to the CHANGELOG.md
  • Does this PR meet or exceed the expected quality standards?
    • Code coverage on new code is 80% or greater
    • Duplications on new code is 3% or less
    • There are no major code smells or security issues
  • Does this introduce breaking changes?
    • If any API-related changes - okapi interfaces and permissions are reviewed/changed correspondingly
    • There are no breaking changes in this PR.

If there are breaking changes, please STOP and consider the following:

  • What other modules will these changes impact?
  • Do JIRAs exist to update the impacted modules?
    • If not, please create them
    • Do they contain the appropriate level of detail? Which endpoints/schemas changed, etc.
    • Do they have all they appropriate links to blocked/related issues?
  • Are the JIRAs under active development?
    • If not, contact the project's PO and make sure they're aware of the urgency.
  • Do PRs exist for these changes?
    • If so, have they been approved?

Ideally all of the PRs involved in breaking changes would be merged in the same day to avoid breaking the folio-testing environment. Communication is paramount if that is to be achieved, especially as the number of intermodule and inter-team dependencies increase.

While it's helpful for reviewers to help identify potential problems, ensuring that it's safe to merge is ultimately the responsibility of the PR assignee.

Copy link

github-actions bot commented Feb 5, 2024

Jest Unit Test Statistics

    1 files  ±0  115 suites  +2   4m 49s ⏱️ +5s
353 tests +3  353 ✔️ +3  0 💤 ±0  0 ±0 
357 runs  +3  357 ✔️ +3  0 💤 ±0  0 ±0 

Results for commit 9385663. ± Comparison against base commit f075b2c.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Feb 5, 2024

BigTest Unit Test Statistics

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
0 suites ±0   0 💤 ±0 
0 files   ±0   0 ±0 

Results for commit 9385663. ± Comparison against base commit f075b2c.

♻️ This comment has been updated with latest results.

@alisher-epam alisher-epam requested review from a team February 5, 2024 15:11
@alisher-epam
Copy link
Contributor Author

@folio-org/fe-tl-reviewers Please review it when you are available

@alisher-epam alisher-epam self-assigned this Feb 7, 2024
Copy link
Contributor

@usavkov-epam usavkov-epam left a comment

Choose a reason for hiding this comment

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

I've faced issues testing this locally:

  • NaN in the request results in bad data and incorrect view
chrome_FFUHnOjcOV.mp4
  • multiple sending of requests
chrome_KLxnC68Dv9.mp4

Question: what is the purpose of displaying the "Exchanged" when creating a new invoice if it does not contain the total amount?

src/common/constants/api.js Show resolved Hide resolved

import { useExchangeCalculation } from '../../hooks';

export const DisplayExchangedAmount = ({ currency, exchangeRate, total }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

"DisplayExchangedAmount" name sounds like a verb. Could you please change the name of the component

@alisher-epam
Copy link
Contributor Author

@usavkov-epam add debounce with 500ms to prevent multiple requests

@alisher-epam
Copy link
Contributor Author

@folio-org/fe-tl-reviewers please review

Copy link
Contributor

@usavkov-epam usavkov-epam left a comment

Choose a reason for hiding this comment

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

Question: what is the purpose of displaying the "Exchanged" when creating a new invoice if it does not contain the total amount?

This question still seems open to me.

rate: exchangeRate,
});

const debouncedSave = useCallback(debounce(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

please pay attention to linter warnings here

@alisher-epam
Copy link
Contributor Author

Question: what is the purpose of displaying the "Exchanged" when creating a new invoice if it does not contain the total amount?

This question still seems open to me.

I updated the condition here. And the amount is required to display it. https://github.com/folio-org/ui-invoice/pull/757/files#diff-8b144285a54c8b51f8ec063b9bb75a054cc4f99aab3edc30793c0bee11127b8cR21

const systemCurrency = stripes.currency;
const enabled = Boolean(systemCurrency !== currency && total);

const [exchangeProps, setExchangeProps] = useState({
Copy link
Contributor

Choose a reason for hiding this comment

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

this state, debouncedSave and useEffect look strange, what do you solve with it?

in query key you don't use object, but it's values - so you don't need to preserve previous state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main purpose is to prevent multiple requests via debounce function

Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need state and effect at all, and it won't make extra requests

Copy link
Contributor

Choose a reason for hiding this comment

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

const { exchangedAmount } = useExchangeCalculation({ to: systemCurrency, amount: +total, etc }, { enabled });

it's the same with what you did, but without extra strange code

Copy link
Contributor

Choose a reason for hiding this comment

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

there is a chance you'll need to update useQuery config a bit to achieve this, but no need to do what you've done

Copy link
Contributor

Choose a reason for hiding this comment

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


now I see why it's required - form changes values, at the same time all this logic should be moved to useExchangeCalculation, component shouldn't know anything about it

@alisher-epam alisher-epam requested review from usavkov-epam and a team February 13, 2024 13:36
package.json Outdated
@@ -12,7 +12,7 @@
"start": "yarn stripes serve",
"build": "yarn stripes build --output ./output",
"test": "yarn run test:unit",
"test:unit": "jest --ci --coverage",
"test:unit": "jest --ci --coverage --updateSnapshot",
Copy link
Contributor

Choose a reason for hiding this comment

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

remove updateSnapshot, it shouldn't be done on CI level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. This was a workaround to fix the failing snapshots. Because the github action couldn't resolve the snapshot issue even though the tests passed locally.

Copy link
Contributor

Choose a reason for hiding this comment

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

update tests locally and commit them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't help. I have done it twice already

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But "test:unit": "jest --ci --coverage --updateSnapshot", did the track

Copy link
Contributor

Choose a reason for hiding this comment

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

stripes-components could be updated after your commits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am on it. I have just merged

Copy link
Contributor

@NikitaSedyx NikitaSedyx left a comment

Choose a reason for hiding this comment

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

it works only when exchange rate is typed manually, try to select Euro and do not enter exchange rate

@@ -131,6 +138,13 @@ const InvoiceForm = ({
vendorInvoiceNo,
fiscalYearId,
} = initialValues;

const { exchangeRate: exchangeRateValue } = useExchangeRateValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

move this to useExchangeCalculation

@alisher-epam
Copy link
Contributor Author

it works only when exchange rate is typed manually, try to select Euro and do not enter exchange rate

Screen.Recording.2024-02-14.at.17.10.37.mp4

const ky = useOkapiKy();
const [namespace] = useNamespace({ key: 'exchange-calculation' });

const { exchangeRate } = useExchangeRateValue(
Copy link
Contributor

Choose a reason for hiding this comment

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

const { exchangeRate } = useExchangeRateValue(from, to, rate)

@NikitaSedyx
Copy link
Contributor

fix tests please

@NikitaSedyx NikitaSedyx dismissed usavkov-epam’s stale review February 14, 2024 14:44

Yury is on vac and his comments are addressed

Copy link

@alisher-epam alisher-epam merged commit 6c7ed75 into develop Feb 14, 2024
6 checks passed
@alisher-epam alisher-epam deleted the UINV-522 branch February 14, 2024 15:04
NikitaSedyx pushed a commit that referenced this pull request Feb 21, 2024
…in foreign currency (#757)

* UINV-522: display exchanged amount

* tests: fix failing snapshot tests

* add changelog

* debounce api request and rename component name

* tests: update failing snapshots

* disable usecallback linter warning

* tests: remove failing snapshot tests

* tests: add missing snapshots

* rename function name

* update `yarn test` command to update snapshot tests

* remove `--updateSnapshot` flag after fixing snapshot test issue

* regenerate snapshot tests

* refactor exchange calculation hook

* refactor `useExchangeCalculation` hook

* tests: update failing snapshot tests

* inline `useExchangeRateValue` hook arguments in one line

* fix sonar issue `Remove this unused import of 'useStripes'.`
NikitaSedyx pushed a commit that referenced this pull request Feb 21, 2024
…in foreign currency (#757)

* UINV-522: display exchanged amount

* tests: fix failing snapshot tests

* add changelog

* debounce api request and rename component name

* tests: update failing snapshots

* disable usecallback linter warning

* tests: remove failing snapshot tests

* tests: add missing snapshots

* rename function name

* update `yarn test` command to update snapshot tests

* remove `--updateSnapshot` flag after fixing snapshot test issue

* regenerate snapshot tests

* refactor exchange calculation hook

* refactor `useExchangeCalculation` hook

* tests: update failing snapshot tests

* inline `useExchangeRateValue` hook arguments in one line

* fix sonar issue `Remove this unused import of 'useStripes'.`
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.

4 participants