@@ -34,34 +34,31 @@ import { FlexBox } from './FlexBox';
34
34
import { LightTooltip , IOSSwitch } from './Shared' ;
35
35
import { Line } from './Text' ;
36
36
37
- const incidentPRFilterFormSchema = yup
38
- . object ( {
39
- setting : yup
40
- . object ( {
41
- include_revert_prs : yup . boolean ( ) ,
42
- filters : yup . array (
43
- yup . object ( {
44
- field : yup . string ( ) . required ( ) ,
45
- value : yup
46
- . string ( )
47
- . required ( )
48
- . test (
49
- 'regex-group' ,
50
- 'Regex must contain exactly one (\\d+) match group' ,
51
- ( val ) => {
52
- if ( ! val ) return false ;
53
- const match = val . match ( / \( \\ d \+ \) / g) ;
54
- return match && match . length === 1 ;
55
- }
56
- )
57
- } )
58
- )
59
- } )
60
- . required ( )
61
- } )
62
- . required ( ) ;
37
+ const individualFilterSchema = yup . object ( {
38
+ field : yup . string ( ) . required ( ) ,
39
+ value : yup
40
+ . string ( )
41
+ . test (
42
+ 'regex-group' ,
43
+ 'Regex must contain exactly one (\\d+) match group' ,
44
+ ( val ) => {
45
+ if ( ! val ) return false ;
46
+ const match = val . match ( / \( \\ d \+ \) / g) ;
47
+ return match && match . length === 1 ;
48
+ }
49
+ )
50
+ } ) ;
51
+
52
+ const settingsSchema = yup . object ( {
53
+ include_revert_prs : yup . boolean ( ) . required ( ) ,
54
+ filters : yup . array ( individualFilterSchema ) . required ( )
55
+ } ) ;
56
+
57
+ const incidentPRFilterFormSchema = yup . object ( {
58
+ setting : settingsSchema . required ( )
59
+ } ) ;
63
60
64
- type incidentPRFilterFormSchema = yup . InferType <
61
+ type IncidentPRFilterFormSchema = yup . InferType <
65
62
typeof incidentPRFilterFormSchema
66
63
> ;
67
64
@@ -103,7 +100,7 @@ export const TeamIncidentPRsFilter: FC<{
103
100
( s ) => s . team . teamIncidentPRsFilters
104
101
) ?. setting ;
105
102
106
- const addUserMethods = useForm < incidentPRFilterFormSchema > ( {
103
+ const formMethods = useForm < IncidentPRFilterFormSchema > ( {
107
104
resolver : yupResolver ( incidentPRFilterFormSchema ) ,
108
105
mode : 'onChange' ,
109
106
defaultValues : {
@@ -115,7 +112,7 @@ export const TeamIncidentPRsFilter: FC<{
115
112
watch,
116
113
formState : { isDirty, isValid, errors } ,
117
114
setValue
118
- } = addUserMethods ;
115
+ } = formMethods ;
119
116
120
117
const settings = watch ( 'setting' ) ;
121
118
@@ -173,6 +170,13 @@ export const TeamIncidentPRsFilter: FC<{
173
170
}
174
171
} , [ settings . filters , setValue ] ) ;
175
172
173
+ const isSingleEmptyFilter =
174
+ settings . filters . length === 1 &&
175
+ ! settings . filters [ 0 ] . field &&
176
+ ! settings . filters [ 0 ] . value ;
177
+
178
+ const isSaveEnabled = isDirty && ( isValid || isSingleEmptyFilter ) ;
179
+
176
180
return (
177
181
< FlexBox gap = { 2 } col maxWidth = { '560px' } >
178
182
< Line white small mt = { - 1 } textAlign = { 'start' } >
@@ -182,7 +186,7 @@ export const TeamIncidentPRsFilter: FC<{
182
186
183
187
< Divider />
184
188
185
- < FormProvider { ...addUserMethods } >
189
+ < FormProvider { ...formMethods } >
186
190
< FlexBox col gap2 >
187
191
< FlexBox >
188
192
< Line big flexGrow = { 1 } >
@@ -364,15 +368,7 @@ export const TeamIncidentPRsFilter: FC<{
364
368
type = "submit"
365
369
variant = "outlined"
366
370
color = "primary"
367
- disabled = {
368
- ! isDirty ||
369
- ! (
370
- isValid ||
371
- ( settings . filters . length === 1 &&
372
- ! settings . filters [ 0 ] . field &&
373
- ! settings . filters [ 0 ] . value )
374
- )
375
- }
371
+ disabled = { ! isSaveEnabled }
376
372
loading = { isSaving . value }
377
373
sx = { {
378
374
'&.Mui-disabled' : {
0 commit comments