Fixed goals query.

This commit is contained in:
Mike Cao 2025-05-31 09:46:36 -07:00
parent 49bcbfd7f9
commit f6c3ad5aa6
8 changed files with 38 additions and 30 deletions

View file

@ -1,6 +1,6 @@
import { Icon, Text, Row, NavMenu, NavMenuItem } from '@umami/react-zen'; import { Icon, Text, Row, NavMenu, NavMenuItem } from '@umami/react-zen';
import { import {
Overview, Eye,
Lightning, Lightning,
User, User,
Clock, Clock,
@ -24,7 +24,7 @@ export function WebsiteNav({ websiteId }: { websiteId: string }) {
{ {
id: 'overview', id: 'overview',
label: formatMessage(labels.overview), label: formatMessage(labels.overview),
icon: <Overview />, icon: <Eye />,
path: '', path: '',
}, },
{ {

View file

@ -16,7 +16,7 @@ import {
AlertDialog, AlertDialog,
} from '@umami/react-zen'; } from '@umami/react-zen';
import { useMessages, useResultQuery } from '@/components/hooks'; import { useMessages, useResultQuery } from '@/components/hooks';
import { Edit, More, Trash, File, Lightning, User, Eye } from '@/components/icons'; import { Edit, More, Trash, File, Lightning, User } from '@/components/icons';
import { LoadingPanel } from '@/components/common/LoadingPanel'; import { LoadingPanel } from '@/components/common/LoadingPanel';
import { formatLongNumber } from '@/lib/format'; import { formatLongNumber } from '@/lib/format';
import { GoalAddForm } from '@/app/(main)/websites/[websiteId]/goals/GoalAddForm'; import { GoalAddForm } from '@/app/(main)/websites/[websiteId]/goals/GoalAddForm';
@ -62,7 +62,7 @@ export function Goal({ id, name, type, parameters, websiteId, startDate, endDate
</Row> </Row>
</Column> </Column>
<Column> <Column>
<ActionsButton id={id} websiteId={websiteId} /> <ActionsButton id={id} name={name} websiteId={websiteId} />
</Column> </Column>
</Grid> </Grid>
<Row alignItems="center" justifyContent="space-between" gap> <Row alignItems="center" justifyContent="space-between" gap>
@ -77,7 +77,9 @@ export function Goal({ id, name, type, parameters, websiteId, startDate, endDate
<Text>{parameters.value}</Text> <Text>{parameters.value}</Text>
</Row> </Row>
<Row alignItems="center" gap> <Row alignItems="center" gap>
<Icon>{isPage ? <Eye /> : <User />}</Icon> <Icon>
<User />
</Icon>
<Text title={`${data?.num} / ${data?.total}`}>{`${formatLongNumber( <Text title={`${data?.num} / ${data?.total}`}>{`${formatLongNumber(
data?.num, data?.num,
)} / ${formatLongNumber(data?.total)}`}</Text> )} / ${formatLongNumber(data?.total)}`}</Text>
@ -99,8 +101,16 @@ export function Goal({ id, name, type, parameters, websiteId, startDate, endDate
); );
} }
const ActionsButton = ({ id, websiteId }: { id: string; websiteId: string }) => { const ActionsButton = ({
const { formatMessage, labels } = useMessages(); id,
name,
websiteId,
}: {
id: string;
name: string;
websiteId: string;
}) => {
const { formatMessage, labels, messages } = useMessages();
const [showEdit, setShowEdit] = useState(false); const [showEdit, setShowEdit] = useState(false);
const [showDelete, setShowDelete] = useState(false); const [showDelete, setShowDelete] = useState(false);
const { mutate, touch } = useDeleteQuery(`/reports/${id}`); const { mutate, touch } = useDeleteQuery(`/reports/${id}`);
@ -154,7 +164,11 @@ const ActionsButton = ({ id, websiteId }: { id: string; websiteId: string }) =>
</MenuTrigger> </MenuTrigger>
<Modal isOpen={showEdit || showDelete} isDismissable={true}> <Modal isOpen={showEdit || showDelete} isDismissable={true}>
{showEdit && ( {showEdit && (
<Dialog variant="modal" style={{ minHeight: 375, minWidth: 300 }}> <Dialog
title={formatMessage(labels.goal)}
variant="modal"
style={{ minHeight: 375, minWidth: 400 }}
>
<GoalAddForm id={id} websiteId={websiteId} onClose={handleClose} /> <GoalAddForm id={id} websiteId={websiteId} onClose={handleClose} />
</Dialog> </Dialog>
)} )}
@ -163,7 +177,9 @@ const ActionsButton = ({ id, websiteId }: { id: string; websiteId: string }) =>
title={formatMessage(labels.delete)} title={formatMessage(labels.delete)}
onConfirm={handleDelete} onConfirm={handleDelete}
onCancel={handleClose} onCancel={handleClose}
/> >
{formatMessage(messages.confirmDelete, { target: name })}
</AlertDialog>
)} )}
</Modal> </Modal>
</> </>

View file

@ -15,7 +15,11 @@ export function GoalAddButton({ websiteId }: { websiteId: string }) {
<Text>{formatMessage(labels.addGoal)}</Text> <Text>{formatMessage(labels.addGoal)}</Text>
</Button> </Button>
<Modal> <Modal>
<Dialog variant="modal" title={formatMessage(labels.addGoal)} style={{ width: '400px' }}> <Dialog
variant="modal"
title={formatMessage(labels.addGoal)}
style={{ minHeight: 375, minWidth: 400 }}
>
{({ close }) => <GoalAddForm websiteId={websiteId} onClose={close} />} {({ close }) => <GoalAddForm websiteId={websiteId} onClose={close} />}
</Dialog> </Dialog>
</Modal> </Modal>

View file

@ -10,7 +10,6 @@ import {
Radio, Radio,
Text, Text,
Icon, Icon,
Loading,
} from '@umami/react-zen'; } from '@umami/react-zen';
import { useApi, useMessages, useModified, useReportQuery } from '@/components/hooks'; import { useApi, useMessages, useModified, useReportQuery } from '@/components/hooks';
import { File, Lightning } from '@/components/icons'; import { File, Lightning } from '@/components/icons';
@ -54,7 +53,7 @@ export function GoalAddForm({
}; };
if (id && !data) { if (id && !data) {
return <Loading position="page" icon="dots" />; return null;
} }
return ( return (

View file

@ -12,5 +12,6 @@ export function useReportQuery(reportId: string) {
...data, ...data,
}); });
}, },
enabled: !!reportId,
}); });
} }

