Added useFilterQuery. Converted websites and reports pages.

This commit is contained in:
Mike Cao 2023-09-26 23:20:29 -07:00
parent 6846355c63
commit 7e626dcd52
29 changed files with 373 additions and 499 deletions

View file

@ -19,6 +19,7 @@ export const DEFAULT_ANIMATION_DURATION = 300;
export const DEFAULT_DATE_RANGE = '24hour';
export const DEFAULT_WEBSITE_LIMIT = 10;
export const DEFAULT_RESET_DATE = '2000-01-01';
export const DEFAULT_PAGE_SIZE = 10;
export const REALTIME_RANGE = 30;
export const REALTIME_INTERVAL = 5000;
@ -30,22 +31,6 @@ export const FILTER_RANGE = 'filter-range';
export const FILTER_REFERRERS = 'filter-referrers';
export const FILTER_PAGES = 'filter-pages';
export const USER_FILTER_TYPES = {
all: 'All',
username: 'Username',
} as const;
export const WEBSITE_FILTER_TYPES = { all: 'All', name: 'Name', domain: 'Domain' } as const;
export const TEAM_FILTER_TYPES = { all: 'All', name: 'Name', 'user:username': 'Owner' } as const;
export const REPORT_FILTER_TYPES = {
all: 'All',
name: 'Name',
description: 'Description',
type: 'Type',
'user:username': 'Username',
'website:name': 'Website Name',
'website:domain': 'Website Domain',
} as const;
export const EVENT_COLUMNS = ['url', 'referrer', 'title', 'query', 'event'];
export const SESSION_COLUMNS = [

View file

@ -1,11 +1,11 @@
import { Prisma } from '@prisma/client';
import prisma from '@umami/prisma-client';
import moment from 'moment-timezone';
import { MYSQL, POSTGRESQL, getDatabaseType } from 'lib/db';
import { FILTER_COLUMNS, SESSION_COLUMNS, OPERATORS } from './constants';
import { FILTER_COLUMNS, SESSION_COLUMNS, OPERATORS, DEFAULT_PAGE_SIZE } from './constants';
import { loadWebsite } from './load';
import { maxDate } from './date';
import { QueryFilters, QueryOptions, SearchFilter } from './types';
import { Prisma } from '@prisma/client';
const MYSQL_DATE_FORMATS = {
minute: '%Y-%m-%d %H:%i:00',
@ -171,7 +171,7 @@ async function rawQuery(sql: string, data: object): Promise<any> {
return prisma.rawQuery(query, params);
}
function getPageFilters(filters: SearchFilter<any>): [
function getPageFilters(filters: SearchFilter): [
{
orderBy: {
[x: string]: string;
@ -185,7 +185,7 @@ function getPageFilters(filters: SearchFilter<any>): [
orderBy: string;
},
] {
const { pageSize = 10, page = 1, orderBy } = filters || {};
const { page = 1, pageSize = DEFAULT_PAGE_SIZE, orderBy } = filters || {};
return [
{
@ -198,7 +198,7 @@ function getPageFilters(filters: SearchFilter<any>): [
],
}),
},
{ pageSize, page: +page, orderBy },
{ page: +page, pageSize, orderBy },
];
}

View file

@ -5,12 +5,8 @@ import {
EVENT_TYPE,
KAFKA_TOPIC,
PERMISSIONS,
REPORT_FILTER_TYPES,
REPORT_TYPES,
ROLES,
TEAM_FILTER_TYPES,
USER_FILTER_TYPES,
WEBSITE_FILTER_TYPES,
} from './constants';
import * as yup from 'yup';
import { TIME_UNIT } from './date';
@ -27,46 +23,42 @@ export type DynamicDataType = ObjectValues<typeof DATA_TYPE>;
export type KafkaTopic = ObjectValues<typeof KAFKA_TOPIC>;
export type ReportType = ObjectValues<typeof REPORT_TYPES>;
export type ReportSearchFilterType = ObjectValues<typeof REPORT_FILTER_TYPES>;
export type UserSearchFilterType = ObjectValues<typeof USER_FILTER_TYPES>;
export type WebsiteSearchFilterType = ObjectValues<typeof WEBSITE_FILTER_TYPES>;
export type TeamSearchFilterType = ObjectValues<typeof TEAM_FILTER_TYPES>;
export interface WebsiteSearchFilter extends SearchFilter<WebsiteSearchFilterType> {
export interface WebsiteSearchFilter extends SearchFilter {
userId?: string;
teamId?: string;
includeTeams?: boolean;
onlyTeams?: boolean;
}
export interface UserSearchFilter extends SearchFilter<UserSearchFilterType> {
export interface UserSearchFilter extends SearchFilter {
teamId?: string;
}
export interface TeamSearchFilter extends SearchFilter<TeamSearchFilterType> {
export interface TeamSearchFilter extends SearchFilter {
userId?: string;
}
export interface ReportSearchFilter extends SearchFilter<ReportSearchFilterType> {
export interface ReportSearchFilter extends SearchFilter {
userId?: string;
websiteId?: string;
includeTeams?: boolean;
}
export interface SearchFilter<T> {
export interface SearchFilter {
query?: string;
page?: number;
pageSize?: number;
orderBy?: string;
data?: T;
sortDescending?: boolean;
}
export interface FilterResult<T> {
data: T;
count: number;
pageSize: number;
page: number;
pageSize: number;
orderBy?: string;
sortDescending?: boolean;
}
export interface DynamicData {