import type { AttachmentTestStepResult } from "@allurereport/core-api"; import { Button, Heading, IconButton, TooltipWrapper, allureIcons } from "@allurereport/web-components"; import { signal } from "@preact/signals"; import type { FunctionalComponent, VNode } from "preact"; import { useEffect } from "preact/hooks"; import Prism from "prismjs"; import type { ClassicTestResult } from "types"; import { Attachment } from "@/components/TestResult/TestResultSteps/attachment"; import { attachmentType, downloadAttachment, openAttachmentInNewTab } from "@/utils/attachments"; import * as styles from "./styles.scss"; export const isModalOpen = signal(false); interface ModalDataProps { data: AttachmentTestStepResult; component: VNode; preview?: boolean; } export const modalData = signal({ data: null, preview: false, component: null, }); const openModal = ({ data, component, preview }: ModalDataProps) => { modalData.value = { data, component, preview, }; isModalOpen.value = true; }; const closeModal = () => { isModalOpen.value = false; }; const ModalThumb: FunctionalComponent<{ item: AttachmentTestStepResult }> = ({ item, children }) => { const isActiveThumb = modalData.value.data?.link?.id === item.link?.id; const showAttach = (showedItem: AttachmentTestStepResult) => { openModal({ data: showedItem, component: , }); }; return (
showAttach(item)}> {children}
); }; export type ModalGalleryProps = { attachments: AttachmentTestStepResult[]; }; const ModalGallery: FunctionalComponent = ({ attachments = [] }) => { const filteredAttachments = attachments.filter(({ link: { contentType } }: AttachmentTestStepResult) => { const type = attachmentType(contentType).type; return !["archive", null].includes(type as string); }); return (
{filteredAttachments.map((item, index) => ( ))}
); }; export type ModalProps = { testResult: ClassicTestResult; }; const Modal: FunctionalComponent = ({ testResult }) => { const { link } = modalData.value.data || {}; const attachName = link?.name ? `${link?.name}` : `${link?.id}${link?.ext}`; useEffect(() => { Prism.highlightAll(); if (isModalOpen.value) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, []); const isImageAttachment = link?.contentType?.startsWith("image"); const isHtmlAttachment = link?.contentType === "text/html"; const isMarkdownAttachment = link?.contentType === "text/markdown"; const isPreviewToggleAttachment = isHtmlAttachment || isMarkdownAttachment; const downloadData = async (e: Event) => { e.stopPropagation(); const { id, ext, contentType } = link || {}; if (id && ext && contentType) { await downloadAttachment(id, ext, contentType); } }; const openInNewWindow = async () => { const { id, ext, contentType } = link || {}; await openAttachmentInNewTab(id, ext, contentType); }; if (!isModalOpen.value) { return null; } return (
e.stopPropagation()}>
{attachName}
{isImageAttachment && (
{modalData.value?.component}
); }; export { openModal, closeModal }; export default Modal;