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

DSD-1905/formatting numbers #1721

Merged
merged 41 commits into from
Jan 29, 2025
Merged

Conversation

gonuguntla
Copy link
Collaborator

@gonuguntla gonuguntla commented Jan 6, 2025

Fixes JIRA ticket DSD-1905

This PR does the following:

How has this been tested?

Accessibility concerns or updates

Accessibility Checklist

  • Checked Storybook's "Accessibility" tab for color contrast and other issues.
  • The feature works with keyboard inputs including tabbing back and forward and pressing space, enter, arrow, and esc keys.
  • For hidden text or when aria-live is used, a screenreader was used to verify the text is read.
  • For features that involve UI updates and focusing on DOM refs, focus management was reviewed.
  • The feature works when the page is zoomed in to 200% and 400%.

Open Questions

Checklist:

  • I have updated the Storybook documentation and changelog accordingly.
  • I have added relevant accessibility documentation for this pull request.
  • All new and existing tests passed.

Front End Review:

  • Review the Vercel preview deployment once it is ready.

Copy link

vercel bot commented Jan 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nypl-design-system ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 29, 2025 8:31pm

Copy link
Collaborator

@bigfishdesign13 bigfishdesign13 left a comment

Choose a reason for hiding this comment

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

I have some formatting requests. Please see my comments.

Additionally, there are requirements in the Jira ticket that have not been implemented, but I am not going to ask for that to be added just yet. The Design Team is making a decision about whether or not that formatting should be implemented.

src/components/Text/Text.stories.tsx Outdated Show resolved Hide resolved
src/utils/utils.ts Outdated Show resolved Hide resolved
Copy link
Member

@EdwinGuzman EdwinGuzman left a comment

Choose a reason for hiding this comment

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

This looks good. At this point @bigfishdesign13 and I need to do a bit more investigation to see how teams can/should use it.

Something I would like to see is for the function to also work with string numbers. So that useFormatNumber(4276835) and useFormatNumber("4276835") both return the same value. I think it's definitely possible that numbers from various sources, databases or APIs, return number values as strings.

Copy link
Collaborator

@bigfishdesign13 bigfishdesign13 left a comment

Choose a reason for hiding this comment

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

As Edwin requested, update the function so it also supports numbers passed as strings

Ex. "123456"

With that, it would also be good to return a console warning when an alphanumeric or purely alphabetic string is passed.

Ex: "one" or "123xxx"

This is what the warning should say:

NYPL Reservoir useFormatNumber: An unsupported value was passed.

src/hooks/__tests__/useFormatNumber.text.ts Outdated Show resolved Hide resolved
src/hooks/useFormatNumber.mdx Outdated Show resolved Hide resolved
src/hooks/useFormatNumber.mdx Outdated Show resolved Hide resolved
src/hooks/useFormatNumber.ts Show resolved Hide resolved
@bigfishdesign13 bigfishdesign13 added the Changes Requested Pull requests where changes have been requested in peer review. label Jan 13, 2025

## Usage

const formatNumber from "../../hooks/useFormatNumber";
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code snippet should show the code that consuming apps can use to import the hook/function.

<Source
  code={`
import {
  formatNumber
} from "@nypl/design-system-react-components";
`} language="jsx" />

};

const formatNumber = (num1: any, num2?: any): string | null => {
let hasWarnig = false; // Track if any warnings occurs
Copy link
Member

Choose a reason for hiding this comment

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

typo: hasWarning

Copy link
Member

@EdwinGuzman EdwinGuzman left a comment

Choose a reason for hiding this comment

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

Some updates but it's looking good.

*/

// export default function useFormatNumber(num1: any, num2?: any) {
const useFormatNumber = (num1: any, num2?: any) => {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of any, use string | number to give the args better types.

// export default function useFormatNumber(num1: any, num2?: any) {
const useFormatNumber = (num1: any, num2?: any) => {
// const num1Pass = num1;
// const num2Pass = num2;
Copy link
Member

Choose a reason for hiding this comment

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

delete comments if you don't need it anymore

)}`;
}

const enDash = "\u2013";
Copy link
Member

Choose a reason for hiding this comment

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

You need this enDash for line 80, so declare it before it and use it there.

Comment on lines 8 to 10
expect(formatNumber("4382", "XX1234")).toEqual(null);
expect(formatNumber("4382XXX", "1234")).toEqual(null);
expect(formatNumber("4382XXX", "1234XXX")).toEqual(null);
Copy link
Member

Choose a reason for hiding this comment

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

Break these expectations out into their own test case and also verify that the warning is being logged.

Copy link
Member

@EdwinGuzman EdwinGuzman 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
Member

@EdwinGuzman EdwinGuzman 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

@bigfishdesign13 bigfishdesign13 left a comment

Choose a reason for hiding this comment

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

Looks great!

@bigfishdesign13 bigfishdesign13 added Ship It Pull requests that have been reviewed and approved. and removed Changes Requested Pull requests where changes have been requested in peer review. labels Jan 24, 2025
@bigfishdesign13 bigfishdesign13 merged commit b84caf9 into development Jan 29, 2025
5 checks passed
@bigfishdesign13 bigfishdesign13 deleted the DSD-1905/format-number branch January 29, 2025 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ship It Pull requests that have been reviewed and approved.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants