-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
@folio-org/fe-tl-reviewers Please review it when you are available |
There was a problem hiding this 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?
|
||
import { useExchangeCalculation } from '../../hooks'; | ||
|
||
export const DisplayExchangedAmount = ({ currency, exchangeRate, total }) => { |
There was a problem hiding this comment.
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
@usavkov-epam add debounce with 500ms to prevent multiple requests |
@folio-org/fe-tl-reviewers please review |
There was a problem hiding this 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(() => { |
There was a problem hiding this comment.
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
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({ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to useExchangeCalculation
Screen.Recording.2024-02-14.at.17.10.37.mp4 |
const ky = useOkapiKy(); | ||
const [namespace] = useNamespace({ key: 'exchange-calculation' }); | ||
|
||
const { exchangeRate } = useExchangeRateValue( |
There was a problem hiding this comment.
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)
fix tests please |
Yury is on vac and his comments are addressed
|
…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'.`
…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'.`
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.
If there are breaking changes, please STOP and consider the following:
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.