diff --git a/package-lock.json b/package-lock.json index 5e663ba0c277..2d3b3048a25e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13112,9 +13112,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.10.13", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.13.tgz", - "integrity": "sha512-BL2sTuHOdy0YT1lYieUxTw/QMtPBC3pmlJC6xk8BBYVv6vcw3SGdKemQ+Xsx9ik2F/lYDO9tqsFQH1r9PFuHKw==", + "version": "2.10.38", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.10.38.tgz", + "integrity": "sha512-31/02mVB4yuQU6adKk5SlY6m+mxDwUq5KZkyYgnLrrKl7TEm1+3PyDtDBz2kOv/wxZz41GHsvV1A/u6RmiyBvw==", "dev": true, "license": "Apache-2.0", "bin": { @@ -13762,9 +13762,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001784", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001784.tgz", - "integrity": "sha512-WU346nBTklUV9YfUl60fqRbU5ZqyXlqvo1SgigE1OAXK5bFL8LL9q1K7aap3N739l4BvNqnkm3YrGHiY9sfUQw==", + "version": "1.0.30001799", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001799.tgz", + "integrity": "sha512-hG1bReV+OUU+MOqK4t/ZWI0tZOyz3rqS9XuhOUz1cIcbwBKjOyJEJuw9ER5JuNyqxNk8u/JUVbGibBOL1yrjFw==", "dev": true, "funding": [ { diff --git a/web-admin/src/features/bookmarks/BookmarksFormDialog.svelte b/web-admin/src/features/bookmarks/BookmarksFormDialog.svelte index 36c0bf9a2510..1a248967b2ec 100644 --- a/web-admin/src/features/bookmarks/BookmarksFormDialog.svelte +++ b/web-admin/src/features/bookmarks/BookmarksFormDialog.svelte @@ -8,7 +8,6 @@ import { invalidateBookmarkQueries } from "@rilldata/web-admin/features/bookmarks/selectors.ts"; import { type BookmarkEntry, - formatTimeRange, getBookmarkData, } from "@rilldata/web-admin/features/bookmarks/utils.ts"; import ProjectAccessControls from "@rilldata/web-admin/features/projects/ProjectAccessControls.svelte"; @@ -20,16 +19,10 @@ import Switch from "@rilldata/web-common/components/forms/Switch.svelte"; import Tooltip from "@rilldata/web-common/components/tooltip/Tooltip.svelte"; import TooltipContent from "@rilldata/web-common/components/tooltip/TooltipContent.svelte"; - import { deriveInterval } from "@rilldata/web-common/features/dashboards/time-controls/new-time-controls"; - import { ExploreStateURLParams } from "@rilldata/web-common/features/dashboards/url-state/url-params"; import { ResourceKind } from "@rilldata/web-common/features/entity-management/resource-selectors.ts"; import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus.ts"; - import { - V1TimeGrain, - type V1TimeRange, - } from "@rilldata/web-common/runtime-client"; + import { type V1TimeRange } from "@rilldata/web-common/runtime-client"; import { InfoIcon } from "lucide-svelte"; - import type { Interval } from "luxon"; import { useRuntimeClient } from "@rilldata/web-common/runtime-client/v2"; import { defaults, superForm } from "sveltekit-superforms"; import { yup } from "sveltekit-superforms/adapters"; @@ -43,6 +36,7 @@ } from "@rilldata/web-common/features/dashboards/providers/DashboardConfigProvider.svelte.ts"; import { onDestroy } from "svelte"; import { syncStoreWithSource } from "@rilldata/web-common/lib/store-utils/url-params-store-sync.svelte.ts"; + import { TimeFilterManager } from "@rilldata/web-common/features/dashboards/time-controls/TimeFilterManager.svelte.ts"; let { organization, @@ -72,11 +66,11 @@ resourceKind === ResourceKind.Canvas ? new CanvasDashboardConfigProvider(runtimeClient, resourceName) : new ExploreDashboardConfigProvider(runtimeClient, resourceName); + const expressionFilterManager = new ExpressionFilterManager( dashboardConfigProvider.metricsViewsProvider, dashboardConfigProvider.yamlConfigProvider, ); - // Always load from current state. This is the only route to overwrite bookmark state. // A future PR will improve this by adding `Replace` action, in that case this should only have bookmark's state. syncStoreWithSource( @@ -85,6 +79,22 @@ () => dashboardConfigProvider.metricsViewsProvider.ready, ); + const timeFilterManager = new TimeFilterManager( + runtimeClient, + dashboardConfigProvider.metricsViewsProvider, + dashboardConfigProvider.yamlConfigProvider, + true, + ); + // Always load from current state. This is the only route to overwrite bookmark state. + // A future PR will improve this by adding `Replace` action, in that case this should only have bookmark's state. + syncStoreWithSource( + timeFilterManager, + async (newUrlParams) => timeFilterManager.setUrlParams(newUrlParams), + () => + timeFilterManager.ready && + dashboardConfigProvider.metricsViewsProvider.ready, + ); + let timeFilterState = $state< | { queryTimeStart: string; @@ -96,70 +106,6 @@ >(undefined); let curUrlParams = $derived(page.url.searchParams); - $effect(() => void processTimeFromUrl()); - async function processTimeFromUrl() { - const searchParamsObj = new URLSearchParams(curUrlParams); - const rangeExpression = searchParamsObj.get( - ExploreStateURLParams.TimeRange, - ); - const timeRange = { - expression: rangeExpression || "", - }; - - const timeZone = - searchParamsObj.get(ExploreStateURLParams.TimeZone) || "UTC"; - - try { - const promises = - dashboardConfigProvider.metricsViewsProvider.metricsViewNames.map( - (mvName) => - deriveInterval( - timeRange.expression || "", - runtimeClient, - mvName, - timeZone, - ), - ); - - const intervals = await Promise.all(promises); - let intervalWithLatestEndPoint: - | { - interval: Interval; - grain?: V1TimeGrain | undefined; - error?: string; - } - | undefined; - intervals.forEach((response) => { - if ( - !intervalWithLatestEndPoint || - (response.interval.end && intervalWithLatestEndPoint.interval.end - ? response.interval.end > intervalWithLatestEndPoint.interval.end - : false) - ) { - intervalWithLatestEndPoint = response; - } - }); - - const start = intervalWithLatestEndPoint?.interval?.start?.toISO(); - const end = intervalWithLatestEndPoint?.interval?.end?.toISO(); - - const grain = - (searchParamsObj.get(ExploreStateURLParams.TimeGrain) as V1TimeGrain) || - intervalWithLatestEndPoint.grain || - V1TimeGrain.TIME_GRAIN_MINUTE; - - const selectedTimeRange = formatTimeRange(start, end, grain, timeZone); - - timeFilterState = { - queryTimeStart: start, - queryTimeEnd: end, - displayTimeRange: timeRange, - selectedTimeRange, - }; - } catch { - timeFilterState = undefined; - } - } const bookmarkCreator = createAdminServiceCreateBookmark(); const bookmarkUpdater = createAdminServiceUpdateBookmark(); @@ -286,14 +232,10 @@ {m.bookmark_filters_inherited()} - {#if timeFilterState} - - {/if} +