-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix: 1773 milestone calculated and adjusted fields #1805
Merged
Sepehr-Sobhani
merged 11 commits into
develop
from
1773-fix-milestone-calculated-and-adjusted-fields
Jul 24, 2023
Merged
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ef015d5
fix: add milestone calculated values to form context
Sepehr-Sobhani 39d7c76
test: add milestone summary report form regression test for calculate…
Sepehr-Sobhani 113b773
chore: move mocked data into corresponding tests
Sepehr-Sobhani ca682c1
chore: styling tweaks to `ReadOnlyAdjustableCalculatedValueWidget`
Sepehr-Sobhani 1ab16bd
test: update snapshots
Sepehr-Sobhani 58929b9
chore: show default message when the calculated values aren't calcula…
Sepehr-Sobhani 5fbcabd
chore: tweaking readonly adjustable calculated calue widget style
Sepehr-Sobhani 1e259aa
chore: update unit test snapshots
Sepehr-Sobhani c15ab03
chore: remove jest snapshots
Sepehr-Sobhani d3e164d
test: fix e2e test
Sepehr-Sobhani 728f1fc
chore: implement review suggestions
Sepehr-Sobhani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { WidgetProps } from "@rjsf/core"; | ||
import NumberFormat from "react-number-format"; | ||
import CalculatedValueWidget from "./CalculatedValueWidget"; | ||
|
||
const ReadOnlyAdjustableCalculatedValueWidget: React.FC<WidgetProps> = ( | ||
props | ||
|
@@ -10,34 +11,14 @@ const ReadOnlyAdjustableCalculatedValueWidget: React.FC<WidgetProps> = ( | |
const isMoney = uiSchema?.isMoney; | ||
const isPercentage = uiSchema?.isPercentage; | ||
|
||
// If we need to set the amount of decimal places, we can set it in the uiSchema, otherwise there will be no decimal places. | ||
const numberOfDecimalPlaces = isMoney | ||
? 2 | ||
: uiSchema?.numberOfDecimalPlaces ?? 0; | ||
|
||
const calculatedValue = | ||
formContext[uiSchema.calculatedValueFormContextProperty]; | ||
|
||
const adjustedInputId = `${id}_adjusted`; | ||
|
||
return ( | ||
<div> | ||
{calculatedValue && ( | ||
<> | ||
{ | ||
<NumberFormat | ||
thousandSeparator | ||
fixedDecimalScale={numberOfDecimalPlaces} | ||
decimalScale={numberOfDecimalPlaces} | ||
id={id} | ||
prefix={isMoney ? "$" : ""} | ||
suffix={isPercentage ? "%" : ""} | ||
value={calculatedValue} | ||
displayType="text" | ||
/> | ||
} | ||
</> | ||
)} | ||
<> | ||
<CalculatedValueWidget {...props} /> | ||
{value !== calculatedValue && ( | ||
<div className={"adjustedValue"}> | ||
<dt>{label} (Adjusted)</dt> | ||
|
@@ -57,21 +38,19 @@ const ReadOnlyAdjustableCalculatedValueWidget: React.FC<WidgetProps> = ( | |
) : ( | ||
<em>Not added</em> | ||
)} | ||
<style jsx>{` | ||
.adjustedValue { | ||
display: flex; | ||
flex-basis: 100%; | ||
padding-top: 0.5em; | ||
Comment on lines
+42
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
} | ||
dt { | ||
margin: 0 1em 0 0; | ||
} | ||
`}</style> | ||
</div> | ||
)} | ||
|
||
<style jsx>{` | ||
div.adjustedValue { | ||
display: flex; | ||
} | ||
div.better { | ||
display: flex; | ||
} | ||
dt { | ||
margin: 0 1em 0 1em; | ||
} | ||
`}</style> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is a great solution, nice work! I think it could be simplified to something like:
```<div className={ uiSchema.calculatedValueFormContextProperty ? "adjustable-calculated-value-widget":"definition-container"}`}>
Then any calculated field will get the style without us having to remember to add classnames to the uiSchema
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.
Great suggestion 🤩