Skip to content

Commit

Permalink
Merge pull request #2659 from umami-software/hotfix
Browse files Browse the repository at this point in the history
v2.11.1
  • Loading branch information
mikecao committed Apr 10, 2024
2 parents 88da20e + 357c13f commit be7f69f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umami",
"version": "2.11.0",
"version": "2.11.1",
"description": "A simple, fast, privacy-focused alternative to Google Analytics.",
"author": "Umami Software, Inc. <hello@umami.is>",
"license": "MIT",
Expand Down
2 changes: 2 additions & 0 deletions src/app/(main)/reports/[reportId]/FilterParameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export function FilterParameters() {
<FilterSelectForm
websiteId={websiteId}
fields={fields.filter(({ name }) => !filters.find(f => f.name === name))}
startDate={dateRange?.startDate}
endDate={dateRange?.endDate}
onChange={handleAdd}
/>
</PopupForm>
Expand Down
6 changes: 4 additions & 2 deletions src/app/(main)/reports/[reportId]/FilterSelectForm.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import { useState } from 'react';
import FieldSelectForm from './FieldSelectForm';
import FieldFilterEditForm from './FieldFilterEditForm';
import { useDateRange } from 'components/hooks';

export interface FilterSelectFormProps {
websiteId?: string;
fields: any[];
startDate?: Date;
endDate?: Date;
onChange?: (filter: { name: string; type: string; operator: string; value: string }) => void;
allowFilterSelect?: boolean;
}

export default function FilterSelectForm({
websiteId,
fields,
startDate,
endDate,
onChange,
allowFilterSelect,
}: FilterSelectFormProps) {
const [field, setField] = useState<{ name: string; label: string; type: string }>();
const [{ startDate, endDate }] = useDateRange(websiteId);

if (!field) {
return <FieldSelectForm fields={fields} onSelect={setField} showType={false} />;
Expand Down
5 changes: 4 additions & 1 deletion src/app/(main)/websites/[websiteId]/WebsiteFilterButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import classNames from 'classnames';
import { Button, Icon, Icons, Popup, PopupTrigger, Text } from 'react-basics';
import PopupForm from 'app/(main)/reports/[reportId]/PopupForm';
import FilterSelectForm from 'app/(main)/reports/[reportId]/FilterSelectForm';
import { useFields, useMessages, useNavigation } from 'components/hooks';
import { useFields, useMessages, useNavigation, useDateRange } from 'components/hooks';
import { OPERATOR_PREFIXES } from 'lib/constants';
import styles from './WebsiteFilterButton.module.css';

Expand All @@ -16,6 +16,7 @@ export function WebsiteFilterButton({
const { formatMessage, labels } = useMessages();
const { renderUrl, router } = useNavigation();
const { fields } = useFields();
const [{ startDate, endDate }] = useDateRange(websiteId);

const handleAddFilter = ({ name, operator, value }) => {
const prefix = OPERATOR_PREFIXES[operator];
Expand All @@ -38,6 +39,8 @@ export function WebsiteFilterButton({
<FilterSelectForm
websiteId={websiteId}
fields={fields}
startDate={startDate}
endDate={endDate}
onChange={value => {
handleAddFilter(value);
close();
Expand Down
8 changes: 8 additions & 0 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ function getTimestampDiffQuery(field1: string, field2: string): string {
}
}

function getSearchQuery(column: string): string {
const db = getDatabaseType();
const like = db === POSTGRESQL ? 'ilike' : 'like';

return `and ${column} ${like} {{search}}`;
}

function mapFilter(column: string, operator: string, name: string, type: string = '') {
const db = getDatabaseType();
const like = db === POSTGRESQL ? 'ilike' : 'like';
Expand Down Expand Up @@ -253,6 +260,7 @@ export default {
getFilterQuery,
getSearchParameters,
getTimestampDiffQuery,
getSearchQuery,
getQueryMode,
pagedQuery,
parseFilters,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/api/websites/[websiteId]/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default async (
}

if (SESSION_COLUMNS.includes(type)) {
const data = await getSessionMetrics(websiteId, column, filters, limit, offset);
const data = await getSessionMetrics(websiteId, type, filters, limit, offset);

if (type === 'language') {
const combined = {};
Expand Down
4 changes: 2 additions & 2 deletions src/queries/analytics/getValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ async function relationalQuery(
endDate: Date,
search: string,
) {
const { rawQuery } = prisma;
const { rawQuery, getSearchQuery } = prisma;
let searchQuery = '';

if (search) {
searchQuery = `and ${column} LIKE {{search}}`;
searchQuery = getSearchQuery(column);
}

return rawQuery(
Expand Down
18 changes: 7 additions & 11 deletions src/queries/analytics/sessions/getSessionMetrics.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import prisma from 'lib/prisma';
import clickhouse from 'lib/clickhouse';
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
import { EVENT_TYPE, SESSION_COLUMNS } from 'lib/constants';
import { EVENT_TYPE, FILTER_COLUMNS, SESSION_COLUMNS } from 'lib/constants';
import { QueryFilters } from 'lib/types';

export async function getSessionMetrics(
...args: [
websiteId: string,
column: string,
filters: QueryFilters,
limit?: number,
offset?: number,
]
...args: [websiteId: string, type: string, filters: QueryFilters, limit?: number, offset?: number]
) {
return runQuery({
[PRISMA]: () => relationalQuery(...args),
Expand All @@ -21,11 +15,12 @@ export async function getSessionMetrics(

async function relationalQuery(
websiteId: string,
column: string,
type: string,
filters: QueryFilters,
limit: number = 500,
offset: number = 0,
) {
const column = FILTER_COLUMNS[type] || type;
const { parseFilters, rawQuery } = prisma;
const { filterQuery, joinSession, params } = await parseFilters(
websiteId,
Expand All @@ -34,7 +29,7 @@ async function relationalQuery(
eventType: EVENT_TYPE.pageView,
},
{
joinSession: SESSION_COLUMNS.includes(column),
joinSession: SESSION_COLUMNS.includes(type),
},
);
const includeCountry = column === 'city' || column === 'subdivision1';
Expand Down Expand Up @@ -63,11 +58,12 @@ async function relationalQuery(

async function clickhouseQuery(
websiteId: string,
column: string,
type: string,
filters: QueryFilters,
limit: number = 500,
offset: number = 0,
): Promise<{ x: string; y: number }[]> {
const column = FILTER_COLUMNS[type] || type;
const { parseFilters, rawQuery } = clickhouse;
const { filterQuery, params } = await parseFilters(websiteId, {
...filters,
Expand Down

0 comments on commit be7f69f

Please sign in to comment.