Skip to content

Commit

Permalink
Use 2-way dashboard state/URL hash syncing to avoid failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
WiNloSt committed Feb 1, 2024
1 parent 0cadbea commit 22bc55f
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions frontend/src/metabase/dashboard/hoc/DashboardControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ export const DashboardControls = ComposedComponent =>
this.loadDashboardParams();
}

componentDidUpdate() {
this.updateDashboardParams();
componentDidUpdate(prevProps) {
if (prevProps.location !== this.props.location) {
this.syncUrlHashToState();
} else {
this.syncStateToUrlHash();
}
this._showNav(!this.state.isFullscreen);
}

Expand Down Expand Up @@ -72,7 +76,16 @@ export const DashboardControls = ComposedComponent =>
this.setHideParameters(options.hide_parameters);
};

updateDashboardParams = () => {
syncUrlHashToState() {
const { location } = this.props;

const { refresh, fullscreen, theme } = parseHashOptions(location.hash);
this.setRefreshPeriod(refresh);
this.setFullscreen(fullscreen);
this.setTheme(theme);
}

syncStateToUrlHash = () => {
const { location, replace } = this.props;

const options = parseHashOptions(location.hash);
Expand All @@ -85,10 +98,7 @@ export const DashboardControls = ComposedComponent =>
};
setValue("refresh", this.state.refreshPeriod);
setValue("fullscreen", this.state.isFullscreen);
const normalizedTheme = options.theme ?? null;
if (normalizedTheme !== this.state.theme) {
this.setTheme(normalizedTheme);
}
setValue("theme", this.state.theme);

delete options.night; // DEPRECATED: options.night

Expand Down

0 comments on commit 22bc55f

Please sign in to comment.