View file

@ -4,23 +4,12 @@ import { useModified } from '../useModified';
export function useReportsQuery({ websiteId, teamId }: { websiteId?: string; teamId?: string }) { export function useReportsQuery({ websiteId, teamId }: { websiteId?: string; teamId?: string }) {
const { modified } = useModified(`reports`); const { modified } = useModified(`reports`);
const { get, del, useMutation } = useApi(); const { get } = useApi();
const queryResult = usePagedQuery({
return usePagedQuery({
queryKey: ['reports', { websiteId, teamId, modified }], queryKey: ['reports', { websiteId, teamId, modified }],
queryFn: (params: any) => { queryFn: (params: any) => {
return get('/reports', { websiteId, teamId, ...params }); return get('/reports', { websiteId, teamId, ...params });
}, },
}); });
const { mutate } = useMutation({ mutationFn: (reportId: string) => del(`/reports/${reportId}`) });
const deleteReport = (reportId: any) => {
mutate(reportId, {
onSuccess: () => {},
});
};
return {
...queryResult,
deleteReport,
};
} }

View file

@ -12,7 +12,7 @@ export function usePagedQuery<T = any>({
const { query: queryParams } = useNavigation(); const { query: queryParams } = useNavigation();
const [params, setParams] = useState<PageParams>({ const [params, setParams] = useState<PageParams>({
search: '', search: '',
page: +queryParams.page || 1, page: +queryParams?.page || 1,
}); });
const { useQuery } = useApi(); const { useQuery } = useApi();

View file

@ -30,7 +30,7 @@ async function relationalQuery(websiteId: string, criteria: GoalCriteria) {
` `
select count(*) as num, select count(*) as num,
( (
select count(${isPage ? '*' : 'distinct session_id'}) select count(distinct session_id)
from website_event from website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
and event_type = ${eventType} and event_type = ${eventType}
@ -59,10 +59,9 @@ async function clickhouseQuery(websiteId: string, criteria: GoalCriteria) {
` `
select count(*) as num, select count(*) as num,
( (
select count(${isPage ? '*' : 'distinct session_id'}) select count(distinct session_id)
from website_event from website_event
where website_id = {websiteId:UUID} where website_id = {websiteId:UUID}
and event_type = ${eventType}
${dateQuery} ${dateQuery}
) as total ) as total
from website_event from website_event