@@ -2,6 +2,7 @@ import { DialogProps } from "components/Dialogs/Dialog";
2
2
import { FC , useRef , useState } from "react" ;
3
3
import { FormFields } from "components/Form/Form" ;
4
4
import TextField from "@mui/material/TextField" ;
5
+ import { makeStyles } from "@mui/styles" ;
5
6
import { ConfirmDialog } from "components/Dialogs/ConfirmDialog/ConfirmDialog" ;
6
7
import { Stack } from "components/Stack/Stack" ;
7
8
import { Template , TemplateVersion } from "api/typesGenerated" ;
@@ -13,6 +14,9 @@ import { Pill } from "components/Pill/Pill";
13
14
import { Avatar } from "components/Avatar/Avatar" ;
14
15
import CircularProgress from "@mui/material/CircularProgress" ;
15
16
import Box from "@mui/material/Box" ;
17
+ import { Alert , AlertDetail } from "components/Alert/Alert" ;
18
+ import AlertTitle from "@mui/material/AlertTitle" ;
19
+ import InfoIcon from "@mui/icons-material/InfoOutlined" ;
16
20
17
21
export type ChangeVersionDialogProps = DialogProps & {
18
22
template : Template | undefined ;
@@ -32,6 +36,9 @@ export const ChangeVersionDialog: FC<ChangeVersionDialogProps> = ({
32
36
} ) => {
33
37
const [ isAutocompleteOpen , setIsAutocompleteOpen ] = useState ( false ) ;
34
38
const selectedTemplateVersion = useRef < TemplateVersion | undefined > ( ) ;
39
+ const version = selectedTemplateVersion . current ;
40
+
41
+ const styles = useStyles ( ) ;
35
42
36
43
return (
37
44
< ConfirmDialog
@@ -51,74 +58,103 @@ export const ChangeVersionDialog: FC<ChangeVersionDialogProps> = ({
51
58
< Stack >
52
59
< p > You are about to change the version of this workspace.</ p >
53
60
{ templateVersions ? (
54
- < FormFields >
55
- < Autocomplete
56
- disableClearable
57
- options = { templateVersions }
58
- defaultValue = { defaultTemplateVersion }
59
- id = "template-version-autocomplete"
60
- open = { isAutocompleteOpen }
61
- onChange = { ( _ , newTemplateVersion ) => {
62
- selectedTemplateVersion . current =
63
- newTemplateVersion ?? undefined ;
64
- } }
65
- onOpen = { ( ) => {
66
- setIsAutocompleteOpen ( true ) ;
67
- } }
68
- onClose = { ( ) => {
69
- setIsAutocompleteOpen ( false ) ;
70
- } }
71
- isOptionEqualToValue = { (
72
- option : TemplateVersion ,
73
- value : TemplateVersion ,
74
- ) => option . id === value . id }
75
- getOptionLabel = { ( option ) => option . name }
76
- renderOption = { ( props , option : TemplateVersion ) => (
77
- < Box component = "li" { ...props } >
78
- < AvatarData
79
- avatar = {
80
- < Avatar src = { option . created_by . avatar_url } >
81
- { option . name }
82
- </ Avatar >
83
- }
84
- title = {
85
- < Stack
86
- direction = "row"
87
- justifyContent = "space-between"
88
- style = { { width : "100%" } }
89
- >
90
- { option . name }
91
- { template ?. active_version_id === option . id && (
92
- < Pill text = "Active" type = "success" />
93
- ) }
94
- </ Stack >
95
- }
96
- subtitle = { createDayString ( option . created_at ) }
97
- />
98
- </ Box >
99
- ) }
100
- renderInput = { ( params ) => (
101
- < >
102
- < TextField
103
- { ...params }
104
- fullWidth
105
- placeholder = "Template version name"
106
- InputProps = { {
107
- ...params . InputProps ,
108
- endAdornment : (
109
- < >
110
- { ! templateVersions ? (
111
- < CircularProgress size = { 16 } />
112
- ) : null }
113
- { params . InputProps . endAdornment }
114
- </ >
115
- ) ,
116
- } }
117
- />
118
- </ >
119
- ) }
120
- />
121
- </ FormFields >
61
+ < >
62
+ < FormFields >
63
+ < Autocomplete
64
+ disableClearable
65
+ options = { templateVersions }
66
+ defaultValue = { defaultTemplateVersion }
67
+ id = "template-version-autocomplete"
68
+ open = { isAutocompleteOpen }
69
+ onChange = { ( _ , newTemplateVersion ) => {
70
+ selectedTemplateVersion . current =
71
+ newTemplateVersion ?? undefined ;
72
+ } }
73
+ onOpen = { ( ) => {
74
+ setIsAutocompleteOpen ( true ) ;
75
+ } }
76
+ onClose = { ( ) => {
77
+ setIsAutocompleteOpen ( false ) ;
78
+ } }
79
+ isOptionEqualToValue = { (
80
+ option : TemplateVersion ,
81
+ value : TemplateVersion ,
82
+ ) => option . id === value . id }
83
+ getOptionLabel = { ( option ) => option . name }
84
+ renderOption = { ( props , option : TemplateVersion ) => (
85
+ < Box component = "li" { ...props } >
86
+ < AvatarData
87
+ avatar = {
88
+ < Avatar src = { option . created_by . avatar_url } >
89
+ { option . name }
90
+ </ Avatar >
91
+ }
92
+ title = {
93
+ < Stack
94
+ direction = "row"
95
+ justifyContent = "space-between"
96
+ style = { { width : "100%" } }
97
+ >
98
+ < Stack
99
+ direction = "row"
100
+ alignItems = "center"
101
+ spacing = { 1 }
102
+ >
103
+ { option . name }
104
+ { option . message && (
105
+ < InfoIcon
106
+ sx = { ( theme ) => ( {
107
+ width : theme . spacing ( 1.5 ) ,
108
+ height : theme . spacing ( 1.5 ) ,
109
+ } ) }
110
+ />
111
+ ) }
112
+ </ Stack >
113
+ { template ?. active_version_id === option . id && (
114
+ < Pill text = "Active" type = "success" />
115
+ ) }
116
+ </ Stack >
117
+ }
118
+ subtitle = { createDayString ( option . created_at ) }
119
+ />
120
+ </ Box >
121
+ ) }
122
+ renderInput = { ( params ) => (
123
+ < >
124
+ < TextField
125
+ { ...params }
126
+ fullWidth
127
+ placeholder = "Template version name"
128
+ InputProps = { {
129
+ ...params . InputProps ,
130
+ endAdornment : (
131
+ < >
132
+ { ! templateVersions ? (
133
+ < CircularProgress size = { 16 } />
134
+ ) : null }
135
+ { params . InputProps . endAdornment }
136
+ </ >
137
+ ) ,
138
+ classes : {
139
+ root : styles . inputRoot ,
140
+ } ,
141
+ } }
142
+ />
143
+ </ >
144
+ ) }
145
+ />
146
+ </ FormFields >
147
+ { version && (
148
+ < Alert severity = "info" >
149
+ < AlertTitle >
150
+ Published by { version . created_by . username }
151
+ </ AlertTitle >
152
+ { version . message && (
153
+ < AlertDetail > { version . message } </ AlertDetail >
154
+ ) }
155
+ </ Alert >
156
+ ) }
157
+ </ >
122
158
) : (
123
159
< Loader />
124
160
) }
@@ -127,3 +163,9 @@ export const ChangeVersionDialog: FC<ChangeVersionDialogProps> = ({
127
163
/>
128
164
) ;
129
165
} ;
166
+
167
+ export const useStyles = makeStyles ( ( theme ) => ( {
168
+ inputRoot : {
169
+ paddingLeft : `${ theme . spacing ( 1.75 ) } !important` , // Same padding left as input
170
+ } ,
171
+ } ) ) ;
0 commit comments