/* eslint-disable no-unused-vars */ import * as React from "react"; import PropTypes from "prop-types"; import TableCell from "@mui/material/TableCell"; import CircularProgress from "@mui/material/CircularProgress"; import { withTheme } from "@mui/styles"; import { MTable } from ".."; /* eslint-enable no-unused-vars */ class MTableEditCell extends React.Component { constructor(props) { super(props); this.state = { isLoading: false, value: this.props.rowData[this.props.columnDef.field], }; } getStyle = () => { let cellStyle = { boxShadow: "2px 0px 15px rgba(125,147,178,.25)", color: "inherit", width: this.props.columnDef.tableData.width, boxSizing: "border-box", fontSize: "inherit", fontFamily: "inherit", fontWeight: "inherit", padding: "0 16px", }; if (typeof this.props.columnDef.cellStyle === "function") { cellStyle = { ...cellStyle, ...this.props.columnDef.cellStyle(this.state.value, this.props.rowData), }; } else { cellStyle = { ...cellStyle, ...this.props.columnDef.cellStyle }; } if (typeof this.props.cellEditable.cellStyle === "function") { cellStyle = { ...cellStyle, ...this.props.cellEditable.cellStyle( this.state.value, this.props.rowData, this.props.columnDef ), }; } else { cellStyle = { ...cellStyle, ...this.props.cellEditable.cellStyle }; } return cellStyle; }; handleKeyDown = (e) => { if (e.keyCode === 13) { this.onApprove(); } else if (e.keyCode === 27) { this.onCancel(); } }; onApprove = () => { this.setState({ isLoading: true }, () => { this.props.cellEditable .onCellEditApproved( this.state.value, // newValue this.props.rowData[this.props.columnDef.field], // oldValue this.props.rowData, // rowData with old value this.props.columnDef // columnDef ) .then(() => { this.setState({ isLoading: false }); this.props.onCellEditFinished( this.props.rowData, this.props.columnDef ); }) .catch((error) => { this.setState({ isLoading: false }); }); }); }; onCancel = () => { this.props.onCellEditFinished(this.props.rowData, this.props.columnDef); }; renderActions() { if (this.state.isLoading) { return (