From 7f55eb4fafbace96bd9003763d3f3a62ff4b3fc4 Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 1 Jul 2025 13:05:14 +0300 Subject: [PATCH 1/5] - Removed immediate validation triggers - Validation only on submit - Improved validation order & logic --- .../src/dashboard/components/add_ip.vue | 103 ++++++++---------- 1 file changed, 46 insertions(+), 57 deletions(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index 3c07c0993f..99b2ba276b 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -6,9 +6,7 @@ - - Add Public IP to Farm - + Add Public IP to Farm - - IPs range - + IPs range @@ -98,21 +94,18 @@

Network:

-
+ +

{{ network }}

- - IP Addresses: - + IP Addresses: - {{ - ip - }} + {{ ip }} @@ -124,30 +117,16 @@
- - Close - + Close
- - Close - - - - Show IPs Range - - - Add - + Close + + Show IPs Range + Add
@@ -176,7 +155,7 @@ export default { }, }, - setup(_, context) { + setup(props, context) { const gridStore = useGrid(); const IPs = ref(); const items = ref([IPType.single, IPType.range]); @@ -196,15 +175,6 @@ export default { const ipsRangeTable = ref([]); const formValidator = ref(); - watch( - [publicIP, toPublicIP, gateway], - async () => { - if (publicIP.value.length || toPublicIP.value.length || gateway.value.length) - await formValidator.value.validate(); - }, - { deep: true }, - ); - watch( type, () => { @@ -225,34 +195,33 @@ export default { return undefined; } function toIpCheck() { - if (toPublicIP.value.split("/")[1] !== publicIP.value.split("/")[1]) { + if (!publicIP.value || !toPublicIP.value) { + return; + } + + const fromParts = publicIP.value.split("/"); + const toParts = toPublicIP.value.split("/"); + + if (toParts[1] !== fromParts[1]) { return { message: "Subnet is different.", }; } - if ( - parseInt(toPublicIP.value.split("/")[0].split(".")[3]) <= parseInt(publicIP.value.split("/")[0].split(".")[3]) - ) { + if (parseInt(toParts[0].split(".")[3]) <= parseInt(fromParts[0].split(".")[3])) { return { message: "To IP must be bigger than From IP.", }; } if ( - toPublicIP.value.substring(0, toPublicIP.value.lastIndexOf(".")) != - publicIP.value.substring(0, publicIP.value.lastIndexOf(".")) + toParts[0].substring(0, toParts[0].lastIndexOf(".")) != fromParts[0].substring(0, fromParts[0].lastIndexOf(".")) ) { return { - message: "IPs are not the same.", + message: "IPs are not in the same network.", }; } - if ( - parseInt(toPublicIP.value.split("/")[0].split(".")[3]) - - parseInt(publicIP.value.split("/")[0].split(".")[3]) + - 1 > - 16 - ) { + if (parseInt(toParts[0].split(".")[3]) - parseInt(fromParts[0].split(".")[3]) + 1 > 16) { return { message: "Range must not exceed 16.", }; @@ -260,6 +229,10 @@ export default { } function gatewayCheck() { + if (!gateway.value || !publicIP.value) { + return; + } + const firstIP = publicIP?.value.split("/")[0]; const lastIP = toPublicIP?.value.split("/")[0]; let isRange = false; @@ -276,13 +249,13 @@ export default { }; } - if (firstIP === gateway.value || lastIP === gateway.value) { + if (firstIP === gateway.value || (lastIP && lastIP === gateway.value)) { return { message: "IPs cannot be the same.", }; } - if (type.value !== IPType.single) { + if (type.value !== IPType.single && lastIP) { try { const range = getIPRange(firstIP, lastIP); if (range.includes(gateway.value)) { @@ -335,6 +308,21 @@ export default { }); } + async function handleAddFarmIp() { + if (!formValidator.value) { + createCustomToast("Form validation error. Please check your inputs.", ToastType.danger); + return; + } + + const isValid = await formValidator.value.validate(); + if (!isValid) { + createCustomToast("Please fix errors before submitting.", ToastType.danger); + return; + } + + await addFarmIp(props.farmId, gateway.value); + } + async function addFarmIp(farmId: number, gw: string) { try { isAdding.value = true; @@ -403,6 +391,7 @@ export default { showRange, addIPs, + handleAddFarmIp, addFarmIp, isExistingIp, toIpCheck, From a12db1d79189c27799189a6d1dec34616e2b5d50 Mon Sep 17 00:00:00 2001 From: samaradel Date: Wed, 2 Jul 2025 13:25:58 +0300 Subject: [PATCH 2/5] Fix validation order --- .../playground/src/dashboard/components/add_ip.vue | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index 99b2ba276b..cd7e8594a6 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -208,12 +208,6 @@ export default { }; } - if (parseInt(toParts[0].split(".")[3]) <= parseInt(fromParts[0].split(".")[3])) { - return { - message: "To IP must be bigger than From IP.", - }; - } - if ( toParts[0].substring(0, toParts[0].lastIndexOf(".")) != fromParts[0].substring(0, fromParts[0].lastIndexOf(".")) ) { @@ -221,6 +215,11 @@ export default { message: "IPs are not in the same network.", }; } + if (parseInt(toParts[0].split(".")[3]) <= parseInt(fromParts[0].split(".")[3])) { + return { + message: "To IP must be bigger than From IP.", + }; + } if (parseInt(toParts[0].split(".")[3]) - parseInt(fromParts[0].split(".")[3]) + 1 > 16) { return { message: "Range must not exceed 16.", From 17d4d573e0af1ff06f13aba63f4746ef11506461 Mon Sep 17 00:00:00 2001 From: samaradel Date: Mon, 7 Jul 2025 13:32:54 +0300 Subject: [PATCH 3/5] Fix the Add button to be disabled when the form is invalid --- packages/playground/src/dashboard/components/add_ip.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index cd7e8594a6..ee5ddb9850 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -126,7 +126,9 @@ Close Show IPs Range - Add + + Add + From 5c1a5f45a6b9dc5419be3abba3b54377c3331256 Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 15 Jul 2025 12:27:45 +0300 Subject: [PATCH 4/5] Fixed "Show IPs Range" Button --- packages/playground/src/dashboard/components/add_ip.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playground/src/dashboard/components/add_ip.vue b/packages/playground/src/dashboard/components/add_ip.vue index ee5ddb9850..828be49681 100644 --- a/packages/playground/src/dashboard/components/add_ip.vue +++ b/packages/playground/src/dashboard/components/add_ip.vue @@ -125,7 +125,7 @@ Close - Show IPs Range + Show IPs Range Add From a54e6c8acf369bdffc7237b73cb2dac63061b291 Mon Sep 17 00:00:00 2001 From: samaradel Date: Tue, 15 Jul 2025 12:49:44 +0300 Subject: [PATCH 5/5] Fix linting --- .../src/components/node_details.vue | 89 +++---------- .../src/components/vm_deployment_table.vue | 118 ++++-------------- 2 files changed, 39 insertions(+), 168 deletions(-) diff --git a/packages/playground/src/components/node_details.vue b/packages/playground/src/components/node_details.vue index 20200034ef..6f47332144 100644 --- a/packages/playground/src/components/node_details.vue +++ b/packages/playground/src/components/node_details.vue @@ -1,7 +1,7 @@