From 646fd7f1e5ebfcd4500bdc5f77186cbbb1b9bb28 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Wed, 30 Aug 2023 22:10:50 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(keypairListComponent):=20fix?= =?UTF-8?q?=20bug=20where=20changing=20key=20in=20input=20field=20would=20?= =?UTF-8?q?overwrite=20existing=20keys=20=E2=9C=A8=20feat(keypairListCompo?= =?UTF-8?q?nent):=20add=20logic=20to=20append=20a=20counter=20to=20new=20k?= =?UTF-8?q?ey=20if=20it=20already=20exists=20in=20the=20list=20to=20ensure?= =?UTF-8?q?=20uniqueness?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/keypairListComponent/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/frontend/src/components/keypairListComponent/index.tsx b/src/frontend/src/components/keypairListComponent/index.tsx index be6ea1f64..ef30ac331 100644 --- a/src/frontend/src/components/keypairListComponent/index.tsx +++ b/src/frontend/src/components/keypairListComponent/index.tsx @@ -23,11 +23,16 @@ export default function KeypairListComponent({ const handleChangeKey = (event, idx) => { const newInputList = _.cloneDeep(value); const oldKey = Object.keys(newInputList[idx])[0]; - const updatedObj = { [event.target.value]: newInputList[idx][oldKey] }; - newInputList[idx] = updatedObj; + let counter = 1; + let newKey = event.target.value; + while (newInputList.some(obj => Object.keys(obj)[0] === newKey)) { + newKey = `${event.target.value}_${counter}`; + counter++; + } + newInputList[idx] = { [newKey]: newInputList[idx][oldKey] }; onChange(newInputList); }; - + const handleChangeValue = (newValue, idx) => { const newInputList = _.cloneDeep(value); const key = Object.keys(newInputList[idx])[0];