Skip to content

Commit

Permalink
fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Amy Chen authored and Amy Chen committed Mar 7, 2024
1 parent 2993375 commit 66027a6
Showing 1 changed file with 41 additions and 14 deletions.
55 changes: 41 additions & 14 deletions src/components/report/CopyPaste.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from "react";
import {
allowCopyClipboardItem,
// writeHTMLToClipboard,
// writeHTMLToClipboard,
writeTextToClipboard,
} from "../../helpers/utility";

Expand Down Expand Up @@ -116,34 +116,61 @@ export default class CopyPaste extends Component {
imageElement.replaceWith(span);
});
const tableElement = scoreSummaryNode.querySelector("table");

if (tableElement) {
copyText += "\r\n";
const rows = tableElement.querySelectorAll("tr");
const arrLengths = [];
rows.forEach((r) => {
const rCells = r.querySelectorAll("th, td");
rCells.forEach((cell, cIndex) => {
if (cIndex === 0) {
arrLengths.push(cell.textContent?.length ?? 0);
}
});
});
console.log("arr Lengths ", arrLengths);
const maxLength = Math.max(...arrLengths);

const headerCells = tableElement.querySelectorAll("th");
headerCells.forEach((cell, index) => {
const delimiter = " | ";
copyText +=
cell.innerText + (index > 0 && index < headerCells.length-1 ? delimiter : "");
const delimiter =
cell.textContent?.length >= maxLength
? " | "
: [...Array(maxLength - cell.textContent?.length).keys()]
.map((item) => " ")
.join("") + " | ";
copyText +=
cell.innerText +
(index < headerCells.length - 1 ? delimiter : "");
});
copyText += "\r\n";
const rows = tableElement.querySelectorAll("tr");

copyText += "\r\n" + [...Array(copyText.length)].map(() => "-").join("") + "\r\n";
// copyText += ([...headerCells].map(h => h.textContent.length)).map(c => Array(c).keys().map(() => "--").join("")).join("");
rows.forEach((row, rindex) => {
const cells = row.querySelectorAll("td");
// const arrCells = [...cells].map(cell=> cell.innerText?.length??0);
// console.log("arrCells ", arrCells)
// const maxLength = Math.max(...arrCells);
// console.log("max length ", maxLength);
// const arrCells = [...cells].map(cell=> cell.innerText?.length??0);
// console.log("arrCells ", arrCells)
// const maxLength = Math.max(...arrCells);
// console.log("max length ", maxLength);
cells.forEach((cell, index) => {
//const delimiter = cell.innerText?.length >= maxLength ? " | " : [...Array(maxLength - cell.innerText?.length).keys()].map(item => " ").join("") + "| ";
const delimiter = " | ";
const delimiter =
cell.innerText?.length >= maxLength
? " | "
: [...Array(maxLength - cell.innerText?.length).keys()]
.map((item) => " ")
.join("") + " | ";
//const delimiter = " | ";
copyText +=
cell.innerText + (index < cells.length-1 ? delimiter : "");
cell.innerText + (index < cells.length - 1 ? delimiter : "");
});
if (rindex !== 0) copyText += "\r\n";
});
}
writeTextToClipboard(copyText).then((text) => {
this.setState(
{
contentHTML: this.getDefaultContent() + "\r\n\r\n" + copyText,
contentHTML: this.getDefaultContent() + "\r\n" + copyText,
},
() => {
this.contentAreaRef.current.value = this.state.contentHTML;
Expand Down

0 comments on commit 66027a6

Please sign in to comment.