🔧 fix(parameterComponent): remove unused errorDuplicateKey state variable

🔧 fix(parameterComponent): remove unused dict and dictArr state variables
🔧 fix(parameterComponent): remove unused useEffect hook
🔧 fix(parameterComponent): update onChange handler to setObj instead of setDict
🔧 fix(keypairListComponent): remove commented out code for future feature
🔧 fix(EditNodeModal): update condition to check for "keypairlist" type instead of "keypair" type
🔧 fix(types): update onChange type in DictComponentType to accept any value
🔧 fix(reactflowUtils): remove unnecessary comments and newline at end of file
This commit is contained in:
Cristhian Zanforlin Lousa 2023-09-05 10:58:11 -03:00
commit 28c8b3160e
5 changed files with 42 additions and 39 deletions

View file

@ -54,7 +54,6 @@ export default function ParameterComponent({
const updateNodeInternals = useUpdateNodeInternals(); const updateNodeInternals = useUpdateNodeInternals();
const [position, setPosition] = useState(0); const [position, setPosition] = useState(0);
const { setTabsState, tabId, save, flows } = useContext(TabsContext); const { setTabsState, tabId, save, flows } = useContext(TabsContext);
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null; const flow = flows.find((flow) => flow.id === tabId)?.data?.nodes ?? null;
@ -96,20 +95,6 @@ export default function ParameterComponent({
renderTooltips(); renderTooltips();
}; };
const [dict, setDict] = useState({
key1: "value1",
key2: "value2",
key3: "value3",
key4: "value4",
key5: "value5",
key6: "value6",
} as {});
const [dictArr, setDictArr] = useState([] as string[]);
useEffect(() => {
setDictArr(convertObjToArray(dict));
}, [dict]);
const [obj, setObj] = useState({ const [obj, setObj] = useState({
arr: ["test", 123456, false, null], arr: ["test", 123456, false, null],
@ -248,30 +233,12 @@ export default function ParameterComponent({
editNode={false} editNode={false}
value={obj} value={obj}
onChange={(newValue) => { onChange={(newValue) => {
setDict(newValue); setObj(newValue);
}} }}
/> />
</div> </div>
) )
: left === true && type === "keypair" ? ( : (
<div className="mt-2 w-full">
<KeypairListComponent
disabled={disabled}
editNode={false}
value={dictArr}
duplicateKey={errorDuplicateKey}
onChange={(newValue: string[]) => {
setErrorDuplicateKey(hasDuplicateKeys(newValue));
if(hasDuplicateKeys(newValue)){
setDictArr(newValue);
}
else{
setDict(convertArrayToObj(newValue));
}
}}
/>
</div>
) : (
<ShadTooltip <ShadTooltip
styleClasses={"tooltip-fixed-width custom-scroll nowheel"} styleClasses={"tooltip-fixed-width custom-scroll nowheel"}
delayDuration={0} delayDuration={0}

View file

@ -20,6 +20,42 @@ export default function KeypairListComponent({
onChange([""]); onChange([""]);
} }
}, [disabled]); }, [disabled]);
//when this feature is available, this code below must be in the parent component
// const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
// const [dict, setDict] = useState({
// key1: "value1",
// key2: "value2",
// key3: "value3",
// key4: "value4",
// key5: "value5",
// key6: "value6",
// } as {});
// const [dictArr, setDictArr] = useState([] as string[]);
// useEffect(() => {
// setDictArr(convertObjToArray(dict));
// }, [dict]);
// left === true && type === "keypairlist" ? (
// <div className="mt-2 w-full">
// <KeypairListComponent
// disabled={disabled}
// editNode={false}
// value={dictArr}
// duplicateKey={errorDuplicateKey}
// onChange={(newValue: string[]) => {
// setErrorDuplicateKey(hasDuplicateKeys(newValue));
// if(hasDuplicateKeys(newValue)){
// setDictArr(newValue);
// }
// else{
// setDict(convertArrayToObj(newValue));
// }
// }}
// />
// </div>
// )
const handleChangeKey = (event, idx) => { const handleChangeKey = (event, idx) => {

View file

@ -219,7 +219,7 @@ const EditNodeModal = forwardRef(
</div> </div>
) )
: myData.node?.template[templateParam] : myData.node?.template[templateParam]
.type === "keypair" ? ( .type === "keypairlist" ? (
<div className="mt-2 w-full"> <div className="mt-2 w-full">
<KeypairListComponent <KeypairListComponent
disabled={disabled} disabled={disabled}

View file

@ -64,7 +64,7 @@ export type KeyPairListComponentType = {
export type DictComponentType = { export type DictComponentType = {
value: any; value: any;
onChange: (value: string[]) => void; onChange: (value) => void;
disabled: boolean; disabled: boolean;
editNode?: boolean; editNode?: boolean;
}; };

View file

@ -321,10 +321,10 @@ export function hasDuplicateKeys(array) {
for (const obj of array) { for (const obj of array) {
for (const key in obj) { for (const key in obj) {
if (keys[key]) { if (keys[key]) {
return true; // Duplicate key found return true;
} }
keys[key] = true; keys[key] = true;
} }
} }
return false; // No duplicate keys found return false;
} }