Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export class DashboardStateSync {
// Since we call this in afterNavigation, there could be a scenario where navigation completes but data for init isnt loaded yet.
// Init already incorporates the url into the state so we can skip this processing.
if (this.updating || !this.initialized) return;
this.updating = true;

const { data: validSpecData } = get(this.dataLoader.validSpecQuery);
const metricsViewSpec = validSpecData?.metricsView ?? {};
Expand All @@ -236,56 +235,65 @@ export class DashboardStateSync {

const pageState = get(page);

if (metricsViewSpec.timeDimension && !import.meta.env.VITEST) {
// Resolve start/end by making a network call.
[
partialExplore.selectedTimeRange,
// partialExplore.selectedComparisonTimeRange,
] = await resolveTimeRanges(
this.client,
exploreSpec,
// Take the lock only once the guards have passed;
// the finally ensures a throw below cannot leave it stuck.
this.updating = true;
let redirectUrl: URL;
try {
if (metricsViewSpec.timeDimension && !import.meta.env.VITEST) {
// Resolve start/end by making a network call.
[
partialExplore.selectedTimeRange,
// partialExplore.selectedComparisonTimeRange,
],
partialExplore.selectedTimezone,
undefined,
partialExplore.selectedTimeDimension,
] = await resolveTimeRanges(
this.client,
exploreSpec,
[
partialExplore.selectedTimeRange,
// partialExplore.selectedComparisonTimeRange,
],
partialExplore.selectedTimezone,
undefined,
partialExplore.selectedTimeDimension,
);
}

// Merge the partial state from url into the store
metricsExplorerStore.mergePartialExplorerEntity(
this.exploreName,
partialExplore,
);
}

// Merge the partial state from url into the store
metricsExplorerStore.mergePartialExplorerEntity(
this.exploreName,
partialExplore,
);
// Get time controls state after explore state is updated.
const timeControlsState = get(this.timeControlStore);
// Get the updated URL, this could be different from the page url if we added extra state.
// The extra state could come from session storage, home bookmark or yaml defaults
const redirectUrl = this.getUrlForExploreState(partialExplore);

// Get the full updated state and save to session storage
const updatedExploreState =
get(metricsExplorerStore).entities[this.exploreName];
updateExploreSessionStore(
this.exploreName,
this.extraPrefix,
updatedExploreState,
exploreSpec,
metricsViewSpec,
timeControlsState,
);
if (!this.dataLoader.disableMostRecentDashboardState) {
// Update "most recent explore state" with updated state from url
saveMostRecentPartialExploreState(
// Get time controls state after explore state is updated.
const timeControlsState = get(this.timeControlStore);
// Get the updated URL, this could be different from the page url if we added extra state.
// The extra state could come from session storage, home bookmark or yaml defaults
redirectUrl = this.getUrlForExploreState(partialExplore);

// Get the full updated state and save to session storage
const updatedExploreState =
get(metricsExplorerStore).entities[this.exploreName];
updateExploreSessionStore(
this.exploreName,
this.extraPrefix,
updatedExploreState,
exploreSpec,
metricsViewSpec,
timeControlsState,
);
if (!this.dataLoader.disableMostRecentDashboardState) {
// Update "most recent explore state" with updated state from url
saveMostRecentPartialExploreState(
this.exploreName,
this.extraPrefix,
updatedExploreState,
);
}
} finally {
// Release before the goto below: state changes made while the navigation is in flight
// must still be picked up by gotoNewState.
this.updating = false;
}

this.updating = false;
// If the url doesn't need to be changed further then we can skip the goto
if (redirectUrl.search === pageState.url.search) {
return;
Expand All @@ -311,44 +319,46 @@ export class DashboardStateSync {
if (this.updating) return;
this.updating = true;

const { data: validSpecData } = get(this.dataLoader.validSpecQuery);
const exploreSpec = validSpecData?.explore ?? {};
const metricsViewSpec = validSpecData?.metricsView ?? {};
const timeControlsState = get(this.timeControlStore);
try {
const { data: validSpecData } = get(this.dataLoader.validSpecQuery);
const exploreSpec = validSpecData?.explore ?? {};
const metricsViewSpec = validSpecData?.metricsView ?? {};
const timeControlsState = get(this.timeControlStore);

const pageState = get(page);
const pageState = get(page);

// Get the new url params for the updated state
const newUrl = this.getUrlForExploreState(exploreState);
// Get the new url params for the updated state
const newUrl = this.getUrlForExploreState(exploreState);

// Update the session storage with the new explore state.
updateExploreSessionStore(
this.exploreName,
this.extraPrefix,
exploreState,
exploreSpec,
metricsViewSpec,
timeControlsState,
);
if (!this.dataLoader.disableMostRecentDashboardState) {
// Update "most recent explore state" with updated state.
// Since we do not update the state per action we do it here as blanket update.
saveMostRecentPartialExploreState(
// Update the session storage with the new explore state.
updateExploreSessionStore(
this.exploreName,
this.extraPrefix,
exploreState,
exploreSpec,
metricsViewSpec,
timeControlsState,
);
}
if (!this.dataLoader.disableMostRecentDashboardState) {
// Update "most recent explore state" with updated state.
// Since we do not update the state per action we do it here as blanket update.
saveMostRecentPartialExploreState(
this.exploreName,
this.extraPrefix,
exploreState,
);
}

// If the state didnt result in a new url then skip goto.
// This avoids adding redundant urls to the history.
if (newUrl.search === pageState.url.search) {
return;
}

// If the state didnt result in a new url then skip goto.
// This avoids adding redundant urls to the history.
if (newUrl.search === pageState.url.search) {
// dashboard changed so we should update the url
await goto(newUrl);
} finally {
this.updating = false;
return;
}

// dashboard changed so we should update the url
await goto(newUrl);
this.updating = false;
}
}
Loading