-
Notifications
You must be signed in to change notification settings - Fork 1k
add support for messages for meter #7445
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
Conversation
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.
Needs the messages property in Meter/index.d.ts and propTypes.js
src/js/components/Meter/__tests__/__snapshots__/Meter-test.tsx.snap
Outdated
Show resolved
Hide resolved
src/js/components/Meter/__tests__/__snapshots__/Meter-test.tsx.snap
Outdated
Show resolved
Hide resolved
src/js/components/Meter/__tests__/__snapshots__/Meter-test.tsx.snap
Outdated
Show resolved
Hide resolved
Co-authored-by: Jessica Rosenquist <54560994+jcfilben@users.noreply.github.com>
Co-authored-by: Jessica Rosenquist <54560994+jcfilben@users.noreply.github.com>
src/js/components/Meter/__tests__/__snapshots__/Meter-test.tsx.snap
Outdated
Show resolved
Hide resolved
Looks like the max bundlesize value needs bumped up a little |
Co-authored-by: Jessica Rosenquist <54560994+jcfilben@users.noreply.github.com>
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.
Looks good!
messages={{ | ||
messages: { | ||
meter: { | ||
singular: `bar value is ${value}% out of 100.`, |
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.
Since we support 'plural', should we have a test coverage for it as well?
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.
adding.
}, | ||
}} | ||
> | ||
<Meter value={value} /> |
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.
A caller can specify messages directly on the Meter instance, correct? Should we have test coverage for the instance 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.
yes correct a user can add on the Meter directly adding
src/js/components/Meter/Meter.js
Outdated
background = { color: 'light-2', opacity: 'medium' }, | ||
color, | ||
direction = 'horizontal', | ||
max, |
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.
Was max
documented, but not an actual prop?
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.
Are there other props documented but not represented as props here?
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.
yes there are other props documented but not represented here I had pulled out the max
so I could use that in the message since that was just being passed in the ...rest
src/js/components/Meter/Meter.js
Outdated
background = { color: 'light-2', opacity: 'medium' }, | ||
color, | ||
direction = 'horizontal', | ||
max, |
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.
max
documentation states "The maximum value for the Meter." Does this imply that if I specify max={10}
, then set value={20}
, the 20 won't be respected? If not, should the definition of max be clarified?
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.
src/js/components/Meter/Meter.js
Outdated
let content; | ||
if (type === 'bar') { | ||
content = ( | ||
<Bar | ||
ref={ref} | ||
max={memoizedMax} | ||
aria-label={meterAriaLabel} | ||
max={max || memoizedMax} |
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 isn't quite the same but probably an improvement.
Previously if the max prop was in rest
I think it would override this property. Now you will get memoizedMax
if max is specified but falsey (e.g. 0, undefined, null). Maybe that's better? That does assume we can't have negative values (e.g. say a range of values from -10 to 0)?
I think it's little fragile that the rules for what max is are now split into 4 places:
- deriveMax
- the message max param
- Bar max property (does logic)
- Cirlce max property (does logic)
This is alot of risk for disagreement. Right now if there are multiple values
but they are 0 you will get a memoizedMax
of 0. The message will say 100 but the Bar and Circle will be passed max=0
memoizedMax
will be 100 or if there are at least 2 values
it adds them up. That also means if values
only contains 1 thing it will return 100 or if there's a value
it will return 100.
To avoid this we might want to refactor to normalize max in one spot and pass that one value to the message, Bar and Circle. Maybe something like:
Change the component prop to be max: maxProp
and then
const max = useMemo(() => {
let maxValue = 100;
if (values?.length > 1) {
maxValue = values.reduce((total, currentValue) => total + currentValue, 0);
}
return maxValue || maxProp || 100;
}, [maxProp, values]);
And then just use max
for the 3 places it's needed (message param, Bar prop and Circle prop).
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.
yes agree there is alot being done here
deriveMax
the message max param
Bar max property (does logic)
Cirlce max property (does logic)
I added the suggestion you provided with a small change.
-
I needed
maxValue = values.reduce((total, currentValue) => total + currentValue, 0);
currentValue.value -
I put the
maxProp
to be the first in our || statement so its the following
return maxProp || maxValue || 100;
for example if I have
<Meter type="bar" max={40} value={30} />
with having maxValue || maxProp || 100
it was taking the maxValue of 100 and not respecting what the user passed in for maxProp
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.
Thanks and good point.
Co-authored-by: Mike Kingdom <michael.kingdom@hpe.com>
…mmet into add-messages-meter
src/js/languages/default.json
Outdated
"singular": "{type} meter with value {meterValue} out of {max}", | ||
"plural": "{type} meter with values {meterValue} out of {max}" |
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.
One thing I just realized is the type
isn't currently localizable. We should have keys in here for type. Although a bit wordy, I think a more flexible thing for localizers would be:
"singular": "{type} meter with value {meterValue} out of {max}", | |
"plural": "{type} meter with values {meterValue} out of {max}" | |
"bar": { | |
"singular": "Bar meter with value {meterValue} out of {max}", | |
"plural": "Bar meter with values {meterValue} out of {max}" | |
}, | |
"circle": { | |
"singular": "Circle meter with value {meterValue} out of {max}", | |
"plural": "Circle meter with values {meterValue} out of {max}" | |
} |
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.
aw okay good point I can restructure
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.
@MikeKingdom updated structure
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.
Thanks!
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.
Looks good!
What does this PR do?
adds
messages
to be passed through theGrommet
tag for Meter componentWhere should the reviewer start?
meter.js
What testing has been done on this PR?
storybook
How should this be manually tested?
storybook
Do Jest tests follow these best practices?
TODO:
screen
is used for querying.asFragment()
is used for snapshot testing.Any background context you want to provide?
previously screen reader just read out that our meter was an image. We need to provide better context
What are the relevant issues?
closes #7326
Screenshots (if appropriate)
Do the grommet docs need to be updated?
yes
Should this PR be mentioned in the release notes?
yes
Is this change backwards compatible or is it a breaking change?
backwards compatible