import {
BackwardIcon,
ForwardIcon,
ChevronDownIcon,
ChevronUpIcon,
} from '@heroicons/react/24/solid';
import React, { ReactNode } from 'react';
export interface ActivityColumn {
label: string;
// The server-side column this header sorts on. Headers without one are
// not sortable — the old tables left Listed, Options and Notes unsorted.
sort?: string;
}
interface ActivityTableArgs {
columns: ActivityColumn[];
rows: any[];
// Rows come from two different routes, so the caller says what identifies
// a row and what its cells are.
rowKey: Function;
renderRow: Function;
sortBy: string;
sortDesc: boolean;
onSort: Function;
loading: boolean;
hasPrev: boolean;
hasNext: boolean;
onPrev: Function;
onNext: Function;
}
// 'neutral' is for a state that is information, not a verdict — the "would be
// blocked" of Watch mode (Redmine #25592).
type PillTone = 'ok' | 'warn' | 'bad' | 'neutral';
const pillTones = {
ok: 'bg-green-500/15 text-green-400',
warn: 'bg-yellow-500/15 text-yellow-400',
bad: 'bg-pink-500/15 text-pink-400',
neutral: 'bg-sky-500/15 text-sky-300',
};
export function Pill( {
tone,
children,
}: {
tone: PillTone;
children: ReactNode;
} ) {
return (
{ children }
);
}
export default function ActivityTable( {
columns,
rows,
rowKey,
renderRow,
sortBy,
sortDesc,
onSort,
loading,
hasPrev,
hasNext,
onPrev,
onNext,
}: ActivityTableArgs ) {
function onSortKeyDown(
event: React.KeyboardEvent< HTMLTableCellElement >,
column: string
) {
if ( event.key === 'Enter' || event.key === ' ' ) {
event.preventDefault();
onSort( column );
}
}
function sortIcon( column: string ) {
if ( column === sortBy ) {
return sortDesc ? (
| onSort( column.sort ) : undefined } onKeyDown={ column.sort ? ( e ) => onSortKeyDown( e, column.sort as string ) : undefined } role={ column.sort ? 'button' : undefined } tabIndex={ column.sort ? 0 : undefined } className={ 'whitespace-nowrap border-b border-sky-800 px-3 py-2 text-left text-xs font-semibold uppercase tracking-wider text-sky-200/70 ' + ( column.sort ? 'cursor-pointer' : '' ) } > { column.label } { column.sort && sortIcon( column.sort ) } | ) ) }
|---|
Nothing recorded yet
) }