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
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,36 @@ describe("setUrlParams", () => {
]);
});

it("lets the per metrics view params override the singular one", () => {
const filterManager = createFilterManager();

// An embed host passes the legacy singular param, and the dashboard has since written its own
// per metrics view params. The latter are the newer state, so the singular param must not be
// ANDed in as a second condition on the same dimension: the chips cannot show that, and the
// two value sets together match nothing.
const searchParams = sharedParam(
`${AD_BIDS_PUBLISHER_DIMENSION} IN ('Google')`,
);
const ownParams = perMetricsViewParams({
[AD_BIDS_METRICS_NAME]: `${AD_BIDS_PUBLISHER_DIMENSION} IN ('Facebook')`,
[AD_BIDS_MIRROR_METRICS_NAME]: `${AD_BIDS_PUBLISHER_DIMENSION} IN ('Facebook')`,
});
ownParams.forEach((value, key) => searchParams.set(key, value));
filterManager.storeSync.setUrlParams(searchParams);

expect(filterManager.isComplexFilter).toBe(false);
expect(names(filterManager.sortedFilterManagers.dimensions)).toEqual([
AD_BIDS_PUBLISHER_DIMENSION,
]);
expect(
filterManager.sortedFilterManagers.dimensions[0].selectedValues,
).toEqual(["Facebook"]);
expect(filterManager.topLevelJoiner.param).toEqual({
[AD_BIDS_METRICS_NAME]: `${AD_BIDS_PUBLISHER_DIMENSION} IN ('Facebook')`,
[AD_BIDS_MIRROR_METRICS_NAME]: `${AD_BIDS_PUBLISHER_DIMENSION} IN ('Facebook')`,
});
});

it("drops filters on identifiers the metrics view does not define", () => {
const filterManager = createFilterManager();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,23 @@ export class ExpressionFilterManager implements UrlParamsStore {
this.unsubscribers.forEach((unsub) => unsub());
}

/**
* Folds the legacy singular `f` param into a param per metrics view.
*
* A metrics view that already has a param of its own keeps it, since that is the newer state:
* an embed host passes the singular param, and the dashboard then writes per metrics view params
* as the filter is edited. Merging the two instead would AND the host's condition with the edited
* one on the same dimension, which no chip can show and which usually matches nothing.
*/
public normalizeParams(urlParams: URLSearchParams): URLSearchParams {
const singularParam = urlParams.get(ExploreStateURLParams.Filters);
if (!singularParam || this.singleParamFormMv) return urlParams;

const newUrlParams = new URLSearchParams();
this.metricsViewsProvider.metricsViewNames.forEach((mvName) =>
newUrlParams.set(
getParamKeyForMv(mvName, this.singleParamFormMv),
singularParam,
),
);
this.metricsViewsProvider.metricsViewNames.forEach((mvName) => {
const paramKey = getParamKeyForMv(mvName, this.singleParamFormMv);
newUrlParams.set(paramKey, urlParams.get(paramKey) ?? singularParam);
});
return newUrlParams;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class UrlParamsChangeTracker {
if (this.searchParams?.toString() === relevantParams.toString()) return;

this.searchParams = this.store.normalizeParams(relevantParams);
this.store.setUrlParams(relevantParams);
this.store.setUrlParams(this.searchParams);
this.events.emit("change", this.searchParams);
}

Expand Down
Loading