Skip to content
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
52 changes: 52 additions & 0 deletions web-common/src/features/canvas/components/markdown/util.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import type { MarkdownCanvasComponent } from "@rilldata/web-common/features/canvas/components/markdown";
import { getResolveTemplatedStringQueryOptions } from "@rilldata/web-common/features/canvas/components/markdown/util";
import type { V1Expression } from "@rilldata/web-common/runtime-client";
import { RuntimeClient } from "@rilldata/web-common/runtime-client/v2";
import { writable } from "svelte/store";
import { describe, expect, it } from "vitest";

describe("getResolveTemplatedStringQueryOptions", () => {
it("Should release the parent spec once unsubscribed, however often the filters changed", () => {
const exprByMetricsView = writable<Record<string, V1Expression>>({});

// Counts the live subscriptions to the parent canvas spec.
let parentSpecSubscribers = 0;
const parentSpec = writable({ data: { metricsViews: {} } });
const parentSpecStore = {
subscribe: (run: (value: unknown) => void) => {
parentSpecSubscribers++;
const unsubscribe = parentSpec.subscribe(run);
return () => {
parentSpecSubscribers--;
unsubscribe();
};
},
};

const component = {
specStore: writable({ content: "{{ metrics_sql 'select 1' }}" }),
timeAndFilterStore: writable({ timeRange: undefined }),
parent: {
specStore: parentSpecStore,
expressionFilterManager: {
exprByMetricsViewStore: exprByMetricsView,
},
timeManager: { hasTimeSeriesStore: writable(false) },
},
} as unknown as MarkdownCanvasComponent;

const optionsStore = getResolveTemplatedStringQueryOptions(
component,
new RuntimeClient({ host: "http://localhost", instanceId: "test" }),
);

const unsubscribe = optionsStore.subscribe(() => {});
// Every filter change re-runs the outer derived, which builds a new inner one.
exprByMetricsView.set({ mv: { ident: "a" } });
exprByMetricsView.set({ mv: { ident: "b" } });
expect(parentSpecSubscribers).toBe(1);

unsubscribe();
expect(parentSpecSubscribers).toBe(0);
});
});
2 changes: 1 addition & 1 deletion web-common/src/features/canvas/components/markdown/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function getResolveTemplatedStringQueryOptions(
return derived(
[component.parent.expressionFilterManager.exprByMetricsViewStore],
([exprByMetricsView], set) => {
derived(
return derived(
[
component.specStore,
component.timeAndFilterStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export function createUnfilteredTotalsForMeasure(

const updatedFilter = getFiltersForOtherDimensions(filter, dimensionName);

createQueryServiceMetricsViewAggregation(
return createQueryServiceMetricsViewAggregation(
ctx.runtimeClient,
{
metricsView: metricsViewName,
Expand Down
2 changes: 1 addition & 1 deletion web-common/src/features/models/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function useAllModelColumns(
return;
}

derived(
return derived(
allModels.data.map((r) =>
createTableColumnsWithName(
queryClient,
Expand Down
2 changes: 1 addition & 1 deletion web-common/src/features/sources/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function useAllSourceColumns(
return;
}

derived(
return derived(
allSources.data.map((r) =>
createTableColumnsWithName(
queryClient,
Expand Down
Loading