Skip to content

Commit

Permalink
[UI] EVEREST-1578 Fix validation for shards for mongodb with more tha…
Browse files Browse the repository at this point in the history
…n 1 node (#780)

* fix: validation for shards for mongo db with more than 1 node

* fix: add trigger for nodes changes
  • Loading branch information
dianabirs authored Oct 23, 2024
1 parent 5f77b08 commit 261fdba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ui/apps/everest/src/components/cluster-form/resources/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,12 @@ export const resourcesFormSchema = (passthrough?: boolean) => {
});
}

const intNrNodes =
numberOfNodes === CUSTOM_NR_UNITS_INPUT_VALUE
? customNrOfNodes
: numberOfNodes;

if (dbType === DbType.Mysql) {
const intNrNodes =
numberOfNodes === CUSTOM_NR_UNITS_INPUT_VALUE
? customNrOfNodes
: numberOfNodes;
const intNrProxies =
numberOfProxies === CUSTOM_NR_UNITS_INPUT_VALUE
? customNrOfProxies
Expand Down Expand Up @@ -292,6 +293,13 @@ export const resourcesFormSchema = (passthrough?: boolean) => {
path: [DbWizardFormFields.shardNr],
});
}
if (+intNrNodes > 1 && intShardNr < 2) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: Messages.sharding.minForNodes,
path: [DbWizardFormFields.shardNr],
});
}
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export const Messages = {
sharding: {
invalid: 'Please fill in valid values for sharding',
min: (val: number) => `The value cannot be less than ${val}`,
minForNodes: 'The minimum number of shards should be 2',
max: (val: number) => `The value cannot be more than ${val}`,
odd: 'The value cannot be even',
numberOfShards: 'Nº of shards',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ const ResourcesForm = ({
trigger(DbWizardFormFields.shardConfigServers);
}, [setValue, getFieldState, numberOfNodes, customNrOfNodes]);

Check warning on line 513 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has missing dependencies: 'clearErrors' and 'trigger'. Either include them or remove the dependency array

useEffect(() => {
trigger();
}, [numberOfNodes, customNrOfNodes]);

Check warning on line 517 in ui/apps/everest/src/components/cluster-form/resources/resources.tsx

View workflow job for this annotation

GitHub Actions / CI_checks (lint)

React Hook useEffect has a missing dependency: 'trigger'. Either include it or remove the dependency array

return (
<>
{!!showSharding && !!sharding && (
Expand All @@ -523,6 +527,7 @@ const ResourcesForm = ({
<TextInput
name={DbWizardFormFields.shardNr}
textFieldProps={{
sx: { maxWidth: '200px' },
type: 'number',
required: true,
inputProps: {
Expand Down

0 comments on commit 261fdba

Please sign in to comment.