import { useMemo } from 'react'; import { GridColumn, GridTable, Flexbox, Button, ButtonGroup } from 'react-basics'; import { useEventDataProperties, useEventDataValues, useMessages } from '@/components/hooks'; import { LoadingPanel } from '@/components/common/LoadingPanel'; import PieChart from '@/components/charts/PieChart'; import ListTable from '@/components/metrics/ListTable'; import { useState } from 'react'; import { CHART_COLORS } from '@/lib/constants'; import styles from './EventProperties.module.css'; export function EventProperties({ websiteId }: { websiteId: string }) { const [propertyName, setPropertyName] = useState(''); const [eventName, setEventName] = useState(''); const [propertyView, setPropertyView] = useState('table'); const { formatMessage, labels } = useMessages(); const { data, isLoading, isFetched, error } = useEventDataProperties(websiteId); const { data: values } = useEventDataValues(websiteId, eventName, propertyName); const propertySum = useMemo(() => { return values?.reduce((sum, { total }) => sum + total, 0) ?? 0; }, [values]); const chartData = useMemo(() => { if (!propertyName || !values) return null; return { labels: values.map(({ value }) => value), datasets: [ { data: values.map(({ total }) => total), backgroundColor: CHART_COLORS, borderWidth: 0, }, ], }; }, [propertyName, values]); const tableData = useMemo(() => { if (!propertyName || !values || propertySum === 0) return []; return values.map(({ value, total }) => ({ x: value, y: total, z: 100 * (total / propertySum), })); }, [propertyName, values, propertySum]); const handleRowClick = row => { setEventName(row.eventName); setPropertyName(row.propertyName); }; return (
{row => (
handleRowClick(row)}> {row.eventName}
)}
{row => (
handleRowClick(row)}> {row.propertyName}
)}
{propertyName && (
{`${eventName}: ${propertyName}`}
setPropertyView(key as string)} >
{values?.length === 0 ? (
{formatMessage(labels.noData)}
) : propertyView === 'table' ? ( ) : ( )}
)}
); } export default EventProperties;