@@ -221,6 +221,23 @@ const PostgresCluster = (props: PostgresClusterProps) => {
221
221
dispatch ( { type : 'set_form_step' , formStep : initialState . formStep } )
222
222
}
223
223
224
+ const checkSyncStandbyCount = ( ) => {
225
+ if ( state . synchronous_mode ) {
226
+ if ( Number ( state . numberOfInstances ) === 1 ) {
227
+ return state . synchronous_node_count > state . numberOfInstances
228
+ } else {
229
+ return state . synchronous_node_count > state . numberOfInstances - 1
230
+ }
231
+ }
232
+ }
233
+
234
+ const disableSubmitButton =
235
+ validateDLEName ( state . name ) ||
236
+ requirePublicKeys ||
237
+ state . numberOfInstances > 32 ||
238
+ checkSyncStandbyCount ( ) ||
239
+ ( state . publicKeys && state . publicKeys . length < 30 )
240
+
224
241
if ( state . isLoading ) return < StubSpinner />
225
242
226
243
return (
@@ -783,16 +800,14 @@ const PostgresCluster = (props: PostgresClusterProps) => {
783
800
fullWidth
784
801
type = "number"
785
802
helperText = {
786
- state . synchronous_node_count >
787
- state . numberOfInstances - 1 &&
803
+ checkSyncStandbyCount ( ) &&
788
804
`Maximum ${
789
- state . numberOfInstances - 1
805
+ Number ( state . numberOfInstances ) === 1
806
+ ? state . numberOfInstances
807
+ : state . numberOfInstances - 1
790
808
} synchronous standbys`
791
809
}
792
- error = {
793
- state . synchronous_node_count >
794
- state . numberOfInstances - 1
795
- }
810
+ error = { checkSyncStandbyCount ( ) }
796
811
value = { state . synchronous_node_count }
797
812
disabled = { ! state . synchronous_mode }
798
813
className = { classes . marginTop }
@@ -843,16 +858,8 @@ const PostgresCluster = (props: PostgresClusterProps) => {
843
858
< DbLabInstanceFormSidebar
844
859
cluster
845
860
state = { state as unknown as typeof dbLabInitialState }
846
- disabled = {
847
- validateDLEName ( state . name ) ||
848
- requirePublicKeys ||
849
- state . numberOfInstances > 32 ||
850
- state . synchronous_node_count > state . numberOfInstances - 1 ||
851
- ( state . publicKeys && state . publicKeys . length < 30 )
852
- }
853
- handleCreate = { ( ) =>
854
- ! validateDLEName ( state . name ) && handleSetFormStep ( 'simple' )
855
- }
861
+ disabled = { disableSubmitButton }
862
+ handleCreate = { ( ) => handleSetFormStep ( 'simple' ) }
856
863
/>
857
864
</ >
858
865
) : state . formStep === 'ansible' && permitted ? (
0 commit comments