From 924bef8b4d26d3c71e5a29e3a62b25eab86bb6a7 Mon Sep 17 00:00:00 2001 From: Vicktor <79470910+Victor-Nyagudi@users.noreply.github.com> Date: Tue, 26 Nov 2024 11:31:04 +0300 Subject: [PATCH] [GH-24981] Fix: Manually selecting EST timezones is confused with daylight savings (#29290) * Give product branding button role The product branding only handled click events to open the switcher menu.These changes make it possible to click on the product branding using SPACE and ENTER to open/close the switcher menu. * Use dynamic index to select timezone utc Some timezones have similar arrays, so hard-coding the first item lead to duplicate items being selected. * Remove 'handleManualTimezone' method This is method is declared but not used anywhere in the code base. * Fix lint errors * Add 'key' prop to input array items Missing 'key' props led to a console error when you click the timezone option to change timezones. This change fixes it. * Revert "Give product branding button role" This reverts commit e781d708dbedaf8af8ba3790edd8c28d8605d6b9. * Add comment providing more context to changes --------- Co-authored-by: Mattermost Build --- .../manage_timezones/manage_timezones.tsx | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/webapp/channels/src/components/user_settings/display/manage_timezones/manage_timezones.tsx b/webapp/channels/src/components/user_settings/display/manage_timezones/manage_timezones.tsx index 87efa51c68..6e7d3b87e3 100644 --- a/webapp/channels/src/components/user_settings/display/manage_timezones/manage_timezones.tsx +++ b/webapp/channels/src/components/user_settings/display/manage_timezones/manage_timezones.tsx @@ -156,25 +156,46 @@ export default class ManageTimezones extends React.PureComponent { }); }; - handleManualTimezone = (e: React.ChangeEvent) => { - this.setState({manualTimezone: e.target.value}); - }; render() { const {timezones} = this.props; const {useAutomaticTimezone} = this.state; + let index = 0; + let previousTimezone: Timezone; + const timeOptions = this.props.timezones.map((timeObject) => { + if (timeObject.utc[index] === previousTimezone?.utc[index]) { + index++; + } else { + // It's safe to use the first item since consecutive timezones + // don't have the same 'utc' array. + index = index === 0 ? index : 0; + } + + previousTimezone = timeObject; + + // Some more context on why different 'utc' items are used can be found here. + // https://github.com/mattermost/mattermost/pull/29290#issuecomment-2478492626 return { - value: timeObject.utc[0], + value: timeObject.utc[index], label: timeObject.text, }; }); + let serverError; if (this.state.serverError) { serverError = ; } const inputs = []; + + // These are passed to the 'key' prop and should all be unique. + const inputId = { + automaticTimezoneInput: 1, + manualTimezoneInput: 2, + message: 3, + }; + const reactStyles = { menuPortal: (provided: React.CSSProperties) => ({ @@ -186,7 +207,10 @@ export default class ManageTimezones extends React.PureComponent { const noTimezonesFromServer = timezones.length === 0; const automaticTimezoneInput = ( -
+