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.

1.3 KB
Raw Blame
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { urls } from 'scenes/urls'

/** The nav section a template page belongs to, read from the URL it was opened under. */
export type TemplateSection = 'transactional' | 'broadcasts' | 'workflows'

export function templateSectionFor(pathname: string): TemplateSection {
    const path = removeProjectIdIfPresent(pathname)
    if (path.startsWith('/transactional/')) {
        return 'transactional'
    }
    if (path.startsWith('/broadcasts/')) {
        return 'broadcasts'
    }
    return 'workflows'
}

/** A template's page in the given section, so opening it keeps the nav and back links in place. */
export function templateUrlInSection(id: string, section: TemplateSection): string {
    if (section === 'transactional') {
        return urls.transactionalTemplate(id)
    }
    if (section === 'broadcasts') {
        return urls.broadcastsTemplate(id)
    }
    return urls.workflowsLibraryTemplate(id)
}

/** The Templates tab a template page returns to. */
export function templateLibraryUrl(section: TemplateSection): string {
    if (section === 'transactional') {
        return urls.transactional('library')
    }
    if (section === 'broadcasts') {
        return urls.broadcasts('library')
    }
    return urls.workflows('library')
}