🔧 fix(parameterComponent): remove unused longString variable to improve code readability and reduce unnecessary code

🔧 fix(parameterComponent): move DictComponent and KeypairListComponent rendering logic to the correct position to fix rendering issues
🔧 fix(keypairListComponent): remove unused imports and fix formatting to improve code readability
🔧 fix(keypairListComponent): fix handleChangeKey function name to improve code clarity
🔧 fix(keypairListComponent): fix className prop in Input component to improve code readability
🔧 fix(keypairListComponent): remove unused GenericModal component and fix formatting to improve code readability
🔧 fix(reactflowUtils.ts): fix formatting and remove unnecessary whitespace to improve code readability
🔧 fix(reactflowUtils.ts): fix function names and formatting to improve code readability
🔧 fix(reactflowUtils.ts): fix formatting and remove unnecessary whitespace to improve code readability
🔧 fix(reactflowUtils.ts): fix formatting and remove unnecessary whitespace to improve code readability
This commit is contained in:
Cristhian Zanforlin Lousa 2023-09-14 19:53:39 -03:00
commit 1c1d6d2c02
3 changed files with 56 additions and 67 deletions

View file

@ -103,8 +103,6 @@ export default function ParameterComponent({
const [obj, setObj] = useState({ const [obj, setObj] = useState({
arr: ["test", 123456, false, null], arr: ["test", 123456, false, null],
boolean: false, boolean: false,
longString:
"long string long string long string long string long string long string",
number: 123456, number: 123456,
try: { try: {
k1: 123, k1: 123,
@ -239,34 +237,6 @@ export default function ParameterComponent({
type === "int") && type === "int") &&
!optionalHandle ? ( !optionalHandle ? (
<></> <></>
) : left === true && type === "NestedDict" ? (
<div className="mt-2 w-full">
<DictComponent
disabled={disabled}
editNode={false}
value={obj}
onChange={(newValue) => {
setObj(newValue);
}}
/>
</div>
) : left === true && type === "dict" ? (
<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"}
@ -400,6 +370,37 @@ export default function ParameterComponent({
onChange={handleOnNewValue} onChange={handleOnNewValue}
/> />
</div> </div>
) : left === true && type === "NestedDict" ? (
<div className="mt-2 w-full">
<DictComponent
disabled={disabled}
editNode={false}
value={obj}
onChange={(newValue) => {
setObj(newValue);
data.node!.template[name].value = newValue;
console.log(data);
}}
/>
</div>
) : left === true && type === "dict" ? (
<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));
data.node!.template[name].value = convertArrayToObj(newValue);
}
}}
/>
</div>
) : ( ) : (
<></> <></>
)} )}

View file

@ -2,8 +2,6 @@ import { useEffect } from "react";
import { KeyPairListComponentType } from "../../types/components"; import { KeyPairListComponentType } from "../../types/components";
import _ from "lodash"; import _ from "lodash";
import { TypeModal } from "../../constants/enums";
import GenericModal from "../../modals/genericModal";
import { classNames } from "../../utils/utils"; import { classNames } from "../../utils/utils";
import IconComponent from "../genericIconComponent"; import IconComponent from "../genericIconComponent";
import { Input } from "../ui/input"; import { Input } from "../ui/input";
@ -13,7 +11,7 @@ export default function KeypairListComponent({
onChange, onChange,
disabled, disabled,
editNode = false, editNode = false,
duplicateKey duplicateKey,
}: KeyPairListComponentType): JSX.Element { }: KeyPairListComponentType): JSX.Element {
useEffect(() => { useEffect(() => {
if (disabled) { if (disabled) {
@ -56,9 +54,8 @@ export default function KeypairListComponent({
// /> // />
// </div> // </div>
// ) // )
const handleChangeKey = (event, idx) => { const handleChangeKey = (event, idx) => {
const newInputList = _.cloneDeep(value); const newInputList = _.cloneDeep(value);
const oldKey = Object.keys(newInputList[idx])[0]; const oldKey = Object.keys(newInputList[idx])[0];
const updatedObj = { [event.target.value]: newInputList[idx][oldKey] }; const updatedObj = { [event.target.value]: newInputList[idx][oldKey] };
@ -89,10 +86,8 @@ export default function KeypairListComponent({
type="text" type="text"
value={key} value={key}
className={classNames( className={classNames(
editNode editNode ? "input-edit-node" : "",
? "input-edit-node" duplicateKey ? "input-invalid" : ""
: "",
duplicateKey ? "input-invalid" : ""
)} )}
placeholder="Type key..." placeholder="Type key..."
onChange={(event) => handleChangeKey(event, index)} onChange={(event) => handleChangeKey(event, index)}
@ -103,23 +98,17 @@ export default function KeypairListComponent({
} }
}} }}
/> />
<GenericModal
type={TypeModal.TEXT} <Input
disabled={false}
type="text"
value={obj[key]} value={obj[key]}
buttonText="Save" className={editNode ? "input-edit-node" : ""}
modalTitle="Edit Value" placeholder="Click to input a value..."
setValue={(value: string) => { onChange={(event) =>
handleChangeValue(value, index); handleChangeValue(event.target.value, index)
}} }
> />
<Input
disabled={true}
type="text"
value={obj[key]}
className={editNode ? "input-edit-node cursor-pointer" : "cursor-pointer"}
placeholder="Click to input a value..."
/>
</GenericModal>
{index === value.length - 1 ? ( {index === value.length - 1 ? (
<button <button

View file

@ -220,10 +220,9 @@ export function validateNode(
edge.targetHandle.split("|")[2] === node.id edge.targetHandle.split("|")[2] === node.id
) )
? [ ? [
`${type} is missing ${ `${type} is missing ${template.display_name || toNormalCase(template[t].name)
template.display_name || toNormalCase(template[t].name) }.`,
}.`, ]
]
: [] : []
), ),
[] as string[] [] as string[]
@ -290,7 +289,7 @@ export function getConnectedNodes(
return nodes.filter((node) => node.id === targetId || node.id === sourceId); return nodes.filter((node) => node.id === targetId || node.id === sourceId);
} }
export function convertObjToArray(singleObject){ export function convertObjToArray(singleObject) {
let arrConverted: any = []; let arrConverted: any = [];
for (const key in singleObject) { for (const key in singleObject) {
if (singleObject.hasOwnProperty(key)) { if (singleObject.hasOwnProperty(key)) {
@ -303,7 +302,7 @@ export function convertObjToArray(singleObject){
return arrConverted; return arrConverted;
} }
export function convertArrayToObj(newValue){ export function convertArrayToObj(newValue) {
const flattenedObject = {}; const flattenedObject = {};
for (const obj of newValue) { for (const obj of newValue) {
for (const key in obj) { for (const key in obj) {
@ -319,12 +318,12 @@ export function convertArrayToObj(newValue){
export function hasDuplicateKeys(array) { export function hasDuplicateKeys(array) {
const keys = {}; const keys = {};
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; return true;
}
keys[key] = true;
} }
keys[key] = true;
}
} }
return false; return false;
} }