import { memo } from 'react'
import { Analytic } from '@app/types'
import { ResponsiveStream, TooltipProps } from '@nivo/stream'
import { useFullAnalytics } from '@app/data/external/analytics/analytics-rest'
const theme = {
axis: {
ticks: {
text: {
fill: 'rgb(115,115,115)',
fontSize: '0.75rem',
},
},
},
}
const axisLeft = {
orient: 'right',
tickSize: 0,
tickPadding: -20,
tickRotation: 0,
legend: '',
legendOffset: -35,
}
const StackTip = ({ item }: { item: Analytic }) => {
if (!item) {
return null
}
return (
{item.errorCount} Error{item.errorCount === 1 ? '' : 's'}
{item.warningCount} Warning{item.warningCount === 1 ? '' : 's'}
)
}
const Tip = ({ item }: { item: TooltipProps }) => {
if (!item) {
return null
}
return (
{item.layer.label === 'error' ? (
) : (
)}
)
}
const getLabel = (item: { id: string | number }) =>
String(item.id).replace('Count', '')
const WebsiteAnalyticStreamComponent = ({
domain,
liveData = [],
}: {
domain: string
liveData?: Analytic[]
}) => {
const { data } = useFullAnalytics({ domain, liveData })
if (!data.length) {
return (
)
}
return (
data &&
}
tooltip={(stack) => data && }
motionConfig='gentle'
/>
)
}
export const WebsiteAnalyticStream = memo(WebsiteAnalyticStreamComponent)