|
1 | 1 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
2 | 2 | import _ from 'lodash';
|
3 | 3 | import { MUIDataTableColumn } from 'mui-datatables';
|
4 |
| -import { useCallback, useMemo, useRef } from 'react'; |
| 4 | +import { useCallback, useMemo, useRef, useState } from 'react'; |
5 | 5 | import { PublishIcon } from '../../icons';
|
6 | 6 | import { CHARCOAL } from '../../theme';
|
7 |
| -import { FormattedTime } from '../../utils'; |
8 | 7 | import { Pattern } from '../CustomCatalog/CustomCard';
|
9 | 8 | import { ErrorBoundary } from '../ErrorBoundary';
|
10 | 9 | import { ColView } from '../Helpers/ResponsiveColumns/responsive-coulmns.tsx/responsive-column';
|
@@ -56,37 +55,7 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
|
56 | 55 | handleBulkpatternsDataUnpublishModal
|
57 | 56 | }) => {
|
58 | 57 | 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); |
90 | 59 |
|
91 | 60 | const handleTableChange = useCallback(
|
92 | 61 | (action: string, tableState: any) => {
|
@@ -176,22 +145,19 @@ export const CatalogDesignsTable: React.FC<CatalogDesignsTableProps> = ({
|
176 | 145 | ]
|
177 | 146 | );
|
178 | 147 |
|
179 |
| - if (!processedColumns.length) { |
180 |
| - return null; |
181 |
| - } |
182 |
| - |
183 | 148 | return (
|
184 | 149 | <ErrorBoundary>
|
185 | 150 | <PromptComponent ref={modalRef} />
|
186 | 151 | <ResponsiveDataTable
|
187 |
| - columns={processedColumns} |
| 152 | + columns={columns} |
188 | 153 | // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
189 | 154 | //@ts-ignore
|
190 | 155 | data={patterns || []}
|
191 | 156 | rowsPerPageOptions={rowsPerPageOptions}
|
192 | 157 | options={options}
|
193 | 158 | colViews={colViews}
|
194 |
| - tableCols={processedColumns} |
| 159 | + tableCols={tableCols} |
| 160 | + updateCols={updateCols} |
195 | 161 | columnVisibility={columnVisibility}
|
196 | 162 | />
|
197 | 163 | </ErrorBoundary>
|
|
0 commit comments