mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +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);
|
||||
|
||||
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) {
|
||||
const cohortFilters = (await getWebsiteSegment(websiteId, params.cohort))
|
||||
const cohortParams = (await getWebsiteSegment(websiteId, params.cohort))
|
||||
?.parameters as Record<string, any>;
|
||||
|
||||
// convert dateRange to startDate and endDate
|
||||
if (cohortFilters.dateRange) {
|
||||
const { startDate, endDate } = parseDateRange(cohortFilters.dateRange);
|
||||
cohortFilters.startDate = startDate;
|
||||
cohortFilters.endDate = endDate;
|
||||
delete cohortFilters.dateRange;
|
||||
if (cohortParams.dateRange) {
|
||||
const { startDate, endDate } = parseDateRange(cohortParams.dateRange);
|
||||
cohortParams.startDate = startDate;
|
||||
cohortParams.endDate = endDate;
|
||||
delete cohortParams.dateRange;
|
||||
}
|
||||
|
||||
if (cohortParams.filters) {
|
||||
Object.assign(cohortParams, cohortParams.filters);
|
||||
delete cohortParams.filters;
|
||||
}
|
||||
|
||||
Object.assign(
|
||||
filters,
|
||||
Object.fromEntries(
|
||||
Object.entries(cohortFilters || {}).map(([key, value]) =>
|
||||
Object.entries(cohortParams || {}).map(([key, value]) =>
|
||||
key === 'startDate' || key === 'endDate'
|
||||
? [`cohort_${key}`, new Date(value)]
|
||||
: [`cohort_${key}`, value],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue