commit bfcf271a64c33a60f61f511cec2198d9c8a9c51a Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Wed Nov 26 12:32:40 2025 +0100 wip commit8cd3b89fa3Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Tue Nov 25 22:33:58 2025 +0100 funnel commit95af86dc44Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Tue Nov 25 22:23:25 2025 +0100 wip commit727a218e6bAuthor: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Tue Nov 25 10:18:26 2025 +0100 conversion wip commit958ba535d6Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Tue Nov 25 10:18:20 2025 +0100 wip commit3bbeb927ccAuthor: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Tue Nov 25 09:18:48 2025 +0100 wip commitd99335e2f4Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Mon Nov 24 18:08:10 2025 +0100 wip commit1fa61b1ae9Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Mon Nov 24 15:50:28 2025 +0100 ts commit548747d826Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Mon Nov 24 13:17:01 2025 +0100 fix typecheck events -> series commit7b18544085Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Mon Nov 24 13:06:46 2025 +0100 fix report table commit57697a5a39Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Sat Nov 22 00:05:13 2025 +0100 wip commit06fb6c4f3cAuthor: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Fri Nov 21 11:21:17 2025 +0100 wip commitdd71fd4e11Author: Carl-Gerhard Lindesvärd <lindesvard@gmail.com> Date: Thu Nov 20 13:56:58 2025 +0100 formulas
393 lines
9.8 KiB
TypeScript
393 lines
9.8 KiB
TypeScript
import { useEventQueryFilters } from '@/hooks/use-event-query-filters';
|
|
import { cn } from '@/utils/cn';
|
|
import { useState } from 'react';
|
|
|
|
import { NOT_SET_VALUE } from '@openpanel/constants';
|
|
import type { IChartType } from '@openpanel/validation';
|
|
|
|
import { useNumber } from '@/hooks/use-numer-formatter';
|
|
import { useTRPC } from '@/integrations/trpc/react';
|
|
import { pushModal } from '@/modals';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { SerieIcon } from '../report-chart/common/serie-icon';
|
|
import { Widget, WidgetBody } from '../widget';
|
|
import { OVERVIEW_COLUMNS_NAME } from './overview-constants';
|
|
import OverviewDetailsButton from './overview-details-button';
|
|
import { WidgetButtons, WidgetFooter, WidgetHead } from './overview-widget';
|
|
import {
|
|
OverviewWidgetTableGeneric,
|
|
OverviewWidgetTableLoading,
|
|
} from './overview-widget-table';
|
|
import { useOverviewOptions } from './useOverviewOptions';
|
|
import { useOverviewWidget } from './useOverviewWidget';
|
|
|
|
interface OverviewTopDevicesProps {
|
|
projectId: string;
|
|
}
|
|
export default function OverviewTopDevices({
|
|
projectId,
|
|
}: OverviewTopDevicesProps) {
|
|
const { interval, range, previous, startDate, endDate } =
|
|
useOverviewOptions();
|
|
const [filters, setFilter] = useEventQueryFilters();
|
|
const [chartType] = useState<IChartType>('bar');
|
|
const isPageFilter = filters.find((filter) => filter.name === 'path');
|
|
const [widget, setWidget, widgets] = useOverviewWidget('tech', {
|
|
device: {
|
|
title: 'Top devices',
|
|
btn: 'Devices',
|
|
chart: {
|
|
options: {
|
|
columns: ['Device', isPageFilter ? 'Views' : 'Sessions'],
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'device',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top devices',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
browser: {
|
|
title: 'Top browser',
|
|
btn: 'Browser',
|
|
chart: {
|
|
options: {
|
|
columns: ['Browser', isPageFilter ? 'Views' : 'Sessions'],
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'browser',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top browser',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
browser_version: {
|
|
title: 'Top Browser Version',
|
|
btn: 'Browser Version',
|
|
chart: {
|
|
options: {
|
|
columns: ['Version', isPageFilter ? 'Views' : 'Sessions'],
|
|
renderSerieName(name) {
|
|
return name[1] || NOT_SET_VALUE;
|
|
},
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'browser',
|
|
},
|
|
{
|
|
id: 'B',
|
|
name: 'browser_version',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top Browser Version',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
os: {
|
|
title: 'Top OS',
|
|
btn: 'OS',
|
|
chart: {
|
|
options: {
|
|
columns: ['OS', isPageFilter ? 'Views' : 'Sessions'],
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'os',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top OS',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
os_version: {
|
|
title: 'Top OS version',
|
|
btn: 'OS Version',
|
|
chart: {
|
|
options: {
|
|
columns: ['Version', isPageFilter ? 'Views' : 'Sessions'],
|
|
renderSerieName(name) {
|
|
return name[1] || NOT_SET_VALUE;
|
|
},
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'os',
|
|
},
|
|
{
|
|
id: 'B',
|
|
name: 'os_version',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top OS version',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
brand: {
|
|
title: 'Top Brands',
|
|
btn: 'Brands',
|
|
chart: {
|
|
options: {
|
|
columns: ['Brand', isPageFilter ? 'Views' : 'Sessions'],
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'brand',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top Brands',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
model: {
|
|
title: 'Top Models',
|
|
btn: 'Models',
|
|
chart: {
|
|
options: {
|
|
columns: ['Model', isPageFilter ? 'Views' : 'Sessions'],
|
|
renderSerieName(name) {
|
|
return name[1] || NOT_SET_VALUE;
|
|
},
|
|
},
|
|
report: {
|
|
limit: 10,
|
|
projectId,
|
|
startDate,
|
|
endDate,
|
|
series: [
|
|
{
|
|
type: 'event',
|
|
segment: 'user',
|
|
filters,
|
|
id: 'A',
|
|
name: isPageFilter ? 'screen_view' : 'session_start',
|
|
},
|
|
],
|
|
breakdowns: [
|
|
{
|
|
id: 'A',
|
|
name: 'brand',
|
|
},
|
|
{
|
|
id: 'B',
|
|
name: 'model',
|
|
},
|
|
],
|
|
chartType,
|
|
lineType: 'monotone',
|
|
interval: interval,
|
|
name: 'Top Models',
|
|
range: range,
|
|
previous: previous,
|
|
metric: 'sum',
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
const trpc = useTRPC();
|
|
|
|
const query = useQuery(
|
|
trpc.overview.topGeneric.queryOptions({
|
|
projectId,
|
|
range,
|
|
filters,
|
|
column: widget.key,
|
|
startDate,
|
|
endDate,
|
|
}),
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<Widget className="col-span-6 md:col-span-3">
|
|
<WidgetHead>
|
|
<div className="title">{widget.title}</div>
|
|
|
|
<WidgetButtons>
|
|
{widgets.map((w) => (
|
|
<button
|
|
type="button"
|
|
key={w.key}
|
|
onClick={() => setWidget(w.key)}
|
|
className={cn(w.key === widget.key && 'active')}
|
|
>
|
|
{w.btn}
|
|
</button>
|
|
))}
|
|
</WidgetButtons>
|
|
</WidgetHead>
|
|
<WidgetBody className="p-0">
|
|
{query.isLoading ? (
|
|
<OverviewWidgetTableLoading />
|
|
) : (
|
|
<OverviewWidgetTableGeneric
|
|
data={query.data ?? []}
|
|
column={{
|
|
name: OVERVIEW_COLUMNS_NAME[widget.key],
|
|
render(item) {
|
|
return (
|
|
<div className="row items-center gap-2 min-w-0 relative">
|
|
<SerieIcon name={item.name || NOT_SET_VALUE} />
|
|
<button
|
|
type="button"
|
|
className="truncate"
|
|
onClick={() => {
|
|
setFilter(widget.key, item.name);
|
|
}}
|
|
>
|
|
{item.name || 'Not set'}
|
|
</button>
|
|
</div>
|
|
);
|
|
},
|
|
}}
|
|
/>
|
|
)}
|
|
</WidgetBody>
|
|
<WidgetFooter>
|
|
<OverviewDetailsButton
|
|
onClick={() =>
|
|
pushModal('OverviewTopGenericModal', {
|
|
projectId,
|
|
column: widget.key,
|
|
})
|
|
}
|
|
/>
|
|
{/* <OverviewChartToggle {...{ chartType, setChartType }} /> */}
|
|
</WidgetFooter>
|
|
</Widget>
|
|
</>
|
|
);
|
|
}
|