diff --git a/web/assets/js/components/accordions/result.js b/web/assets/js/components/accordions/result.js index 75bad3b..ac34c51 100644 --- a/web/assets/js/components/accordions/result.js +++ b/web/assets/js/components/accordions/result.js @@ -14,6 +14,8 @@ * limitations under the License. */ +import { createTooltip } from "../tooltips/index.js"; + const outputResultEl = document.getElementById("editor__output-result"); const holderEl = document.querySelector(".editor__output-holder"); @@ -29,9 +31,9 @@ function createAccordionItemsByResults(name, result, index) { const accordionContent = document.createElement("div"); accordionContent.className = "result-accordion-content"; - accordionContent.innerHTML = createLabel(result, name, index); + accordionContent.appendChild(createLabel(result, name, index)); const costSpan = document.createElement("span"); - costSpan.innerHTML = `Cost: ${result.cost}`; + costSpan.innerHTML = `Cost: ${result?.cost ?? "-"}`; accordionContent.appendChild(costSpan); const expansibleContent = document.createElement("div"); @@ -44,7 +46,9 @@ function createAccordionItemsByResults(name, result, index) { outputResultEl.appendChild(listItem); } function getResultValue(result) { - if ("value" in result) { + if (result.isError) { + return `${result.error}`; + } else if ("value" in result) { if (typeof result.value === "object") return `
${JSON.stringify(result.value, null, 2)}
`; return String(result.value); @@ -54,25 +58,58 @@ function getResultValue(result) { } function createLabel(item, name, i) { - return `
- -
- ${ - item?.isError - ? `` - : "" - } -
- - Validation compilation failed. - -
-
- - ${name}[${i}] -
`; + const parentContainer = document.createElement("div"); + parentContainer.style = + "display: flex; align-items: center; gap: 0.5rem; position:relative"; + + const arrowIcon = document.createElement("i"); + arrowIcon.className = "ph ph-caret-right ph-bold result-arrow"; + + const span = document.createElement("span"); + span.innerHTML = `${name}[${i}]`; + + parentContainer.appendChild(arrowIcon); + + if (item?.isError) { + const errorIcon = document.createElement("i"); + errorIcon.className = "ph ph-x-circle ph-fill"; + errorIcon.style = + "color: #e01e5a; z-index:999999; display:flex;align-items:center;justify-content: center;"; + + const errorIconWithTooltip = createTooltip({ + contentText: "Validation compilation failed.", + triggerElement: errorIcon, + position: { + left: 50, + top: -10, + }, + }); + parentContainer.appendChild(errorIconWithTooltip); + } + + parentContainer.appendChild(span); + + return parentContainer; + + // return `
+ // + //
+ // ${ + // item?.isError + // ? `` + // : "" + // } + //
+ // + // Validation compilation failed. + // + //
+ //
+ + // ${name}[${i}] + //
`; } function renderAccordions(key, values, index = 0) { diff --git a/web/assets/js/components/tooltips/index.js b/web/assets/js/components/tooltips/index.js index 35d8bbd..5118662 100644 --- a/web/assets/js/components/tooltips/index.js +++ b/web/assets/js/components/tooltips/index.js @@ -31,6 +31,7 @@ tooltipContainers.forEach((container) => { export function createTooltip({ triggerElement, contentText, + position = {}, onMouseOver, onMouseLeave, }) { @@ -41,6 +42,13 @@ export function createTooltip({ const divContent = document.createElement("div"); divContent.className = "tooltip tooltip__content"; + if (!!position) { + const positionKeys = Object.keys(position); + positionKeys.forEach((key) => { + divContent.style[key] = `${position[key]}px`; + }); + } + const spanContent = document.createElement("span"); spanContent.className = "tooltip__content--text"; spanContent.innerHTML = contentText; @@ -50,11 +58,11 @@ export function createTooltip({ container.appendChild(divContent); triggerElement.onmouseover = () => { - onMouseOver(); + onMouseOver?.(); divContent.style.display = "initial"; }; triggerElement.onmouseleave = () => { - onMouseLeave(); + onMouseLeave?.(); divContent.style.display = "none"; };