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.9 KB
Raw Blame
import { useActions, useValues } from 'kea'

import { LemonButton, LemonCheckbox, LemonDivider, LemonDropdown } from '@posthog/lemon-ui'

import { IconTuning } from 'lib/lemon-ui/icons'

import { isTicketColumnMandatory, offerableTicketColumns, ticketColumnLabel } from './ticketColumns'
import { ticketColumnsLogic } from './ticketColumnsLogic'

interface TicketColumnsDropdownProps {
    aiEnabled: boolean
    embedded?: boolean
}

export function TicketColumnsDropdown({ aiEnabled, embedded = false }: TicketColumnsDropdownProps): JSX.Element {
    const { visibleColumns } = useValues(ticketColumnsLogic)
    const { toggleColumn, setVisibleColumns } = useActions(ticketColumnsLogic)

    const offerable = offerableTicketColumns({ aiEnabled, embedded })
    const shownCount = offerable.filter((key) => visibleColumns.includes(key) || isTicketColumnMandatory(key)).length
    const allShown = shownCount === offerable.length

    return (
        <LemonDropdown
            closeOnClickInside={false}
            overlay={
                <div className="space-y-px p-1 min-w-48">
                    {offerable.map((key) => {
                        const mandatory = isTicketColumnMandatory(key)
                        return (
                            <LemonButton
                                key={key}
                                type="tertiary"
                                size="small"
                                fullWidth
                                icon={
                                    <LemonCheckbox
                                        checked={mandatory || visibleColumns.includes(key)}
                                        className="pointer-events-none"
                                    />
                                }
                                disabledReason={mandatory ? 'This column identifies the ticket' : undefined}
                                onClick={() => toggleColumn(key)}
                            >
                                {ticketColumnLabel(key)}
                            </LemonButton>
                        )
                    })}
                    <LemonDivider className="my-1" />
                    <LemonButton
                        type="tertiary"
                        size="small"
                        fullWidth
                        disabledReason={allShown ? 'Every column is already shown' : undefined}
                        onClick={() => setVisibleColumns(offerable)}
                    >
                        Show all columns
                    </LemonButton>
                </div>
            }
        >
            <LemonButton
                type="tertiary"
                size="small"
                icon={<IconTuning />}
                data-attr="support-tickets-column-selector"
                tooltip={allShown ? 'Show all columns' : `Show ${shownCount} of ${offerable.length} columns`}
            />
        </LemonDropdown>
    )
}