1
1
'use client'
2
2
3
+ import { CopyPlus } from 'lucide-react'
3
4
import Link from 'next/link'
4
5
5
6
import { Table , TableBody , TableCell , TableHead , TableHeader , TableRow } from '@/components/ui/table'
6
7
7
8
import type { TSuite } from '../../app/suite/[suiteId]/loader'
8
- import { formatDate } from '../shared/utils '
9
+ import { Button } from '../ui/button '
9
10
10
11
/**
11
12
* Shows a list of tests in a suite.
12
13
*/
13
- export function TestsTab ( { suite, suiteId } : { suite : TSuite ; suiteId : number } ) {
14
+ export function TestsTab ( {
15
+ suite,
16
+ suiteId,
17
+
18
+ duplicate,
19
+ } : {
20
+ suite : TSuite
21
+ suiteId : number
22
+
23
+ duplicate : ( testId : number , formData : FormData ) => void
24
+ } ) {
14
25
return (
15
26
< Table >
16
27
< TableHeader >
17
28
< TableRow >
18
29
< TableHead > Test</ TableHead >
19
- < TableHead > Created At</ TableHead >
20
30
< TableHead > { /* Actions */ } </ TableHead >
21
31
</ TableRow >
22
32
</ TableHeader >
@@ -30,15 +40,35 @@ export function TestsTab({ suite, suiteId }: { suite: TSuite; suiteId: number })
30
40
) }
31
41
32
42
{ suite . tests . map ( ( test ) => (
33
- < TableRow key = { test . id } >
34
- < TableCell > { test . label } </ TableCell >
35
- < TableCell suppressHydrationWarning > { formatDate ( test . createdAt ) } </ TableCell >
36
- < TableCell className = "text-right" >
37
- < Link href = { `/suite/${ suiteId } /test/${ test . id } ` } > View</ Link >
38
- </ TableCell >
39
- </ TableRow >
43
+ < TestRow key = { test . id } test = { test } suiteId = { suiteId } duplicate = { duplicate } />
40
44
) ) }
41
45
</ TableBody >
42
46
</ Table >
43
47
)
44
48
}
49
+
50
+ const TestRow = ( {
51
+ test,
52
+ suiteId,
53
+ duplicate,
54
+ } : {
55
+ test : TSuite [ 'tests' ] [ number ]
56
+ suiteId : number
57
+ duplicate : ( testId : number , formData : FormData ) => void
58
+ } ) => {
59
+ const action = duplicate . bind ( null , test . id )
60
+
61
+ return (
62
+ < TableRow key = { test . id } >
63
+ < TableCell > { test . label } </ TableCell >
64
+ < TableCell className = "text-right flex justify-end gap-1" >
65
+ < form action = { action } >
66
+ < Button variant = "ghost" type = "submit" className = "-my-2" >
67
+ < CopyPlus className = "size-3.5" />
68
+ </ Button >
69
+ </ form >
70
+ < Link href = { `/suite/${ suiteId } /test/${ test . id } ` } > View</ Link >
71
+ </ TableCell >
72
+ </ TableRow >
73
+ )
74
+ }
0 commit comments