Skip to content

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

Merged
merged 21 commits into from
Nov 27, 2024

Conversation

britt6612
Copy link
Collaborator

What does this PR do?

adds messages to be passed through the Grommet tag for Meter component

Where 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.
  • The correct query is used. (Refer to this list of queries)
  • 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

@britt6612 britt6612 requested a review from jcfilben November 21, 2024 20:58
Copy link
Collaborator

@MikeKingdom MikeKingdom left a 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

britt6612 and others added 5 commits November 25, 2024 11:47
Co-authored-by: Jessica Rosenquist <54560994+jcfilben@users.noreply.github.com>
Co-authored-by: Jessica Rosenquist <54560994+jcfilben@users.noreply.github.com>
@britt6612 britt6612 requested a review from jcfilben November 25, 2024 21:28
@jcfilben
Copy link
Collaborator

Looks like the max bundlesize value needs bumped up a little

britt6612 and others added 2 commits November 25, 2024 15:22
Co-authored-by: Jessica Rosenquist <54560994+jcfilben@users.noreply.github.com>
Copy link
Collaborator

@jcfilben jcfilben left a 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.`,
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

adding.

},
}}
>
<Meter value={value} />
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

background = { color: 'light-2', opacity: 'medium' },
color,
direction = 'horizontal',
max,
Copy link
Collaborator

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?

Copy link
Collaborator

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?

Copy link
Collaborator Author

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

background = { color: 'light-2', opacity: 'medium' },
color,
direction = 'horizontal',
max,
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

correct we can clarify our documentation.

so if we have the following:

      <Meter type="bar" max={50} value={60} />

The whole meter will be filled.

Screenshot 2024-11-25 at 7 18 01 PM

let content;
if (type === 'bar') {
content = (
<Bar
ref={ref}
max={memoizedMax}
aria-label={meterAriaLabel}
max={max || memoizedMax}
Copy link
Collaborator

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:

  1. deriveMax
  2. the message max param
  3. Bar max property (does logic)
  4. 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).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@MikeKingdom

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.

  1. I needed
    maxValue = values.reduce((total, currentValue) => total + currentValue, 0);
    currentValue.value

  2. 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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks and good point.

@britt6612 britt6612 requested review from MikeKingdom, jcfilben and halocline and removed request for jcfilben November 26, 2024 16:14
Comment on lines 108 to 109
"singular": "{type} meter with value {meterValue} out of {max}",
"plural": "{type} meter with values {meterValue} out of {max}"
Copy link
Collaborator

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:

Suggested change
"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}"
}

Copy link
Collaborator Author

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@MikeKingdom updated structure

Copy link
Collaborator

@MikeKingdom MikeKingdom left a comment

Choose a reason for hiding this comment

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

Thanks!

Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Looks good!

@jcfilben jcfilben merged commit c7ab851 into grommet:master Nov 27, 2024
12 of 14 checks passed
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.

Meter - screenreader accessibility
4 participants