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