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.

2.0 KB
Raw Blame
import { useValues } from 'kea'
import posthog from 'posthog-js'

import { LemonButton } from '@posthog/lemon-ui'

import { Shortcut } from 'lib/components/Shortcuts/Shortcut'
import { sanitizeDashboard } from 'scenes/dashboard/dashboardEvents'
import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import { Scene } from 'scenes/sceneTypes'

interface DashboardZoomControlProps {
    layoutZoom: number
    setLayoutZoom: (value: number) => void
}

export function DashboardZoomControl({ layoutZoom, setLayoutZoom }: DashboardZoomControlProps): JSX.Element | null {
    const { dashboard, currentLayoutSize } = useValues(dashboardLogic)

    if (currentLayoutSize === 'xs') {
        return null
    }

    return (
        <div className="flex items-center gap-2 text-sm text-muted hidden md:flex">
            <Shortcut
                name="DashboardLayoutZoomToggle"
                keybind={[['z']]}
                intent="Toggle dashboard layout zoom while editing"
                interaction="click"
                scope={Scene.Dashboard}
            >
                <LemonButton
                    size="small"
                    type="secondary"
                    active={layoutZoom < 1}
                    onClick={() => {
                        const nextZoom = layoutZoom < 1 ? 1 : 0.25
                        setLayoutZoom(nextZoom)
                        posthog.capture('dashboard layout zoom changed', {
                            dashboard_id: (dashboard ?? null)?.id,
                            dashboard: sanitizeDashboard(dashboard ?? null),
                            layout_zoom: nextZoom,
                            source: 'button',
                        })
                    }}
                    tooltip="Collapse/Expand view. Makes it easier to edit the layout for busier dashboards."
                >
                    {layoutZoom < 1 ? 'Expand view' : 'Collapse view'}
                </LemonButton>
            </Shortcut>
        </div>
    )
}