import styled from '@emotion/styled'; import Link from 'sentry/components/links/link'; import QuestionTooltip from 'sentry/components/questionTooltip'; import {IconArrow} from 'sentry/icons'; import {space} from 'sentry/styles/space'; import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent'; import type {Sort} from 'sentry/utils/discover/fields'; import {useLocation} from 'sentry/utils/useLocation'; import useOrganization from 'sentry/utils/useOrganization'; import type {ReplayListLocationQuery} from 'sentry/views/replays/types'; import {ReplayRecordNestedFieldName} from 'sentry/views/replays/types'; type NotSortable = { label: string; tooltip?: string; }; type Sortable = { fieldName: ReplayRecordNestedFieldName; label: string; sort: undefined | Sort; tooltip?: string; }; type Props = NotSortable | Sortable; function SortableHeader(props: Props) { const location = useLocation(); const organization = useOrganization(); if (!('sort' in props) || !props.sort) { const {label, tooltip} = props; return (
{label} {tooltip ? ( ) : null}
); } const {fieldName, label, sort, tooltip} = props; const arrowDirection = sort?.kind === 'asc' ? 'up' : 'down'; const sortArrow = ; return (
{ const column = sort?.field.endsWith(fieldName) ? sort?.kind === 'desc' ? fieldName : '-' + fieldName : '-' + fieldName; trackAdvancedAnalyticsEvent('replay.list-sorted', { organization, column, }); }} to={{ pathname: location.pathname, query: { ...location.query, sort: sort?.field.endsWith(fieldName) ? sort?.kind === 'desc' ? fieldName : '-' + fieldName : '-' + fieldName, }, }} > {label} {sort?.field === fieldName && sortArrow} {tooltip ? ( ) : null}
); } const Header = styled('div')` display: grid; grid-template-columns: repeat(2, max-content); align-items: center; padding: ${space(1.5)}; `; const SortLink = styled(Link)` color: inherit; :hover { color: inherit; } svg { vertical-align: top; } `; const StyledQuestionTooltip = styled(QuestionTooltip)` margin-left: ${space(0.5)}; `; export default SortableHeader;