: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useActions, useValues } from 'kea'
import { IconArchive, IconPin, IconPinFilled, IconX } from '@posthog/icons'
import { Button, Text, Tooltip, TooltipContent, TooltipTrigger } from '@posthog/quill'
import { TodaySessionBulkArchiveDialog } from './TodaySessionBulkArchiveDialog'
import { sessionsLabel } from './todaySessionSelection'
import { TodayBulkAction, todaySessionSelectionLogic } from './todaySessionSelectionLogic'
import { todayShellLogic } from './todayShellLogic'
const BUSY_REASON = 'Wait for the current change to finish'
interface BulkButtonProps {
label: string
action: TodayBulkAction | null
icon: JSX.Element
dataAttr: string
onClick: () => void
}
/** The sidebar is narrow, so each action is an icon button that names itself in its tooltip, like Desktop's bar. */
function BulkButton({ label, action, icon, dataAttr, onClick }: BulkButtonProps): JSX.Element {
const { bulkAction } = useValues(todaySessionSelectionLogic)
const loading = action !== null && bulkAction === action
const busy = bulkAction !== null && !loading
const button = (
<Button
size="icon-sm"
aria-label={label}
loading={loading}
disabled={busy}
onClick={onClick}
data-attr={dataAttr}
/>
)
return (
<Tooltip>
<TooltipTrigger delay={0} render={button}>
{icon}
</TooltipTrigger>
<TooltipContent side="top">{busy ? BUSY_REASON : label}</TooltipContent>
</Tooltip>
)
}
export function TodaySessionBulkBar(): JSX.Element {
const { selectedSessionIds, bulkPinDirection, bulkArchiveConfirm, bulkAction } =
useValues(todaySessionSelectionLogic)
const { pinSelected, requestBulkArchive, clearSelection, closeBulkArchiveConfirm, archiveSelected } =
useActions(todaySessionSelectionLogic)
const { phoneLayout } = useValues(todayShellLogic)
const count = selectedSessionIds.length
const minimum = phoneLayout ? 1 : 2
const sessions = sessionsLabel(count)
const pin = bulkPinDirection === 'pin'
return (
<>
{/* The bar is the only sign of a selection and unmounts below two, so the announcement lives outside it. */}
<span aria-live="polite" className="sr-only">
{count >= minimum ? `${sessions} selected` : ''}
</span>
{count >= minimum && (
<div
className="-mx-3 flex items-center justify-between gap-2 border-t border-border px-3 py-1.5"
data-attr="today-session-bulk-bar"
>
<div className="flex min-w-0 items-baseline gap-1.5">
<Text size="xs" weight="medium" render={<span />} className="shrink-0">
{`${count} selected`}
</Text>
{!phoneLayout && (
<Text size="xxs" variant="muted" render={<span />} className="truncate">
Esc to clear
</Text>
)}
</div>
<div className="flex shrink-0 items-center gap-0.5">
<BulkButton
label={`${pin ? 'Pin' : 'Unpin'} ${sessions}`}
action="pin"
icon={pin ? <IconPin /> : <IconPinFilled />}
onClick={pinSelected}
dataAttr="today-session-bulk-pin"
/>
<BulkButton
label={`Archive ${sessions}`}
action="archive"
icon={<IconArchive />}
onClick={requestBulkArchive}
dataAttr="today-session-bulk-archive"
/>
<BulkButton
label="Clear selection"
action={null}
icon={<IconX />}
onClick={clearSelection}
dataAttr="today-session-bulk-clear"
/>
</div>
</div>
)}
<TodaySessionBulkArchiveDialog
confirm={bulkArchiveConfirm}
archiving={bulkAction === 'archive'}
onCancel={closeBulkArchiveConfirm}
onConfirm={archiveSelected}
dataAttrPrefix="today-session-bulk"
/>
</>
)
}