Skip to content

Commit

Permalink
WIP cell check improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodwyer committed Nov 3, 2023
1 parent 99807b8 commit f16ce45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 0 additions & 2 deletions assets/src/scripts/_file-elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import { highlightJsName } from "./_utils";
export async function createTableElement(el, ext, url, outcome, index) {
const data = await fileLoader(ext, url);

el.classList.add("overflow-x-auto");

tableBuilder({
csvString: data,
el,
Expand Down
21 changes: 15 additions & 6 deletions assets/src/scripts/_table-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ import Papa from "papaparse";
import { html } from "./_utils";

/**
* @param {{ [x: string]: string[]; }} cellIndex
* @param {{[x: string]: string[];}} cellIndex
* @param {string} tableId
*/
function highlightFailingCells(cellIndex, tableId) {
/** @type {HTMLElement|null} */
const tableBody = document.getElementById(tableId);
if (!tableBody) return;

Object.keys(cellIndex).forEach((index) => {
let [x, y] = index.split(",");
x = parseFloat(x) + 1;
y = parseFloat(y) + 2;
const x = parseFloat(index.split(",")[0]) + 1;
const y = parseFloat(index.split(",")[1]) + 2;

/** @type {HTMLTableCellElement|null} */
const tableCell = tableBody.querySelector(
`tr:nth-child(${x}) > td:nth-child(${y})`
);
if (!tableCell) return;

tableCell.classList.add(
"bg-red-50",
Expand All @@ -26,14 +30,18 @@ function highlightFailingCells(cellIndex, tableId) {
"cursor-pointer"
);

/** @type {string} */
const tooltipContent = cellIndex?.[index]
.map((i) => html`<span class="block">${i}</span>`)
.join("");

/** @type {HTMLTemplateElement|null} */
const tooltipTemplateEl = document.getElementById(`tooltip`);
const tooltipEl = tooltipTemplateEl?.content?.firstElementChild;
if (!tooltipEl) return;

const cellTooltip =
tooltipTemplateEl?.content?.firstElementChild.cloneNode(true);
/** @type {HTMLSpanElement} */
const cellTooltip = tooltipEl.cloneNode(true);

cellTooltip.classList.add("flex", "-bottom-2");
cellTooltip.querySelector(`[data-sacro-el="tooltip-content"]`).innerHTML =
Expand All @@ -50,6 +58,7 @@ function highlightFailingCells(cellIndex, tableId) {
* @param {Object.<string, string[]>} params.outcome
* @param {HTMLElement} params.el
* @param {string} params.csvString
* @param {string} params.index
*/
function tableBuilder({ csvString, el, outcome, index }) {
const csvToJson = Papa.parse(csvString).data;
Expand Down

0 comments on commit f16ce45

Please sign in to comment.