Skip to content

Comments

Pmm-14550: preferred timezone when displaying dates#878

Open
fabio-silva wants to merge 2 commits intomainfrom
PMM-14550-user-timezone
Open

Pmm-14550: preferred timezone when displaying dates#878
fabio-silva wants to merge 2 commits intomainfrom
PMM-14550-user-timezone

Conversation

@fabio-silva
Copy link

PMM-14550

With this PR, we send an event to notify the user preferred timezone has changed

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new application event intended to notify the UI when a user’s preferred timezone changes, so other components can react to preference updates.

Changes:

  • Introduces a new TimeZoneUpdatedEvent on the Grafana runtime app event bus.
  • Publishes the new event from the Shared Preferences “Save” flow when a timezone value is present.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
public/app/core/components/SharedPreferences/SharedPreferences.tsx Publishes a new timezone-updated app event after saving preferences.
packages/grafana-runtime/src/services/appEvents.ts Adds the TimeZoneUpdatedEvent event definition to the runtime event bus API.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 170 to +175
window.location.reload();

// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezone) {
getAppEvents().publish(new TimeZoneUpdatedEvent(timezone));
}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

TimeZoneUpdatedEvent is published after window.location.reload(), which will typically stop JS execution and drop any in-memory subscribers. Also this path calls getAppEvents().publish(...) without checking the event bus exists (elsewhere in this component you guard before subscribing). Publish the event (and optionally verify the timezone actually changed) before triggering the reload, and guard against getAppEvents() being undefined/without publish to avoid runtime/test failures.

Suggested change
window.location.reload();
// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezone) {
getAppEvents().publish(new TimeZoneUpdatedEvent(timezone));
}
// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezone) {
const eventBus = getAppEvents();
if (eventBus && typeof eventBus.publish === 'function') {
eventBus.publish(new TimeZoneUpdatedEvent(timezone));
}
}
window.location.reload();

Copilot uses AI. Check for mistakes.
Comment on lines +172 to +175
// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezone) {
getAppEvents().publish(new TimeZoneUpdatedEvent(timezone));
}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

This publishes TimeZoneUpdatedEvent whenever preferences are saved and timezone is truthy, even if the user didn’t actually change the timezone. Since this event is intended to represent a change, consider comparing against the originally loaded timezone and only publishing when the value differs to avoid unnecessary downstream recalculation/work.

Copilot uses AI. Check for mistakes.
Comment on lines 169 to +173
await this.service.update({ homeDashboardUID, theme, timezone, weekStart, language, queryHistory, navbar });
window.location.reload();

// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezone) {
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

New TimeZoneUpdatedEvent behavior isn’t covered by the existing SharedPreferences tests (this component already has good test coverage). Add/adjust a test to assert the timezone-updated event is published (and not published when unchanged) when the user saves preferences, so regressions around the save flow/reload ordering are caught.

Suggested change
await this.service.update({ homeDashboardUID, theme, timezone, weekStart, language, queryHistory, navbar });
window.location.reload();
// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezone) {
const timezoneChanged = timezone && timezone !== config.bootData.user?.timezone;
await this.service.update({ homeDashboardUID, theme, timezone, weekStart, language, queryHistory, navbar });
window.location.reload();
// @PERCONA: Publish TimeZoneUpdatedEvent to allow other components to listen to timezone changes
if (timezoneChanged) {

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant