[MM-61683]: Ensure radio button groups are properly formed (#30013)

* MM-61683: Ensure radio button groups are properly formed

* MM-61683: Fix the failing i18 CI

* MM-61683: Fix desktop notification translation IDs

* MM-61683: Fix lint-style

* MM-61683: Update name attribute inside channel notification modal
Add aria-label inside RadioSettingItem
Update snapshot

* MM-61683: Revert creating a constant for default messages and id

* MM-61683: Add legend tag inside radio setting item component

* MM-61683: Update snapshot

---------

Co-authored-by: Saurabh Sharma <saurabh.sharma@brightscout.com>
Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
ayush-chauhan233 2025-02-11 21:16:06 +05:30 committed by GitHub
parent d3dcc74e5a
commit 9aaa52136c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 195 additions and 162 deletions

View File

@ -201,6 +201,11 @@ Object {
<fieldset <fieldset
class="mm-modal-generic-section-item__fieldset-radio" class="mm-modal-generic-section-item__fieldset-radio"
> >
<legend
class="hidden-label"
>
Notify me about…
</legend>
<label <label
class="mm-modal-generic-section-item__label-radio" class="mm-modal-generic-section-item__label-radio"
> >
@ -208,7 +213,7 @@ Object {
checked="" checked=""
data-testid="desktopNotification-all" data-testid="desktopNotification-all"
id="desktopNotification-all" id="desktopNotification-all"
name="desktopNotification-all" name="desktop"
type="radio" type="radio"
value="all" value="all"
/> />
@ -221,7 +226,7 @@ Object {
<input <input
data-testid="desktopNotification-mention" data-testid="desktopNotification-mention"
id="desktopNotification-mention" id="desktopNotification-mention"
name="desktopNotification-mention" name="desktop"
type="radio" type="radio"
value="mention" value="mention"
/> />
@ -233,7 +238,7 @@ Object {
<input <input
data-testid="desktopNotification-none" data-testid="desktopNotification-none"
id="desktopNotification-none" id="desktopNotification-none"
name="desktopNotification-none" name="desktop"
type="radio" type="radio"
value="none" value="none"
/> />
@ -637,6 +642,11 @@ Object {
<fieldset <fieldset
class="mm-modal-generic-section-item__fieldset-radio" class="mm-modal-generic-section-item__fieldset-radio"
> >
<legend
class="hidden-label"
>
Notify me about…
</legend>
<label <label
class="mm-modal-generic-section-item__label-radio" class="mm-modal-generic-section-item__label-radio"
> >
@ -644,7 +654,7 @@ Object {
checked="" checked=""
data-testid="desktopNotification-all" data-testid="desktopNotification-all"
id="desktopNotification-all" id="desktopNotification-all"
name="desktopNotification-all" name="desktop"
type="radio" type="radio"
value="all" value="all"
/> />
@ -657,7 +667,7 @@ Object {
<input <input
data-testid="desktopNotification-mention" data-testid="desktopNotification-mention"
id="desktopNotification-mention" id="desktopNotification-mention"
name="desktopNotification-mention" name="desktop"
type="radio" type="radio"
value="mention" value="mention"
/> />
@ -669,7 +679,7 @@ Object {
<input <input
data-testid="desktopNotification-none" data-testid="desktopNotification-none"
id="desktopNotification-none" id="desktopNotification-none"
name="desktopNotification-none" name="desktop"
type="radio" type="radio"
value="none" value="none"
/> />
@ -836,13 +846,18 @@ Object {
<fieldset <fieldset
class="mm-modal-generic-section-item__fieldset-radio" class="mm-modal-generic-section-item__fieldset-radio"
> >
<legend
class="hidden-label"
>
Notify me about…
</legend>
<label <label
class="mm-modal-generic-section-item__label-radio" class="mm-modal-generic-section-item__label-radio"
> >
<input <input
data-testid="MobileNotification-all" data-testid="MobileNotification-all"
id="MobileNotification-all" id="MobileNotification-all"
name="MobileNotification-all" name="push"
type="radio" type="radio"
value="all" value="all"
/> />
@ -855,7 +870,7 @@ Object {
checked="" checked=""
data-testid="MobileNotification-mention" data-testid="MobileNotification-mention"
id="MobileNotification-mention" id="MobileNotification-mention"
name="MobileNotification-mention" name="push"
type="radio" type="radio"
value="mention" value="mention"
/> />
@ -868,7 +883,7 @@ Object {
<input <input
data-testid="MobileNotification-none" data-testid="MobileNotification-none"
id="MobileNotification-none" id="MobileNotification-none"
name="MobileNotification-none" name="push"
type="radio" type="radio"
value="none" value="none"
/> />
@ -1530,6 +1545,11 @@ Object {
<fieldset <fieldset
class="mm-modal-generic-section-item__fieldset-radio" class="mm-modal-generic-section-item__fieldset-radio"
> >
<legend
class="hidden-label"
>
Notify me about…
</legend>
<label <label
class="mm-modal-generic-section-item__label-radio" class="mm-modal-generic-section-item__label-radio"
> >
@ -1537,7 +1557,7 @@ Object {
checked="" checked=""
data-testid="desktopNotification-all" data-testid="desktopNotification-all"
id="desktopNotification-all" id="desktopNotification-all"
name="desktopNotification-all" name="desktop"
type="radio" type="radio"
value="all" value="all"
/> />
@ -1550,7 +1570,7 @@ Object {
<input <input
data-testid="desktopNotification-mention" data-testid="desktopNotification-mention"
id="desktopNotification-mention" id="desktopNotification-mention"
name="desktopNotification-mention" name="desktop"
type="radio" type="radio"
value="mention" value="mention"
/> />
@ -1562,7 +1582,7 @@ Object {
<input <input
data-testid="desktopNotification-none" data-testid="desktopNotification-none"
id="desktopNotification-none" id="desktopNotification-none"
name="desktopNotification-none" name="desktop"
type="radio" type="radio"
value="none" value="none"
/> />
@ -2047,6 +2067,11 @@ Object {
<fieldset <fieldset
class="mm-modal-generic-section-item__fieldset-radio" class="mm-modal-generic-section-item__fieldset-radio"
> >
<legend
class="hidden-label"
>
Notify me about…
</legend>
<label <label
class="mm-modal-generic-section-item__label-radio" class="mm-modal-generic-section-item__label-radio"
> >
@ -2054,7 +2079,7 @@ Object {
checked="" checked=""
data-testid="desktopNotification-all" data-testid="desktopNotification-all"
id="desktopNotification-all" id="desktopNotification-all"
name="desktopNotification-all" name="desktop"
type="radio" type="radio"
value="all" value="all"
/> />
@ -2067,7 +2092,7 @@ Object {
<input <input
data-testid="desktopNotification-mention" data-testid="desktopNotification-mention"
id="desktopNotification-mention" id="desktopNotification-mention"
name="desktopNotification-mention" name="desktop"
type="radio" type="radio"
value="mention" value="mention"
/> />
@ -2079,7 +2104,7 @@ Object {
<input <input
data-testid="desktopNotification-none" data-testid="desktopNotification-none"
id="desktopNotification-none" id="desktopNotification-none"
name="desktopNotification-none" name="desktop"
type="radio" type="radio"
value="none" value="none"
/> />
@ -2564,6 +2589,11 @@ Object {
<fieldset <fieldset
class="mm-modal-generic-section-item__fieldset-radio" class="mm-modal-generic-section-item__fieldset-radio"
> >
<legend
class="hidden-label"
>
Notify me about…
</legend>
<label <label
class="mm-modal-generic-section-item__label-radio" class="mm-modal-generic-section-item__label-radio"
> >
@ -2571,7 +2601,7 @@ Object {
checked="" checked=""
data-testid="desktopNotification-all" data-testid="desktopNotification-all"
id="desktopNotification-all" id="desktopNotification-all"
name="desktopNotification-all" name="desktop"
type="radio" type="radio"
value="all" value="all"
/> />
@ -2584,7 +2614,7 @@ Object {
<input <input
data-testid="desktopNotification-mention" data-testid="desktopNotification-mention"
id="desktopNotification-mention" id="desktopNotification-mention"
name="desktopNotification-mention" name="desktop"
type="radio" type="radio"
value="mention" value="mention"
/> />
@ -2596,7 +2626,7 @@ Object {
<input <input
data-testid="desktopNotification-none" data-testid="desktopNotification-none"
id="desktopNotification-none" id="desktopNotification-none"
name="desktopNotification-none" name="desktop"
type="radio" type="radio"
value="none" value="none"
/> />

View File

@ -240,22 +240,22 @@ export default function ChannelNotificationsModal(props: Props) {
handleChange={(e) => handleChange({push: e.target.value})} handleChange={(e) => handleChange({push: e.target.value})}
/> />
{props.collapsedReplyThreads && settings.push === 'mention' && {props.collapsedReplyThreads && settings.push === 'mention' &&
<CheckboxSettingItem <CheckboxSettingItem
dataTestId='mobile-reply-threads-checkbox-section' dataTestId='mobile-reply-threads-checkbox-section'
title={formatMessage({ title={formatMessage({
id: 'channel_notifications.ThreadsReplyTitle', id: 'channel_notifications.ThreadsReplyTitle',
defaultMessage: 'Thread reply notifications', defaultMessage: 'Thread reply notifications',
})} })}
inputFieldTitle={ inputFieldTitle={
<FormattedMessage <FormattedMessage
id='channel_notifications.checkbox.threadsReplyTitle' id='channel_notifications.checkbox.threadsReplyTitle'
defaultMessage="Notify me about replies to threads I\'m following" defaultMessage="Notify me about replies to threads I\'m following"
/> />
} }
inputFieldValue={settings.push_threads === 'all'} inputFieldValue={settings.push_threads === 'all'}
inputFieldData={utils.MobileReplyThreadsInputFieldData} inputFieldData={utils.MobileReplyThreadsInputFieldData}
handleChange={(e) => handleChange({push_threads: e ? 'all' : 'mention'})} handleChange={(e) => handleChange({push_threads: e ? 'all' : 'mention'})}
/>} />}
</> </>
)} )}
</> </>

View File

@ -2,7 +2,7 @@
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import React from 'react'; import React from 'react';
import {FormattedMessage} from 'react-intl'; import {defineMessage, FormattedMessage} from 'react-intl';
import type {FieldsetCheckbox} from 'components/widgets/modals/components/checkbox_setting_item'; import type {FieldsetCheckbox} from 'components/widgets/modals/components/checkbox_setting_item';
import type {FieldsetRadio} from 'components/widgets/modals/components/radio_setting_item'; import type {FieldsetRadio} from 'components/widgets/modals/components/radio_setting_item';
@ -41,69 +41,70 @@ export const AutoFollowThreadsInputFieldData: FieldsetCheckbox = {
dataTestId: 'autoFollowThreads', dataTestId: 'autoFollowThreads',
}; };
export const desktopNotificationInputFieldData = (defaultOption: string): FieldsetRadio => { const defaultMessage = defineMessage({
return { id: 'channel_notifications.default',
options: [ defaultMessage: '(default)',
{ });
dataTestId: `desktopNotification-${NotificationLevels.ALL}`,
title: ( export const desktopNotificationInputFieldData = (defaultOption: string): FieldsetRadio => ({
<FormattedMessage options: [
id='channelNotifications.desktopNotification.allMessages' {
defaultMessage='All new messages {optionalDefault}' dataTestId: `desktopNotification-${NotificationLevels.ALL}`,
values={{ title: (
optionalDefault: defaultOption === NotificationLevels.ALL ? ( <FormattedMessage
<FormattedMessage id='channelNotifications.desktopNotification.allMessages'
id='channel_notifications.default' defaultMessage='All new messages {optionalDefault}'
defaultMessage='(default)' values={{
/>) : undefined, optionalDefault: defaultOption === NotificationLevels.ALL ? (
}} <FormattedMessage
/> {...defaultMessage}
), />) : undefined,
name: `desktopNotification-${NotificationLevels.ALL}`, }}
key: `desktopNotification-${NotificationLevels.ALL}`, />
value: NotificationLevels.ALL, ),
}, name: 'desktop',
{ key: `desktopNotification-${NotificationLevels.ALL}`,
dataTestId: `desktopNotification-${NotificationLevels.MENTION}`, value: NotificationLevels.ALL,
title: ( },
<FormattedMessage {
id='channelNotifications.desktopNotification.mention' dataTestId: `desktopNotification-${NotificationLevels.MENTION}`,
defaultMessage='Mentions, direct messages, and keywords only {optionalDefault}' title: (
values={{ <FormattedMessage
optionalDefault: defaultOption === NotificationLevels.MENTION ? ( id='channelNotifications.desktopNotification.mention'
<FormattedMessage defaultMessage='Mentions, direct messages, and keywords only {optionalDefault}'
id='channel_notifications.default' values={{
defaultMessage='(default)' optionalDefault: defaultOption === NotificationLevels.MENTION ? (
/>) : undefined, <FormattedMessage
}} {...defaultMessage}
/> />) : undefined,
), }}
name: `desktopNotification-${NotificationLevels.MENTION}`, />
key: `desktopNotification-${NotificationLevels.MENTION}`, ),
value: NotificationLevels.MENTION, name: 'desktop',
}, key: `desktopNotification-${NotificationLevels.MENTION}`,
{ value: NotificationLevels.MENTION,
dataTestId: `desktopNotification-${NotificationLevels.NONE}`, },
title: ( {
<FormattedMessage dataTestId: `desktopNotification-${NotificationLevels.NONE}`,
id='channelNotifications.desktopNotification.nothing' title: (
defaultMessage='Nothing {optionalDefault}' <FormattedMessage
values={{ id='channelNotifications.desktopNotification.nothing'
optionalDefault: defaultOption === NotificationLevels.NONE ? ( defaultMessage='Nothing {optionalDefault}'
<FormattedMessage values={{
id='channel_notifications.default' optionalDefault: defaultOption === NotificationLevels.NONE ? (
defaultMessage='(default)' <FormattedMessage
/>) : undefined, {...defaultMessage}
}} />) : undefined,
/> }}
), />
name: `desktopNotification-${NotificationLevels.NONE}`, ),
key: `desktopNotification-${NotificationLevels.NONE}`, name: 'desktop',
value: NotificationLevels.NONE, key: `desktopNotification-${NotificationLevels.NONE}`,
}, value: NotificationLevels.NONE,
], },
}; ],
}; }
);
export const desktopNotificationSoundsCheckboxFieldData: FieldsetCheckbox = { export const desktopNotificationSoundsCheckboxFieldData: FieldsetCheckbox = {
name: 'desktopNotificationSoundsCheckbox', name: 'desktopNotificationSoundsCheckbox',
@ -116,69 +117,66 @@ export const desktopNotificationSoundsSelectFieldData: FieldsetReactSelect = {
options: optionsOfMessageNotificationSoundsSelect, options: optionsOfMessageNotificationSoundsSelect,
}; };
export const mobileNotificationInputFieldData = (defaultOption: string): FieldsetRadio => { export const mobileNotificationInputFieldData = (defaultOption: string): FieldsetRadio => ({
return { options: [
options: [ {
{ dataTestId: `MobileNotification-${NotificationLevels.ALL}`,
dataTestId: `MobileNotification-${NotificationLevels.ALL}`, title: (
title: ( <FormattedMessage
<FormattedMessage id='channelNotifications.mobileNotification.newMessages'
id='channelNotifications.mobileNotification.newMessages' defaultMessage='All new messages {optionalDefault}'
defaultMessage='All new messages {optionalDefault}' values={{
values={{ optionalDefault: defaultOption === NotificationLevels.ALL ? (
optionalDefault: defaultOption === NotificationLevels.ALL ? ( <FormattedMessage
<FormattedMessage {...defaultMessage}
id='channel_notifications.default' />) : undefined,
defaultMessage='(default)' }}
/>) : undefined, />
}} ),
/> name: 'push',
), key: `MobileNotification-${NotificationLevels.ALL}`,
name: `MobileNotification-${NotificationLevels.ALL}`, value: NotificationLevels.ALL,
key: `MobileNotification-${NotificationLevels.ALL}`, },
value: NotificationLevels.ALL, {
}, dataTestId: `MobileNotification-${NotificationLevels.MENTION}`,
{ title: (
dataTestId: `MobileNotification-${NotificationLevels.MENTION}`, <FormattedMessage
title: (
<FormattedMessage id='channelNotifications.mobileNotification.mention'
id='channelNotifications.mobileNotification.mention' defaultMessage='Mentions, direct messages, and keywords only {optionalDefault}'
defaultMessage='Mentions, direct messages, and keywords only {optionalDefault}' values={{
values={{ optionalDefault: defaultOption === NotificationLevels.MENTION ? (
optionalDefault: defaultOption === NotificationLevels.MENTION ? ( <FormattedMessage
<FormattedMessage {...defaultMessage}
id='channel_notifications.default' />) : undefined,
defaultMessage='(default)' }}
/>) : undefined, />
}} ),
/> name: 'push',
), key: `MobileNotification-${NotificationLevels.MENTION}`,
name: `MobileNotification-${NotificationLevels.MENTION}`, value: NotificationLevels.MENTION,
key: `MobileNotification-${NotificationLevels.MENTION}`, },
value: NotificationLevels.MENTION, {
}, dataTestId: `MobileNotification-${NotificationLevels.NONE}`,
{ title: (
dataTestId: `MobileNotification-${NotificationLevels.NONE}`, <FormattedMessage
title: ( id='channelNotifications.mobileNotification.nothing'
<FormattedMessage defaultMessage='Nothing {optionalDefault}'
id='channelNotifications.mobileNotification.nothing' values={{
defaultMessage='Nothing {optionalDefault}' optionalDefault: defaultOption === NotificationLevels.NONE ? (
values={{ <FormattedMessage
optionalDefault: defaultOption === NotificationLevels.NONE ? ( {...defaultMessage}
<FormattedMessage />) : undefined,
id='channel_notifications.default' }}
defaultMessage='(default)' />
/>) : undefined, ),
}} name: 'push',
/> key: `MobileNotification-${NotificationLevels.NONE}`,
), value: NotificationLevels.NONE,
name: `MobileNotification-${NotificationLevels.NONE}`, },
key: `MobileNotification-${NotificationLevels.NONE}`, ],
value: NotificationLevels.NONE, }
}, );
],
};
};
export default { export default {
desktopNotificationInputFieldData, desktopNotificationInputFieldData,

View File

@ -54,7 +54,12 @@ function RadioSettingItem({
}); });
const content = ( const content = (
<fieldset className='mm-modal-generic-section-item__fieldset-radio'> <fieldset
className='mm-modal-generic-section-item__fieldset-radio'
>
<legend className='hidden-label'>
{title}
</legend>
{[...fields]} {[...fields]}
</fieldset> </fieldset>
); );