@@ -8,6 +8,8 @@ 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 { ChooseOne , Cond } from "components/Conditionals/ChooseOne"
12
+ import { Maybe } from "components/Conditionals/Maybe"
11
13
import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
12
14
import { FC } from "react"
13
15
import { useTranslation } from "react-i18next"
@@ -103,7 +105,7 @@ export const TemplatesPageView: FC<React.PropsWithChildren<TemplatesPageViewProp
103
105
< TemplateHelpTooltip />
104
106
</ Stack >
105
107
</ PageHeaderTitle >
106
- { props . templates && props . templates . length > 0 && (
108
+ < Maybe condition = { Boolean ( props . templates && props . templates . length > 0 ) } >
107
109
< PageHeaderSubtitle >
108
110
Choose a template to create a new workspace
109
111
{ props . canCreateTemplate ? (
@@ -121,113 +123,122 @@ export const TemplatesPageView: FC<React.PropsWithChildren<TemplatesPageViewProp
121
123
"."
122
124
) }
123
125
</ PageHeaderSubtitle >
124
- ) }
126
+ </ Maybe >
125
127
</ PageHeader >
126
128
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 >
141
- < TableRow >
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 >
147
- </ TableRow >
148
- </ TableHead >
149
- < TableBody >
150
- { props . loading && < TableLoader /> }
151
-
152
- { empty ? (
129
+ < ChooseOne >
130
+ < Cond condition = { Boolean ( props . getOrganizationsError ) } >
131
+ < ErrorSummary
132
+ error = { props . getOrganizationsError }
133
+ defaultMessage = { t ( "errors.getOrganizationsError" ) }
134
+ />
135
+ </ Cond >
136
+ < Cond condition = { Boolean ( props . getTemplatesError ) } >
137
+ < ErrorSummary
138
+ error = { props . getTemplatesError }
139
+ defaultMessage = { t ( "errors.getTemplatesError" ) }
140
+ />
141
+ </ Cond >
142
+ < Cond condition >
143
+ < TableContainer >
144
+ < Table >
145
+ < TableHead >
153
146
< TableRow >
154
- < TableCell colSpan = { 999 } >
155
- < EmptyState
156
- message = { Language . emptyMessage }
157
- description = {
158
- props . canCreateTemplate
159
- ? Language . emptyDescription
160
- : Language . emptyViewNoPerms
161
- }
162
- descriptionClassName = { styles . emptyDescription }
163
- cta = { < CodeExample code = "coder templates init" /> }
164
- />
165
- </ TableCell >
147
+ < TableCell width = "50%" > { Language . nameLabel } </ TableCell >
148
+ < TableCell width = "16%" > { Language . usedByLabel } </ TableCell >
149
+ < TableCell width = "16%" > { Language . lastUpdatedLabel } </ TableCell >
150
+ < TableCell width = "16%" > { Language . createdByLabel } </ TableCell >
151
+ < TableCell width = "1%" > </ TableCell >
166
152
</ TableRow >
167
- ) : (
168
- props . templates ?. map ( ( template ) => {
169
- const templatePageLink = `/templates/${ template . name } `
170
- const hasIcon = template . icon && template . icon !== ""
153
+ </ TableHead >
154
+ < TableBody >
155
+ < Maybe condition = { Boolean ( props . loading ) } >
156
+ < TableLoader />
157
+ </ Maybe >
171
158
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
- )
159
+ < ChooseOne >
160
+ < Cond condition = { empty } >
161
+ < TableRow >
162
+ < TableCell colSpan = { 999 } >
163
+ < EmptyState
164
+ message = { Language . emptyMessage }
165
+ description = {
166
+ props . canCreateTemplate
167
+ ? Language . emptyDescription
168
+ : Language . emptyViewNoPerms
196
169
}
170
+ descriptionClassName = { styles . emptyDescription }
171
+ cta = { < CodeExample code = "coder templates init" /> }
197
172
/>
198
- </ TableCellLink >
173
+ </ TableCell >
174
+ </ TableRow >
175
+ </ Cond >
176
+ < Cond condition >
177
+ { props . templates ?. map ( ( template ) => {
178
+ const templatePageLink = `/templates/${ template . name } `
179
+ const hasIcon = template . icon && template . icon !== ""
199
180
200
- < TableCellLink to = { templatePageLink } >
201
- < span style = { { color : theme . palette . text . secondary } } >
202
- { Language . developerCount ( template . active_user_count ) }
203
- </ span >
204
- </ TableCellLink >
181
+ return (
182
+ < TableRow
183
+ key = { template . id }
184
+ hover
185
+ data-testid = { `template-${ template . id } ` }
186
+ tabIndex = { 0 }
187
+ onKeyDown = { ( event ) => {
188
+ if ( event . key === "Enter" ) {
189
+ navigate ( templatePageLink )
190
+ }
191
+ } }
192
+ className = { styles . clickableTableRow }
193
+ >
194
+ < TableCellLink to = { templatePageLink } >
195
+ < AvatarData
196
+ title = { template . name }
197
+ subtitle = { template . description }
198
+ highlightTitle
199
+ avatar = {
200
+ hasIcon && (
201
+ < div className = { styles . templateIconWrapper } >
202
+ < img alt = "" src = { template . icon } />
203
+ </ div >
204
+ )
205
+ }
206
+ />
207
+ </ TableCellLink >
205
208
206
- < TableCellLink data-chromatic = "ignore" to = { templatePageLink } >
207
- < span style = { { color : theme . palette . text . secondary } } >
208
- { createDayString ( template . updated_at ) }
209
- </ span >
210
- </ TableCellLink >
209
+ < TableCellLink to = { templatePageLink } >
210
+ < span style = { { color : theme . palette . text . secondary } } >
211
+ { Language . developerCount ( template . active_user_count ) }
212
+ </ span >
213
+ </ TableCellLink >
211
214
212
- < TableCellLink to = { templatePageLink } >
213
- < span style = { { color : theme . palette . text . secondary } } >
214
- { template . created_by_name }
215
- </ span >
216
- </ TableCellLink >
215
+ < TableCellLink data-chromatic = "ignore" to = { templatePageLink } >
216
+ < span style = { { color : theme . palette . text . secondary } } >
217
+ { createDayString ( template . updated_at ) }
218
+ </ span >
219
+ </ TableCellLink >
217
220
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
- ) }
221
+ < TableCellLink to = { templatePageLink } >
222
+ < span style = { { color : theme . palette . text . secondary } } >
223
+ { template . created_by_name }
224
+ </ span >
225
+ </ TableCellLink >
226
+
227
+ < TableCellLink to = { templatePageLink } >
228
+ < div className = { styles . arrowCell } >
229
+ < KeyboardArrowRight className = { styles . arrowRight } />
230
+ </ div >
231
+ </ TableCellLink >
232
+ </ TableRow >
233
+ )
234
+ } ) }
235
+ </ Cond >
236
+ </ ChooseOne >
237
+ </ TableBody >
238
+ </ Table >
239
+ </ TableContainer >
240
+ </ Cond >
241
+ </ ChooseOne >
231
242
</ Margins >
232
243
)
233
244
}
0 commit comments