Skip to content

Commit

Permalink
Fix time range params vanishing on reloading (#6315)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde authored Dec 19, 2024
1 parent d59498f commit a00746a
Showing 1 changed file with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
hasSessionStorageData,
updateExploreSessionStore,
} from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import { waitUntil } from "@rilldata/web-common/lib/waitUtils";
import {
createQueryServiceMetricsViewSchema,
type V1ExplorePreset,
Expand Down Expand Up @@ -49,7 +50,11 @@
metricsViewName,
);
$: ({ error: schemaError } = $metricsViewSchema);
$: ({ error, data: timeRangeSummaryResp } = $timeRangeSummaryStore);
$: ({
error,
data: timeRangeSummaryResp,
isLoading: timeRangeSummaryIsLoading,
} = $timeRangeSummaryStore);
$: timeRangeSummaryError = error as HTTPError;
let timeControlsState: TimeControlState | undefined = undefined;
Expand All @@ -63,13 +68,14 @@
}
let prevUrl = "";
let initializing = false;
onMount(() => {
// in some cases afterNavigate is not always triggered
// so this is the escape hatch to make sure dashboard store gets initialised
setTimeout(() => {
if (!$dashboardStore) {
handleExploreInit(true);
void handleExploreInit(true);
}
});
});
Expand Down Expand Up @@ -103,7 +109,7 @@
// When a user changes url manually and clears the params the `type` will be "enter"
// This signal is used in handleExploreInit to make sure we do not use sessionStorage
const isManualUrlChange = type === "enter";
handleExploreInit(isManualUrlChange);
void handleExploreInit(isManualUrlChange);
return;
}
Expand Down Expand Up @@ -160,8 +166,9 @@
});
});
function handleExploreInit(isManualUrlChange: boolean) {
if (!exploreSpec || !metricsSpec) return;
async function handleExploreInit(isManualUrlChange: boolean) {
if (!exploreSpec || !metricsSpec || initializing) return;
initializing = true;
let initState: Partial<MetricsExplorerEntity> | undefined;
let shouldUpdateUrl = false;
Expand All @@ -187,7 +194,14 @@
};
}
await waitUntil(() => !timeRangeSummaryIsLoading);
metricsExplorerStore.init(exploreName, initState);
timeControlsState ??= getTimeControlState(
metricsSpec,
exploreSpec,
timeRangeSummaryResp?.timeRangeSummary,
get(metricsExplorerStore).entities[exploreName],
);
const redirectUrl = new URL($page.url);
redirectUrl.search = getUpdatedUrlForExploreState(
exploreSpec,
Expand Down

2 comments on commit a00746a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.