// eslint-disable-next-line no-restricted-imports import {browserHistory, withRouter, WithRouterProps} from 'react-router'; import styled from '@emotion/styled'; import {Query} from 'history'; import Button from 'sentry/components/button'; import ButtonBar from 'sentry/components/buttonBar'; import {IconChevron} from 'sentry/icons'; import {t} from 'sentry/locale'; import space from 'sentry/styles/space'; import parseLinkHeader from 'sentry/utils/parseLinkHeader'; /** * @param cursor The string cursor value * @param path The current page pathname * @param query The current query object * @param delta The delta in page number change triggered by the * click. A negative delta would be a "previous" page. */ export type CursorHandler = ( cursor: string | undefined, path: string, query: Query, delta: number ) => void; type Props = WithRouterProps & { caption?: React.ReactNode; className?: string; disabled?: boolean; onCursor?: CursorHandler; pageLinks?: string | null; paginationAnalyticsEvent?: (direction: string) => void; size?: 'zero' | 'xs' | 'sm'; to?: string; }; const defaultOnCursor: CursorHandler = (cursor, path, query, _direction) => browserHistory.push({ pathname: path, query: {...query, cursor}, }); const Pagination = ({ to, location, className, onCursor = defaultOnCursor, paginationAnalyticsEvent, pageLinks, size = 'sm', caption, disabled = false, }: Props) => { if (!pageLinks) { return null; } const path = to ?? location.pathname; const query = location.query; const links = parseLinkHeader(pageLinks); const previousDisabled = disabled || links.previous?.results === false; const nextDisabled = disabled || links.next?.results === false; return ( {caption && {caption}}