1
-
2
- import { Stack } from 'components/Stack/Stack' ;
3
- import { TopbarButton } from 'components/FullPageLayout/Topbar' ;
1
+ import { Stack } from "components/Stack/Stack" ;
2
+ import { TopbarButton } from "components/FullPageLayout/Topbar" ;
4
3
import {
5
4
Popover ,
6
5
PopoverContent ,
7
6
PopoverTrigger ,
8
7
} from "components/Popover/Popover" ;
9
- import { ProvisionerTag } from ' pages/HealthPage/ProvisionerDaemonsPage' ;
10
- import { type FC } from ' react' ;
11
- import useTheme from ' @mui/system/useTheme' ;
12
- import { useFormik } from ' formik' ;
8
+ import { ProvisionerTag } from " pages/HealthPage/ProvisionerDaemonsPage" ;
9
+ import { type FC } from " react" ;
10
+ import useTheme from " @mui/system/useTheme" ;
11
+ import { useFormik } from " formik" ;
13
12
import * as Yup from "yup" ;
14
- import { getFormHelpers , onChangeTrimmed } from ' utils/formUtils' ;
15
- import { FormFields , FormSection , VerticalForm } from ' components/Form/Form' ;
16
- import TextField from ' @mui/material/TextField' ;
17
- import Button from ' @mui/material/Button' ;
18
- import ExpandMoreOutlined from ' @mui/icons-material/ExpandMoreOutlined' ;
19
- import AddIcon from ' @mui/icons-material/Add' ;
13
+ import { getFormHelpers , onChangeTrimmed } from " utils/formUtils" ;
14
+ import { FormFields , FormSection , VerticalForm } from " components/Form/Form" ;
15
+ import TextField from " @mui/material/TextField" ;
16
+ import Button from " @mui/material/Button" ;
17
+ import ExpandMoreOutlined from " @mui/icons-material/ExpandMoreOutlined" ;
18
+ import AddIcon from " @mui/icons-material/Add" ;
20
19
21
20
const initialValues = {
22
21
key : "" ,
23
22
value : "" ,
24
23
} ;
25
24
26
25
const validationSchema = Yup . object ( {
27
- key : Yup . string ( ) . required ( "Required" ) . notOneOf ( [ "owner" ] , "Cannot override owner tag" ) ,
28
- value : Yup . string ( ) . required ( "Required" ) . when ( "key" , ( [ key ] , schema ) => {
29
- if ( key === "scope" ) {
30
- return schema . oneOf ( [ "organization" , "scope" ] , "Scope value must be 'organization' or 'user'" ) ;
31
- }
26
+ key : Yup . string ( )
27
+ . required ( "Required" )
28
+ . notOneOf ( [ "owner" ] , "Cannot override owner tag" ) ,
29
+ value : Yup . string ( )
30
+ . required ( "Required" )
31
+ . when ( "key" , ( [ key ] , schema ) => {
32
+ if ( key === "scope" ) {
33
+ return schema . oneOf (
34
+ [ "organization" , "scope" ] ,
35
+ "Scope value must be 'organization' or 'user'" ,
36
+ ) ;
37
+ }
32
38
33
- return schema ;
34
- } )
39
+ return schema ;
40
+ } ) ,
35
41
} ) ;
36
42
37
43
interface ProviderTagsPopoverProps {
38
- tags : Record < string , string > ;
44
+ tags : Record < string , string > ;
39
45
onSubmit : ( values : typeof initialValues ) => void ;
40
46
onDelete : ( key : string ) => void ;
41
47
}
42
48
43
- export const ProviderTagsPopover : FC < ProviderTagsPopoverProps > = ( { tags, onSubmit, onDelete } ) => {
49
+ export const ProviderTagsPopover : FC < ProviderTagsPopoverProps > = ( {
50
+ tags,
51
+ onSubmit,
52
+ onDelete,
53
+ } ) => {
44
54
const theme = useTheme ( ) ;
45
55
46
56
const form = useFormik ( {
@@ -55,74 +65,83 @@ export const ProviderTagsPopover: FC<ProviderTagsPopoverProps> = ({ tags, onSubm
55
65
56
66
return (
57
67
< Popover >
58
- < PopoverTrigger >
59
- < TopbarButton
60
- color = "neutral"
61
- css = { { paddingLeft : 0 , paddingRight : 0 , minWidth : "28px !important" } }
62
- >
63
- < ExpandMoreOutlined css = { { fontSize : 14 } } />
64
- </ TopbarButton >
65
- </ PopoverTrigger >
66
- < PopoverContent
67
- horizontal = "right"
68
- css = { { ".MuiPaper-root" : { width : 300 } } }
69
- >
70
- < div
71
- css = { {
72
- color : theme . palette . text . secondary ,
73
- padding : 20 ,
74
- borderBottom : `1px solid ${ theme . palette . divider } ` ,
75
- } }
68
+ < PopoverTrigger >
69
+ < TopbarButton
70
+ color = "neutral"
71
+ css = { { paddingLeft : 0 , paddingRight : 0 , minWidth : "28px !important" } }
72
+ >
73
+ < ExpandMoreOutlined css = { { fontSize : 14 } } />
74
+ </ TopbarButton >
75
+ </ PopoverTrigger >
76
+ < PopoverContent
77
+ horizontal = "right"
78
+ css = { { ".MuiPaper-root" : { width : 300 } } }
76
79
>
77
- < VerticalForm onSubmit = { form . handleSubmit } >
78
- < Stack >
79
- < FormSection title = "Provisioner Tags" description = "Tags are a way to control which provisoner daemons process which build jobs. To learn more read the docs. " />
80
- { Object . keys ( tags ) . length > 0 && (
81
- < Stack direction = "row" spacing = { 1 } wrap = "wrap" >
82
- { Object . keys ( tags ) . filter ( ( key ) => {
83
- // filter out owner since you cannot override it
84
- return key !== "owner"
85
- } ) . map ( ( k ) =>
86
- < >
87
- { k === "scope" ? (
88
- < ProvisionerTag key = { k } k = { k } v = { tags [ k ] } />
89
- ) : (
90
- < ProvisionerTag key = { k } k = { k } v = { tags [ k ] } onDelete = { onDelete } />
91
- ) }
92
- </ >
93
- ) }
94
- </ Stack >
95
- ) }
96
-
80
+ < div
81
+ css = { {
82
+ color : theme . palette . text . secondary ,
83
+ padding : 20 ,
84
+ borderBottom : `1px solid ${ theme . palette . divider } ` ,
85
+ } }
86
+ >
87
+ < VerticalForm onSubmit = { form . handleSubmit } >
88
+ < Stack >
89
+ < FormSection
90
+ title = "Provisioner Tags"
91
+ description = "Tags are a way to control which provisoner daemons process which build jobs. To learn more read the docs. "
92
+ />
93
+ { Object . keys ( tags ) . length > 0 && (
94
+ < Stack direction = "row" spacing = { 1 } wrap = "wrap" >
95
+ { Object . keys ( tags )
96
+ . filter ( ( key ) => {
97
+ // filter out owner since you cannot override it
98
+ return key !== "owner" ;
99
+ } )
100
+ . map ( ( k ) => (
101
+ < >
102
+ { k === "scope" ? (
103
+ < ProvisionerTag key = { k } k = { k } v = { tags [ k ] } />
104
+ ) : (
105
+ < ProvisionerTag
106
+ key = { k }
107
+ k = { k }
108
+ v = { tags [ k ] }
109
+ onDelete = { onDelete }
110
+ />
111
+ ) }
112
+ </ >
113
+ ) ) }
114
+ </ Stack >
115
+ ) }
97
116
98
- < FormFields >
99
- < Stack direction = "row" >
100
- < TextField
101
- { ...getFieldHelpers ( "key" ) }
102
- size = "small"
103
- onChange = { onChangeTrimmed ( form ) }
104
- label = "Key"
105
- />
106
- < TextField
107
- { ...getFieldHelpers ( "value" ) }
108
- size = "small"
109
- onChange = { onChangeTrimmed ( form ) }
110
- label = "Value"
111
- />
112
- < Button
113
- variant = "contained"
114
- color = "secondary"
115
- type = "submit"
116
- disabled = { ! form . dirty || ! form . isValid }
117
- >
118
- < AddIcon />
119
- </ Button >
120
- </ Stack >
121
- </ FormFields >
122
- </ Stack >
123
- </ VerticalForm >
124
- </ div >
125
- </ PopoverContent >
126
- </ Popover >
117
+ < FormFields >
118
+ < Stack direction = "row" >
119
+ < TextField
120
+ { ...getFieldHelpers ( "key" ) }
121
+ size = "small"
122
+ onChange = { onChangeTrimmed ( form ) }
123
+ label = "Key"
124
+ />
125
+ < TextField
126
+ { ...getFieldHelpers ( "value" ) }
127
+ size = "small"
128
+ onChange = { onChangeTrimmed ( form ) }
129
+ label = "Value"
130
+ />
131
+ < Button
132
+ variant = "contained"
133
+ color = "secondary"
134
+ type = "submit"
135
+ disabled = { ! form . dirty || ! form . isValid }
136
+ >
137
+ < AddIcon />
138
+ </ Button >
139
+ </ Stack >
140
+ </ FormFields >
141
+ </ Stack >
142
+ </ VerticalForm >
143
+ </ div >
144
+ </ PopoverContent >
145
+ </ Popover >
127
146
) ;
128
147
} ;
0 commit comments