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.

3.8 KB
Raw Blame
import { MakeLogicType, connect, kea, path, selectors } from 'kea'
import { router } from 'kea-router'

import { sceneLogic } from '~/scenes/sceneLogic'
import { Breadcrumb } from '~/types'

import { repoBreadcrumbs } from '../lib/repoBreadcrumbs'
import { engineeringAnalyticsLogic } from './engineeringAnalyticsLogic'

/** The root scene's views: the repo hub and the pull request, workflow, test, deploy, team, and author list pages. */
export type EngineeringAnalyticsView = 'hub' | 'pull-requests' | 'workflows' | 'tests' | 'deploys' | 'teams' | 'authors'

/** The scene subtitle. Teams and authors are organization-wide on GitHub, so their tabs say which
 *  repository's figures they show. */
export function viewDescription(view: EngineeringAnalyticsView, repo: string | null): string {
    const inRepo = repo ? ` in ${repo}` : ''
    const descriptions: Record<EngineeringAnalyticsView, string> = {
        hub: 'CI health, pull requests, workflows, and cost for the connected repo.',
        'pull-requests': 'Pull requests and their CI status.',
        workflows: 'Run volume, success rate, and duration per workflow over the selected window.',
        tests: 'Quarantine debt by team: which quarantined tests each team owns, and how long they have stood.',
        deploys:
            'DORA-style deploy metrics from GitHub deployments: frequency, merge to deploy lead time, and failure proxies.',
        teams: `Tests each team owns${inRepo} and their CI signal, from the owners.yaml map.`,
        authors: `Friction each author meets${inRepo}: CI, review, and the merge queue, against the typical author.`,
    }
    return descriptions[view]
}

const SCENE_KEY_TO_VIEW: Record<string, EngineeringAnalyticsView> = {
    engineeringAnalytics: 'hub',
    engineeringAnalyticsPullRequestList: 'pull-requests',
    engineeringAnalyticsWorkflows: 'workflows',
    engineeringAnalyticsTests: 'tests',
    engineeringAnalyticsTeams: 'teams',
    engineeringAnalyticsAuthors: 'authors',
    engineeringAnalyticsDeploys: 'deploys',
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface engineeringAnalyticsSceneLogicValues {
    scopeRepo: string | null // engineeringAnalyticsLogic
    sourceId: string | null // engineeringAnalyticsLogic
    sceneKey: string | null // sceneLogic
    activeView: EngineeringAnalyticsView
    breadcrumbs: Breadcrumb[]
}

// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface engineeringAnalyticsSceneLogicMeta {
    __keaTypeGenInternalSelectorTypes: {
        activeView: (sceneKey: string | null) => EngineeringAnalyticsView
        breadcrumbs: (
            scopeRepo: string | null,
            sourceId: string | null,
            searchParams: Record<string, any>
        ) => Breadcrumb[]
    }
}

export type engineeringAnalyticsSceneLogicType = MakeLogicType<
    engineeringAnalyticsSceneLogicValues,
    {},
    Record<string, any>,
    engineeringAnalyticsSceneLogicMeta
>

export const engineeringAnalyticsSceneLogic = kea<engineeringAnalyticsSceneLogicType>([
    path(['products', 'engineering_analytics', 'frontend', 'scenes', 'engineeringAnalyticsSceneLogic']),
    connect(() => ({
        values: [sceneLogic, ['sceneKey'], engineeringAnalyticsLogic, ['scopeRepo', 'sourceId']],
    })),
    selectors({
        activeView: [
            (s) => [s.sceneKey],
            (sceneKey: string): EngineeringAnalyticsView => SCENE_KEY_TO_VIEW[sceneKey] ?? 'hub',
        ],
        breadcrumbs: [
            (s) => [s.scopeRepo, s.sourceId, router.selectors.searchParams],
            (
                scopeRepo: string | null,
                sourceId: string | null,
                searchParams: Record<string, string | undefined>
            ): Breadcrumb[] => repoBreadcrumbs(scopeRepo, searchParams, sourceId),
        ],
    }),
])