/* eslint-disable no-unused-vars */
import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow";
import IconButton from "@mui/material/IconButton";
import PropTypes from "prop-types";
import * as React from "react";
/* eslint-enable no-unused-vars */
export default class MTableGroupRow extends React.Component {
rotateIconStyle = (isOpen) => ({
transform: isOpen ? "rotate(90deg)" : "none",
});
render() {
let colSpan = this.props.columns.filter((columnDef) => !columnDef.hidden)
.length;
this.props.options.selection && colSpan++;
this.props.detailPanel && colSpan++;
this.props.actions && this.props.actions.length > 0 && colSpan++;
const column = this.props.groups[this.props.level];
let detail;
if (this.props.groupData.isExpanded) {
if (this.props.groups.length > this.props.level + 1) {
// Is there another group
detail = this.props.groupData.groups.map((groupData, index) => (
));
} else {
detail = this.props.groupData.data.map((rowData, index) => {
if (rowData.tableData.editing) {
return (
);
} else {
return (
);
}
});
}
}
const freeCells = [];
for (let i = 0; i < this.props.level; i++) {
freeCells.push();
}
let value = this.props.groupData.value;
if (column.lookup) {
value = column.lookup[value];
}
let title = column.title;
if (typeof this.props.options.groupTitle === "function") {
title = this.props.options.groupTitle(this.props.groupData);
} else if (typeof title !== "string") {
title = React.cloneElement(title);
}
let separator = this.props.options.groupRowSeparator || ": ";
return (
<>
{freeCells}
{
this.props.onGroupExpandChanged(this.props.path);
}}
size="large"
>
{title}
{separator}
{detail}
>
);
}
}
MTableGroupRow.defaultProps = {
columns: [],
groups: [],
options: {},
level: 0,
};
MTableGroupRow.propTypes = {
actions: PropTypes.array,
columns: PropTypes.arrayOf(PropTypes.object),
components: PropTypes.object,
detailPanel: PropTypes.oneOfType([
PropTypes.func,
PropTypes.arrayOf(PropTypes.object),
]),
getFieldValue: PropTypes.func,
groupData: PropTypes.object,
groups: PropTypes.arrayOf(PropTypes.object),
hasAnyEditingRow: PropTypes.bool,
icons: PropTypes.object,
isTreeData: PropTypes.bool.isRequired,
level: PropTypes.number,
localization: PropTypes.object,
onGroupExpandChanged: PropTypes.func,
onRowSelected: PropTypes.func,
onRowClick: PropTypes.func,
onToggleDetailPanel: PropTypes.func.isRequired,
onTreeExpandChanged: PropTypes.func.isRequired,
onEditingCanceled: PropTypes.func,
onEditingApproved: PropTypes.func,
options: PropTypes.object,
path: PropTypes.arrayOf(PropTypes.number),
scrollWidth: PropTypes.number.isRequired,
cellEditable: PropTypes.object,
onCellEditStarted: PropTypes.func,
onCellEditFinished: PropTypes.func,
onBulkEditRowChanged: PropTypes.func,
};