Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

788 B
Raw Blame
import { ComponentType } from 'react'

import { isNonEmptyObject } from 'lib/utils/guards'

import { isNodeWithSource } from '~/queries/schema/node-guards'
import { InsightModel } from '~/types'

import { QUERY_TYPES_METADATA } from './insightTypesMetadata'

export function InsightIcon({ insight, className }: { insight: InsightModel; className?: string }): JSX.Element | null {
    let Icon: ComponentType<any> | null = null

    if ('query' in insight && isNonEmptyObject(insight.query)) {
        const insightType = isNodeWithSource(insight.query) ? insight.query.source.kind : insight.query.kind
        const insightMetadata = QUERY_TYPES_METADATA[insightType]
        Icon = insightMetadata && insightMetadata.icon
    }

    return Icon ? <Icon className={className} /> : null
}