Grafana-UI: Fixes timezone offset for default timezone when it is different from browser timezone (#46796)

This commit is contained in:
Joao Silva 2022-03-29 12:23:37 +01:00 committed by GitHub
parent 280b1ee828
commit 8e3b5dce76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -33,16 +33,24 @@ export const WideTimeZoneOption: React.FC<PropsWithChildren<Props>> = (props, re
return null;
}
const timeZoneInfo = getTimeZoneInfo(data.value, timestamp);
return (
<div className={containerStyles} {...innerProps} aria-label="Select option">
<div className={cx(styles.leftColumn, styles.row)}>
<div className={cx(styles.leftColumn, styles.wideRow)}>
<TimeZoneTitle title={children} />
<div className={styles.spacer} />
<TimeZoneDescription info={getTimeZoneInfo(data.value, timestamp)} />
<TimeZoneDescription info={timeZoneInfo} />
</div>
<div className={styles.rightColumn}>
<TimeZoneOffset timeZone={data.value} timestamp={timestamp} className={offsetClassName} />
<TimeZoneOffset
/* Use the timeZoneInfo to pass the correct timeZone name,
as 'Default' has value '' which defaults to browser timezone */
timeZone={timeZoneInfo?.ianaName || data.value}
timestamp={timestamp}
className={offsetClassName}
/>
{isSelected && (
<span>
<Icon name="check" />
@ -65,6 +73,8 @@ export const CompactTimeZoneOption: React.FC<PropsWithChildren<Props>> = (props,
return null;
}
const timeZoneInfo = getTimeZoneInfo(data.value, timestamp);
return (
<div className={containerStyles} {...innerProps} aria-label="Select option">
<div className={styles.body}>
@ -82,10 +92,16 @@ export const CompactTimeZoneOption: React.FC<PropsWithChildren<Props>> = (props,
</div>
<div className={styles.row}>
<div className={styles.leftColumn}>
<TimeZoneDescription info={getTimeZoneInfo(data.value, timestamp)} />
<TimeZoneDescription info={timeZoneInfo} />
</div>
<div className={styles.rightColumn}>
<TimeZoneOffset timestamp={timestamp} timeZone={data.value} className={offsetClassName} />
<TimeZoneOffset
timestamp={timestamp}
/* Use the timeZoneInfo to pass the correct timeZone name,
as 'Default' has value '' which defaults to browser timezone */
timeZone={timeZoneInfo?.ianaName || data.value}
className={offsetClassName}
/>
</div>
</div>
</div>