Copilot commented on code in PR #337:
URL:
https://github.com/apache/kvrocks-controller/pull/337#discussion_r2278823738
##########
webui/src/app/ui/formCreation.tsx:
##########
@@ -168,31 +169,51 @@ export const ShardCreation: React.FC<ShardFormProps> = ({
}) => {
const router = useRouter();
const handleSubmit = async (formData: FormData) => {
- const fieldsToValidate = ["nodes"];
- const errorMessage = validateFormData(formData, fieldsToValidate);
- if (errorMessage) {
- return errorMessage;
- }
+ try {
+ const fieldsToValidate = ["nodes"];
+ const errorMessage = validateFormData(formData, fieldsToValidate);
+ if (errorMessage) {
+ return errorMessage;
+ }
- const formObj = Object.fromEntries(formData.entries());
- const nodes = JSON.parse(formObj["nodes"] as string) as string[];
- const password = formObj["password"] as string;
+ const formObj = Object.fromEntries(formData.entries());
+
+ let nodes: string[];
+ try {
+ const nodesString = formObj["nodes"] as string;
+ if (!nodesString) {
+ return "Nodes field is required.";
+ }
+ nodes = JSON.parse(nodesString) as string[];
+ } catch (parseError) {
+ return "Invalid nodes format. Please check your input.";
+ }
- if (nodes.length === 0) {
- return "Nodes cannot be empty.";
- }
+ const password = (formObj["password"] as string) || "";
- for (const node of nodes) {
- if (containsWhitespace(node)) {
- return "Nodes cannot contain any whitespace characters.";
+ if (!Array.isArray(nodes) || nodes.length === 0) {
+ return "At least one node is required.";
}
- }
- const response = await createShard(namespace, cluster, nodes,
password);
- if (response === "") {
- router.push(`/namespaces/${namespace}/clusters/${cluster}`);
- } else {
- return "Invalid form data";
+ for (const node of nodes) {
+ if (!node || typeof node !== "string") {
+ return "All nodes must be valid address strings.";
+ }
+ if (containsWhitespace(node)) {
+ return "Node addresses cannot contain whitespace
characters.";
+ }
+ }
+
+ const response = await createShard(namespace, cluster, nodes,
password);
+ if (response === "") {
+ // rrefresh the page to show the new shard
Review Comment:
There is a typo in the comment: 'rrefresh' should be 'refresh'.
```suggestion
// refresh the page to show the new shard
```
##########
webui/src/app/lib/api.ts:
##########
@@ -261,11 +261,8 @@ export async function createNode(
`${apiHost}/namespaces/${namespace}/clusters/${cluster}/shards/${shard}/nodes`,
{ addr, role, password }
);
- if (responseData?.data == null) {
- return "";
- } else {
- return handleError(responseData);
- }
+ if (responseData?.data !== undefined) return "";
+ return handleError(responseData);
Review Comment:
The condition `responseData?.data !== undefined` will return success even
when there's an error. This should check for null/undefined or specific success
values like the other delete functions.
```suggestion
if (responseData == null || responseData.data == null ||
responseData.data === "ok") {
return "";
} else {
return handleError(responseData);
}
```
##########
webui/src/app/ui/formCreation.tsx:
##########
@@ -288,11 +309,80 @@ export const MigrateSlot: React.FC<ShardFormProps> = ({
position, namespace, clu
const slot = parseInt(formObj["slot"] as string);
const slotOnly = formObj["slot_only"] === "true";
+ // basic Validation for numeric inputs
Review Comment:
The comment has inconsistent capitalization: 'basic Validation' should be
'Basic validation' or 'basic validation'.
```suggestion
// Basic validation for numeric inputs
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]