Skip to content

Commit 5a018bd

Browse files
mohas22mohas22
authored andcommitted
updated simpe table manual
1 parent babf570 commit 5a018bd

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

packages/react-sdk-components/src/components/template/SimpleTable/SimpleTableManual/SimpleTableManual.tsx

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable no-nested-ternary */
21
import React, { PropsWithChildren, useEffect, useLayoutEffect, useRef, useState } from 'react';
32
import Table from '@material-ui/core/Table';
43
import TableBody from '@material-ui/core/TableBody';
@@ -176,14 +175,9 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
176175
});
177176

178177
useEffect(() => {
179-
if ((editableMode || readOnlyMode) && !allowEditingInModal) {
180-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
181-
buildElementsForTable();
182-
}
183-
}, [referenceList.length]);
184-
185-
useEffect(() => {
186-
if (allowEditingInModal) {
178+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
179+
buildElementsForTable();
180+
if (readOnlyMode || allowEditingInModal) {
187181
// eslint-disable-next-line @typescript-eslint/no-use-before-define
188182
generateRowsData();
189183
}
@@ -340,7 +334,7 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
340334
const data: any = [];
341335
rawFields.forEach(item => {
342336
// removing label field from config to hide title in the table cell
343-
item = { ...item, config: { ...item.config, label: '', displayMode: readOnlyMode ? 'LABELS_LEFT' : undefined } };
337+
item = { ...item, config: { ...item.config, label: '', displayMode: readOnlyMode || allowEditingInModal ? 'LABELS_LEFT' : undefined } };
344338
const referenceListData = getReferenceList(pConn);
345339
const isDatapage = referenceListData.startsWith('D_');
346340
const pageReferenceValue = isDatapage
@@ -401,7 +395,11 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
401395
return a[1] - b[1];
402396
});
403397

404-
return stabilizedThis.map(el => el[0]);
398+
const newElements = new Array(stabilizedThis.length);
399+
stabilizedThis.forEach((el, index) => {
400+
newElements[index] = elements[el[1]];
401+
});
402+
return newElements;
405403
}
406404

407405
function _menuClick(event, columnId: string, columnType: string, labelValue: string) {
@@ -581,7 +579,7 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
581579
{fieldDefs.map((field: any, index) => {
582580
return (
583581
<TableCell key={`head-${displayedColumns[index]}`} className={classes.tableCell}>
584-
{readOnlyMode ? (
582+
{(readOnlyMode || allowEditingInModal) && field.cellRenderer !== 'DeleteIcon' ? (
585583
<div>
586584
<TableSortLabel
587585
active={orderBy === displayedColumns[index]}
@@ -611,7 +609,8 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
611609
</TableRow>
612610
</TableHead>
613611
<TableBody>
614-
{(editableMode || readOnlyMode) &&
612+
{editableMode &&
613+
!allowEditingInModal &&
615614
elements.map((row: any, index) => {
616615
const theKey = `row-${index}`;
617616
return (
@@ -640,7 +639,7 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
640639
</TableRow>
641640
);
642641
})}
643-
{allowEditingInModal &&
642+
{(readOnlyMode || allowEditingInModal) &&
644643
rowData &&
645644
rowData.length > 0 &&
646645
stableSort(rowData, getComparator(order, orderBy))
@@ -649,33 +648,31 @@ export default function SimpleTableManual(props: PropsWithChildren<SimpleTableMa
649648
return (
650649
// eslint-disable-next-line react/no-array-index-key
651650
<TableRow key={index}>
652-
{displayedColumns.map(colKey => {
651+
{row.map((item, childIndex) => {
652+
const theColKey = displayedColumns[childIndex];
653653
return (
654-
<TableCell key={colKey} className={classes.tableCell}>
655-
{showDeleteButton && colKey === 'DeleteIcon' ? (
656-
<div>
657-
<MoreIcon
658-
id='table-edit-menu-icon'
659-
className={classes.moreIcon}
660-
onClick={event => {
661-
editMenuClick(event, index);
662-
}}
663-
/>
664-
<Menu id='table-edit-menu' anchorEl={editAnchorEl} keepMounted open={Boolean(editAnchorEl)} onClose={_menuClose}>
665-
<MenuItem onClick={() => editRecord()}>Edit</MenuItem>
666-
<MenuItem onClick={() => deleteRecord()}>Delete</MenuItem>
667-
</Menu>
668-
</div>
669-
) : typeof row[colKey] === 'boolean' && !row[colKey] ? (
670-
'False'
671-
) : typeof row[colKey] === 'boolean' && row[colKey] ? (
672-
'True'
673-
) : (
674-
row[colKey] || '---'
675-
)}
654+
<TableCell key={theColKey} className={classes.tableCell}>
655+
{item}
676656
</TableCell>
677657
);
678658
})}
659+
{showDeleteButton && (
660+
<TableCell key='DeleteIcon' className={classes.tableCell}>
661+
<div>
662+
<MoreIcon
663+
id='table-edit-menu-icon'
664+
className={classes.moreIcon}
665+
onClick={event => {
666+
editMenuClick(event, index);
667+
}}
668+
/>
669+
<Menu id='table-edit-menu' anchorEl={editAnchorEl} keepMounted open={Boolean(editAnchorEl)} onClose={_menuClose}>
670+
<MenuItem onClick={() => editRecord()}>Edit</MenuItem>
671+
<MenuItem onClick={() => deleteRecord()}>Delete</MenuItem>
672+
</Menu>
673+
</div>
674+
</TableCell>
675+
)}
679676
</TableRow>
680677
);
681678
})}

0 commit comments

Comments
 (0)