🐛 fix(keypairListComponent): fix bug where onChange event was not updating the correct value in the ref object
✨ feat(keypairListComponent): add support for dataValue prop to pass down initial data value to the component ✨ feat(EditNodeModal): add support for dataValue state to store the current data value ✨ feat(EditNodeModal): pass down dataValue prop to KeypairListComponent to initialize the component with the current data value ✨ feat(types): add dataValue property to KeyPairListComponentType to reflect the changes in the component
This commit is contained in:
parent
9d9a1177f2
commit
4e48360e2a
3 changed files with 12 additions and 9 deletions
|
|
@ -13,6 +13,7 @@ export default function KeypairListComponent({
|
||||||
editNode = false,
|
editNode = false,
|
||||||
duplicateKey,
|
duplicateKey,
|
||||||
advanced = false,
|
advanced = false,
|
||||||
|
dataValue,
|
||||||
}: KeyPairListComponentType): JSX.Element {
|
}: KeyPairListComponentType): JSX.Element {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
|
|
@ -30,18 +31,16 @@ export default function KeypairListComponent({
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
const handleChangeKey = (event, idx) => {
|
const handleChangeKey = (event, idx) => {
|
||||||
const newInputList = _.cloneDeep(ref.current);
|
const oldKey = Object.keys(ref.current[idx])[0];
|
||||||
const oldKey = Object.keys(newInputList[idx])[0];
|
const updatedObj = { [event.target.value]: ref.current[idx][oldKey] };
|
||||||
const updatedObj = { [event.target.value]: newInputList[idx][oldKey] };
|
ref.current[idx] = updatedObj;
|
||||||
newInputList[idx] = updatedObj;
|
onChange(ref.current);
|
||||||
onChange(newInputList);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChangeValue = (newValue, idx) => {
|
const handleChangeValue = (newValue, idx) => {
|
||||||
const newInputList = _.cloneDeep(ref.current);
|
const key = Object.keys(ref.current[idx])[0];
|
||||||
const key = Object.keys(newInputList[idx])[0];
|
ref.current[idx][key] = newValue;
|
||||||
newInputList[idx][key] = newValue;
|
onChange(ref.current);
|
||||||
onChange(newInputList);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ const EditNodeModal = forwardRef(
|
||||||
|
|
||||||
const handleOnNewValue = (newValue: any, name) => {
|
const handleOnNewValue = (newValue: any, name) => {
|
||||||
myData.current.node!.template[name].value = newValue;
|
myData.current.node!.template[name].value = newValue;
|
||||||
|
setDataValue(newValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -90,6 +91,7 @@ const EditNodeModal = forwardRef(
|
||||||
|
|
||||||
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
|
||||||
const [adv, setAdv] = useState<boolean | null>(null);
|
const [adv, setAdv] = useState<boolean | null>(null);
|
||||||
|
const [dataValue, setDataValue] = useState(data);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseModal
|
<BaseModal
|
||||||
|
|
@ -268,6 +270,7 @@ const EditNodeModal = forwardRef(
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<KeypairListComponent
|
<KeypairListComponent
|
||||||
|
dataValue={dataValue}
|
||||||
advanced={adv}
|
advanced={adv}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
editNode={true}
|
editNode={true}
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ export type KeyPairListComponentType = {
|
||||||
editNode?: boolean;
|
editNode?: boolean;
|
||||||
duplicateKey?: boolean;
|
duplicateKey?: boolean;
|
||||||
advanced?: boolean | null;
|
advanced?: boolean | null;
|
||||||
|
dataValue?: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DictComponentType = {
|
export type DictComponentType = {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue