1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-08-13 13:48:59 +02:00

chore: timeagocell default fallback (#10475)

https://linear.app/unleash/issue/2-3759/set-timeagocell-default-fallback-to-never

Sets the default `emptyText` fallback to 'Never'. This should help with
consistency and DRYness.

Also noticed some of our TimeAgoCell `title` properties were redundant,
so I removed them for simplicity.

Examples:

<img width="1268" height="1063" alt="image"
src="https://github.com/user-attachments/assets/b7a8118b-bd73-45bc-8823-fa9f211f9ea9"
/>

<img width="793" height="366" alt="image"
src="https://github.com/user-attachments/assets/f494e1de-2bbb-46c8-ad87-adc7a1d4ea56"
/>
This commit is contained in:
Nuno Góis 2025-08-07 18:05:28 +01:00 committed by GitHub
parent 057a906892
commit 57424312b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 39 additions and 71 deletions

View File

@ -117,14 +117,8 @@ export const Group: VFC = () => {
}, },
{ {
Header: 'Last login', Header: 'Last login',
accessor: (row: IGroupUser) => row.seenAt || '', accessor: 'seenAt',
Cell: ({ row: { original: user } }: any) => ( Cell: TimeAgoCell,
<TimeAgoCell
value={user.seenAt}
emptyText='Never'
title={(date) => `Last login: ${date}`}
/>
),
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -47,14 +47,8 @@ export const RoleDeleteDialogUsers = ({
{ {
id: 'last-login', id: 'last-login',
Header: 'Last login', Header: 'Last login',
accessor: (row: any) => row.seenAt || '', accessor: 'seenAt',
Cell: ({ row: { original: user } }: any) => ( Cell: TimeAgoCell,
<TimeAgoCell
value={user.seenAt}
emptyText='Never'
title={(date) => `Last login: ${date}`}
/>
),
maxWidth: 150, maxWidth: 150,
}, },
] as Column<IUser>[], ] as Column<IUser>[],

View File

@ -147,27 +147,15 @@ export const InactiveUsersList = () => {
{ {
id: 'last-login', id: 'last-login',
Header: 'Last login', Header: 'Last login',
accessor: (row: any) => row.seenAt || '', accessor: 'seenAt',
Cell: ({ row: { original: user } }: any) => ( Cell: TimeAgoCell,
<TimeAgoCell
value={user.seenAt}
emptyText='Never'
title={(date) => `Last login: ${date}`}
/>
),
maxWidth: 150, maxWidth: 150,
}, },
{ {
id: 'pat-last-login', id: 'pat-last-login',
Header: 'PAT last used', Header: 'PAT last used',
accessor: (row: any) => row.patSeenAt || '', accessor: 'patSeenAt',
Cell: ({ row: { original: user } }: any) => ( Cell: TimeAgoCell,
<TimeAgoCell
value={user.patSeenAt}
emptyText='Never'
title={(date) => `Last used: ${date}`}
/>
),
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -186,14 +186,8 @@ const UsersList = () => {
{ {
id: 'last-login', id: 'last-login',
Header: 'Last login', Header: 'Last login',
accessor: (row: any) => row.seenAt || '', accessor: 'seenAt',
Cell: ({ row: { original: user } }: any) => ( Cell: TimeAgoCell,
<TimeAgoCell
value={user.seenAt}
emptyText='Never'
title={(date) => `Last login: ${date}`}
/>
),
maxWidth: 150, maxWidth: 150,
}, },
{ {

View File

@ -4,9 +4,11 @@ import type { FC } from 'react';
import { formatDateYMD } from 'utils/formatDate'; import { formatDateYMD } from 'utils/formatDate';
import { TextCell } from '../TextCell/TextCell.tsx'; import { TextCell } from '../TextCell/TextCell.tsx';
import { TimeAgo } from 'component/common/TimeAgo/TimeAgo'; import { TimeAgo } from 'component/common/TimeAgo/TimeAgo';
import type { ColumnInstance } from 'react-table';
interface ITimeAgoCellProps { interface ITimeAgoCellProps {
value?: string | number | Date; value?: string | number | Date | null;
column?: ColumnInstance;
live?: boolean; live?: boolean;
emptyText?: string; emptyText?: string;
title?: (date: string) => string; title?: (date: string) => string;
@ -15,9 +17,10 @@ interface ITimeAgoCellProps {
export const TimeAgoCell: FC<ITimeAgoCellProps> = ({ export const TimeAgoCell: FC<ITimeAgoCellProps> = ({
value, value,
column,
live = false, live = false,
emptyText, emptyText = 'Never',
title, title = (date) => (column ? `${column.Header}: ${date}` : date),
dateFormat = formatDateYMD, dateFormat = formatDateYMD,
}) => { }) => {
const { locationSettings } = useLocationSettings(); const { locationSettings } = useLocationSettings();
@ -28,7 +31,7 @@ export const TimeAgoCell: FC<ITimeAgoCellProps> = ({
return ( return (
<TextCell> <TextCell>
<Tooltip title={title?.(date) ?? date} arrow> <Tooltip title={title(date)} arrow>
<Typography <Typography
noWrap noWrap
sx={{ sx={{

View File

@ -75,8 +75,12 @@ export const LoginHistoryTable = () => {
{ {
Header: 'Created', Header: 'Created',
accessor: 'created_at', accessor: 'created_at',
Cell: ({ value }: { value: Date }) => ( Cell: ({ value, column }) => (
<TimeAgoCell value={value} dateFormat={formatDateYMDHMS} /> <TimeAgoCell
value={value}
column={column}
dateFormat={formatDateYMDHMS}
/>
), ),
maxWidth: 150, maxWidth: 150,
}, },

View File

@ -179,13 +179,8 @@ export const ProjectAccessTable: VFC = () => {
{ {
id: 'added', id: 'added',
Header: 'Added', Header: 'Added',
accessor: (row: IProjectAccess) => { accessor: 'entity.addedAt',
const userRow = row.entity as IUser | IGroup; Cell: TimeAgoCell,
return userRow.addedAt || '';
},
Cell: ({ value }: { value: Date }) => (
<TimeAgoCell value={value} emptyText='Never' />
),
maxWidth: 130, maxWidth: 130,
}, },
{ {
@ -202,9 +197,7 @@ export const ProjectAccessTable: VFC = () => {
.sort() .sort()
.reverse()[0]; .reverse()[0];
}, },
Cell: ({ value }: { value: Date }) => ( Cell: TimeAgoCell,
<TimeAgoCell value={value} emptyText='Never' />
),
maxWidth: 130, maxWidth: 130,
}, },
{ {

View File

@ -88,14 +88,8 @@ const columns = [
{ {
id: 'lastLogin', id: 'lastLogin',
Header: 'Last login', Header: 'Last login',
accessor: (row: IGroupUser) => row.seenAt || '', accessor: 'seenAt',
Cell: ({ row: { original: user } }: any) => ( Cell: TimeAgoCell,
<TimeAgoCell
value={user.seenAt}
emptyText='Never'
title={(date) => `Last login: ${date}`}
/>
),
maxWidth: 150, maxWidth: 150,
}, },
// Always hidden -- for search // Always hidden -- for search

View File

@ -55,12 +55,12 @@ export const ProjectsListTable = ({ projects }: ProjectsListTableProps) => {
}, },
{ {
Header: 'Last updated', Header: 'Last updated',
id: 'lastUpdatedAt', accessor: (row: ProjectSchema) =>
Cell: ({ row }: { row: { original: ProjectSchema } }) => ( row.lastUpdatedAt || row.createdAt,
Cell: ({ value, column }) => (
<TimeAgoCell <TimeAgoCell
value={ value={value}
row.original.lastUpdatedAt || row.original.createdAt column={column}
}
dateFormat={formatDateYMDHMS} dateFormat={formatDateYMDHMS}
/> />
), ),

View File

@ -62,8 +62,12 @@ export const UnknownFlagsTable = () => {
{ {
Header: 'Last seen', Header: 'Last seen',
accessor: 'seenAt', accessor: 'seenAt',
Cell: ({ value }: { value: Date }) => ( Cell: ({ value, column }) => (
<TimeAgoCell value={value} dateFormat={formatDateYMDHMS} /> <TimeAgoCell
value={value}
column={column}
dateFormat={formatDateYMDHMS}
/>
), ),
}, },
{ {