Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaHegde committed Dec 9, 2024
1 parent 010a89f commit 66d545a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
<script lang="ts">
import { page } from "$app/stores";
import { WithTween } from "@rilldata/web-common/components/data-graphic/functional-components";
import PercentageChange from "@rilldata/web-common/components/data-types/PercentageChange.svelte";
import Tooltip from "@rilldata/web-common/components/tooltip/Tooltip.svelte";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { getUrlForWebView } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params";
import DelayedSpinner from "@rilldata/web-common/features/entity-management/DelayedSpinner.svelte";
import { EntityStatus } from "@rilldata/web-common/features/entity-management/types";
Expand All @@ -14,10 +11,7 @@
import { FormatPreset } from "@rilldata/web-common/lib/number-formatting/humanizer-types";
import { formatMeasurePercentageDifference } from "@rilldata/web-common/lib/number-formatting/percentage-formatter";
import { numberPartsToString } from "@rilldata/web-common/lib/number-formatting/utils/number-parts-utils";
import {
V1ExploreWebView,
type MetricsViewSpecMeasureV2,
} from "@rilldata/web-common/runtime-client";
import { type MetricsViewSpecMeasureV2 } from "@rilldata/web-common/runtime-client";
import {
crossfade,
fly,
Expand All @@ -36,8 +30,6 @@
export let withTimeseries = true;
export let isMeasureExpanded = false;
const { defaultExploreState } = getStateManagers();
$: comparisonPercChange =
comparisonValue && value !== undefined && value !== null
? (value - comparisonValue) / comparisonValue
Expand Down Expand Up @@ -88,14 +80,7 @@
$: copyValue = measureValueFormatterUnabridged(value) ?? "no data";
$: tooltipValue = measureValueFormatterTooltip(value) ?? "no data";
$: tddHref = getUrlForWebView(
$page.url,
V1ExploreWebView.EXPLORE_WEB_VIEW_TIME_DIMENSION,
$defaultExploreState,
{
[ExploreStateURLParams.ExpandedMeasure]: measure.name,
} as Record<string, string>,
);
$: ttdHref = `?${ExploreStateURLParams.WebView}=ttd&${ExploreStateURLParams.ExpandedMeasure}=${measure.name}`;
function shiftClickHandler(number: string | undefined) {
if (number === undefined) return;
Expand Down Expand Up @@ -142,7 +127,7 @@
}, 1000);
},
})}
href={tddHref}
href={ttdHref}
>
<h2
class="line-clamp-2 ui-header-primary font-semibold whitespace-normal"
Expand Down
3 changes: 2 additions & 1 deletion web-common/src/features/dashboards/tab-bar/TabBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Chart from "@rilldata/web-common/components/icons/Chart.svelte";
import Pivot from "@rilldata/web-common/components/icons/Pivot.svelte";
import Tag from "@rilldata/web-common/components/tag/Tag.svelte";
import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params";
import { behaviourEvent } from "@rilldata/web-common/metrics/initMetrics";
import { BehaviourEventMedium } from "@rilldata/web-common/metrics/service/BehaviourEventTypes";
import {
Expand Down Expand Up @@ -58,7 +59,7 @@
{@const selected = tab === currentTab}
<Tab
{selected}
href="?view={tab}"
href="?{ExploreStateURLParams.WebView}={tab}"
on:click={() => handleTabChange(tab)}
>
<Icon />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
<script lang="ts">
import { page } from "$app/stores";
import Back from "@rilldata/web-common/components/icons/Back.svelte";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import { getUrlForWebView } from "@rilldata/web-common/features/dashboards/url-state/explore-web-view-store";
import { V1ExploreWebView } from "@rilldata/web-common/runtime-client";
import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params";
import { Button } from "../../../components/button";
const { defaultExploreState } = getStateManagers();
$: href = getUrlForWebView(
$page.url,
V1ExploreWebView.EXPLORE_WEB_VIEW_EXPLORE,
$defaultExploreState,
);
</script>

<a class="flex items-center" {href}>
<a class="flex items-center" href="?{ExploreStateURLParams.WebView}=explore">
<Button type="link" forcedStyle="padding: 0; gap: 0px;">
<Back size="16px" />
<span>All measures</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { metricsExplorerStore } from "@rilldata/web-common/features/dashboards/stores/dashboard-stores";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { convertExploreStateToURLSearchParams } from "@rilldata/web-common/features/dashboards/url-state/convertExploreStateToURLSearchParams";
import { FromURLParamViewMap } from "@rilldata/web-common/features/dashboards/url-state/mappers";
import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params";
import {
createQueryServiceMetricsViewSchema,
type V1ExplorePreset,
Expand Down Expand Up @@ -79,9 +81,17 @@
exploreSpec,
defaultExplorePreset,
);
curUrl.searchParams.forEach((value, key) =>
redirectUrl.searchParams.set(key, value),
);
curUrl.searchParams.forEach((value, key) => {
if (
key === ExploreStateURLParams.WebView &&
FromURLParamViewMap[value] === defaultExplorePreset.view
) {
// ignore default view.
// since we do not add params equal to default this will append to the end of the URL breaking the param order.
return;
}
redirectUrl.searchParams.set(key, value);
});
history.replaceState(history.state, "", redirectUrl);
prevUrl = redirectUrl.toString();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<script lang="ts">
import { goto } from "$app/navigation";
import { page } from "$app/stores";
import { useMetricsViewTimeRange } from "@rilldata/web-common/features/dashboards/selectors";
import { getStateManagers } from "@rilldata/web-common/features/dashboards/state-managers/state-managers";
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { convertURLToExploreState } from "@rilldata/web-common/features/dashboards/url-state/convertPresetToExploreState";
import DashboardURLStateSync from "@rilldata/web-common/features/dashboards/url-state/DashboardURLStateSync.svelte";
import { getDefaultExplorePreset } from "@rilldata/web-common/features/dashboards/url-state/getDefaultExplorePreset";
import { shouldRedirectToViewWithParams } from "@rilldata/web-common/features/explores/selectors";
import type { V1ExplorePreset } from "@rilldata/web-common/runtime-client";
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
Expand Down Expand Up @@ -36,36 +34,30 @@
);
let partialExploreState: Partial<MetricsExplorerEntity> = {};
let loaded = false;
function parseUrl(url: URL, defaultExplorePreset: V1ExplorePreset) {
const redirectUrl = shouldRedirectToViewWithParams(
// Get Explore state from URL params
const {
partialExploreState: partialExploreStateFromUrl,
loaded: loadedFromStorage,
} = convertURLToExploreState(
$exploreName,
storeKeyPrefix,
url.searchParams,
metricsViewSpec,
exploreSpec,
defaultExplorePreset,
storeKeyPrefix,
url,
);
if (redirectUrl) {
return goto(redirectUrl);
}
// Get Explore state from URL params
const { partialExploreState: partialExploreStateFromUrl } =
convertURLToExploreState(
url.searchParams,
metricsViewSpec,
exploreSpec,
defaultExplorePreset,
);
partialExploreState = partialExploreStateFromUrl;
loaded = loadedFromStorage;
}
// only reactive to url and defaultExplorePreset
$: parseUrl($page.url, defaultExplorePreset);
</script>

{#if !$validSpecStore.isLoading && !$metricsViewTimeRange.isLoading}
<DashboardURLStateSync {defaultExplorePreset} {partialExploreState}>
<DashboardURLStateSync {defaultExplorePreset} {partialExploreState} {loaded}>
<slot />
</DashboardURLStateSync>
{/if}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import type { MetricsExplorerEntity } from "@rilldata/web-common/features/dashboards/stores/metrics-explorer-entity";
import { convertExploreStateToPreset } from "@rilldata/web-common/features/dashboards/url-state/convertExploreStateToPreset";
import {
FromActivePageMap,
ToURLParamViewMap,
} from "@rilldata/web-common/features/dashboards/url-state/mappers";
import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params";
import { FromActivePageMap } from "@rilldata/web-common/features/dashboards/url-state/mappers";
import {
type V1ExplorePreset,
type V1ExploreSpec,
Expand Down Expand Up @@ -188,20 +184,3 @@ export function getExplorePresetForWebView(
return undefined;
}
}

export function getUrlForWebView(
pageUrl: URL,
view: V1ExploreWebView,
defaultExplorePreset: V1ExplorePreset,
extraParams: Record<string, string> = {},
) {
const u = new URL(pageUrl);
u.search = "";
if (view !== defaultExplorePreset.view) {
u.searchParams.set(ExploreStateURLParams.WebView, ToURLParamViewMap[view]!);
}
for (const param in extraParams) {
u.searchParams.set(param, extraParams[param]);
}
return u.pathname + u.search;
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ describe("Human readable URL state variations", () => {
});

beforeEach(() => {
sessionStorage.clear();
metricsExplorerStore.remove(AD_BIDS_EXPLORE_NAME);
});

Expand Down Expand Up @@ -407,6 +408,8 @@ describe("Human readable URL state variations", () => {
url.searchParams.set("state", getProtoFromDashboardState(curState));
// get back the entity from url params
const { partialExploreState: entityFromUrl } = convertURLToExploreState(
AD_BIDS_EXPLORE_NAME,
undefined,
url.searchParams,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
Expand All @@ -418,6 +421,8 @@ describe("Human readable URL state variations", () => {
const defaultUrl = new URL("http://localhost");
const { partialExploreState: entityFromDefaultUrl } =
convertURLToExploreState(
AD_BIDS_EXPLORE_NAME,
undefined,
defaultUrl.searchParams,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
explore,
Expand All @@ -438,6 +443,8 @@ export function applyURLToExploreState(
) {
const { partialExploreState: partialExploreStateDefaultUrl, errors } =
convertURLToExploreState(
AD_BIDS_EXPLORE_NAME,
undefined,
url.searchParams,
AD_BIDS_METRICS_3_MEASURES_DIMENSIONS,
exploreSpec,
Expand Down

0 comments on commit 66d545a

Please sign in to comment.