mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 22:57:12 +01:00
update getQueryFilters to support new segment/cohort data structure
This commit is contained in:
parent
f06ef6fbc9
commit
984f426cfe
1 changed files with 16 additions and 8 deletions
|
|
@ -100,25 +100,33 @@ export async function getQueryFilters(
|
||||||
await setWebsiteDate(websiteId, dateRange);
|
await setWebsiteDate(websiteId, dateRange);
|
||||||
|
|
||||||
if (params.segment) {
|
if (params.segment) {
|
||||||
Object.assign(filters, (await getWebsiteSegment(websiteId, params.segment))?.parameters);
|
const segmentParams = (await getWebsiteSegment(websiteId, params.segment))
|
||||||
|
?.parameters as Record<string, any>;
|
||||||
|
|
||||||
|
Object.assign(filters, segmentParams.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params.cohort) {
|
if (params.cohort) {
|
||||||
const cohortFilters = (await getWebsiteSegment(websiteId, params.cohort))
|
const cohortParams = (await getWebsiteSegment(websiteId, params.cohort))
|
||||||
?.parameters as Record<string, any>;
|
?.parameters as Record<string, any>;
|
||||||
|
|
||||||
// convert dateRange to startDate and endDate
|
// convert dateRange to startDate and endDate
|
||||||
if (cohortFilters.dateRange) {
|
if (cohortParams.dateRange) {
|
||||||
const { startDate, endDate } = parseDateRange(cohortFilters.dateRange);
|
const { startDate, endDate } = parseDateRange(cohortParams.dateRange);
|
||||||
cohortFilters.startDate = startDate;
|
cohortParams.startDate = startDate;
|
||||||
cohortFilters.endDate = endDate;
|
cohortParams.endDate = endDate;
|
||||||
delete cohortFilters.dateRange;
|
delete cohortParams.dateRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cohortParams.filters) {
|
||||||
|
Object.assign(cohortParams, cohortParams.filters);
|
||||||
|
delete cohortParams.filters;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(
|
Object.assign(
|
||||||
filters,
|
filters,
|
||||||
Object.fromEntries(
|
Object.fromEntries(
|
||||||
Object.entries(cohortFilters || {}).map(([key, value]) =>
|
Object.entries(cohortParams || {}).map(([key, value]) =>
|
||||||
key === 'startDate' || key === 'endDate'
|
key === 'startDate' || key === 'endDate'
|
||||||
? [`cohort_${key}`, new Date(value)]
|
? [`cohort_${key}`, new Date(value)]
|
||||||
: [`cohort_${key}`, value],
|
: [`cohort_${key}`, value],
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue