Skip to content

Commit b675257

Browse files
authored
Merge pull request #971 from amitamrutiya/master
feat: update date formate for the table
2 parents 34ade11 + d94c265 commit b675257

File tree

13 files changed

+57
-84
lines changed

13 files changed

+57
-84
lines changed

package-lock.json

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"billboard.js": "^3.14.3",
105105
"js-yaml": "^4.1.0",
106106
"lodash": "^4.17.21",
107-
"moment": "^2.30.1",
107+
"moment-timezone": "^0.5.47",
108108
"mui-datatables": "*",
109109
"re-resizable": "^6.10.3",
110110
"react-draggable": "^4.4.6",

src/custom/CatalogDesignTable/CatalogDesignTable.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { MUIDataTableColumn } from 'mui-datatables';
44
import { useCallback, useMemo, useRef } from 'react';
55
import { PublishIcon } from '../../icons';
66
import { CHARCOAL } from '../../theme';
7+
import { FormattedTime } from '../../utils';
78
import { Pattern } from '../CustomCatalog/CustomCard';
89
import { ErrorBoundary } from '../ErrorBoundary';
910
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
@@ -56,16 +57,6 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
5657
}) => {
5758
const modalRef = useRef<PromptRef>(null);
5859

59-
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);
67-
}, []);
68-
6960
const processedColumns: MUIDataTableColumn[] = useMemo(() => {
7061
return columns.map((col) => {
7162
const newCol = { ...col };
@@ -86,16 +77,16 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
8677
if (!value || value === 'NA') return <>NA</>;
8778
if (typeof value === 'object' && 'Valid' in value) {
8879
if (value.Valid && value.Time) {
89-
return <>{formatDate(value.Time)}</>;
80+
return <FormattedTime date={value.Time} />;
9081
}
9182
return <>NA</>;
9283
}
93-
return <>{formatDate(value)}</>;
84+
return <FormattedTime date={value.Time} />;
9485
};
9586
}
9687
return newCol;
9788
});
98-
}, [columns, columnVisibility, formatDate]);
89+
}, [columns, columnVisibility]);
9990

10091
const handleTableChange = useCallback(
10192
(action: string, tableState: any) => {

src/custom/CatalogDetail/UserInfo.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Avatar } from '../../base';
22
import { CLOUD_URL } from '../../constants/constants';
33
import { LockIcon, PublicIcon } from '../../icons';
4+
import { getFormatDate } from '../../utils';
45
import { Pattern } from '../CustomCatalog/CustomCard';
56
import { getVersion } from '../CustomCatalog/Helper';
67
import { VisibilityChipMenu } from '../VisibilityChipMenu';
78
import { VIEW_VISIBILITY } from '../VisibilityChipMenu/VisibilityChipMenu';
8-
import { formatDate } from './helper';
99
import { ContentDetailsPoints, ContentDetailsText, ContentRow, RedirectLink } from './style';
1010
import { UserProfile } from './types';
1111

@@ -56,11 +56,11 @@ const UserInfo: React.FC<UserInfoProps> = ({
5656
</ContentRow>
5757
<ContentRow>
5858
<ContentDetailsPoints>CREATED AT</ContentDetailsPoints>
59-
<ContentDetailsText>{formatDate(details?.created_at)}</ContentDetailsText>
59+
<ContentDetailsText>{getFormatDate(details?.created_at.toString())}</ContentDetailsText>
6060
</ContentRow>
6161
<ContentRow>
6262
<ContentDetailsPoints>UPDATED AT</ContentDetailsPoints>
63-
<ContentDetailsText>{formatDate(details?.updated_at)}</ContentDetailsText>
63+
<ContentDetailsText>{getFormatDate(details?.updated_at.toString())}</ContentDetailsText>
6464
</ContentRow>
6565
{showVersion && (
6666
<ContentRow>

src/custom/CatalogDetail/helper.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,6 @@ export const formatToTitleCase = (value: string): string => {
5656
return '';
5757
};
5858

59-
export const formatDate = (date: Date) => {
60-
const options = { year: 'numeric', month: 'short', day: 'numeric' };
61-
const formattedDate = new Date(date).toLocaleDateString('en-US', options);
62-
return formattedDate;
63-
};
64-
6559
interface HeadingProps {
6660
type: string;
6761
userProfile?: {

src/custom/DashboardWidgets/RecentDesignWidget.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
import { iconMedium } from '../../constants/iconsSizes';
1818
import { AddIcon, OpenInNewIcon } from '../../icons';
1919
import { useTheme } from '../../theme';
20+
import { getFullFormattedTime, getRelativeTime } from '../../utils';
2021
import { CustomTooltip } from '../CustomTooltip';
2122
import { Modal, ModalBody } from '../Modal';
22-
import { formatDateTime, formatRelativeDate } from './utils';
2323

2424
interface Resource {
2525
link: string;
@@ -297,15 +297,15 @@ interface RelativeFormattedDateProps {
297297

298298
const RelativeFormattedDate: React.FC<RelativeFormattedDateProps> = ({ date, style }) => {
299299
return (
300-
<Tooltip title={formatDateTime(date)} placement="top">
300+
<Tooltip title={getFullFormattedTime(date)} placement="top">
301301
<div>
302302
<Typography
303303
style={{
304304
fontStyle: 'italic',
305305
...style
306306
}}
307307
>
308-
{formatRelativeDate(date)}
308+
{getRelativeTime(date)}
309309
</Typography>
310310
</div>
311311
</Tooltip>

src/custom/DashboardWidgets/WorkspaceActivityWidget.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SelectChangeEvent } from '@mui/material';
22
import { styled } from '@mui/material/styles';
3-
import moment from 'moment';
3+
import moment from 'moment-timezone';
44
import {
55
Box,
66
Button,

src/custom/DashboardWidgets/utils.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/custom/ResourceDetailFormatters/useResourceCleanData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import _ from 'lodash';
3-
import moment from 'moment';
3+
import moment from 'moment-timezone';
44
import { GetResourceCleanDataProps, NumberState } from './types';
55

66
export const useResourceCleanData = () => {

src/custom/ResponsiveDataTable.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import React, { useCallback } from 'react';
33
import { Checkbox, Collapse, ListItemIcon, ListItemText, Menu, MenuItem } from '../base';
44
import { ShareIcon } from '../icons';
55
import { EllipsisIcon } from '../icons/Ellipsis';
6+
import { FormattedTime } from '../utils';
67
import { styled, useTheme } from './../theme';
78
import { ColView } from './Helpers/ResponsiveColumns/responsive-coulmns.tsx';
89
import { TooltipIcon } from './TooltipIconButton';
@@ -156,17 +157,6 @@ const ResponsiveDataTable = ({
156157
rowsPerPageOptions = [10, 25, 50, 100],
157158
...props
158159
}: ResponsiveDataTableProps): JSX.Element => {
159-
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);
168-
};
169-
170160
const updatedOptions = {
171161
...options,
172162
print: false,
@@ -226,14 +216,12 @@ const ResponsiveDataTable = ({
226216
} else if (typeof value === 'object' && 'Valid' in value) {
227217
const obj = value as { Valid: boolean; Time: string | undefined };
228218
if (obj.Valid && obj.Time) {
229-
const date = new Date(obj.Time);
230-
return <>{formatDate(date)}</>;
219+
return <FormattedTime date={obj.Time} />;
231220
} else {
232221
return <>NA</>;
233222
}
234223
} else if (typeof value === 'string') {
235-
const date = new Date(value);
236-
return <>{formatDate(date)}</>;
224+
return <FormattedTime date={value} />;
237225
} else {
238226
return <>{value}</>;
239227
}

0 commit comments

Comments
 (0)