🐛 fix(keypairListComponent): fix bug where changing key in input field would overwrite existing keys
✨ feat(keypairListComponent): add logic to append a counter to new key if it already exists in the list to ensure uniqueness
This commit is contained in:
parent
66a9056b92
commit
646fd7f1e5
1 changed files with 8 additions and 3 deletions
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue