Skip to content

Commit

Permalink
Add schema requests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 16, 2024
1 parent a902ded commit 273a675
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import { getDefaultExplorePreset } from "@rilldata/web-common/features/dashboards/url-state/getDefaultExplorePreset";
import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors";
import { useExploreValidSpec } from "@rilldata/web-common/features/explores/selectors";
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";
Expand All @@ -51,6 +52,10 @@
exploreSpec,
$metricsViewTimeRange.data,
);
$: schemaResp = createQueryServiceMetricsViewSchema(
$runtime.instanceId,
metricsViewName,
);
$: projectIdResp = useProjectId(organization, project);
const userResp = createAdminServiceGetCurrentUser();
Expand All @@ -72,7 +77,7 @@
$bookamrksResp.data?.bookmarks ?? [],
metricsViewSpec,
exploreSpec,
{},
$schemaResp.data?.schema,
$exploreState,
defaultExplorePreset,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { fetchMagicAuthToken } from "@rilldata/web-admin/features/projects/selectors";
import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboards/proto-state/fromProto";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { fetchExploreSpec } from "@rilldata/web-common/features/explores/selectors";
import {
fetchExploreSpec,
fetchMetricsViewSchema,
} from "@rilldata/web-common/features/explores/selectors";
import { error } from "@sveltejs/kit";

export const load = async ({ params: { token }, parent }) => {
Expand All @@ -28,11 +31,15 @@ export const load = async ({ params: { token }, parent }) => {
let tokenExploreState: Partial<MetricsExplorerEntity> | undefined =
undefined;
if (tokenData.token?.state) {
const schema = await fetchMetricsViewSchema(
runtime?.instanceId,
exploreSpec.metricsView ?? "",
);
tokenExploreState = getDashboardStateFromUrl(
tokenData.token?.state,
metricsViewSpec,
exploreSpec,
{}, // TODO
schema,
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type { V1Bookmark } from "@rilldata/web-admin/client";
import {
fetchBookmarks,
isHomeBookmark,
} from "@rilldata/web-admin/features/bookmarks/selectors";
import { getDashboardStateFromUrl } from "@rilldata/web-common/features/dashboards/proto-state/fromProto";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { fetchExploreSpec } from "@rilldata/web-common/features/explores/selectors";
import {
fetchExploreSpec,
fetchMetricsViewSchema,
} from "@rilldata/web-common/features/explores/selectors";
import {
type V1ExplorePreset,
type V1Resource,
Expand All @@ -21,13 +25,21 @@ export const load = async ({ params, depends, parent }) => {
let metricsView: V1Resource | undefined;
let defaultExplorePreset: V1ExplorePreset | undefined;
let exploreStateFromYAMLConfig: Partial<MetricsExplorerEntity> = {};
let bookmarks: V1Bookmark[] | undefined;

try {
({
explore,
metricsView,
defaultExplorePreset,
exploreStateFromYAMLConfig,
} = await fetchExploreSpec(runtime?.instanceId, exploreName));
[
{
explore,
metricsView,
defaultExplorePreset,
exploreStateFromYAMLConfig,
},
bookmarks,
] = await Promise.all([
fetchExploreSpec(runtime?.instanceId, exploreName),
fetchBookmarks(project.id, exploreName),
]);
} catch {
// error handled in +page.svelte for now
// TODO: move it here
Expand All @@ -45,15 +57,18 @@ export const load = async ({ params, depends, parent }) => {
let homeBookmarkExploreState: Partial<MetricsExplorerEntity> | undefined =
undefined;
try {
const bookmarks = await fetchBookmarks(project.id, exploreName);
const homeBookmark = bookmarks.find(isHomeBookmark);
const schema = await fetchMetricsViewSchema(
runtime?.instanceId,
exploreSpec.metricsView ?? "",
);

if (homeBookmark) {
homeBookmarkExploreState = getDashboardStateFromUrl(
homeBookmark.data ?? "",
metricsViewSpec,
exploreSpec,
{}, // TODO
schema,
);
}
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
const isInit = !$dashboardStore;
if (isInit) {
handleExploreInit(type === "enter");
// 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);
return;
}
Expand Down
16 changes: 16 additions & 0 deletions web-common/src/features/explores/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
type V1MetricsViewSpec,
type V1MetricsViewTimeRangeResponse,
type V1ExplorePreset,
getQueryServiceMetricsViewSchemaQueryKey,
queryServiceMetricsViewSchema,
} from "@rilldata/web-common/runtime-client";
import type { ErrorType } from "@rilldata/web-common/runtime-client/http-client";
import { error } from "@sveltejs/kit";
Expand Down Expand Up @@ -147,6 +149,20 @@ export async function fetchExploreSpec(
};
}

export async function fetchMetricsViewSchema(
instanceId: string,
metricsViewName: string,
) {
const schemaResp = await queryClient.fetchQuery({
queryKey: getQueryServiceMetricsViewSchemaQueryKey(
instanceId,
metricsViewName,
),
queryFn: () => queryServiceMetricsViewSchema(instanceId, metricsViewName),
});
return schemaResp.schema ?? {};
}

export function getExploreStores(
exploreName: string,
prefix: string | undefined,
Expand Down

0 comments on commit 273a675

Please sign in to comment.