1
1
import Box from "@material-ui/core/Box"
2
- import { Theme } from "@material-ui/core/styles"
2
+ import { makeStyles , Theme } from "@material-ui/core/styles"
3
3
import Table from "@material-ui/core/Table"
4
4
import TableBody from "@material-ui/core/TableBody"
5
5
import TableCell from "@material-ui/core/TableCell"
6
6
import TableHead from "@material-ui/core/TableHead"
7
7
import TableRow from "@material-ui/core/TableRow"
8
8
import useTheme from "@material-ui/styles/useTheme"
9
- import dayjs from "dayjs"
10
- import duration from "dayjs/plugin/duration"
11
- import relativeTime from "dayjs/plugin/relativeTime"
12
9
import React from "react"
10
+ import { useNavigate } from "react-router-dom"
13
11
import * as TypesGen from "../../api/typesGenerated"
14
- import { getDisplayStatus } from "../../util/workspace"
12
+ import { displayWorkspaceBuildDuration , getDisplayStatus } from "../../util/workspace"
15
13
import { EmptyState } from "../EmptyState/EmptyState"
16
14
import { TableLoader } from "../TableLoader/TableLoader"
17
15
18
- dayjs . extend ( relativeTime )
19
- dayjs . extend ( duration )
20
-
21
16
export const Language = {
22
17
emptyMessage : "No builds found" ,
23
18
inProgressLabel : "In progress" ,
@@ -27,19 +22,6 @@ export const Language = {
27
22
statusLabel : "Status" ,
28
23
}
29
24
30
- const getDurationInSeconds = ( build : TypesGen . WorkspaceBuild ) => {
31
- let display = Language . inProgressLabel
32
-
33
- if ( build . job . started_at && build . job . completed_at ) {
34
- const startedAt = dayjs ( build . job . started_at )
35
- const completedAt = dayjs ( build . job . completed_at )
36
- const diff = completedAt . diff ( startedAt , "seconds" )
37
- display = `${ diff } seconds`
38
- }
39
-
40
- return display
41
- }
42
-
43
25
export interface BuildsTableProps {
44
26
builds ?: TypesGen . WorkspaceBuild [ ]
45
27
className ?: string
@@ -48,6 +30,8 @@ export interface BuildsTableProps {
48
30
export const BuildsTable : React . FC < BuildsTableProps > = ( { builds, className } ) => {
49
31
const isLoading = ! builds
50
32
const theme : Theme = useTheme ( )
33
+ const navigate = useNavigate ( )
34
+ const styles = useStyles ( )
51
35
52
36
return (
53
37
< Table className = { className } >
@@ -62,18 +46,35 @@ export const BuildsTable: React.FC<BuildsTableProps> = ({ builds, className }) =
62
46
< TableBody >
63
47
{ isLoading && < TableLoader /> }
64
48
{ builds &&
65
- builds . map ( ( b ) => {
66
- const status = getDisplayStatus ( theme , b )
67
- const duration = getDurationInSeconds ( b )
49
+ builds . map ( ( build ) => {
50
+ const status = getDisplayStatus ( theme , build )
51
+
52
+ const navigateToBuildPage = ( ) => {
53
+ navigate ( `/builds/${ build . id } ` )
54
+ }
68
55
69
56
return (
70
- < TableRow key = { b . id } data-testid = { `build-${ b . id } ` } >
71
- < TableCell > { b . transition } </ TableCell >
57
+ < TableRow
58
+ hover
59
+ key = { build . id }
60
+ data-testid = { `build-${ build . id } ` }
61
+ tabIndex = { 0 }
62
+ onClick = { navigateToBuildPage }
63
+ onKeyDown = { ( event ) => {
64
+ if ( event . key === "Enter" ) {
65
+ navigateToBuildPage ( )
66
+ }
67
+ } }
68
+ className = { styles . clickableTableRow }
69
+ >
70
+ < TableCell > { build . transition } </ TableCell >
72
71
< TableCell >
73
- < span style = { { color : theme . palette . text . secondary } } > { duration } </ span >
72
+ < span style = { { color : theme . palette . text . secondary } } > { displayWorkspaceBuildDuration ( build ) } </ span >
74
73
</ TableCell >
75
74
< TableCell >
76
- < span style = { { color : theme . palette . text . secondary } } > { new Date ( b . created_at ) . toLocaleString ( ) } </ span >
75
+ < span style = { { color : theme . palette . text . secondary } } >
76
+ { new Date ( build . created_at ) . toLocaleString ( ) }
77
+ </ span >
77
78
</ TableCell >
78
79
< TableCell >
79
80
< span style = { { color : status . color } } > { status . status } </ span >
@@ -95,3 +96,17 @@ export const BuildsTable: React.FC<BuildsTableProps> = ({ builds, className }) =
95
96
</ Table >
96
97
)
97
98
}
99
+
100
+ const useStyles = makeStyles ( ( theme ) => ( {
101
+ clickableTableRow : {
102
+ cursor : "pointer" ,
103
+
104
+ "&:hover td" : {
105
+ backgroundColor : theme . palette . background . default ,
106
+ } ,
107
+
108
+ "&:focus" : {
109
+ outline : `1px solid ${ theme . palette . primary . dark } ` ,
110
+ } ,
111
+ } ,
112
+ } ) )
0 commit comments