Skip to content

fix(NotificationsPanel): new date-time formatting function#6904

Merged
elycheea merged 17 commits into
carbon-design-system:mainfrom
paul-balchin-ibm:6761_update-time-stamp-code
Mar 7, 2025
Merged

fix(NotificationsPanel): new date-time formatting function#6904
elycheea merged 17 commits into
carbon-design-system:mainfrom
paul-balchin-ibm:6761_update-time-stamp-code

Conversation

@paul-balchin-ibm
Copy link
Copy Markdown
Contributor

@paul-balchin-ibm paul-balchin-ibm commented Feb 13, 2025

Closes #6761

Direct link to NotificationsPanel Story

Introduced new Carbon utilities dateTimeFormat() function, which follows official date and time and language guidance.

dateTimeFormat() and 2 new props replaces:

  • 13 existing date/time props, which must be filled out by the app developer, for each supported language,
  • bespoke code to support those 13 props.

* These older props are now marked as deprecated and remain functional.

What did you change?

packages/ibm-products/src/components/NotificationsPanel/NotificationsPanel.tsx
packages/ibm-products/src/components/NotificationsPanel/NotificationsPanel.stories.jsx

Added @carbon/utilities.

packages/core/package.json

How did you test and verify your work?

  • Storybook

@paul-balchin-ibm paul-balchin-ibm requested a review from a team as a code owner February 13, 2025 14:27
@paul-balchin-ibm paul-balchin-ibm requested review from elycheea and makafsal and removed request for a team February 13, 2025 14:27
@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 13, 2025

Deploy Preview for ibm-products-web-components ready!

Name Link
🔨 Latest commit ae35f83
🔍 Latest deploy log https://app.netlify.com/sites/ibm-products-web-components/deploys/67c9ad51408da70008814ff1
😎 Deploy Preview https://deploy-preview-6904--ibm-products-web-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 13, 2025

Deploy Preview for carbon-for-ibm-products ready!

Name Link
🔨 Latest commit ae35f83
🔍 Latest deploy log https://app.netlify.com/sites/carbon-for-ibm-products/deploys/67c9ad515fcb9a000812147f
😎 Deploy Preview https://deploy-preview-6904--carbon-for-ibm-products.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.74%. Comparing base (dcf9591) to head (ae35f83).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6904   +/-   ##
=======================================
  Coverage   81.73%   81.74%           
=======================================
  Files         401      401           
  Lines       13025    13030    +5     
  Branches     4293     4296    +3     
=======================================
+ Hits        10646    10651    +5     
  Misses       2379     2379           
Components Coverage Δ
ibm-products ∅ <ø> (∅)
ibm-products-web-components ∅ <ø> (∅)
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread packages/core/package.json Outdated
"vite": "^6.0.7"
},
"dependencies": {
"@carbon/utilities": "^0.4.0",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is being used by the actual NotificationsPanel component, we would need to move this into the packages/ibm-products/package.json.

However, re-reading the original issue, it looks like we actually intended for the user to use dateTimeFormat, which means we would probably want to use the utility in the data or story rather than in the component itself.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @elycheea, based on recent meetings, is this still the case?

Copy link
Copy Markdown
Contributor

@elycheea elycheea Feb 28, 2025

Choose a reason for hiding this comment

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

Yep. Move it to our ibm-products/package.json! (Only for the first part those. Second part you can disregard.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@paul-balchin-ibm paul-balchin-ibm marked this pull request as draft February 20, 2025 19:33
@paul-balchin-ibm
Copy link
Copy Markdown
Contributor Author

paul-balchin-ibm commented Feb 20, 2025

Draft mode - follow up discussions

After further discussion, there are still open questions on how to deprecate the old props gracefully.

We can keep the old props, mark them as deprecated, and remove the timeAgo() function. The new, internal dateTimeFormat() will take over gracefully.

But, if the app developer was providing translations using the old props, these will now only render the default English, since the old functionality has been removed. For the app developer to specify other languages, they will need to know to use the new dateTimeLocale prop (i.e. 'en-US', 'fr_CA', etc).

Ready for review - Post discussion fix

Removed default value for dateTimeLocale. Applying a value to dateTimeLocale will make use of the new feature.

@paul-balchin-ibm paul-balchin-ibm marked this pull request as ready for review February 28, 2025 19:07
Comment on lines +320 to +339
/**
* The `NotificationsPanel` sets expectations on the behavior for notifications,
* allowing the user to view and interact with them all in one place.
*
* #### Updated localization feature for the "time ago" timestamp
*
* The new localization reduces a dev's effort to apply language
* support for the "time ago" timestamp applied to each notification
* by using the new Carbon utility [dateTimeFormat()](https://github.com/carbon-design-system/carbon/blob/main/packages/utilities/src/dateTimeFormat/README.md) function.
* It will provide relative timestamps that adhere to Carbon's
* [date and time guidance](https://pages.github.ibm.com/carbon/ibm-products/guidelines/content/date-and-time/).
*
* **Step 1:** ignore the following _deprecated_ props: `daysAgoText`,
* `hourAgoText`, `hoursAgoText`, `minuteAgoText`, `minutesAgoText`,
* `monthAgoText`, `monthsAgoText`, `nowText`, `secondsAgoText`,
* `yearAgoText`, `yearsAgoText`, `yesterdayAtText`.
*
* **Step 2:** provide the `dateTimeLocale` prop with a valid locale—such as "de" or "fr-CA"—and it will do the work.
* You must provide a value, otherwise the deprecated props above will be used instead.
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we’d typically just include this in the actual documentation (StoryDocs or mdx) rather than in the component file.

I would consider reversing the order for adopting the new props though. Rather than “ignore” as a task, I think it makes more sense to 1) adopt, 2) remove.

To adopt the new localization:

Step 1: Provide a valid locale to the dateTimeLocale prop, such as de or fr-CA.
Step 2: Remove the now deprecated props: daysAgoText, hourAgoText, hoursAgoText, minuteAgoText, minutesAgoText, monthAgoText, monthsAgoText, nowText, secondsAgoText, yearAgoText, yearsAgoText, yesterdayAtText.

If you do not provide a locale, the deprecated props will be applied instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

<StoryDocsPage /> is picking up this comment and dropping into the Overview section on the Docs page. I can't find an example of telling <StoryDocsPage /> to fill in the Overview section directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

RE this comment, <StoryDocsPage /> is definitely designed to pick up the component comment as the "Overview":

image

Here's where it's output

image

However, altDescription is ignored if used as a prop.

Still looking.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I actually imagine we’ll eventually move back to MDX through the docs epic 👀, but for now, I’d just focus on revising the docs you added rather than unpacking the StoryDocsPage. I want to say that was a workaround when we ran into issues with MDX when we first moved to Storybook 7 or 8? 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Works for me 👍 I'll stop digging into StoryDocsPage if we're planning to move back to mdx.

Copy link
Copy Markdown
Contributor

@elycheea elycheea left a comment

Choose a reason for hiding this comment

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

Changes look good but since I see there’s a conflict, I’ll add one tiny fix to the updated docs. (Just colon instead of period.)

Comment thread packages/ibm-products/src/components/NotificationsPanel/NotificationsPanel.tsx Outdated
@paul-balchin-ibm
Copy link
Copy Markdown
Contributor Author

I noticed the doc change while resolving the conflict.

Both are completed.

@elycheea elycheea added this pull request to the merge queue Mar 7, 2025
Merged via the queue into carbon-design-system:main with commit 3e6072f Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NotificationsPanel: "relative" time stamp is bespoke code and not localized

3 participants