Skip to content

Commit 48759f4

Browse files
committed
feat: update date formate for the table
Signed-off-by: amitamrutiya <[email protected]>
1 parent 53c819b commit 48759f4

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

src/custom/CatalogDesignTable/CatalogDesignTable.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import _ from 'lodash';
3+
import moment from 'moment';
34
import { MUIDataTableColumn } from 'mui-datatables';
45
import { useCallback, useMemo, useRef } from 'react';
56
import { PublishIcon } from '../../icons';
67
import { CHARCOAL } from '../../theme';
78
import { Pattern } from '../CustomCatalog/CustomCard';
9+
import { CustomTooltip } from '../CustomTooltip';
810
import { ErrorBoundary } from '../ErrorBoundary';
911
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
1012
import PromptComponent from '../Prompt';
@@ -57,13 +59,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
5759
const modalRef = useRef<PromptRef>(null);
5860

5961
const formatDate = useCallback((date: string | Date): string => {
60-
const dateOptions: Intl.DateTimeFormatOptions = {
61-
weekday: 'short',
62-
day: 'numeric',
63-
month: 'long',
64-
year: 'numeric'
65-
};
66-
return new Date(date).toLocaleDateString('en-US', dateOptions);
62+
return moment(date).fromNow();
6763
}, []);
6864

6965
const processedColumns: MUIDataTableColumn[] = useMemo(() => {
@@ -86,11 +82,20 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
8682
if (!value || value === 'NA') return <>NA</>;
8783
if (typeof value === 'object' && 'Valid' in value) {
8884
if (value.Valid && value.Time) {
89-
return <>{formatDate(value.Time)}</>;
85+
const date = new Date(value.Time);
86+
return (
87+
<CustomTooltip title={date.toString()} disableInteractive>
88+
<div>{formatDate(date)}</div>
89+
</CustomTooltip>
90+
);
9091
}
9192
return <>NA</>;
9293
}
93-
return <>{formatDate(value)}</>;
94+
return (
95+
<CustomTooltip title={new Date(value).toString()} disableInteractive>
96+
<div>{formatDate(value)}</div>
97+
</CustomTooltip>
98+
);
9499
};
95100
}
96101
return newCol;

src/custom/ResponsiveDataTable.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import moment from 'moment';
12
import MUIDataTable, { MUIDataTableColumn } from 'mui-datatables';
23
import React, { useCallback } from 'react';
34
import { Checkbox, Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
45
import { ShareIcon } from '../icons';
56
import { EllipsisIcon } from '../icons/Ellipsis';
67
import { styled, useTheme } from './../theme';
8+
import { CustomTooltip } from './CustomTooltip';
79
import { ColView } from './Helpers/ResponsiveColumns/responsive-coulmns.tsx';
810
import { TooltipIcon } from './TooltipIconButton';
911

@@ -157,14 +159,7 @@ const ResponsiveDataTable = ({
157159
...props
158160
}: ResponsiveDataTableProps): JSX.Element => {
159161
const formatDate = (date: Date): string => {
160-
const dateOptions: Intl.DateTimeFormatOptions = {
161-
weekday: 'short',
162-
day: 'numeric',
163-
month: 'long',
164-
year: 'numeric'
165-
};
166-
167-
return new Intl.DateTimeFormat('en-US', dateOptions).format(date);
162+
return moment(date).fromNow();
168163
};
169164

170165
const updatedOptions = {
@@ -227,13 +222,21 @@ const ResponsiveDataTable = ({
227222
const obj = value as { Valid: boolean; Time: string | undefined };
228223
if (obj.Valid && obj.Time) {
229224
const date = new Date(obj.Time);
230-
return <>{formatDate(date)}</>;
225+
return (
226+
<CustomTooltip title={date.toString()} disableInteractive>
227+
<div>{formatDate(date)}</div>
228+
</CustomTooltip>
229+
);
231230
} else {
232231
return <>NA</>;
233232
}
234233
} else if (typeof value === 'string') {
235234
const date = new Date(value);
236-
return <>{formatDate(date)}</>;
235+
return (
236+
<CustomTooltip title={date.toString()} disableInteractive>
237+
<div>{formatDate(date)}</div>
238+
</CustomTooltip>
239+
);
237240
} else {
238241
return <>{value}</>;
239242
}

0 commit comments

Comments
 (0)