-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Apply home bookmark on page load (#4269)
* Apply home bookmark on page load * Fix lint
- Loading branch information
1 parent
50a4fb9
commit c9deff2
Showing
7 changed files
with
140 additions
and
44 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
web-admin/src/features/dashboards/DashboardAdminStateProvider.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<script lang="ts"> | ||
import { page } from "$app/stores"; | ||
import { useQueryClient } from "@rilldata/svelte-query"; | ||
import { getBookmarks } from "@rilldata/web-admin/features/bookmarks/selectors"; | ||
import { | ||
createTimeRangeSummary, | ||
useMetricsView, | ||
useModelHasTimeSeries, | ||
} from "@rilldata/web-common/features/dashboards/selectors/index"; | ||
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers"; | ||
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores"; | ||
import { hasPersistentDashboardData } from "@rilldata/web-common/features/dashboards/stores/persistent-dashboard-state"; | ||
import { syncDashboardState } from "@rilldata/web-common/features/dashboards/stores/syncDashboardState"; | ||
import { initLocalUserPreferenceStore } from "@rilldata/web-common/features/dashboards/user-preferences"; | ||
import { createQueryServiceMetricsViewSchema } from "@rilldata/web-common/runtime-client"; | ||
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store"; | ||
import Spinner from "@rilldata/web-common/features/entity-management/Spinner.svelte"; | ||
import { EntityStatus } from "@rilldata/web-common/features/entity-management/types"; | ||
export let metricViewName: string; | ||
$: initLocalUserPreferenceStore(metricViewName); | ||
const stateManagers = getStateManagers(); | ||
const metricsView = useMetricsView(stateManagers); | ||
const hasTimeSeries = useModelHasTimeSeries(stateManagers); | ||
const timeRangeQuery = createTimeRangeSummary(stateManagers); | ||
const metricsViewSchema = createQueryServiceMetricsViewSchema( | ||
$runtime.instanceId, | ||
metricViewName, | ||
); | ||
const queryClient = useQueryClient(); | ||
$: bookmarks = getBookmarks( | ||
queryClient, | ||
$runtime?.instanceId, | ||
$page.params.organization, | ||
$page.params.project, | ||
metricViewName, | ||
); | ||
function syncDashboardStateLocal() { | ||
let stateToLoad = $page.url.searchParams.get("state"); | ||
if ( | ||
!hasPersistentDashboardData() && | ||
!stateToLoad && | ||
$bookmarks.data?.home.resource.data | ||
) { | ||
stateToLoad = $bookmarks.data?.home.resource.data; | ||
} | ||
syncDashboardState( | ||
metricViewName, | ||
$metricsView.data, | ||
$metricsViewSchema.data?.schema, | ||
$timeRangeQuery.data, | ||
stateToLoad, | ||
); | ||
} | ||
$: if ( | ||
$metricsView.data && | ||
$metricsViewSchema.data && | ||
($timeRangeQuery.data || !$hasTimeSeries.data) && | ||
!$bookmarks.isFetching | ||
) { | ||
syncDashboardStateLocal(); | ||
} | ||
$: ready = metricViewName in $metricsExplorerStore.entities; | ||
</script> | ||
|
||
{#if ready} | ||
<slot /> | ||
{:else} | ||
<div class="grid place-items-center mt-40"> | ||
<Spinner status={EntityStatus.Running} size="40px" /> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
} | ||
onDestroy(() => { | ||
if (unsubscribe) unsubscribe(); | ||
unsubscribe?.(); | ||
}); | ||
</script> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
web-common/src/features/dashboards/stores/syncDashboardState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores"; | ||
import type { | ||
V1MetricsViewSpec, | ||
V1MetricsViewTimeRangeResponse, | ||
V1StructType, | ||
} from "@rilldata/web-common/runtime-client"; | ||
import { get } from "svelte/store"; | ||
|
||
export function syncDashboardState( | ||
metricViewName: string, | ||
metricsViewSpec: V1MetricsViewSpec | undefined, | ||
metricsViewSchema: V1StructType | undefined, | ||
timeRangeQuery: V1MetricsViewTimeRangeResponse | undefined, | ||
preloadUrlState: string | null, | ||
) { | ||
if (!metricsViewSpec || !metricsViewSchema) return; | ||
if (metricViewName in get(metricsExplorerStore).entities) { | ||
metricsExplorerStore.sync(metricViewName, metricsViewSpec); | ||
} else { | ||
metricsExplorerStore.init(metricViewName, metricsViewSpec, timeRangeQuery); | ||
if (preloadUrlState) { | ||
metricsExplorerStore.syncFromUrl( | ||
metricViewName, | ||
preloadUrlState, | ||
metricsViewSpec, | ||
metricsViewSchema, | ||
); | ||
// Call sync to make sure changes in dashboard are honoured | ||
metricsExplorerStore.sync(metricViewName, metricsViewSpec); | ||
} | ||
} | ||
} |
c9deff2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://ui.rilldata.in as production
🚀 Deployed on https://65ef2485aaf1ae72aaf26fca--rill-ui-dev.netlify.app