Skip to content

Commit

Permalink
tweak: standardize instanceId access
Browse files Browse the repository at this point in the history
  • Loading branch information
briangregoryholmes committed Dec 20, 2024
1 parent 774395f commit 3596b0d
Show file tree
Hide file tree
Showing 87 changed files with 294 additions and 236 deletions.
9 changes: 4 additions & 5 deletions web-admin/src/features/alerts/CreateAlert.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,18 @@
import { useMetricsViewValidSpec } from "@rilldata/web-common/features/dashboards/selectors";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { BellPlusIcon } from "lucide-svelte";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
const {
selectors: {
timeRangeSelectors: { isCustomTimeRange },
},
runtime,
metricsViewName,
} = getStateManagers();
$: metricsView = useMetricsViewValidSpec(
$runtime?.instanceId,
$metricsViewName,
);
$: ({ instanceId } = $runtime);
$: metricsView = useMetricsViewValidSpec(instanceId, $metricsViewName);
$: hasTimeDimension = !!$metricsView?.data?.timeDimension;
let open = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
export let alert: string;
$: alertQuery = useAlert($runtime.instanceId, alert);
$: ({ instanceId } = $runtime);
$: alertQuery = useAlert(instanceId, alert);
/**
* Table column definitions.
Expand Down
4 changes: 3 additions & 1 deletion web-admin/src/features/alerts/listing/AlertsTable.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
export let organization: string;
export let project: string;
$: alerts = useAlerts($runtime.instanceId);
$: ({ instanceId } = $runtime);
$: alerts = useAlerts(instanceId);
/**
* Table column definitions.
Expand Down
3 changes: 2 additions & 1 deletion web-admin/src/features/alerts/metadata/AlertFilters.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
whereFilter = dimensionFilters;
havingFilter = dimensionThresholdFilters;
}
$: ({ instanceId } = $runtime);
$: metricsView = useMetricsView($runtime.instanceId, metricsViewName);
$: metricsView = useMetricsView(instanceId, metricsViewName);
$: dimensionIdMap = getMapFromArray(
$metricsView.data?.metricsView?.state?.validSpec?.dimensions ?? [],
(dimension) => dimension.name,
Expand Down
12 changes: 7 additions & 5 deletions web-admin/src/features/alerts/metadata/AlertMetadata.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@
export let project: string;
export let alert: string;
$: alertQuery = useAlert($runtime.instanceId, alert);
$: isAlertCreatedByCode = useIsAlertCreatedByCode($runtime.instanceId, alert);
$: ({ instanceId } = $runtime);
$: alertQuery = useAlert(instanceId, alert);
$: isAlertCreatedByCode = useIsAlertCreatedByCode(instanceId, alert);
// Get dashboard
$: dashboardName = useAlertDashboardName($runtime.instanceId, alert);
$: dashboard = useExploreValidSpec($runtime.instanceId, $dashboardName.data);
$: dashboardName = useAlertDashboardName(instanceId, alert);
$: dashboard = useExploreValidSpec(instanceId, $dashboardName.data);
$: metricsViewName = $dashboard.data?.explore?.metricsView;
$: dashboardTitle =
$dashboard.data?.explore?.displayName || $dashboardName.data;
Expand Down Expand Up @@ -69,7 +71,7 @@
name: $alertQuery.data.resource.meta.name.name,
});
await queryClient.invalidateQueries(
getRuntimeServiceListResourcesQueryKey($runtime.instanceId),
getRuntimeServiceListResourcesQueryKey(instanceId),
);
// goto only after invalidate is complete
goto(`/${organization}/${project}/-/alerts`);
Expand Down
4 changes: 3 additions & 1 deletion web-admin/src/features/bookmarks/BaseBookmarkForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
export let exploreName: string;
export let formState: ReturnType<typeof createForm<BookmarkFormValues>>;
$: ({ instanceId } = $runtime);
$: exploreState = useExploreState(exploreName);
let timeRange: V1TimeRange;
Expand All @@ -32,7 +34,7 @@
$: selectedTimeRange = getPrettySelectedTimeRange(
queryClient,
$runtime?.instanceId,
instanceId,
metricsViewName,
exploreName,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<script lang="ts">
import Label from "@rilldata/web-common/components/forms/Label.svelte";
import Switch from "@rilldata/web-common/components/forms/Switch.svelte";
import { useQueryClient } from "@rilldata/svelte-query";
import { getPrettySelectedTimeRange } from "@rilldata/web-admin/features/bookmarks/selectors.js";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store.js";
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
export let metricsViewName: string;
export let exploreName: string;
export let checked: boolean;
const queryClient = useQueryClient();
$: ({ instanceId } = $runtime);
$: selectedTimeRange = getPrettySelectedTimeRange(
queryClient,
$runtime?.instanceId,
instanceId,
metricsViewName,
exploreName,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,25 @@
const dispatch = createEventDispatcher();
$: ({ instanceId } = $runtime);
$: organization = $page.params.organization;
$: project = $page.params.project;
$: exploreState = useExploreState(exploreName);
$: validExploreSpec = useExploreValidSpec($runtime.instanceId, exploreName);
$: validExploreSpec = useExploreValidSpec(instanceId, exploreName);
$: metricsViewSpec = $validExploreSpec.data?.metricsView ?? {};
$: exploreSpec = $validExploreSpec.data?.explore ?? {};
$: metricsViewTimeRange = useMetricsViewTimeRange(
$runtime.instanceId,
instanceId,
metricsViewName,
);
$: defaultExplorePreset = getDefaultExplorePreset(
exploreSpec,
$metricsViewTimeRange.data,
);
$: schemaResp = createQueryServiceMetricsViewSchema(
$runtime.instanceId,
instanceId,
metricsViewName,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
export let isEmbedded = false;
$: dashboards = useDashboardsV2($runtime.instanceId);
$: ({ instanceId } = $runtime);
$: dashboards = useDashboardsV2(instanceId);
/**
* Table column definitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
export let dashboard: string;
$: dashboardQuery = useDashboardV2($runtime?.instanceId, dashboard);
$: ({ instanceId } = $runtime);
$: dashboardQuery = useDashboardV2(instanceId, dashboard);
$: lastRefreshedDate =
$dashboardQuery?.data?.refreshedOn &&
new Date($dashboardQuery.data.refreshedOn);
Expand Down
2 changes: 1 addition & 1 deletion web-admin/src/features/navigation/TopNavigationBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
const user = createAdminServiceGetCurrentUser();
$: instanceId = $runtime?.instanceId;
$: ({ instanceId } = $runtime);
// These can be undefined
$: ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
export let project: string;
const deleteProjectConnection = createAdminServiceUploadProjectAssets();
$: ({ instanceId } = $runtime);
$: ({ error, isLoading } = $deleteProjectConnection);
$: parsedError = extractGithubDisconnectError(
error as unknown as AxiosError<RpcStatus>,
Expand All @@ -39,7 +42,7 @@
});
open = false;
void invalidateProjectQueries($runtime.instanceId, organization, project);
void invalidateProjectQueries(instanceId, organization, project);
eventBus.emit("notification", {
message: `Disconnected github repo`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@
export let organization: string;
export let project: string;
$: ({ instanceId } = $runtime);
$: proj = createAdminServiceGetProject(organization, project);
$: isGithubConnected = !!$proj.data?.project?.githubUrl;
$: repoName =
$proj.data?.project?.githubUrl &&
getRepoNameFromGithubUrl($proj.data.project.githubUrl);
$: subpath = $proj.data?.project?.subpath;
$: githubLastSynced = useDashboardsLastUpdated(
$runtime.instanceId,
instanceId,
organization,
project,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
isReconciling = true;
void $createTrigger.mutateAsync({
instanceId: $runtime.instanceId,
instanceId,
data: {
allSourcesModels: true,
},
});
void queryClient.invalidateQueries(
getRuntimeServiceListResourcesQueryKey(
$runtime.instanceId,
instanceId,
// All resource "kinds"
undefined,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
export let report: string;
$: reportQuery = useReport($runtime.instanceId, report);
$: ({ instanceId } = $runtime);
$: reportQuery = useReport(instanceId, report);
/**
* Table column definitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
export let organization: string;
export let project: string;
$: reports = useReports($runtime.instanceId);
$: ({ instanceId } = $runtime);
$: reports = useReports(instanceId);
/**
* Table column definitions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
export let project: string;
export let report: string;
$: reportQuery = useReport($runtime.instanceId, report);
$: isReportCreatedByCode = useIsReportCreatedByCode(
$runtime.instanceId,
report,
);
$: ({ instanceId } = $runtime);
$: reportQuery = useReport(instanceId, report);
$: isReportCreatedByCode = useIsReportCreatedByCode(instanceId, report);
// Get dashboard
$: dashboardName = useReportDashboardName($runtime.instanceId, report);
$: dashboard = useExploreValidSpec($runtime.instanceId, $dashboardName.data);
$: dashboardName = useReportDashboardName(instanceId, report);
$: dashboard = useExploreValidSpec(instanceId, $dashboardName.data);
$: dashboardTitle =
$dashboard.data?.explore?.displayName || $dashboardName.data;
Expand Down Expand Up @@ -71,7 +70,7 @@
name: $reportQuery.data.resource.meta.name.name,
});
queryClient.invalidateQueries(
getRuntimeServiceListResourcesQueryKey($runtime.instanceId),
getRuntimeServiceListResourcesQueryKey(instanceId),
);
goto(`/${organization}/${project}/-/reports`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
export let project: string;
export let report: string;
$: ({ instanceId } = $runtime);
const queryClient = useQueryClient();
const triggerReport = createAdminServiceTriggerReport();
const reportQuery = useReport($runtime.instanceId, report);
const reportQuery = useReport(instanceId, report);
async function handleRunNow() {
const lastExecution =
Expand All @@ -38,8 +40,8 @@
$reportQuery.data.resource.report.state.executionHistory[0] ===
lastExecution
) {
queryClient.invalidateQueries(
getRuntimeServiceGetResourceQueryKey($runtime.instanceId, {
await queryClient.invalidateQueries(
getRuntimeServiceGetResourceQueryKey(instanceId, {
"name.name": report,
"name.kind": ResourceKind.Report,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import { EntityStatus } from "@rilldata/web-common/features/entity-management/types";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
$: ({ instanceId } = $runtime);
$: organization = $page.params.organization;
$: project = $page.params.project;
$: alertId = $page.params.alert;
$: executionTime = $page.url.searchParams.get("execution_time");
$: alert = useAlert($runtime.instanceId, alertId);
$: alert = useAlert(instanceId, alertId);
$: exploreName = getExploreName(
$alert.data?.resource?.alert?.spec?.annotations?.web_open_path,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
} from "@rilldata/web-common/features/entity-management/resource-selectors.js";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store.js";
$: instanceId = $runtime?.instanceId;
$: ({ instanceId } = $runtime);
$: canvasName = $page.params.dashboard;
$: canvasQuery = useResource(instanceId, canvasName, ResourceKind.Canvas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { V1ExportFormat } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
$: ({ instanceId } = $runtime);
$: organization = $page.params.organization;
$: project = $page.params.project;
$: reportId = $page.params.report;
Expand All @@ -19,12 +20,12 @@
const downloadReportMutation = createDownloadReportMutation();
let downloadOnce = false;
function triggerDownload() {
async function triggerDownload() {
if (downloadOnce) return;
downloadOnce = true;
$downloadReportMutation.mutateAsync({
await $downloadReportMutation.mutateAsync({
data: {
instanceId: $runtime.instanceId,
instanceId,
reportId,
format: (format as V1ExportFormat) ?? V1ExportFormat.EXPORT_FORMAT_CSV,
executionTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
import { EntityStatus } from "@rilldata/web-common/features/entity-management/types";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
$: ({ instanceId } = $runtime);
$: organization = $page.params.organization;
$: project = $page.params.project;
$: reportId = $page.params.report;
$: executionTime = $page.url.searchParams.get("execution_time");
$: report = useReport($runtime.instanceId, reportId);
$: report = useReport(instanceId, reportId);
$: exploreName = getExploreName(
$report?.data?.resource?.report?.spec?.annotations?.web_open_path,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import { useQueryClient } from "@tanstack/svelte-query";
$: ({ instanceId } = $runtime);
$: organization = $page.params.organization;
$: project = $page.params.project;
Expand All @@ -36,7 +37,7 @@
(page) => page.tokens ?? [],
) ?? [];
$: dashboards = useDashboardsV2($runtime.instanceId);
$: dashboards = useDashboardsV2(instanceId);
$: allRowsWithDashboardTitle = allRows.map((token) => {
const dashboard = $dashboards.data?.find(
Expand Down
Loading

0 comments on commit 3596b0d

Please sign in to comment.