mirror of
https://github.com/umami-software/umami.git
synced 2026-02-05 13:17:19 +01:00
Updated cohort processing.
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
This commit is contained in:
parent
c3b62e3a74
commit
f9442001e4
8 changed files with 46 additions and 56 deletions
|
|
@ -53,7 +53,7 @@ export const SESSION_COLUMNS = [
|
|||
'region',
|
||||
];
|
||||
|
||||
export const FILTER_GROUPS = {
|
||||
export const SEGMENT_TYPES = {
|
||||
segment: 'segment',
|
||||
cohort: 'cohort',
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export function isSearchOperator(operator: any) {
|
|||
return [OPERATORS.contains, OPERATORS.doesNotContain].includes(operator);
|
||||
}
|
||||
|
||||
export function filtersObjectToArray(filters: QueryFilters, options: QueryOptions = {}) {
|
||||
export function filtersObjectToArray(filters: QueryFilters, options: QueryOptions = {}): Filter[] {
|
||||
if (!filters) {
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import { badRequest, unauthorized } from '@/lib/response';
|
|||
import { QueryFilters } from '@/lib/types';
|
||||
import { getWebsiteSegment } from '@/queries';
|
||||
import { z } from 'zod/v4';
|
||||
import { filtersArrayToObject } from '@/lib/params';
|
||||
|
||||
export async function parseRequest(
|
||||
request: Request,
|
||||
|
|
@ -103,36 +104,31 @@ export async function getQueryFilters(
|
|||
const segmentParams = (await getWebsiteSegment(websiteId, params.segment))
|
||||
?.parameters as Record<string, any>;
|
||||
|
||||
Object.assign(filters, segmentParams.filters);
|
||||
Object.assign(filters, filtersArrayToObject(segmentParams.filters));
|
||||
}
|
||||
|
||||
if (params.cohort) {
|
||||
const cohortParams = (await getWebsiteSegment(websiteId, params.cohort))
|
||||
?.parameters as Record<string, any>;
|
||||
|
||||
// convert dateRange to startDate and endDate
|
||||
if (cohortParams.dateRange) {
|
||||
const { startDate, endDate } = parseDateRange(cohortParams.dateRange);
|
||||
cohortParams.startDate = startDate;
|
||||
cohortParams.endDate = endDate;
|
||||
delete cohortParams.dateRange;
|
||||
}
|
||||
const { startDate, endDate } = parseDateRange(cohortParams.dateRange);
|
||||
|
||||
if (cohortParams.filters) {
|
||||
Object.assign(cohortParams, cohortParams.filters);
|
||||
delete cohortParams.filters;
|
||||
}
|
||||
const cohortFilters = cohortParams.filters.map(({ name, ...props }) => ({
|
||||
...props,
|
||||
name: `cohort_${name}`,
|
||||
}));
|
||||
|
||||
Object.assign(
|
||||
filters,
|
||||
Object.fromEntries(
|
||||
Object.entries(cohortParams || {}).map(([key, value]) =>
|
||||
key === 'startDate' || key === 'endDate'
|
||||
? [`cohort_${key}`, new Date(value)]
|
||||
: [`cohort_${key}`, value],
|
||||
),
|
||||
),
|
||||
);
|
||||
cohortFilters.push({
|
||||
name: cohortParams.action.type,
|
||||
operator: 'eq',
|
||||
value: cohortParams.action.value,
|
||||
});
|
||||
|
||||
Object.assign(filters, {
|
||||
...filtersArrayToObject(cohortFilters),
|
||||
cohort_startDate: startDate,
|
||||
cohort_endDate: endDate,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ export interface Filter {
|
|||
operator: string;
|
||||
value: string;
|
||||
type?: string;
|
||||
columns?: string;
|
||||
prefix?: string;
|
||||
}
|
||||
|
||||
export interface DateRange {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue