feat(dashboard): reuse reports filter on overview and add more operators (#31)

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-09-05 15:55:31 +02:00
parent 7e941080dc
commit 18b3bc3018
20 changed files with 464 additions and 168 deletions

View File

@@ -7,6 +7,8 @@ import {
createSqlBuilder,
db,
formatClickhouseDate,
getPropertyKey,
getSelectPropertyKey,
TABLE_NAMES,
toDate,
} from '@openpanel/db';
@@ -126,14 +128,7 @@ export const chartRouter = createTRPCRouter({
if (event !== '*') {
sb.where.event = `name = ${escape(event)}`;
}
if (property.startsWith('properties.')) {
sb.select.values = `distinct arrayMap(x -> trim(x), mapValues(mapExtractKeyLike(properties, ${escape(
property.replace(/^properties\./, '').replace('.*.', '.%.')
)}))) as values`;
} else {
sb.select.values = `distinct ${property} as values`;
}
sb.select.values = `distinct ${getSelectPropertyKey(property)} as values`;
sb.where.date = `${toDate('created_at', input.interval)} BETWEEN ${toDate(formatClickhouseDate(startDate), input.interval)} AND ${toDate(formatClickhouseDate(endDate), input.interval)};`;
const events = await chQuery<{ values: string[] }>(getSql());