Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bookmark interaction with url params #6318

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 6 additions & 5 deletions web-admin/src/features/bookmarks/Bookmarks.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@
</Button>
</DropdownMenuTrigger>
<BookmarksContent
on:create={() => (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}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<void>;
$: organization = $page.params.organization;
$: project = $page.params.project;
Expand Down Expand Up @@ -89,17 +91,14 @@
</script>

<DropdownMenuContent class="w-[450px]">
<DropdownMenuItem on:click={() => dispatch("create")}>
<DropdownMenuItem on:click={() => onCreate(false)}>
<div class="flex flex-row gap-x-2 items-center">
<BookmarkPlusIcon size="16px" strokeWidth={1.5} />
<div class="text-xs">Bookmark current view</div>
</div>
</DropdownMenuItem>
{#if manageProject}
<DropdownMenuItem
on:click={() => dispatch("create-home")}
slot="manage-project"
>
<DropdownMenuItem on:click={() => onCreate(true)} slot="manage-project">
<div class="flex flex-row gap-x-2">
<HomeBookmarkPlus size="16px" />
<div>
Expand Down Expand Up @@ -130,7 +129,7 @@
{#if filteredBookmarks.personal?.length}
{#each filteredBookmarks.personal as bookmark}
{#key bookmark.resource.id}
<BookmarkItem {bookmark} on:edit on:select on:delete />
<BookmarkItem {bookmark} {onEdit} {onDelete} on:select />
{/key}
{/each}
{:else}
Expand All @@ -150,8 +149,8 @@
{#key filteredBookmarks.home.resource.id}
<BookmarkItem
bookmark={filteredBookmarks.home}
on:edit
on:delete
{onEdit}
{onDelete}
readOnly={!manageProject}
/>
{/key}
Expand All @@ -160,8 +159,8 @@
{#key bookmark.resource.id}
<BookmarkItem
{bookmark}
on:edit
on:delete
{onEdit}
{onDelete}
readOnly={!manageProject}
/>
{/key}
Expand Down
21 changes: 15 additions & 6 deletions web-admin/src/features/bookmarks/BookmarksDropdownMenuItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
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;
Expand All @@ -34,7 +41,7 @@
role="menuitem"
tabindex="-1"
>
<a href={bookmark.url} class="flex flex-row gap-x-2 w-full">
<a href={bookmark.url} class="flex flex-row gap-x-2 w-full min-h-7">
{#if bookmark.resource.default}
<HomeBookmark size="16px" />
{:else if bookmark.filtersOnly}
Expand Down Expand Up @@ -69,6 +76,8 @@
<button
on:click={deleteBookmark}
class="bg-gray-100 hover:bg-primary-100 px-2 h-7 text-gray-400 hover:text-gray-500"
disabled={disableDelete}
aria-disabled={disableDelete}
>
<Trash size="16px" />
</button>
Expand Down
36 changes: 9 additions & 27 deletions web-admin/src/features/bookmarks/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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(),
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading