mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 09:05:36 +01:00
segments implementation and migration update. update getRequestFilters to include filter groups.
This commit is contained in:
parent
1ccc8a1a86
commit
f61421b742
16 changed files with 188 additions and 23 deletions
|
|
@ -47,7 +47,7 @@ export const SESSION_COLUMNS = [
|
|||
'host',
|
||||
];
|
||||
|
||||
export const GROUP_FILTERS = ['segment', 'cohort'];
|
||||
export const FILTER_GROUPS = ['segment', 'cohort'];
|
||||
|
||||
export const FILTER_COLUMNS = {
|
||||
url: 'url_path',
|
||||
|
|
@ -67,6 +67,7 @@ export const FILTER_COLUMNS = {
|
|||
event: 'event_name',
|
||||
tag: 'tag',
|
||||
segment: 'segment',
|
||||
cohort: 'cohort',
|
||||
};
|
||||
|
||||
export const COLLECTION_TYPE = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { z, ZodSchema } from 'zod';
|
||||
import { FILTER_COLUMNS } from '@/lib/constants';
|
||||
import { FILTER_COLUMNS, FILTER_GROUPS } from '@/lib/constants';
|
||||
import { badRequest, unauthorized } from '@/lib/response';
|
||||
import { getAllowedUnits, getMinimumUnit } from '@/lib/date';
|
||||
import { checkAuth } from '@/lib/auth';
|
||||
import { getWebsiteDateRange } from '@/queries';
|
||||
import { getWebsiteSegment, getWebsiteDateRange } from '@/queries';
|
||||
|
||||
export async function getJsonBody(request: Request) {
|
||||
try {
|
||||
|
|
@ -85,14 +85,21 @@ export async function getRequestDateRange(query: Record<string, any>) {
|
|||
};
|
||||
}
|
||||
|
||||
export function getRequestFilters(query: Record<string, any>) {
|
||||
return Object.keys(FILTER_COLUMNS).reduce((obj, key) => {
|
||||
export async function getRequestFilters(query: Record<string, any>, websiteId?: string) {
|
||||
const result: Record<string, any> = {};
|
||||
|
||||
for (const key of Object.keys(FILTER_COLUMNS)) {
|
||||
const value = query[key];
|
||||
|
||||
if (value !== undefined) {
|
||||
obj[key] = value;
|
||||
if (FILTER_GROUPS.includes(key)) {
|
||||
const segment = await getWebsiteSegment(websiteId, value);
|
||||
// merge filters into result
|
||||
Object.assign(result, segment.filters);
|
||||
} else {
|
||||
result[key] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}, {});
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ export const filterParams = {
|
|||
host: z.string().optional(),
|
||||
language: z.string().optional(),
|
||||
event: z.string().optional(),
|
||||
segment: z.string().optional(),
|
||||
cohort: z.string().optional(),
|
||||
};
|
||||
|
||||
export const pagingParams = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue