mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
udpate constants and references to filter groups
This commit is contained in:
parent
5ffafc71fc
commit
657ae8ebdb
6 changed files with 39 additions and 22 deletions
|
|
@ -7,7 +7,7 @@ import WebsiteExpandedView from './WebsiteExpandedView';
|
||||||
import WebsiteHeader from './WebsiteHeader';
|
import WebsiteHeader from './WebsiteHeader';
|
||||||
import WebsiteMetricsBar from './WebsiteMetricsBar';
|
import WebsiteMetricsBar from './WebsiteMetricsBar';
|
||||||
import WebsiteTableView from './WebsiteTableView';
|
import WebsiteTableView from './WebsiteTableView';
|
||||||
import { FILTER_COLUMNS } from '@/lib/constants';
|
import { FILTER_COLUMNS, FILTER_GROUPS } from '@/lib/constants';
|
||||||
|
|
||||||
export default function WebsiteDetailsPage({ websiteId }: { websiteId: string }) {
|
export default function WebsiteDetailsPage({ websiteId }: { websiteId: string }) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
|
|
@ -17,7 +17,7 @@ export default function WebsiteDetailsPage({ websiteId }: { websiteId: string })
|
||||||
const { view } = query;
|
const { view } = query;
|
||||||
|
|
||||||
const params = Object.keys(query).reduce((obj, key) => {
|
const params = Object.keys(query).reduce((obj, key) => {
|
||||||
if (FILTER_COLUMNS[key]) {
|
if (FILTER_COLUMNS[key] || FILTER_GROUPS[key]) {
|
||||||
obj[key] = query[key];
|
obj[key] = query[key];
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import WebsiteHeader from '../WebsiteHeader';
|
||||||
import WebsiteMetricsBar from '../WebsiteMetricsBar';
|
import WebsiteMetricsBar from '../WebsiteMetricsBar';
|
||||||
import FilterTags from '@/components/metrics/FilterTags';
|
import FilterTags from '@/components/metrics/FilterTags';
|
||||||
import { useNavigation } from '@/components/hooks';
|
import { useNavigation } from '@/components/hooks';
|
||||||
import { FILTER_COLUMNS } from '@/lib/constants';
|
import { FILTER_COLUMNS, FILTER_GROUPS } from '@/lib/constants';
|
||||||
import WebsiteChart from '../WebsiteChart';
|
import WebsiteChart from '../WebsiteChart';
|
||||||
import WebsiteCompareTables from './WebsiteCompareTables';
|
import WebsiteCompareTables from './WebsiteCompareTables';
|
||||||
|
|
||||||
|
|
@ -11,7 +11,7 @@ export function WebsiteComparePage({ websiteId }) {
|
||||||
const { query } = useNavigation();
|
const { query } = useNavigation();
|
||||||
|
|
||||||
const params = Object.keys(query).reduce((obj, key) => {
|
const params = Object.keys(query).reduce((obj, key) => {
|
||||||
if (FILTER_COLUMNS[key]) {
|
if (FILTER_COLUMNS[key] || FILTER_GROUPS[key]) {
|
||||||
obj[key] = query[key];
|
obj[key] = query[key];
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
|
|
||||||
|
|
@ -30,17 +30,13 @@ export async function GET(
|
||||||
return unauthorized();
|
return unauthorized();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (!SESSION_COLUMNS.includes(type) && !EVENT_COLUMNS.includes(type) && !FILTER_GROUPS[type]) {
|
||||||
!SESSION_COLUMNS.includes(type) &&
|
|
||||||
!EVENT_COLUMNS.includes(type) &&
|
|
||||||
!FILTER_GROUPS.includes(type)
|
|
||||||
) {
|
|
||||||
return badRequest('Invalid type.');
|
return badRequest('Invalid type.');
|
||||||
}
|
}
|
||||||
|
|
||||||
let values;
|
let values;
|
||||||
|
|
||||||
if (FILTER_GROUPS.includes(type)) {
|
if (FILTER_GROUPS[type]) {
|
||||||
values = (await getWebsiteSegments(websiteId, type)).map(segment => ({ value: segment.name }));
|
values = (await getWebsiteSegments(websiteId, type)).map(segment => ({ value: segment.name }));
|
||||||
} else {
|
} else {
|
||||||
values = await getValues(websiteId, FILTER_COLUMNS[type], startDate, endDate, search);
|
values = await getValues(websiteId, FILTER_COLUMNS[type], startDate, endDate, search);
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,22 @@ function getFilterQuery(filters: QueryFilters = {}, options: QueryOptions = {})
|
||||||
return query.join('\n');
|
return query.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCohortQuery(filters: QueryFilters = {}, options: QueryOptions = {}) {
|
||||||
|
const query = filtersToArray(filters, options).reduce((arr, { name, column, operator }) => {
|
||||||
|
if (column) {
|
||||||
|
arr.push(`and ${mapFilter(column, operator, name)}`);
|
||||||
|
|
||||||
|
if (name === 'referrer') {
|
||||||
|
arr.push(`and referrer_domain != hostname`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return arr;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return query.join('\n');
|
||||||
|
}
|
||||||
|
|
||||||
function getDateQuery(filters: QueryFilters = {}) {
|
function getDateQuery(filters: QueryFilters = {}) {
|
||||||
const { startDate, endDate, timezone } = filters;
|
const { startDate, endDate, timezone } = filters;
|
||||||
|
|
||||||
|
|
@ -146,6 +162,7 @@ async function parseFilters(websiteId: string, filters: QueryFilters = {}, optio
|
||||||
websiteId,
|
websiteId,
|
||||||
startDate: maxDate(filters.startDate, new Date(website?.resetAt)),
|
startDate: maxDate(filters.startDate, new Date(website?.resetAt)),
|
||||||
},
|
},
|
||||||
|
cohortQuery: getCohortQuery(filters),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,10 @@ export const SESSION_COLUMNS = [
|
||||||
'host',
|
'host',
|
||||||
];
|
];
|
||||||
|
|
||||||
export const FILTER_GROUPS = ['segment', 'cohort'];
|
export const FILTER_GROUPS = {
|
||||||
|
segment: 'segment',
|
||||||
|
cohort: 'cohort',
|
||||||
|
};
|
||||||
|
|
||||||
export const FILTER_COLUMNS = {
|
export const FILTER_COLUMNS = {
|
||||||
url: 'url_path',
|
url: 'url_path',
|
||||||
|
|
@ -66,8 +69,6 @@ export const FILTER_COLUMNS = {
|
||||||
language: 'language',
|
language: 'language',
|
||||||
event: 'event_name',
|
event: 'event_name',
|
||||||
tag: 'tag',
|
tag: 'tag',
|
||||||
segment: 'segment',
|
|
||||||
cohort: 'cohort',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const COLLECTION_TYPE = {
|
export const COLLECTION_TYPE = {
|
||||||
|
|
|
||||||
|
|
@ -91,16 +91,19 @@ export async function getRequestFilters(query: Record<string, any>, websiteId?:
|
||||||
for (const key of Object.keys(FILTER_COLUMNS)) {
|
for (const key of Object.keys(FILTER_COLUMNS)) {
|
||||||
const value = query[key];
|
const value = query[key];
|
||||||
if (value !== undefined) {
|
if (value !== undefined) {
|
||||||
if (FILTER_GROUPS.includes(key)) {
|
result[key] = value;
|
||||||
const segment = await getWebsiteSegment(websiteId, key, value);
|
}
|
||||||
if (key === 'segment') {
|
}
|
||||||
// merge filters into result
|
|
||||||
Object.assign(result, segment.parameters);
|
for (const key of Object.keys(FILTER_GROUPS)) {
|
||||||
} else {
|
const value = query[key];
|
||||||
result[key] = segment.parameters;
|
if (value !== undefined) {
|
||||||
}
|
const segment = await getWebsiteSegment(websiteId, key, value);
|
||||||
|
if (key === 'segment') {
|
||||||
|
// merge filters into result
|
||||||
|
Object.assign(result, segment.parameters);
|
||||||
} else {
|
} else {
|
||||||
result[key] = value;
|
result[key] = segment.parameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue