Skip to content

Commit e887f28

Browse files
authored
Merge pull request #1030 from amitamrutiya/catalog-date
remove duplicate date handle logic in catalog table
2 parents 5632011 + 5124494 commit e887f28

File tree

1 file changed

+5
-39
lines changed

1 file changed

+5
-39
lines changed

src/custom/CatalogDesignTable/CatalogDesignTable.tsx

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import _ from 'lodash';
33
import { MUIDataTableColumn } from 'mui-datatables';
4-
import { useCallback, useMemo, useRef } from 'react';
4+
import { useCallback, useMemo, useRef, useState } from 'react';
55
import { PublishIcon } from '../../icons';
66
import { CHARCOAL } from '../../theme';
7-
import { FormattedTime } from '../../utils';
87
import { Pattern } from '../CustomCatalog/CustomCard';
98
import { ErrorBoundary } from '../ErrorBoundary';
109
import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
@@ -56,37 +55,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
5655
handleBulkpatternsDataUnpublishModal
5756
}) => {
5857
const modalRef = useRef<PromptRef>(null);
59-
60-
const processedColumns: MUIDataTableColumn[] = useMemo(() => {
61-
return columns.map((col) => {
62-
const newCol = { ...col };
63-
if (!newCol.options) newCol.options = {};
64-
newCol.options.display = columnVisibility[col.name];
65-
if (
66-
[
67-
'updated_at',
68-
'created_at',
69-
'deleted_at',
70-
'last_login_time',
71-
'joined_at',
72-
'last_run',
73-
'next_run'
74-
].includes(col.name)
75-
) {
76-
newCol.options.customBodyRender = (value: any) => {
77-
if (!value || value === 'NA') return <>NA</>;
78-
if (typeof value === 'object' && 'Valid' in value) {
79-
if (value.Valid && value.Time) {
80-
return <FormattedTime date={value.Time} />;
81-
}
82-
return <>NA</>;
83-
}
84-
return <FormattedTime date={value.Time} />;
85-
};
86-
}
87-
return newCol;
88-
});
89-
}, [columns, columnVisibility]);
58+
const [tableCols, updateCols] = useState(columns);
9059

9160
const handleTableChange = useCallback(
9261
(action: string, tableState: any) => {
@@ -176,22 +145,19 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
176145
]
177146
);
178147

179-
if (!processedColumns.length) {
180-
return null;
181-
}
182-
183148
return (
184149
<ErrorBoundary>
185150
<PromptComponent ref={modalRef} />
186151
<ResponsiveDataTable
187-
columns={processedColumns}
152+
columns={columns}
188153
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
189154
//@ts-ignore
190155
data={patterns || []}
191156
rowsPerPageOptions={rowsPerPageOptions}
192157
options={options}
193158
colViews={colViews}
194-
tableCols={processedColumns}
159+
tableCols={tableCols}
160+
updateCols={updateCols}
195161
columnVisibility={columnVisibility}
196162
/>
197163
</ErrorBoundary>

0 commit comments

Comments
 (0)