Skip to content

Commit

Permalink
Fix runtime-sort for github actions runtime not working with textCont…
Browse files Browse the repository at this point in the history
…ent.
  • Loading branch information
LeeWannacott committed May 9, 2023
1 parent 10e9b8e commit de573af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "table-sort-js",
"version": "1.12.0",
"version": "1.12.1",
"description": "A JavaScript client-side HTML table sorting library with no dependencies required.",
"license": "MIT",
"repository": "LeeWannacott/table-sort-js",
Expand Down
50 changes: 29 additions & 21 deletions public/table-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,30 +177,38 @@ function tableSortJs(testingTableSortJS = false, domDocumentWindow = document) {
}

function sortByRuntime(tableRows, columnData) {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = tr
.querySelectorAll("td")
.item(columnIndex).textContent;
let match = columnOfTd.match(regexMinutesAndSeconds);
let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0];
if (match) {
const regexHours = match[1];
if (regexHours) {
hours = Number(regexHours.replace("h", "")) * 60 * 60;
}
const regexMinutes = match[2];
if (regexMinutes) {
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60;
try {
for (let [i, tr] of tableRows.entries()) {
const regexMinutesAndSeconds = /^(\d+h)?\s?(\d+m)?\s?(\d+s)?$/i;
let columnOfTd = "";
// TODO: github actions runtime didn't like textContent, tests didn't like innerText?
if (testingTableSortJS) {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).textContent;
} else {
columnOfTd = tr.querySelectorAll("td").item(columnIndex).innerText;
}
const regexSeconds = match[3];
if (regexSeconds) {
seconds = Number(regexSeconds.replace("s", ""));
let match = columnOfTd.match(regexMinutesAndSeconds);
let [minutesInSeconds, hours, seconds, timeinSeconds] = [0, 0, 0, 0];
if (match) {
const regexHours = match[1];
if (regexHours) {
hours = Number(regexHours.replace("h", "")) * 60 * 60;
}
const regexMinutes = match[2];
if (regexMinutes) {
minutesInSeconds = Number(regexMinutes.replace("m", "")) * 60;
}
const regexSeconds = match[3];
if (regexSeconds) {
seconds = Number(regexSeconds.replace("s", ""));
}
timeinSeconds = hours + minutesInSeconds + seconds;
}
timeinSeconds = hours + minutesInSeconds + seconds;
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
}
columnData.push(`${timeinSeconds}#${i}`);
columnIndexAndTableRow[columnData[i]] = tr.innerHTML;
} catch (e) {
console.log(e);
}
}

Expand Down

0 comments on commit de573af

Please sign in to comment.