dashboard: just toggle one chart at the time (overview)

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-21 09:55:46 +01:00
parent 7ba60cdaf3
commit e78e88e267
8 changed files with 42 additions and 36 deletions

View File

@@ -1,10 +1,15 @@
import type { Dispatch, SetStateAction } from 'react';
import { BarChartIcon, LineChartIcon } from 'lucide-react'; import { BarChartIcon, LineChartIcon } from 'lucide-react';
import { Button } from '../ui/button'; import type { IChartType } from '@openpanel/validation';
import { useOverviewOptions } from './useOverviewOptions';
export function OverviewChartToggle() { import { Button } from '../ui/button';
const { chartType, setChartType } = useOverviewOptions();
interface Props {
chartType: IChartType;
setChartType: Dispatch<SetStateAction<IChartType>>;
}
export function OverviewChartToggle({ chartType, setChartType }: Props) {
return ( return (
<Button <Button
size={'icon'} size={'icon'}

View File

@@ -3,12 +3,10 @@
import { Fragment } from 'react'; import { Fragment } from 'react';
import { api } from '@/app/_trpc/client'; import { api } from '@/app/_trpc/client';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import { ChevronsUpDownIcon } from 'lucide-react';
import AnimateHeight from 'react-animate-height'; import AnimateHeight from 'react-animate-height';
import type { IChartInput } from '@openpanel/validation'; import type { IChartInput } from '@openpanel/validation';
import { redisSub } from '../../../../../packages/redis';
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip'; import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
import { useOverviewOptions } from './useOverviewOptions'; import { useOverviewOptions } from './useOverviewOptions';

View File

@@ -1,9 +1,12 @@
'use client'; 'use client';
import { useState } from 'react';
import { ChartSwitch } from '@/components/report/chart'; import { ChartSwitch } from '@/components/report/chart';
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters'; import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import type { IChartType } from '@openpanel/validation';
import { Widget, WidgetBody } from '../widget'; import { Widget, WidgetBody } from '../widget';
import { OverviewChartToggle } from './overview-chart-toggle'; import { OverviewChartToggle } from './overview-chart-toggle';
import { WidgetButtons, WidgetHead } from './overview-widget'; import { WidgetButtons, WidgetHead } from './overview-widget';
@@ -16,9 +19,10 @@ interface OverviewTopDevicesProps {
export default function OverviewTopDevices({ export default function OverviewTopDevices({
projectId, projectId,
}: OverviewTopDevicesProps) { }: OverviewTopDevicesProps) {
const { interval, range, previous, startDate, endDate, chartType } = const { interval, range, previous, startDate, endDate } =
useOverviewOptions(); useOverviewOptions();
const [filters, setFilter] = useEventQueryFilters(); const [filters, setFilter] = useEventQueryFilters();
const [chartType, setChartType] = useState<IChartType>('bar');
const isPageFilter = filters.find((filter) => filter.name === 'path'); const isPageFilter = filters.find((filter) => filter.name === 'path');
const [widget, setWidget, widgets] = useOverviewWidget('tech', { const [widget, setWidget, widgets] = useOverviewWidget('tech', {
devices: { devices: {
@@ -179,7 +183,7 @@ export default function OverviewTopDevices({
<WidgetHead> <WidgetHead>
<div className="title"> <div className="title">
{widget.title} {widget.title}
<OverviewChartToggle /> <OverviewChartToggle {...{ chartType, setChartType }} />
</div> </div>
<WidgetButtons> <WidgetButtons>
{widgets.map((w) => ( {widgets.map((w) => (

View File

@@ -1,11 +1,14 @@
'use client'; 'use client';
import { useState } from 'react';
import { ChartSwitch } from '@/components/report/chart'; import { ChartSwitch } from '@/components/report/chart';
import { Button } from '@/components/ui/button'; import { Button } from '@/components/ui/button';
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters'; import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import { BarChartIcon, LineChart, LineChartIcon } from 'lucide-react'; import { BarChartIcon, LineChart, LineChartIcon } from 'lucide-react';
import type { IChartType } from '@openpanel/validation';
import { Widget, WidgetBody } from '../../widget'; import { Widget, WidgetBody } from '../../widget';
import { OverviewChartToggle } from '../overview-chart-toggle'; import { OverviewChartToggle } from '../overview-chart-toggle';
import { WidgetButtons, WidgetHead } from '../overview-widget'; import { WidgetButtons, WidgetHead } from '../overview-widget';
@@ -20,16 +23,10 @@ export default function OverviewTopEvents({
projectId, projectId,
conversions, conversions,
}: OverviewTopEventsProps) { }: OverviewTopEventsProps) {
const { const { interval, range, previous, startDate, endDate } =
interval, useOverviewOptions();
range,
previous,
startDate,
endDate,
chartType,
setChartType,
} = useOverviewOptions();
const [filters] = useEventQueryFilters(); const [filters] = useEventQueryFilters();
const [chartType, setChartType] = useState<IChartType>('bar');
const [widget, setWidget, widgets] = useOverviewWidget('ev', { const [widget, setWidget, widgets] = useOverviewWidget('ev', {
all: { all: {
title: 'Top events', title: 'Top events',
@@ -60,7 +57,7 @@ export default function OverviewTopEvents({
name: 'name', name: 'name',
}, },
], ],
chartType: chartType, chartType,
lineType: 'monotone', lineType: 'monotone',
interval: interval, interval: interval,
name: 'Top sources', name: 'Top sources',
@@ -99,7 +96,7 @@ export default function OverviewTopEvents({
name: 'name', name: 'name',
}, },
], ],
chartType: chartType, chartType,
lineType: 'monotone', lineType: 'monotone',
interval: interval, interval: interval,
name: 'Top sources', name: 'Top sources',
@@ -116,7 +113,7 @@ export default function OverviewTopEvents({
<WidgetHead> <WidgetHead>
<div className="title"> <div className="title">
{widget.title} {widget.title}
<OverviewChartToggle /> <OverviewChartToggle {...{ chartType, setChartType }} />
</div> </div>
<WidgetButtons> <WidgetButtons>
{widgets {widgets

View File

@@ -1,9 +1,12 @@
'use client'; 'use client';
import { useState } from 'react';
import { ChartSwitch } from '@/components/report/chart'; import { ChartSwitch } from '@/components/report/chart';
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters'; import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import type { IChartType } from '@openpanel/validation';
import { Widget, WidgetBody } from '../widget'; import { Widget, WidgetBody } from '../widget';
import { OverviewChartToggle } from './overview-chart-toggle'; import { OverviewChartToggle } from './overview-chart-toggle';
import { WidgetButtons, WidgetHead } from './overview-widget'; import { WidgetButtons, WidgetHead } from './overview-widget';
@@ -14,8 +17,9 @@ interface OverviewTopGeoProps {
projectId: string; projectId: string;
} }
export default function OverviewTopGeo({ projectId }: OverviewTopGeoProps) { export default function OverviewTopGeo({ projectId }: OverviewTopGeoProps) {
const { interval, range, previous, startDate, endDate, chartType } = const { interval, range, previous, startDate, endDate } =
useOverviewOptions(); useOverviewOptions();
const [chartType, setChartType] = useState<IChartType>('bar');
const [filters, setFilter] = useEventQueryFilters(); const [filters, setFilter] = useEventQueryFilters();
const isPageFilter = filters.find((filter) => filter.name === 'path'); const isPageFilter = filters.find((filter) => filter.name === 'path');
const [widget, setWidget, widgets] = useOverviewWidget('geo', { const [widget, setWidget, widgets] = useOverviewWidget('geo', {
@@ -117,7 +121,7 @@ export default function OverviewTopGeo({ projectId }: OverviewTopGeoProps) {
<WidgetHead> <WidgetHead>
<div className="title"> <div className="title">
{widget.title} {widget.title}
<OverviewChartToggle /> <OverviewChartToggle {...{ chartType, setChartType }} />
</div> </div>
<WidgetButtons> <WidgetButtons>
{widgets.map((w) => ( {widgets.map((w) => (

View File

@@ -1,9 +1,12 @@
'use client'; 'use client';
import { useState } from 'react';
import { ChartSwitch } from '@/components/report/chart'; import { ChartSwitch } from '@/components/report/chart';
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters'; import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import type { IChartType } from '@openpanel/validation';
import { Widget, WidgetBody } from '../widget'; import { Widget, WidgetBody } from '../widget';
import { OverviewChartToggle } from './overview-chart-toggle'; import { OverviewChartToggle } from './overview-chart-toggle';
import { WidgetButtons, WidgetHead } from './overview-widget'; import { WidgetButtons, WidgetHead } from './overview-widget';
@@ -14,8 +17,9 @@ interface OverviewTopPagesProps {
projectId: string; projectId: string;
} }
export default function OverviewTopPages({ projectId }: OverviewTopPagesProps) { export default function OverviewTopPages({ projectId }: OverviewTopPagesProps) {
const { interval, range, previous, startDate, endDate, chartType } = const { interval, range, previous, startDate, endDate } =
useOverviewOptions(); useOverviewOptions();
const [chartType, setChartType] = useState<IChartType>('bar');
const [filters, setFilter] = useEventQueryFilters(); const [filters, setFilter] = useEventQueryFilters();
const [widget, setWidget, widgets] = useOverviewWidget('pages', { const [widget, setWidget, widgets] = useOverviewWidget('pages', {
top: { top: {
@@ -116,7 +120,7 @@ export default function OverviewTopPages({ projectId }: OverviewTopPagesProps) {
<WidgetHead> <WidgetHead>
<div className="title"> <div className="title">
{widget.title} {widget.title}
<OverviewChartToggle /> <OverviewChartToggle {...{ chartType, setChartType }} />
</div> </div>
<WidgetButtons> <WidgetButtons>
{widgets.map((w) => ( {widgets.map((w) => (

View File

@@ -1,9 +1,12 @@
'use client'; 'use client';
import { useState } from 'react';
import { ChartSwitch } from '@/components/report/chart'; import { ChartSwitch } from '@/components/report/chart';
import { useEventQueryFilters } from '@/hooks/useEventQueryFilters'; import { useEventQueryFilters } from '@/hooks/useEventQueryFilters';
import { cn } from '@/utils/cn'; import { cn } from '@/utils/cn';
import type { IChartType } from '@openpanel/validation';
import { Widget, WidgetBody } from '../widget'; import { Widget, WidgetBody } from '../widget';
import { OverviewChartToggle } from './overview-chart-toggle'; import { OverviewChartToggle } from './overview-chart-toggle';
import { WidgetButtons, WidgetHead } from './overview-widget'; import { WidgetButtons, WidgetHead } from './overview-widget';
@@ -16,8 +19,9 @@ interface OverviewTopSourcesProps {
export default function OverviewTopSources({ export default function OverviewTopSources({
projectId, projectId,
}: OverviewTopSourcesProps) { }: OverviewTopSourcesProps) {
const { interval, range, previous, startDate, endDate, chartType } = const { interval, range, previous, startDate, endDate } =
useOverviewOptions(); useOverviewOptions();
const [chartType, setChartType] = useState<IChartType>('bar');
const [filters, setFilter] = useEventQueryFilters(); const [filters, setFilter] = useEventQueryFilters();
const isPageFilter = filters.find((filter) => filter.name === 'path'); const isPageFilter = filters.find((filter) => filter.name === 'path');
const [widget, setWidget, widgets] = useOverviewWidget('sources', { const [widget, setWidget, widgets] = useOverviewWidget('sources', {
@@ -269,7 +273,7 @@ export default function OverviewTopSources({
<WidgetHead> <WidgetHead>
<div className="title"> <div className="title">
{widget.title} {widget.title}
<OverviewChartToggle /> <OverviewChartToggle {...{ chartType, setChartType }} />
</div> </div>
<WidgetButtons> <WidgetButtons>

View File

@@ -16,12 +16,6 @@ import { mapKeys } from '@openpanel/validation';
const nuqsOptions = { history: 'push' } as const; const nuqsOptions = { history: 'push' } as const;
export function useOverviewOptions() { export function useOverviewOptions() {
const [chartType, setChartType] = useQueryState(
'ct',
parseAsStringEnum(['bar', 'linear'])
.withDefault('bar')
.withOptions(nuqsOptions)
);
const [previous, setPrevious] = useQueryState( const [previous, setPrevious] = useQueryState(
'compare', 'compare',
parseAsBoolean.withDefault(true).withOptions(nuqsOptions) parseAsBoolean.withDefault(true).withOptions(nuqsOptions)
@@ -74,9 +68,5 @@ export function useOverviewOptions() {
// Toggles // Toggles
liveHistogram, liveHistogram,
setLiveHistogram, setLiveHistogram,
// Other
chartType,
setChartType,
}; };
} }