@@ -8,6 +8,7 @@ import TableHead from "@material-ui/core/TableHead"
8
8
import TableRow from "@material-ui/core/TableRow"
9
9
import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight"
10
10
import useTheme from "@material-ui/styles/useTheme"
11
+ import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
11
12
import { FC } from "react"
12
13
import { useNavigate } from "react-router-dom"
13
14
import { createDayString } from "util/createDayString"
@@ -76,12 +77,14 @@ export interface TemplatesPageViewProps {
76
77
loading ?: boolean
77
78
canCreateTemplate ?: boolean
78
79
templates ?: TypesGen . Template [ ]
80
+ error ?: Error | unknown
79
81
}
80
82
81
83
export const TemplatesPageView : FC < React . PropsWithChildren < TemplatesPageViewProps > > = ( props ) => {
82
84
const styles = useStyles ( )
83
85
const navigate = useNavigate ( )
84
86
const theme : Theme = useTheme ( )
87
+ const empty = ! props . loading && ! props . error && ! props . templates ?. length
85
88
86
89
return (
87
90
< Margins >
@@ -113,94 +116,98 @@ export const TemplatesPageView: FC<React.PropsWithChildren<TemplatesPageViewProp
113
116
) }
114
117
</ PageHeader >
115
118
116
- < TableContainer >
117
- < Table >
118
- < TableHead >
119
- < TableRow >
120
- < TableCell width = "50%" > { Language . nameLabel } </ TableCell >
121
- < TableCell width = "16%" > { Language . usedByLabel } </ TableCell >
122
- < TableCell width = "16%" > { Language . lastUpdatedLabel } </ TableCell >
123
- < TableCell width = "16%" > { Language . createdByLabel } </ TableCell >
124
- < TableCell width = "1%" > </ TableCell >
125
- </ TableRow >
126
- </ TableHead >
127
- < TableBody >
128
- { props . loading && < TableLoader /> }
129
- { ! props . loading && ! props . templates ?. length && (
119
+ { props . error ? (
120
+ < ErrorSummary error = { props . error } />
121
+ ) : (
122
+ < TableContainer >
123
+ < Table >
124
+ < TableHead >
130
125
< TableRow >
131
- < TableCell colSpan = { 999 } >
132
- < EmptyState
133
- message = { Language . emptyMessage }
134
- description = {
135
- props . canCreateTemplate
136
- ? Language . emptyDescription
137
- : Language . emptyViewNoPerms
138
- }
139
- descriptionClassName = { styles . emptyDescription }
140
- cta = { < CodeExample code = "coder templates init" /> }
141
- />
142
- </ TableCell >
126
+ < TableCell width = "50%" > { Language . nameLabel } </ TableCell >
127
+ < TableCell width = "16%" > { Language . usedByLabel } </ TableCell >
128
+ < TableCell width = "16%" > { Language . lastUpdatedLabel } </ TableCell >
129
+ < TableCell width = "16%" > { Language . createdByLabel } </ TableCell >
130
+ < TableCell width = "1%" > </ TableCell >
143
131
</ TableRow >
144
- ) }
145
- { props . templates ?. map ( ( template ) => {
146
- const templatePageLink = `/templates/${ template . name } `
147
- const hasIcon = template . icon && template . icon !== ""
148
-
149
- return (
150
- < TableRow
151
- key = { template . id }
152
- hover
153
- data-testid = { `template-${ template . id } ` }
154
- tabIndex = { 0 }
155
- onKeyDown = { ( event ) => {
156
- if ( event . key === "Enter" ) {
157
- navigate ( templatePageLink )
158
- }
159
- } }
160
- className = { styles . clickableTableRow }
161
- >
162
- < TableCellLink to = { templatePageLink } >
163
- < AvatarData
164
- title = { template . name }
165
- subtitle = { template . description }
166
- highlightTitle
167
- avatar = {
168
- hasIcon ? (
169
- < div className = { styles . templateIconWrapper } >
170
- < img alt = "" src = { template . icon } />
171
- </ div >
172
- ) : undefined
132
+ </ TableHead >
133
+ < TableBody >
134
+ { props . loading && < TableLoader /> }
135
+ { empty && (
136
+ < TableRow >
137
+ < TableCell colSpan = { 999 } >
138
+ < EmptyState
139
+ message = { Language . emptyMessage }
140
+ description = {
141
+ props . canCreateTemplate
142
+ ? Language . emptyDescription
143
+ : Language . emptyViewNoPerms
173
144
}
145
+ descriptionClassName = { styles . emptyDescription }
146
+ cta = { < CodeExample code = "coder templates init" /> }
174
147
/>
175
- </ TableCellLink >
148
+ </ TableCell >
149
+ </ TableRow >
150
+ ) }
151
+ { props . templates ?. map ( ( template ) => {
152
+ const templatePageLink = `/templates/${ template . name } `
153
+ const hasIcon = template . icon && template . icon !== ""
176
154
177
- < TableCellLink to = { templatePageLink } >
178
- < span style = { { color : theme . palette . text . secondary } } >
179
- { Language . developerCount ( template . workspace_owner_count ) }
180
- </ span >
181
- </ TableCellLink >
155
+ return (
156
+ < TableRow
157
+ key = { template . id }
158
+ hover
159
+ data-testid = { `template-${ template . id } ` }
160
+ tabIndex = { 0 }
161
+ onKeyDown = { ( event ) => {
162
+ if ( event . key === "Enter" ) {
163
+ navigate ( templatePageLink )
164
+ }
165
+ } }
166
+ className = { styles . clickableTableRow }
167
+ >
168
+ < TableCellLink to = { templatePageLink } >
169
+ < AvatarData
170
+ title = { template . name }
171
+ subtitle = { template . description }
172
+ highlightTitle
173
+ avatar = {
174
+ hasIcon ? (
175
+ < div className = { styles . templateIconWrapper } >
176
+ < img alt = "" src = { template . icon } />
177
+ </ div >
178
+ ) : undefined
179
+ }
180
+ />
181
+ </ TableCellLink >
182
182
183
- < TableCellLink data-chromatic = "ignore" to = { templatePageLink } >
184
- < span style = { { color : theme . palette . text . secondary } } >
185
- { createDayString ( template . updated_at ) }
186
- </ span >
187
- </ TableCellLink >
188
- < TableCellLink to = { templatePageLink } >
189
- < span style = { { color : theme . palette . text . secondary } } >
190
- { template . created_by_name }
191
- </ span >
192
- </ TableCellLink >
193
- < TableCellLink to = { templatePageLink } >
194
- < div className = { styles . arrowCell } >
195
- < KeyboardArrowRight className = { styles . arrowRight } />
196
- </ div >
197
- </ TableCellLink >
198
- </ TableRow >
199
- )
200
- } ) }
201
- </ TableBody >
202
- </ Table >
203
- </ TableContainer >
183
+ < TableCellLink to = { templatePageLink } >
184
+ < span style = { { color : theme . palette . text . secondary } } >
185
+ { Language . developerCount ( template . workspace_owner_count ) }
186
+ </ span >
187
+ </ TableCellLink >
188
+
189
+ < TableCellLink data-chromatic = "ignore" to = { templatePageLink } >
190
+ < span style = { { color : theme . palette . text . secondary } } >
191
+ { createDayString ( template . updated_at ) }
192
+ </ span >
193
+ </ TableCellLink >
194
+ < TableCellLink to = { templatePageLink } >
195
+ < span style = { { color : theme . palette . text . secondary } } >
196
+ { template . created_by_name }
197
+ </ span >
198
+ </ TableCellLink >
199
+ < TableCellLink to = { templatePageLink } >
200
+ < div className = { styles . arrowCell } >
201
+ < KeyboardArrowRight className = { styles . arrowRight } />
202
+ </ div >
203
+ </ TableCellLink >
204
+ </ TableRow >
205
+ )
206
+ } ) }
207
+ </ TableBody >
208
+ </ Table >
209
+ </ TableContainer >
210
+ ) }
204
211
</ Margins >
205
212
)
206
213
}
0 commit comments