start refactor event list
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { ChartSwitchShortcut } from '@/components/report/chart';
|
import { ChartSwitchShortcut } from '@/components/report/chart';
|
||||||
|
import { Widget, WidgetBody, WidgetHead } from '@/components/widget';
|
||||||
|
|
||||||
import type { IChartEvent } from '@openpanel/validation';
|
import type { IChartEvent } from '@openpanel/validation';
|
||||||
|
|
||||||
@@ -20,23 +21,28 @@ export function EventsPerDayChart({ projectId, filters, events }: Props) {
|
|||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="card mb-8 p-4">
|
<Widget className="w-full">
|
||||||
<ChartSwitchShortcut
|
<WidgetHead>
|
||||||
projectId={projectId}
|
<span className="title">Events per day</span>
|
||||||
range="30d"
|
</WidgetHead>
|
||||||
chartType="histogram"
|
<WidgetBody>
|
||||||
events={
|
<ChartSwitchShortcut
|
||||||
events && events.length > 0
|
projectId={projectId}
|
||||||
? events.map((name) => ({
|
range="30d"
|
||||||
id: name,
|
chartType="histogram"
|
||||||
name,
|
events={
|
||||||
displayName: name,
|
events && events.length > 0
|
||||||
segment: 'event',
|
? events.map((name) => ({
|
||||||
filters: filters ?? [],
|
id: name,
|
||||||
}))
|
name,
|
||||||
: fallback
|
displayName: name,
|
||||||
}
|
segment: 'event',
|
||||||
/>
|
filters: filters ?? [],
|
||||||
</div>
|
}))
|
||||||
|
: fallback
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</WidgetBody>
|
||||||
|
</Widget>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { isSameDay } from 'date-fns';
|
|||||||
|
|
||||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||||
|
|
||||||
import { EventListItem } from '../event-list-item';
|
import { EventListItem } from '../event-list/event-list-item';
|
||||||
|
|
||||||
function showDateHeader(a: Date, b?: Date) {
|
function showDateHeader(a: Date, b?: Date) {
|
||||||
if (!b) return true;
|
if (!b) return true;
|
||||||
@@ -18,7 +18,7 @@ interface EventListProps {
|
|||||||
}
|
}
|
||||||
export function EventConversionsList({ data }: EventListProps) {
|
export function EventConversionsList({ data }: EventListProps) {
|
||||||
return (
|
return (
|
||||||
<Widget>
|
<Widget className="w-full">
|
||||||
<WidgetHead>
|
<WidgetHead>
|
||||||
<div className="title">Conversions</div>
|
<div className="title">Conversions</div>
|
||||||
</WidgetHead>
|
</WidgetHead>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import withLoadingWidget from '@/hocs/with-loading-widget';
|
||||||
import { escape } from 'sqlstring';
|
import { escape } from 'sqlstring';
|
||||||
|
|
||||||
import { db, getEvents } from '@openpanel/db';
|
import { db, getEvents } from '@openpanel/db';
|
||||||
@@ -8,7 +9,7 @@ interface Props {
|
|||||||
projectId: string;
|
projectId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function EventConversionsListServer({ projectId }: Props) {
|
async function EventConversionsListServer({ projectId }: Props) {
|
||||||
const conversions = await db.eventMeta.findMany({
|
const conversions = await db.eventMeta.findMany({
|
||||||
where: {
|
where: {
|
||||||
projectId,
|
projectId,
|
||||||
@@ -30,3 +31,5 @@ export default async function EventConversionsListServer({ projectId }: Props) {
|
|||||||
|
|
||||||
return <EventConversionsList data={events} />;
|
return <EventConversionsList data={events} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default withLoadingWidget(EventConversionsListServer);
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import type { Dispatch, SetStateAction } from 'react';
|
import type { Dispatch, SetStateAction } from 'react';
|
||||||
import { ChartSwitchShortcut } from '@/components/report/chart';
|
import { ChartSwitchShortcut } from '@/components/report/chart';
|
||||||
@@ -27,6 +25,7 @@ interface Props {
|
|||||||
open: boolean;
|
open: boolean;
|
||||||
setOpen: Dispatch<SetStateAction<boolean>>;
|
setOpen: Dispatch<SetStateAction<boolean>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function EventDetails({ event, open, setOpen }: Props) {
|
export function EventDetails({ event, open, setOpen }: Props) {
|
||||||
const { name } = event;
|
const { name } = event;
|
||||||
const [isEditOpen, setIsEditOpen] = useState(false);
|
const [isEditOpen, setIsEditOpen] = useState(false);
|
||||||
@@ -1,25 +1,8 @@
|
|||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Checkbox } from '@/components/ui/checkbox';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import {
|
|
||||||
Sheet,
|
|
||||||
SheetContent,
|
|
||||||
SheetFooter,
|
|
||||||
SheetHeader,
|
|
||||||
SheetTitle,
|
|
||||||
SheetTrigger,
|
|
||||||
} from '@/components/ui/sheet';
|
|
||||||
import { Tooltip, TooltipContent } from '@/components/ui/tooltip';
|
|
||||||
import { api } from '@/trpc/client';
|
|
||||||
import { cn } from '@/utils/cn';
|
import { cn } from '@/utils/cn';
|
||||||
import { TooltipTrigger } from '@radix-ui/react-tooltip';
|
|
||||||
import type { VariantProps } from 'class-variance-authority';
|
import type { VariantProps } from 'class-variance-authority';
|
||||||
import { cva } from 'class-variance-authority';
|
import { cva } from 'class-variance-authority';
|
||||||
import type { LucideIcon } from 'lucide-react';
|
import type { LucideIcon } from 'lucide-react';
|
||||||
import * as Icons from 'lucide-react';
|
import * as Icons from 'lucide-react';
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import { toast } from 'sonner';
|
|
||||||
|
|
||||||
import type { EventMeta } from '@openpanel/db';
|
import type { EventMeta } from '@openpanel/db';
|
||||||
|
|
||||||
@@ -1,19 +1,13 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Fragment, Suspense } from 'react';
|
import { Fragment } from 'react';
|
||||||
import { FullPageEmptyState } from '@/components/full-page-empty-state';
|
import { FullPageEmptyState } from '@/components/full-page-empty-state';
|
||||||
import { Pagination } from '@/components/pagination';
|
import { Pagination } from '@/components/pagination';
|
||||||
import { ChartSwitch, ChartSwitchShortcut } from '@/components/report/chart';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { useAppParams } from '@/hooks/useAppParams';
|
|
||||||
import { useCursor } from '@/hooks/useCursor';
|
import { useCursor } from '@/hooks/useCursor';
|
||||||
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
|
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
|
||||||
import { isSameDay } from 'date-fns';
|
import { isSameDay } from 'date-fns';
|
||||||
import {
|
import { GanttChartIcon } from 'lucide-react';
|
||||||
ChevronLeftIcon,
|
|
||||||
ChevronRightIcon,
|
|
||||||
GanttChartIcon,
|
|
||||||
} from 'lucide-react';
|
|
||||||
|
|
||||||
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
import type { IServiceCreateEventPayload } from '@openpanel/db';
|
||||||
|
|
||||||
@@ -29,9 +23,11 @@ interface EventListProps {
|
|||||||
data: IServiceCreateEventPayload[];
|
data: IServiceCreateEventPayload[];
|
||||||
count: number;
|
count: number;
|
||||||
}
|
}
|
||||||
export function EventList({ data, count }: EventListProps) {
|
|
||||||
|
function EventList({ data, count }: EventListProps) {
|
||||||
const { cursor, setCursor, loading } = useCursor();
|
const { cursor, setCursor, loading } = useCursor();
|
||||||
const [filters] = useEventQueryFilters();
|
const [filters] = useEventQueryFilters();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{data.length === 0 ? (
|
{data.length === 0 ? (
|
||||||
@@ -100,3 +96,5 @@ export function EventList({ data, count }: EventListProps) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default EventList;
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import withSuspense from '@/hocs/with-suspense';
|
||||||
|
|
||||||
|
import { getEventList, getEventsCount } from '@openpanel/db';
|
||||||
|
import type { IChartEventFilter } from '@openpanel/validation';
|
||||||
|
|
||||||
|
import EventList from './event-list';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
cursor?: number;
|
||||||
|
projectId: string;
|
||||||
|
filters?: IChartEventFilter[];
|
||||||
|
eventNames?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
const EventListServer = async ({
|
||||||
|
cursor,
|
||||||
|
projectId,
|
||||||
|
eventNames,
|
||||||
|
filters,
|
||||||
|
}: Props) => {
|
||||||
|
const [events, count] = await Promise.all([
|
||||||
|
getEventList({
|
||||||
|
cursor,
|
||||||
|
projectId,
|
||||||
|
take: 50,
|
||||||
|
events: eventNames,
|
||||||
|
filters,
|
||||||
|
}),
|
||||||
|
getEventsCount({
|
||||||
|
projectId,
|
||||||
|
events: eventNames,
|
||||||
|
filters,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return <EventList data={events} count={count} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default withSuspense(EventListServer, () => (
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
<div className="card h-[74px] w-full animate-pulse items-center justify-between rounded-lg p-4"></div>
|
||||||
|
<div className="card h-[74px] w-full animate-pulse items-center justify-between rounded-lg p-4"></div>
|
||||||
|
<div className="card h-[74px] w-full animate-pulse items-center justify-between rounded-lg p-4"></div>
|
||||||
|
<div className="card h-[74px] w-full animate-pulse items-center justify-between rounded-lg p-4"></div>
|
||||||
|
<div className="card h-[74px] w-full animate-pulse items-center justify-between rounded-lg p-4"></div>
|
||||||
|
</div>
|
||||||
|
));
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
import FullPageLoadingState from '@/components/full-page-loading-state';
|
|
||||||
|
|
||||||
export default FullPageLoadingState;
|
|
||||||
@@ -7,12 +7,10 @@ import {
|
|||||||
} from '@/hooks/useEventQueryFilters';
|
} from '@/hooks/useEventQueryFilters';
|
||||||
import { parseAsInteger } from 'nuqs';
|
import { parseAsInteger } from 'nuqs';
|
||||||
|
|
||||||
import { getEventList, getEventsCount } from '@openpanel/db';
|
|
||||||
|
|
||||||
import { StickyBelowHeader } from '../layout-sticky-below-header';
|
import { StickyBelowHeader } from '../layout-sticky-below-header';
|
||||||
import { EventsPerDayChart } from './charts/events-per-day-chart';
|
import { EventsPerDayChart } from './charts/events-per-day-chart';
|
||||||
import EventConversionsListServer from './event-conversions-list';
|
import EventConversionsListServer from './event-conversions-list';
|
||||||
import { EventList } from './event-list';
|
import EventListServer from './event-list';
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: {
|
params: {
|
||||||
@@ -30,30 +28,16 @@ const nuqsOptions = {
|
|||||||
shallow: false,
|
shallow: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function Page({
|
export default function Page({
|
||||||
params: { projectId, organizationSlug },
|
params: { projectId, organizationSlug },
|
||||||
searchParams,
|
searchParams,
|
||||||
}: PageProps) {
|
}: PageProps) {
|
||||||
|
const cursor =
|
||||||
|
parseAsInteger.parseServerSide(searchParams.cursor ?? '') ?? undefined;
|
||||||
const filters =
|
const filters =
|
||||||
eventQueryFiltersParser.parseServerSide(searchParams.f ?? '') ?? undefined;
|
eventQueryFiltersParser.parseServerSide(searchParams.f ?? '') ?? undefined;
|
||||||
const eventsFilter = eventQueryNamesFilter.parseServerSide(
|
const eventNames =
|
||||||
searchParams.events ?? ''
|
eventQueryNamesFilter.parseServerSide(searchParams.events) ?? undefined;
|
||||||
);
|
|
||||||
const [events, count] = await Promise.all([
|
|
||||||
getEventList({
|
|
||||||
cursor:
|
|
||||||
parseAsInteger.parseServerSide(searchParams.cursor ?? '') ?? undefined,
|
|
||||||
projectId,
|
|
||||||
take: 50,
|
|
||||||
events: eventsFilter,
|
|
||||||
filters,
|
|
||||||
}),
|
|
||||||
getEventsCount({
|
|
||||||
projectId,
|
|
||||||
events: eventsFilter,
|
|
||||||
filters,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -72,12 +56,17 @@ export default async function Page({
|
|||||||
</StickyBelowHeader>
|
</StickyBelowHeader>
|
||||||
<div className="grid gap-4 p-4 md:grid-cols-2">
|
<div className="grid gap-4 p-4 md:grid-cols-2">
|
||||||
<div>
|
<div>
|
||||||
<EventList data={events} count={count} />
|
<EventListServer
|
||||||
|
projectId={projectId}
|
||||||
|
cursor={cursor}
|
||||||
|
filters={filters}
|
||||||
|
eventNames={eventNames}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div className="flex flex-col gap-4">
|
||||||
<EventsPerDayChart
|
<EventsPerDayChart
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
events={eventsFilter}
|
events={eventNames}
|
||||||
filters={filters}
|
filters={filters}
|
||||||
/>
|
/>
|
||||||
<EventConversionsListServer projectId={projectId} />
|
<EventConversionsListServer projectId={projectId} />
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ async function ProfileTopServer({ organizationSlug, projectId }: Props) {
|
|||||||
const res = await chQuery<{ profile_id: string; count: number }>(
|
const res = await chQuery<{ profile_id: string; count: number }>(
|
||||||
`SELECT profile_id, count(*) as count from events where profile_id != '' and project_id = ${escape(projectId)} group by profile_id order by count() DESC LIMIT 50`
|
`SELECT profile_id, count(*) as count from events where profile_id != '' and project_id = ${escape(projectId)} group by profile_id order by count() DESC LIMIT 50`
|
||||||
);
|
);
|
||||||
const profiles = await getProfiles({ ids: res.map((r) => r.profile_id) });
|
const profiles = await getProfiles(res.map((r) => r.profile_id));
|
||||||
const list = res.map((item) => {
|
const list = res.map((item) => {
|
||||||
return {
|
return {
|
||||||
count: item.count,
|
count: item.count,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { EventListItem } from '@/app/(app)/[organizationSlug]/[projectId]/events/event-list-item';
|
import { EventListItem } from '@/app/(app)/[organizationSlug]/[projectId]/events/event-list/event-list-item';
|
||||||
import useWS from '@/hooks/useWS';
|
import useWS from '@/hooks/useWS';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { EventListItem } from '@/app/(app)/[organizationSlug]/[projectId]/events/event-list-item';
|
import { EventListItem } from '@/app/(app)/[organizationSlug]/[projectId]/events/event-list/event-list-item';
|
||||||
import useWS from '@/hooks/useWS';
|
import useWS from '@/hooks/useWS';
|
||||||
import { AnimatePresence, motion } from 'framer-motion';
|
import { AnimatePresence, motion } from 'framer-motion';
|
||||||
|
|
||||||
|
|||||||
@@ -44,21 +44,12 @@ export function Pagination({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex select-none items-center justify-end gap-2',
|
'flex select-none items-center justify-end gap-1',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{size === 'base' && (
|
|
||||||
<>
|
|
||||||
<div className="text-xs font-medium">Page: {cursor + 1}</div>
|
|
||||||
{typeof count === 'number' && (
|
|
||||||
<div className="text-xs font-medium">Total rows: {count}</div>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
{size === 'base' && (
|
{size === 'base' && (
|
||||||
<Button
|
<Button
|
||||||
loading={loading}
|
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => setCursor(0)}
|
onClick={() => setCursor(0)}
|
||||||
@@ -68,7 +59,6 @@ export function Pagination({
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Button
|
<Button
|
||||||
loading={loading}
|
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => setCursor((p) => Math.max(0, p - 1))}
|
onClick={() => setCursor((p) => Math.max(0, p - 1))}
|
||||||
@@ -76,8 +66,11 @@ export function Pagination({
|
|||||||
icon={ChevronLeftIcon}
|
icon={ChevronLeftIcon}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Button loading={loading} disabled variant="outline" size="icon">
|
||||||
|
{loading ? '' : cursor}
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
loading={loading}
|
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => setCursor((p) => Math.min(lastCursor, p + 1))}
|
onClick={() => setCursor((p) => Math.min(lastCursor, p + 1))}
|
||||||
@@ -87,7 +80,6 @@ export function Pagination({
|
|||||||
|
|
||||||
{size === 'base' && (
|
{size === 'base' && (
|
||||||
<Button
|
<Button
|
||||||
loading={loading}
|
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
onClick={() => setCursor(lastCursor)}
|
onClick={() => setCursor(lastCursor)}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const withSuspense = <P,>(
|
|||||||
) => {
|
) => {
|
||||||
const WithSuspense: React.ComponentType<P> = (props) => {
|
const WithSuspense: React.ComponentType<P> = (props) => {
|
||||||
const fallback = <Fallback {...(props as any)} />;
|
const fallback = <Fallback {...(props as any)} />;
|
||||||
|
// return <>{fallback}</>;
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={fallback}>
|
<Suspense fallback={fallback}>
|
||||||
<Component {...(props as any)} />
|
<Component {...(props as any)} />
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
// prettier-ignore
|
|
||||||
import type { Options as NuqsOptions } from 'nuqs';
|
import type { Options as NuqsOptions } from 'nuqs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
createParser,
|
createParser,
|
||||||
parseAsArrayOf,
|
parseAsArrayOf,
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ export async function getEvents(
|
|||||||
const events = await chQuery<IClickhouseEvent>(sql);
|
const events = await chQuery<IClickhouseEvent>(sql);
|
||||||
if (options.profile) {
|
if (options.profile) {
|
||||||
const ids = events.map((e) => e.profile_id);
|
const ids = events.map((e) => e.profile_id);
|
||||||
const profiles = await getProfiles({ ids });
|
const profiles = await getProfiles(ids);
|
||||||
|
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
event.profile = profiles.find((p) => p.id === event.profile_id);
|
event.profile = profiles.find((p) => p.id === event.profile_id);
|
||||||
|
|||||||
@@ -59,10 +59,7 @@ interface GetProfileListOptions {
|
|||||||
filters?: IChartEventFilter[];
|
filters?: IChartEventFilter[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface GetProfilesOptions {
|
export async function getProfiles(ids: string[]) {
|
||||||
ids: string[];
|
|
||||||
}
|
|
||||||
export async function getProfiles({ ids }: GetProfilesOptions) {
|
|
||||||
if (ids.length === 0) {
|
if (ids.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -483,7 +483,7 @@ export async function getFunnelStep({
|
|||||||
id: string;
|
id: string;
|
||||||
}>(profileIdsQuery);
|
}>(profileIdsQuery);
|
||||||
|
|
||||||
return getProfiles({ ids: res.map((r) => r.id) });
|
return getProfiles(res.map((r) => r.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSeriesFromEvents(input: IChartInput) {
|
export async function getSeriesFromEvents(input: IChartInput) {
|
||||||
|
|||||||
Reference in New Issue
Block a user