Skip to content

Commit

Permalink
feat: ✨ displayed image attachment instead of base64 string (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
WasiqB authored Sep 27, 2024
1 parent 4b30082 commit f33d052
Show file tree
Hide file tree
Showing 5 changed files with 403 additions and 354 deletions.
22 changes: 11 additions & 11 deletions app/(app)/results/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const ResultsPage = (): JSX.Element => {

return (
<section className='container mx-auto space-y-6 p-4'>
<h1 className='mb-8 text-center text-3xl font-bold'>
<h1 className='mb-8 text-balance text-center text-3xl font-bold'>
Ultra Report for {date}
</h1>
<div className='grid grid-cols-1 gap-6'>
Expand All @@ -110,28 +110,28 @@ const ResultsPage = (): JSX.Element => {
<CardDescription>Overall Test execution statistics</CardDescription>
</CardHeader>
<CardContent>
<div className='grid grid-cols-4 gap-4'>
<div className='rounded-lg bg-blue-200 p-4'>
<div className='grid grid-cols-2 gap-4 md:grid-cols-4'>
<Card className='rounded-lg bg-blue-200 p-4'>
<CardDescription>Total Tests</CardDescription>
<CardTitle>{passed + failed + skipped}</CardTitle>
</div>
<div className='rounded-lg bg-green-200 p-4'>
</Card>
<Card className='rounded-lg bg-green-200 p-4'>
<CardDescription>Passed</CardDescription>
<CardTitle>{passed}</CardTitle>
</div>
<div className='rounded-lg bg-red-200 p-4'>
</Card>
<Card className='rounded-lg bg-red-200 p-4'>
<CardDescription>Failed</CardDescription>
<CardTitle>{failed}</CardTitle>
</div>
<div className='rounded-lg bg-yellow-200 p-4'>
</Card>
<Card className='rounded-lg bg-yellow-200 p-4'>
<CardDescription>Skipped</CardDescription>
<CardTitle>{skipped}</CardTitle>
</div>
</Card>
</div>
</CardContent>
</Card>
</div>
<div className='grid grid-cols-2 gap-6'>
<div className='grid grid-cols-1 gap-6 md:grid-cols-2'>
<DoughNutComponent
title='Test Summary Counts'
description='Status based distribution of Test results'
Expand Down
70 changes: 70 additions & 0 deletions components/data-table/attachment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use client';

import React, { useState } from 'react';
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@/components/ui/dialog';
import { Button } from '@/components/ui/button';
import { Link } from 'lucide-react';

interface AttachmentDialogProps {
content: string;
title: string;
description?: string;
}

/* eslint-disable @typescript-eslint/no-unused-vars */
const isBase64Image = (str: string): boolean => {
try {
return btoa(atob(str)) === str;
} catch (err) {
return false;
}
};

export function AttachmentDialog({
content,
title,
description,
}: AttachmentDialogProps): JSX.Element {
const [isOpen, setIsOpen] = useState(false);
const isImage = isBase64Image(content);

return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
<Button variant='outline'>
<Link className='h-4 w-4' />
</Button>
</DialogTrigger>
<DialogContent className='flex flex-col sm:max-h-[90vh] sm:max-w-[90vw]'>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
{description && <DialogDescription>{description}</DialogDescription>}
</DialogHeader>
<div className='mt-4 flex-grow overflow-auto'>
{isImage ? (
<div className='relative h-full min-h-[300px] w-full border border-gray-500'>
<img
src={`data:image/png;base64,${content}`}
alt='Attachment'
className='h-full w-full object-contain'
/>
</div>
) : (
<div className='max-h-[60vh] overflow-y-auto'>
<p className='whitespace-pre-wrap text-lg text-gray-800'>
{content}
</p>
</div>
)}
</div>
</DialogContent>
</Dialog>
);
}
43 changes: 11 additions & 32 deletions components/data-table/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { formatDuration, formatTime } from '@/lib/formatting';
import { GearIcon } from '@radix-ui/react-icons';
import { TooltipWrapper } from '@/components/utils/tooltip-wrapper';
import { useState } from 'react';
import { AttachmentDialog } from './attachment';

export const columns: ColumnDef<TestResultData>[] = [
{
Expand Down Expand Up @@ -129,7 +130,7 @@ export const columns: ColumnDef<TestResultData>[] = [
<CircleAlert className='h-4 w-4 text-red-500' />
</Button>
</DialogTrigger>
<DialogContent className='sm:max-w-[75%]'>
<DialogContent className='flex flex-col sm:max-h-[90vh] sm:max-w-[90vw]'>
<DialogHeader>
<DialogTitle>Exception</DialogTitle>
<DialogDescription>
Expand All @@ -152,6 +153,7 @@ export const columns: ColumnDef<TestResultData>[] = [
<pre className='mockup-code max-h-[300px] overflow-auto'>
{exception.stack_trace.map((line, index) => (
<code key={index} className='block pl-2'>
{line.startsWith('at') && '\t'}
{line.trim()}
</code>
))}
Expand All @@ -174,39 +176,16 @@ export const columns: ColumnDef<TestResultData>[] = [
accessorKey: 'attachment',
header: () => <Link className='h-4 w-4' />,
cell: ({ row }) => {
const [isOpen, setIsOpen] = useState(false);
const attachment = row.getValue('attachment') as TestLog;
const content = attachment.line?.trim();
return (
<>
{attachment && (
<div className='flex items-center'>
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger asChild>
<Button
variant='outline'
onClick={() => setIsOpen(true)}
className='w-15'
>
<Link className='h-4 w-4' />
</Button>
</DialogTrigger>
<DialogContent className='sm:max-w-[75%]'>
<DialogHeader>
<DialogTitle>Attachment</DialogTitle>
<DialogDescription>
Below is the attachment from your Test
</DialogDescription>
</DialogHeader>
<div className='grid gap-4 py-4'>
<div className='grid grid-cols-4 items-center gap-4'>
{attachment.line?.trim()}
</div>
</div>
</DialogContent>
</Dialog>
</div>
)}
</>
attachment && (
<AttachmentDialog
title='Attachment'
description='Below is the attachment from your Test'
content={content}
/>
)
);
},
},
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
"@next/eslint-plugin-next": "^14.2.13",
"@stylistic/eslint-plugin-js": "^2.8.0",
"@stylistic/eslint-plugin-ts": "^2.8.0",
"@types/node": "^22.7.2",
"@types/react": "^18.3.9",
"@types/node": "^22.7.4",
"@types/react": "^18.3.10",
"@types/react-dom": "^18",
"@types/xml2js": "^0.4.14",
"daisyui": "^4.12.10",
Expand Down
Loading

0 comments on commit f33d052

Please sign in to comment.