Skip to content

Commit

Permalink
Fix time ranges missing from bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 19, 2024
1 parent b742deb commit 169e986
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
$schemaResp.data?.schema,
$exploreState,
defaultExplorePreset,
$metricsViewTimeRange.data?.timeRangeSummary,
);
$: filteredBookmarks = searchBookmarks(categorizedBookmarks, searchText);
Expand Down
27 changes: 21 additions & 6 deletions web-admin/src/features/bookmarks/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboar
import { useMetricsViewTimeRange } from "@rilldata/web-common/features/dashboards/selectors";
import { useExploreState } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { timeControlStateSelector } from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import {
getTimeControlState,
timeControlStateSelector,
} from "@rilldata/web-common/features/dashboards/time-controls/time-control-store";
import { convertExploreStateToURLSearchParams } from "@rilldata/web-common/features/dashboards/url-state/convertExploreStateToURLSearchParams";
import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors";
import { useExploreValidSpec } from "@rilldata/web-common/features/explores/selectors";
Expand All @@ -20,6 +23,7 @@ import {
type V1ExploreSpec,
type V1MetricsViewSpec,
type V1StructType,
type V1TimeRangeSummary,
} from "@rilldata/web-common/runtime-client";
import type { QueryClient } from "@tanstack/query-core";
import { derived, get, type Readable } from "svelte/store";
Expand Down Expand Up @@ -61,6 +65,7 @@ export function categorizeBookmarks(
schema: V1StructType | undefined,
exploreState: MetricsExplorerEntity,
defaultExplorePreset: V1ExplorePreset,
timeRangeSummary: V1TimeRangeSummary | undefined,
) {
const bookmarks: Bookmarks = {
home: undefined,
Expand All @@ -76,6 +81,7 @@ export function categorizeBookmarks(
schema ?? {},
exploreState,
defaultExplorePreset,
timeRangeSummary,
);
if (isHomeBookmark(bookmarkResource)) {
bookmarks.home = bookmark;
Expand Down Expand Up @@ -143,20 +149,27 @@ export function convertBookmarkToUrlSearchParams(
schema: V1StructType,
exploreState: MetricsExplorerEntity | undefined,
defaultExplorePreset: V1ExplorePreset,
timeRangeSummary: V1TimeRangeSummary | undefined,
) {
const exploreStateFromBookmark = getDashboardStateFromUrl(
bookmarkResource.data ?? "",
metricsViewSpec,
exploreSpec,
schema,
);
const finalExploreState = {
...(exploreState ?? {}),
...exploreStateFromBookmark,
} as MetricsExplorerEntity;
return convertExploreStateToURLSearchParams(
{
...(exploreState ?? {}),
...exploreStateFromBookmark,
} as MetricsExplorerEntity,
finalExploreState,
exploreSpec,
undefined, // TODO
getTimeControlState(
metricsViewSpec,
exploreSpec,
timeRangeSummary,
finalExploreState,
),
defaultExplorePreset,
);
}
Expand All @@ -168,6 +181,7 @@ function parseBookmark(
schema: V1StructType,
exploreState: MetricsExplorerEntity,
defaultExplorePreset: V1ExplorePreset,
timeRangeSummary: V1TimeRangeSummary | undefined,
): BookmarkEntry {
const url = new URL(get(page).url);
url.search = convertBookmarkToUrlSearchParams(
Expand All @@ -177,6 +191,7 @@ function parseBookmark(
schema,
exploreState,
defaultExplorePreset,
timeRangeSummary,
);
return {
resource: bookmarkResource,
Expand Down

0 comments on commit 169e986

Please sign in to comment.