diff --git a/web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts b/web-common/src/features/dashboards/url-state/convertURLSearchParamsToExploreState.spec.ts similarity index 86% rename from web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts rename to web-common/src/features/dashboards/url-state/convertURLSearchParamsToExploreState.spec.ts index 2b3fe471f59d..c9a7a99e691a 100644 --- a/web-common/src/features/dashboards/url-state/invalid-url-state-variations.spec.ts +++ b/web-common/src/features/dashboards/url-state/convertURLSearchParamsToExploreState.spec.ts @@ -75,6 +75,28 @@ Unexpected " ".`, }, }, + { + title: "Time range only with default grain", + url: "http://localhost/explore/AdBids_explore?tr=7D", + errors: [], + entity: { + selectedTimeRange: { + interval: "TIME_GRAIN_DAY", + name: "7D", + } as DashboardTimeControls, + }, + }, + { + title: "Time range only with no default grain", + url: "http://localhost/explore/AdBids_explore?tr=inf", + errors: [], + entity: { + selectedTimeRange: { + interval: "TIME_GRAIN_HOUR", + name: "inf", + } as DashboardTimeControls, + }, + }, { title: "Invalid time ranges", url: "http://localhost/explore/AdBids_explore?tr=abc&grain=xyz", @@ -131,7 +153,12 @@ Unexpected " ".`, }, ]; -describe("Invalid Human readable URL State", () => { +/** + * Has tests that call convertURLSearchParamsToExploreState directly. + * Unlike url-state-variations that tests actions on explore state. + * TODO: find a good unification of test cases so that a single set of cases run all variations. + */ +describe("direct convertURLSearchParamsToExploreState variations", () => { beforeEach(() => { metricsExplorerStore.remove(AD_BIDS_EXPLORE_NAME); }); diff --git a/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts b/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts index 35ea0df51d5d..ee9ae56cbeb9 100644 --- a/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts +++ b/web-common/src/features/dashboards/url-state/convertURLToExplorePreset.ts @@ -390,8 +390,9 @@ export function fromTimeRangesParams( if (grain && grain in V1TimeGrainToDateTimeUnit) { preset.timeGrain = V1TimeGrainToDateTimeUnit[grain]; - } else { - errors.push(getSingleFieldError("time grain", grain ?? "undefined")); + } else if (grain) { + // Only throw error if grain is defined + errors.push(getSingleFieldError("time grain", grain)); } } catch { // ignore