Skip to content

Commit f372af4

Browse files
Adrinlolvitabaks
authored andcommitted
fix(ui): postgres ha cluster - add support for cluster deployment with 1 server (https://gitlab.com/postgres-ai/database-lab/-/issues/547)
1 parent 47ca31c commit f372af4

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

Diff for: ui/packages/platform/src/components/PostgresClusterForm/PostgresCluster.tsx

+24-17
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,23 @@ const PostgresCluster = (props: PostgresClusterProps) => {
221221
dispatch({ type: 'set_form_step', formStep: initialState.formStep })
222222
}
223223

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+
224241
if (state.isLoading) return <StubSpinner />
225242

226243
return (
@@ -783,16 +800,14 @@ const PostgresCluster = (props: PostgresClusterProps) => {
783800
fullWidth
784801
type="number"
785802
helperText={
786-
state.synchronous_node_count >
787-
state.numberOfInstances - 1 &&
803+
checkSyncStandbyCount() &&
788804
`Maximum ${
789-
state.numberOfInstances - 1
805+
Number(state.numberOfInstances) === 1
806+
? state.numberOfInstances
807+
: state.numberOfInstances - 1
790808
} synchronous standbys`
791809
}
792-
error={
793-
state.synchronous_node_count >
794-
state.numberOfInstances - 1
795-
}
810+
error={checkSyncStandbyCount()}
796811
value={state.synchronous_node_count}
797812
disabled={!state.synchronous_mode}
798813
className={classes.marginTop}
@@ -843,16 +858,8 @@ const PostgresCluster = (props: PostgresClusterProps) => {
843858
<DbLabInstanceFormSidebar
844859
cluster
845860
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')}
856863
/>
857864
</>
858865
) : state.formStep === 'ansible' && permitted ? (

0 commit comments

Comments
 (0)