mirror of
https://github.com/Unleash/unleash.git
synced 2025-04-19 01:17:18 +02: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:
parent
ff58e2aeaf
commit
aa961823fe
@ -1,7 +1,7 @@
|
|||||||
import { Tooltip, Typography } from '@mui/material';
|
import { Tooltip, Typography } from '@mui/material';
|
||||||
import { useLocationSettings } from 'hooks/useLocationSettings';
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
||||||
import { VFC } from 'react';
|
import { VFC } from 'react';
|
||||||
import { formatDateYMD, formatDateYMDHMS } from 'utils/formatDate';
|
import { formatDateYMD } from 'utils/formatDate';
|
||||||
import { TextCell } from '../TextCell/TextCell';
|
import { TextCell } from '../TextCell/TextCell';
|
||||||
import TimeAgo from 'react-timeago';
|
import TimeAgo from 'react-timeago';
|
||||||
|
|
||||||
@ -10,7 +10,7 @@ interface ITimeAgoCellProps {
|
|||||||
live?: boolean;
|
live?: boolean;
|
||||||
emptyText?: string;
|
emptyText?: string;
|
||||||
title?: (date: string) => string;
|
title?: (date: string) => string;
|
||||||
timestamp?: boolean;
|
dateFormat?: (value: string | number | Date, locale: string) => string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TimeAgoCell: VFC<ITimeAgoCellProps> = ({
|
export const TimeAgoCell: VFC<ITimeAgoCellProps> = ({
|
||||||
@ -18,15 +18,13 @@ export const TimeAgoCell: VFC<ITimeAgoCellProps> = ({
|
|||||||
live = false,
|
live = false,
|
||||||
emptyText,
|
emptyText,
|
||||||
title,
|
title,
|
||||||
timestamp,
|
dateFormat = formatDateYMD,
|
||||||
}) => {
|
}) => {
|
||||||
const { locationSettings } = useLocationSettings();
|
const { locationSettings } = useLocationSettings();
|
||||||
|
|
||||||
if (!value) return <TextCell>{emptyText}</TextCell>;
|
if (!value) return <TextCell>{emptyText}</TextCell>;
|
||||||
|
|
||||||
const date = timestamp
|
const date = dateFormat(value, locationSettings.locale);
|
||||||
? formatDateYMDHMS(value, locationSettings.locale)
|
|
||||||
: formatDateYMD(value, locationSettings.locale);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TextCell>
|
<TextCell>
|
||||||
|
@ -22,6 +22,7 @@ import { ISignOnEvent } from 'interfaces/signOnEvent';
|
|||||||
import { SignOnLogActionsCell } from './SignOnLogActionsCell/SignOnLogActionsCell';
|
import { SignOnLogActionsCell } from './SignOnLogActionsCell/SignOnLogActionsCell';
|
||||||
import { SignOnLogDeleteDialog } from './SignOnLogDeleteDialog/SignOnLogDeleteDialog';
|
import { SignOnLogDeleteDialog } from './SignOnLogDeleteDialog/SignOnLogDeleteDialog';
|
||||||
import { useSignOnLogApi } from 'hooks/api/actions/useSignOnLogApi/useSignOnLogApi';
|
import { useSignOnLogApi } from 'hooks/api/actions/useSignOnLogApi/useSignOnLogApi';
|
||||||
|
import { formatDateYMDHMS } from 'utils/formatDate';
|
||||||
|
|
||||||
export const SignOnLogTable = () => {
|
export const SignOnLogTable = () => {
|
||||||
const { setToastData, setToastApiError } = useToast();
|
const { setToastData, setToastApiError } = useToast();
|
||||||
@ -56,7 +57,7 @@ export const SignOnLogTable = () => {
|
|||||||
Header: 'Created',
|
Header: 'Created',
|
||||||
accessor: 'created_at',
|
accessor: 'created_at',
|
||||||
Cell: ({ value }: { value: Date }) => (
|
Cell: ({ value }: { value: Date }) => (
|
||||||
<TimeAgoCell value={value} timestamp />
|
<TimeAgoCell value={value} dateFormat={formatDateYMDHMS} />
|
||||||
),
|
),
|
||||||
sortType: 'date',
|
sortType: 'date',
|
||||||
maxWidth: 150,
|
maxWidth: 150,
|
||||||
|
Loading…
Reference in New Issue
Block a user