1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

feat: dateFormat in TimeAgoCell (#3202)

Slight refactor to `TimeAgoCell` that allows passing in a date format
function.
Suggested by @gastonfournier in
https://github.com/Unleash/unleash/pull/3193#pullrequestreview-1315064957
This commit is contained in:
Nuno Góis 2023-02-27 12:00:03 +00:00 committed by GitHub
parent ff58e2aeaf
commit aa961823fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -1,7 +1,7 @@
import { Tooltip, Typography } from '@mui/material';
import { useLocationSettings } from 'hooks/useLocationSettings';
import { VFC } from 'react';
import { formatDateYMD, formatDateYMDHMS } from 'utils/formatDate';
import { formatDateYMD } from 'utils/formatDate';
import { TextCell } from '../TextCell/TextCell';
import TimeAgo from 'react-timeago';
@ -10,7 +10,7 @@ interface ITimeAgoCellProps {
live?: boolean;
emptyText?: string;
title?: (date: string) => string;
timestamp?: boolean;
dateFormat?: (value: string | number | Date, locale: string) => string;
}
export const TimeAgoCell: VFC<ITimeAgoCellProps> = ({
@ -18,15 +18,13 @@ export const TimeAgoCell: VFC<ITimeAgoCellProps> = ({
live = false,
emptyText,
title,
timestamp,
dateFormat = formatDateYMD,
}) => {
const { locationSettings } = useLocationSettings();
if (!value) return <TextCell>{emptyText}</TextCell>;
const date = timestamp
? formatDateYMDHMS(value, locationSettings.locale)
: formatDateYMD(value, locationSettings.locale);
const date = dateFormat(value, locationSettings.locale);
return (
<TextCell>

View File

@ -22,6 +22,7 @@ import { ISignOnEvent } from 'interfaces/signOnEvent';
import { SignOnLogActionsCell } from './SignOnLogActionsCell/SignOnLogActionsCell';
import { SignOnLogDeleteDialog } from './SignOnLogDeleteDialog/SignOnLogDeleteDialog';
import { useSignOnLogApi } from 'hooks/api/actions/useSignOnLogApi/useSignOnLogApi';
import { formatDateYMDHMS } from 'utils/formatDate';
export const SignOnLogTable = () => {
const { setToastData, setToastApiError } = useToast();
@ -56,7 +57,7 @@ export const SignOnLogTable = () => {
Header: 'Created',
accessor: 'created_at',
Cell: ({ value }: { value: Date }) => (
<TimeAgoCell value={value} timestamp />
<TimeAgoCell value={value} dateFormat={formatDateYMDHMS} />
),
sortType: 'date',
maxWidth: 150,