123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import type {ReactNode} from 'react';
- 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 {trackAnalytics} from 'sentry/utils/analytics';
- import type {Sort} from 'sentry/utils/discover/fields';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- import type {
- ReplayListLocationQuery,
- ReplayRecordNestedFieldName,
- } from 'sentry/views/replays/types';
- type NotSortable = {
- label: string;
- tooltip?: string | ReactNode;
- };
- type Sortable = {
- fieldName: ReplayRecordNestedFieldName;
- label: string;
- sort: undefined | Sort;
- tooltip?: string | ReactNode;
- };
- type Props = NotSortable | Sortable;
- function SortableHeader(props: Props) {
- const location = useLocation<ReplayListLocationQuery>();
- const organization = useOrganization();
- if (!('sort' in props) || !props.sort) {
- const {label, tooltip} = props;
- return (
- <Header>
- {label}
- {tooltip ? (
- <StyledQuestionTooltip size="xs" position="top" title={tooltip} isHoverable />
- ) : null}
- </Header>
- );
- }
- const {fieldName, label, sort, tooltip} = props;
- const arrowDirection = sort?.kind === 'asc' ? 'up' : 'down';
- const sortArrow = <IconArrow color="gray300" size="xs" direction={arrowDirection} />;
- return (
- <Header>
- <SortLink
- role="columnheader"
- aria-sort={
- sort?.field.endsWith(fieldName)
- ? sort?.kind === 'asc'
- ? 'ascending'
- : 'descending'
- : 'none'
- }
- onClick={() => {
- const column = sort?.field.endsWith(fieldName)
- ? sort?.kind === 'desc'
- ? fieldName
- : '-' + fieldName
- : '-' + fieldName;
- trackAnalytics('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}
- </SortLink>
- {tooltip ? (
- <StyledQuestionTooltip size="xs" position="top" title={tooltip} isHoverable />
- ) : null}
- </Header>
- );
- }
- 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;
|