Skip to content

Commit

Permalink
feat: show relative date in tree listing
Browse files Browse the repository at this point in the history
Close #939
  • Loading branch information
Francisco2002 committed Feb 19, 2025
1 parent 8c41b7c commit e8fddcf
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dashboard/src/components/TreeListingPage/TreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { FormattedMessage } from 'react-intl';
import type { LinkProps } from '@tanstack/react-router';
import { Link, useNavigate, useSearch } from '@tanstack/react-router';

import { differenceInDays } from 'date-fns';

import { TooltipDateTime } from '@/components/TooltipDateTime';

import type { TreeTableBody } from '@/types/tree/Tree';
Expand Down Expand Up @@ -67,6 +69,16 @@ import { InputTime } from './InputTime';

const MemoizedInputTime = memo(InputTime);

const RELATIVE_DAYS_EDGE = 3;

function showRelative(date: string): boolean {
const treeDate = new Date(date);
const currentDate = new Date();
const days = differenceInDays(currentDate, treeDate);

return days <= RELATIVE_DAYS_EDGE;
}

const getLinkProps = (
row: Row<TreeTableBody>,
origin: TOrigins,
Expand Down Expand Up @@ -186,7 +198,11 @@ const getColumns = (origin: TOrigins): ColumnDef<TreeTableBody>[] => {
<TableHeader column={column} intlKey="global.date" />
),
cell: ({ row }): JSX.Element => (
<TooltipDateTime dateTime={row.getValue('date')} lineBreak={true} />
<TooltipDateTime
dateTime={row.getValue('date')}
lineBreak={true}
showRelative={showRelative(row.getValue('date'))}
/>
),
meta: {
tabTarget: 'global.builds',
Expand Down

0 comments on commit e8fddcf

Please sign in to comment.