Skip to content

Commit

Permalink
Fix type checking issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tomodwyer committed Nov 3, 2023
1 parent a103029 commit 13a6069
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion assets/src/scripts/_output-click.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default async function outputClick({ outputName, metadata }) {

// Clear existing content
const filePreviewContainer = document.getElementById("filePreviewContainer");
filePreviewContainer.innerHTML = "";
if (filePreviewContainer) filePreviewContainer.innerHTML = "";

/** @type {HTMLTemplateElement|null} */
const filePreviewTemplate = document.querySelector(
Expand Down
37 changes: 24 additions & 13 deletions assets/src/scripts/_table-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html } from "./_utils";

/**
* @param {Object} params
* @param {{[x: string]: string[];}} params.cellIndex
* @param {Object.<string, string[]>} params.cellIndex
* @param {string} params.tableId
*/
function highlightFailingCells({ cellIndex, tableId }) {
Expand Down Expand Up @@ -33,21 +33,30 @@ function highlightFailingCells({ cellIndex, tableId }) {

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

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

/** @type {Node} */
const cellTooltip = tooltipEl.cloneNode(true);

cellTooltip.classList.add("flex", "-bottom-2");
cellTooltip.querySelector(`[data-sacro-el="tooltip-content"]`).innerHTML =
tooltipContent;
tableCell.appendChild(cellTooltip);

const tooltip = tableCell.querySelector("span:first-child");
if (tooltip) {
tooltip.classList.add("flex", "-bottom-2");

const tooltipContentSpan = tooltip?.querySelector(
`[data-sacro-el="tooltip-content"]`
);
if (tooltipContentSpan) {
tooltipContentSpan.innerHTML = tooltipContent;
}
}
});
}

Expand Down Expand Up @@ -88,12 +97,14 @@ function tableBuilder({ csvString, el, outcome, fileIndex }) {
</table>
`;

el.innerHTML = table; // eslint-disable-line no-param-reassign
if (typeof table === "string") {
el.innerHTML = table; // eslint-disable-line no-param-reassign

highlightFailingCells({
cellIndex: outcome,
tableId: `csvTable${fileIndex}`,
});
highlightFailingCells({
cellIndex: outcome,
tableId: `csvTable${fileIndex}`,
});
}
}

export default tableBuilder;

0 comments on commit 13a6069

Please sign in to comment.