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.

4.0 KB
Raw Blame
import { useActions, useValues } from 'kea'

import { LemonBanner, LemonTable, LemonTag } from '@posthog/lemon-ui'

import { TZLabel } from 'lib/components/TZLabel'
import { LemonTableColumns } from 'lib/lemon-ui/LemonTable'
import { SceneExport } from 'scenes/sceneTypes'

import { SceneContent } from '~/layout/scenes/components/SceneContent'
import { SceneTitleSection } from '~/layout/scenes/components/SceneTitleSection'

import { StamphogTabs } from '../../components/StamphogTabs'
import { DigestRunApi } from '../../generated/api.schemas'
import { digestDestinationLabel, digestRunHasDetails, digestStatusDisplay } from './digestDisplay'
import { DigestRunDetails } from './DigestRunDetails'
import { DIGESTS_PAGE_SIZE, stamphogDigestsSceneLogic } from './stamphogDigestsSceneLogic'

export const scene: SceneExport = {
    component: StamphogDigestsScene,
    logic: stamphogDigestsSceneLogic,
}

function DigestsTable(): JSX.Element {
    const { digestRuns, digestRunsCount, digestRunsResponseLoading, digestRunsFailed, page } =
        useValues(stamphogDigestsSceneLogic)
    const { setPage, loadDigestRuns, digestRunExpanded } = useActions(stamphogDigestsSceneLogic)

    const columns: LemonTableColumns<DigestRunApi> = [
        {
            title: 'Created',
            dataIndex: 'created_at',
            render: (created_at) => <TZLabel time={created_at as string} />,
        },
        {
            title: 'Channel',
            key: 'slack_channel_id',
            render: (_, run) => <span className="font-mono text-xs">{digestDestinationLabel(run)}</span>,
        },
        {
            title: 'Audience',
            dataIndex: 'audience_key',
            render: (audience_key) => <span className="font-mono text-xs">{audience_key as string}</span>,
        },
        {
            title: 'Status',
            key: 'status',
            render: (_, run) => {
                const { type, label } = digestStatusDisplay(run)
                return <LemonTag type={type}>{label}</LemonTag>
            },
        },
        {
            title: 'PRs',
            dataIndex: 'pr_count',
            render: (pr_count) => <span className="font-mono text-xs">{pr_count as number}</span>,
        },
        {
            title: 'Posted',
            key: 'posted_at',
            render: (_, run) => (run.posted_at ? <TZLabel time={run.posted_at} /> : null),
        },
    ]

    if (digestRunsFailed) {
        return (
            <LemonBanner
                type="error"
                action={{ children: 'Try again', onClick: () => loadDigestRuns() }}
                data-attr="stamphog-digests-error"
            >
                Could not load digests. This is usually temporary.
            </LemonBanner>
        )
    }

    return (
        <LemonTable
            columns={columns}
            dataSource={digestRuns}
            loading={digestRunsResponseLoading}
            rowKey="id"
            expandable={{
                expandedRowRender: (run) => <DigestRunDetails run={run} />,
                rowExpandable: digestRunHasDetails,
                onRowExpand: digestRunExpanded,
            }}
            pagination={{
                controlled: true,
                pageSize: DIGESTS_PAGE_SIZE,
                currentPage: page,
                entryCount: digestRunsCount,
                onForward: () => setPage(page + 1),
                onBackward: () => setPage(page - 1),
            }}
            emptyState="No digests yet. Stamphog posts one per audience on its digest schedule."
            data-attr="stamphog-digests-table"
        />
    )
}

export function StamphogDigestsScene(): JSX.Element {
    return (
        <SceneContent>
            <SceneTitleSection
                name="Digests"
                description="Every digest Stamphog posted, and where it went."
                resourceType={{ type: 'stamphog' }}
            />
            <StamphogTabs activeKey="digests" />
            <DigestsTable />
        </SceneContent>
    )
}

export default StamphogDigestsScene