From 1e0dcba3c747a2951e775ebfda42b6c53e7ab2dc Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Fri, 20 Dec 2024 18:29:21 +0530 Subject: [PATCH 1/3] Disable delete bookmark button while deleting --- .../src/features/bookmarks/Bookmarks.svelte | 11 +++++---- .../BookmarksDropdownMenuContent.svelte | 23 +++++++++---------- .../BookmarksDropdownMenuItem.svelte | 21 ++++++++++++----- 3 files changed, 32 insertions(+), 23 deletions(-) diff --git a/web-admin/src/features/bookmarks/Bookmarks.svelte b/web-admin/src/features/bookmarks/Bookmarks.svelte index 5d5cded278f..11596b36820 100644 --- a/web-admin/src/features/bookmarks/Bookmarks.svelte +++ b/web-admin/src/features/bookmarks/Bookmarks.svelte @@ -98,13 +98,14 @@ (showDialog = true)} - on:create-home={() => createHomeBookmark()} - on:delete={({ detail }) => deleteBookmark(detail)} - on:edit={({ detail }) => { + onCreate={(isHome) => { + isHome ? createHomeBookmark() : (showDialog = true); + }} + onEdit={(editingBookmark) => { showDialog = true; - bookmark = detail; + bookmark = editingBookmark; }} + onDelete={deleteBookmark} {metricsViewName} {exploreName} /> diff --git a/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte b/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte index 7d738ab2a65..7f218204527 100644 --- a/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte +++ b/web-admin/src/features/bookmarks/BookmarksDropdownMenuContent.svelte @@ -6,6 +6,7 @@ } from "@rilldata/web-admin/client"; import BookmarkItem from "@rilldata/web-admin/features/bookmarks/BookmarksDropdownMenuItem.svelte"; import { + type BookmarkEntry, categorizeBookmarks, searchBookmarks, } from "@rilldata/web-admin/features/bookmarks/selectors"; @@ -30,12 +31,13 @@ import { createQueryServiceMetricsViewSchema } from "@rilldata/web-common/runtime-client"; import { runtime } from "@rilldata/web-common/runtime-client/runtime-store"; import { BookmarkPlusIcon } from "lucide-svelte"; - import { createEventDispatcher } from "svelte"; export let metricsViewName: string; export let exploreName: string; - const dispatch = createEventDispatcher(); + export let onCreate: (isHome: boolean) => void; + export let onEdit: (bookmark: BookmarkEntry) => void; + export let onDelete: (bookmark: BookmarkEntry) => Promise; $: organization = $page.params.organization; $: project = $page.params.project; @@ -89,17 +91,14 @@ - dispatch("create")}> + onCreate(false)}>
Bookmark current view
{#if manageProject} - dispatch("create-home")} - slot="manage-project" - > + onCreate(true)} slot="manage-project">
@@ -130,7 +129,7 @@ {#if filteredBookmarks.personal?.length} {#each filteredBookmarks.personal as bookmark} {#key bookmark.resource.id} - + {/key} {/each} {:else} @@ -150,8 +149,8 @@ {#key filteredBookmarks.home.resource.id} {/key} @@ -160,8 +159,8 @@ {#key bookmark.resource.id} {/key} diff --git a/web-admin/src/features/bookmarks/BookmarksDropdownMenuItem.svelte b/web-admin/src/features/bookmarks/BookmarksDropdownMenuItem.svelte index 19c0cf13b64..6078e90b142 100644 --- a/web-admin/src/features/bookmarks/BookmarksDropdownMenuItem.svelte +++ b/web-admin/src/features/bookmarks/BookmarksDropdownMenuItem.svelte @@ -6,21 +6,28 @@ import HomeBookmark from "@rilldata/web-common/components/icons/HomeBookmark.svelte"; import Trash from "@rilldata/web-common/components/icons/Trash.svelte"; import { BookmarkIcon } from "lucide-svelte"; - import { createEventDispatcher } from "svelte"; export let bookmark: BookmarkEntry; export let readOnly = false; - const dispatch = createEventDispatcher(); + export let onEdit: (bookmark: BookmarkEntry) => void; + export let onDelete: (bookmark: BookmarkEntry) => Promise; function editBookmark(e) { e.skipSelection = true; - dispatch("edit", bookmark); + onEdit(bookmark); } - function deleteBookmark(e) { + let disableDelete = false; + async function deleteBookmark(e) { + disableDelete = true; e.skipSelection = true; - dispatch("delete", bookmark); + try { + await onDelete(bookmark); + } catch { + // no-op + } + disableDelete = false; } let hovered = false; @@ -34,7 +41,7 @@ role="menuitem" tabindex="-1" > - + {#if bookmark.resource.default} {:else if bookmark.filtersOnly} @@ -69,6 +76,8 @@ From bd9e09b19fea639ab43ae48b3a9efb39202cc12e Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Fri, 20 Dec 2024 18:30:24 +0530 Subject: [PATCH 2/3] Fix filterOnly calucation for bookmark edit --- web-admin/src/features/bookmarks/selectors.ts | 36 +++++-------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/web-admin/src/features/bookmarks/selectors.ts b/web-admin/src/features/bookmarks/selectors.ts index cdba5a8f2ba..e77b2274049 100644 --- a/web-admin/src/features/bookmarks/selectors.ts +++ b/web-admin/src/features/bookmarks/selectors.ts @@ -142,15 +142,15 @@ export function getPrettySelectedTimeRange( ); } -export function convertBookmarkToUrlSearchParams( +function parseBookmark( bookmarkResource: V1Bookmark, metricsViewSpec: V1MetricsViewSpec, exploreSpec: V1ExploreSpec, schema: V1StructType, - exploreState: MetricsExplorerEntity | undefined, + exploreState: MetricsExplorerEntity, defaultExplorePreset: V1ExplorePreset, timeRangeSummary: V1TimeRangeSummary | undefined, -) { +): BookmarkEntry { const exploreStateFromBookmark = getDashboardStateFromUrl( bookmarkResource.data ?? "", metricsViewSpec, @@ -161,7 +161,9 @@ export function convertBookmarkToUrlSearchParams( ...(exploreState ?? {}), ...exploreStateFromBookmark, } as MetricsExplorerEntity; - return convertExploreStateToURLSearchParams( + + const url = new URL(get(page).url); + url.search = convertExploreStateToURLSearchParams( finalExploreState, exploreSpec, getTimeControlState( @@ -172,32 +174,12 @@ export function convertBookmarkToUrlSearchParams( ), defaultExplorePreset, ); -} - -function parseBookmark( - bookmarkResource: V1Bookmark, - metricsViewSpec: V1MetricsViewSpec, - exploreSpec: V1ExploreSpec, - schema: V1StructType, - exploreState: MetricsExplorerEntity, - defaultExplorePreset: V1ExplorePreset, - timeRangeSummary: V1TimeRangeSummary | undefined, -): BookmarkEntry { - const url = new URL(get(page).url); - url.search = convertBookmarkToUrlSearchParams( - bookmarkResource, - metricsViewSpec, - exploreSpec, - schema, - exploreState, - defaultExplorePreset, - timeRangeSummary, - ); return { resource: bookmarkResource, absoluteTimeRange: - exploreState.selectedTimeRange?.name === TimeRangePreset.CUSTOM, - filtersOnly: !exploreState.pivot, + exploreStateFromBookmark.selectedTimeRange?.name === + TimeRangePreset.CUSTOM, + filtersOnly: !exploreStateFromBookmark.pivot, url: url.toString(), }; } From 595fc88383d162bf65270a499f63a640ddc70ebb Mon Sep 17 00:00:00 2001 From: Aditya Hegde Date: Fri, 20 Dec 2024 18:31:14 +0530 Subject: [PATCH 3/3] Fix dashboards without timestamp and home bookmark --- .../dashboards/url-state/DashboardURLStateSync.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte b/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte index 4a0d7d775da..8730fdc2dfd 100644 --- a/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte +++ b/web-common/src/features/dashboards/url-state/DashboardURLStateSync.svelte @@ -160,6 +160,8 @@ } prevUrl = redirectUrl.toString(); + // using `replaceState` directly messes up the navigation entries, + // `from` and `to` have the old url before being replaced in `afterNavigate` calls leading to incorrect handling. void goto(redirectUrl, { replaceState: true, state: $page.state, @@ -194,7 +196,11 @@ }; } - await waitUntil(() => !timeRangeSummaryIsLoading); + // time range summary query has `enabled` based on `metricsSpec.timeDimension` + // isLoading will never be true when the query is disabled, so we need this check before waiting for it. + if (metricsSpec.timeDimension) { + await waitUntil(() => !timeRangeSummaryIsLoading); + } metricsExplorerStore.init(exploreName, initState); timeControlsState ??= getTimeControlState( metricsSpec,