From fb7ba6f392b65809a932b5a26fe60111bba24081 Mon Sep 17 00:00:00 2001 From: Allison Levine <1689238+allilevine@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:29:35 -0500 Subject: [PATCH] Notifications: Refactor gridicons as functional component and add translations (#97784) * Refactor gridicons as functional component and add translations. * Fix more tooltip text. * Fix failing test by filtering instead of checking for an exact match. * Convert file to tsx, change class variable name, change Hide to Dismiss. * Undo svg path changes. * Undo another svg path change. --- .../{gridicons.jsx => gridicons.tsx} | 106 +++++++++--------- .../lib/components/notifications-component.ts | 3 +- 2 files changed, 53 insertions(+), 56 deletions(-) rename apps/notifications/src/panel/templates/{gridicons.jsx => gridicons.tsx} (77%) diff --git a/apps/notifications/src/panel/templates/gridicons.jsx b/apps/notifications/src/panel/templates/gridicons.tsx similarity index 77% rename from apps/notifications/src/panel/templates/gridicons.jsx rename to apps/notifications/src/panel/templates/gridicons.tsx index 829b37bbf56fe..6fd77bc06e318 100644 --- a/apps/notifications/src/panel/templates/gridicons.jsx +++ b/apps/notifications/src/panel/templates/gridicons.tsx @@ -1,33 +1,33 @@ import clsx from 'clsx'; -import PropTypes from 'prop-types'; -import { Component } from 'react'; +import { useTranslate } from 'i18n-calypso'; +import { forwardRef } from 'react'; -export default class extends Component { - static displayName = 'Gridicons'; - - static propTypes = { - icon: PropTypes.string.isRequired, - size: PropTypes.number, - onClick: PropTypes.func, - }; +interface GridiconsProps { + icon: string; + size?: number; + onClick?: () => void; +} - render() { - const { onClick, size = 24 } = this.props; - const icon = `gridicons-${ this.props.icon }`; +const Gridicons = forwardRef< SVGSVGElement, GridiconsProps >( + ( { icon, size = 24, onClick }, ref ) => { + const translate = useTranslate(); + const gridiconClass = `gridicons-${ icon }`; const sharedProps = { - className: clsx( 'gridicon', icon ), + className: clsx( 'gridicon', gridiconClass ), height: size, width: size, onClick, + ref, }; - switch ( icon ) { + switch ( gridiconClass ) { default: return ; case 'gridicons-checkmark': return ( + { translate( 'Approve' ) } @@ -36,6 +36,7 @@ export default class extends Component { case 'gridicons-spam': return ( + { translate( 'Spam' ) } @@ -44,6 +45,7 @@ export default class extends Component { case 'gridicons-star': return ( + { translate( 'Like' ) } @@ -52,7 +54,7 @@ export default class extends Component { case 'gridicons-star-outline': return ( - Star Outline + { translate( 'Like' ) } @@ -62,6 +64,7 @@ export default class extends Component { case 'gridicons-trash': return ( + { translate( 'Trash' ) } @@ -70,7 +73,7 @@ export default class extends Component { case 'gridicons-reader-follow': return ( - Reader Follow + { translate( 'Reader Follow' ) } @@ -80,7 +83,7 @@ export default class extends Component { case 'gridicons-reader-following': return ( - Reader Following + { translate( 'Reader Following' ) } @@ -90,7 +93,7 @@ export default class extends Component { case 'gridicons-mention': return ( - Mention + { translate( 'Mention' ) } @@ -100,7 +103,7 @@ export default class extends Component { case 'gridicons-comment': return ( - Comment + { translate( 'Comment' ) } @@ -110,7 +113,7 @@ export default class extends Component { case 'gridicons-add': return ( - Add + { translate( 'Add' ) } @@ -120,7 +123,7 @@ export default class extends Component { case 'gridicons-info': return ( - Info + { translate( 'Info' ) } @@ -130,7 +133,7 @@ export default class extends Component { case 'gridicons-info-outline': return ( - Info + { translate( 'Info' ) } @@ -140,7 +143,7 @@ export default class extends Component { case 'gridicons-lock': return ( - Lock + { translate( 'Lock' ) } @@ -150,7 +153,7 @@ export default class extends Component { case 'gridicons-stats-alt': return ( - Stats Alt + { translate( 'Stats' ) } @@ -160,7 +163,7 @@ export default class extends Component { case 'gridicons-reblog': return ( - Reblog + { translate( 'Reblog' ) } @@ -170,7 +173,7 @@ export default class extends Component { case 'gridicons-trophy': return ( - Trophy + { translate( 'Trophy' ) } @@ -180,7 +183,7 @@ export default class extends Component { case 'gridicons-notice': return ( - Notice + { translate( 'Notice' ) } @@ -190,7 +193,7 @@ export default class extends Component { case 'gridicons-time': return ( - Time + { translate( 'Time' ) } @@ -200,7 +203,7 @@ export default class extends Component { case 'gridicons-reply': return ( - Reply + { translate( 'Reply' ) } @@ -210,7 +213,7 @@ export default class extends Component { case 'gridicons-arrow-up': return ( - Arrow Up + { translate( 'Arrow Up' ) } @@ -220,7 +223,7 @@ export default class extends Component { case 'gridicons-arrow-down': return ( - Arrow Down + { translate( 'Arrow Down' ) } @@ -230,7 +233,7 @@ export default class extends Component { case 'gridicons-arrow-left': return ( - Arrow Left + { translate( 'Arrow Left' ) } @@ -240,7 +243,7 @@ export default class extends Component { case 'gridicons-arrow-right': return ( - Arrow Left + { translate( 'Arrow Right' ) } @@ -250,7 +253,7 @@ export default class extends Component { case 'gridicons-cross': return ( - Cross + { translate( 'Dismiss' ) } @@ -260,15 +263,9 @@ export default class extends Component { case 'gridicons-cog': return ( - Open notification settings + { translate( 'Open notification settings' ) } - + ); @@ -276,12 +273,9 @@ export default class extends Component { case 'gridicons-cart': return ( - Cart + { translate( 'Cart' ) } - + ); @@ -289,13 +283,9 @@ export default class extends Component { case 'gridicons-pencil': return ( + { translate( 'Edit' ) } - + ); @@ -303,6 +293,7 @@ export default class extends Component { case 'gridicons-pinned': return ( + { translate( 'Pinned' ) } + { translate( 'Bell Off' ) } { await this.anchor .getByRole( 'list' ) - .getByRole( 'button', { name: action, exact: true } ) + .getByRole( 'button' ) + .filter( { hasText: action } ) .click(); }