formatting
This commit is contained in:
parent
891abae528
commit
078626052f
3 changed files with 88 additions and 78 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { cloneDeep, flow } from "lodash";
|
import { cloneDeep } from "lodash";
|
||||||
import React, { useContext, useEffect, useRef, useState } from "react";
|
import React, { useContext, useEffect, useRef, useState } from "react";
|
||||||
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
import { Handle, Position, useUpdateNodeInternals } from "reactflow";
|
||||||
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
import ShadTooltip from "../../../../components/ShadTooltipComponent";
|
||||||
|
|
@ -14,6 +14,7 @@ import PromptAreaComponent from "../../../../components/promptComponent";
|
||||||
import TextAreaComponent from "../../../../components/textAreaComponent";
|
import TextAreaComponent from "../../../../components/textAreaComponent";
|
||||||
import ToggleShadComponent from "../../../../components/toggleShadComponent";
|
import ToggleShadComponent from "../../../../components/toggleShadComponent";
|
||||||
import { MAX_LENGTH_TO_SCROLL_TOOLTIP } from "../../../../constants/constants";
|
import { MAX_LENGTH_TO_SCROLL_TOOLTIP } from "../../../../constants/constants";
|
||||||
|
import { PopUpContext } from "../../../../contexts/popUpContext";
|
||||||
import { TabsContext } from "../../../../contexts/tabsContext";
|
import { TabsContext } from "../../../../contexts/tabsContext";
|
||||||
import { typesContext } from "../../../../contexts/typesContext";
|
import { typesContext } from "../../../../contexts/typesContext";
|
||||||
import { ParameterComponentType } from "../../../../types/components";
|
import { ParameterComponentType } from "../../../../types/components";
|
||||||
|
|
@ -51,6 +52,7 @@ 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 { closeEdit } = useContext(PopUpContext);
|
||||||
|
|
||||||
// Update component position
|
// Update component position
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -100,25 +102,33 @@ export default function ParameterComponent({
|
||||||
);
|
);
|
||||||
}, [info]);
|
}, [info]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let groupedObj = groupByFamily(myData, tooltipTitle, left, data.type, flows.find((f) => f.id === tabId).data.nodes);
|
console.log(flows.find((f) => f.id === tabId).data.nodes);
|
||||||
|
|
||||||
if(groupedObj?.length === 0){
|
|
||||||
groupedObj = groupByFamilyCustom(myData, tooltipTitle, left, data.type, flows.find((f) => f.id === tabId).data.nodes)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let groupedObj = groupByFamily(
|
||||||
|
myData,
|
||||||
|
tooltipTitle,
|
||||||
|
left,
|
||||||
|
data.type,
|
||||||
|
flows.find((f) => f.id === tabId).data.nodes
|
||||||
|
);
|
||||||
|
|
||||||
if(groupedObj){
|
if (groupedObj?.length === 0) {
|
||||||
|
groupedObj = groupByFamilyCustom(
|
||||||
|
myData,
|
||||||
|
tooltipTitle,
|
||||||
|
left,
|
||||||
|
data.type,
|
||||||
|
flows.find((f) => f.id === tabId).data.nodes
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (groupedObj) {
|
||||||
refNumberComponents.current = groupedObj[0]?.type?.length;
|
refNumberComponents.current = groupedObj[0]?.type?.length;
|
||||||
|
|
||||||
refHtml.current = groupedObj.map((item, i) => {
|
refHtml.current = groupedObj.map((item, i) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const Icon: any = nodeIconsLucide[item.family];
|
const Icon: any = nodeIconsLucide[item.family];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
key={getRandomKeyByssmm() + item.family + i}
|
key={getRandomKeyByssmm() + item.family + i}
|
||||||
|
|
@ -141,31 +151,34 @@ export default function ParameterComponent({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className="ps-2 text-xs text-foreground">
|
<span className="ps-2 text-xs text-foreground">
|
||||||
{item.family !== 'custom_components' ? nodeNames[item.family] : item.component ?? ""}{" "}
|
{item.family !== "custom_components"
|
||||||
<span className="text-xs">
|
? nodeNames[item.family]
|
||||||
{" "}
|
: item.component ?? ""}{" "}
|
||||||
{item.type === "" ? "" : " - "}
|
<span className="text-xs">
|
||||||
{item.type.split(", ").length > 2
|
{" "}
|
||||||
? item.type.split(", ").map((el, i) => (
|
{item.type === "" ? "" : " - "}
|
||||||
<React.Fragment key={el + i}>
|
{item.type.split(", ").length > 2
|
||||||
<span>
|
? item.type.split(", ").map((el, i) => (
|
||||||
{i === item.type.split(", ").length - 1
|
<React.Fragment key={el + i}>
|
||||||
? el
|
<span>
|
||||||
: (el += `, `)}
|
{i === item.type.split(", ").length - 1
|
||||||
</span>
|
? el
|
||||||
</React.Fragment>
|
: (el += `, `)}
|
||||||
))
|
</span>
|
||||||
: item.type}
|
</React.Fragment>
|
||||||
|
))
|
||||||
|
: item.type}
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</span>
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}, [
|
||||||
|
tooltipTitle,
|
||||||
}, [tooltipTitle, flows.find((f) => f.id === tabId).data.nodes]);
|
flows.find((f) => f.id === tabId).data.nodes.length,
|
||||||
|
closeEdit,
|
||||||
|
]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,11 @@ import { Button } from "../../components/ui/button";
|
||||||
import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants/constants";
|
import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants/constants";
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
import { alertContext } from "../../contexts/alertContext";
|
||||||
import { darkContext } from "../../contexts/darkContext";
|
import { darkContext } from "../../contexts/darkContext";
|
||||||
|
import { PopUpContext } from "../../contexts/popUpContext";
|
||||||
import { typesContext } from "../../contexts/typesContext";
|
import { typesContext } from "../../contexts/typesContext";
|
||||||
import { postCustomComponent, postValidateCode } from "../../controllers/API";
|
import { postCustomComponent, postValidateCode } from "../../controllers/API";
|
||||||
import { APIClassType } from "../../types/api";
|
import { APIClassType } from "../../types/api";
|
||||||
|
import { getRandomKeyByssmm } from "../../utils/utils";
|
||||||
import BaseModal from "../baseModal";
|
import BaseModal from "../baseModal";
|
||||||
|
|
||||||
export default function CodeAreaModal({
|
export default function CodeAreaModal({
|
||||||
|
|
@ -39,6 +41,7 @@ export default function CodeAreaModal({
|
||||||
const [error, setError] = useState<{
|
const [error, setError] = useState<{
|
||||||
detail: { error: string; traceback: string };
|
detail: { error: string; traceback: string };
|
||||||
}>(null);
|
}>(null);
|
||||||
|
const { setCloseEdit } = useContext(PopUpContext);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// if nodeClass.template has more fields other than code and dynamic is true
|
// if nodeClass.template has more fields other than code and dynamic is true
|
||||||
|
|
@ -61,6 +64,7 @@ export default function CodeAreaModal({
|
||||||
});
|
});
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
setValue(code);
|
setValue(code);
|
||||||
|
setCloseEdit(getRandomKeyByssmm().toString());
|
||||||
// setValue(code);
|
// setValue(code);
|
||||||
} else {
|
} else {
|
||||||
if (funcErrors.length !== 0) {
|
if (funcErrors.length !== 0) {
|
||||||
|
|
@ -97,6 +101,7 @@ export default function CodeAreaModal({
|
||||||
setNodeClass(data);
|
setNodeClass(data);
|
||||||
setValue(code);
|
setValue(code);
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
|
setCloseEdit(getRandomKeyByssmm().toString());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,6 @@ export function groupByFamily(data, baseClasses, left, type, flow) {
|
||||||
export function groupByFamilyCustom(data, baseClasses, left, type, flow) {
|
export function groupByFamilyCustom(data, baseClasses, left, type, flow) {
|
||||||
let arrOfParentCustom: string[] = [];
|
let arrOfParentCustom: string[] = [];
|
||||||
let arrOfType: { family: string; type: string; component: string }[] = [];
|
let arrOfType: { family: string; type: string; component: string }[] = [];
|
||||||
|
|
||||||
|
|
||||||
if (type === "CustomComponent") {
|
if (type === "CustomComponent") {
|
||||||
const uniqueValuesSet = new Set();
|
const uniqueValuesSet = new Set();
|
||||||
|
|
@ -222,8 +221,6 @@ export function groupByFamilyCustom(data, baseClasses, left, type, flow) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (left === false) {
|
if (left === false) {
|
||||||
arrOfParentCustom.map((n) => {
|
arrOfParentCustom.map((n) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -236,13 +233,13 @@ export function groupByFamilyCustom(data, baseClasses, left, type, flow) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
flow.forEach((element) => {
|
flow.forEach((element) => {
|
||||||
Object.keys(element["data"]["node"]["template"]).map((el) => {
|
Object.keys(element["data"]["node"]["template"]).map((el) => {
|
||||||
if(element["data"]["node"]["template"][el].input_types && element["data"]["node"]["template"][el].input_types.length > 0){
|
if (
|
||||||
|
element["data"]["node"]["template"][el].input_types &&
|
||||||
|
element["data"]["node"]["template"][el].input_types.length > 0
|
||||||
|
) {
|
||||||
element["data"]["node"]["template"][el].input_types.map((n) => {
|
element["data"]["node"]["template"][el].input_types.map((n) => {
|
||||||
try {
|
try {
|
||||||
arrOfType.push({
|
arrOfType.push({
|
||||||
|
|
@ -255,52 +252,47 @@ export function groupByFamilyCustom(data, baseClasses, left, type, flow) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const groupedResult = {};
|
const groupedResult = {};
|
||||||
|
|
||||||
arrOfType.forEach((item) => {
|
arrOfType.forEach((item) => {
|
||||||
const { family, type, component } = item;
|
const { family, type, component } = item;
|
||||||
if (groupedResult.hasOwnProperty(family)) {
|
if (groupedResult.hasOwnProperty(family)) {
|
||||||
if (!groupedResult[family].type.includes(type)) {
|
if (!groupedResult[family].type.includes(type)) {
|
||||||
groupedResult[family].type += `, ${type}`;
|
groupedResult[family].type += `, ${type}`;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
groupedResult[family] = { family, type, component };
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
const result = Object.values(groupedResult);
|
|
||||||
|
|
||||||
if(left === false)
|
|
||||||
{
|
|
||||||
let resultFiltered = [];
|
|
||||||
flow.forEach((element) => {
|
|
||||||
Object.keys(element["data"]["node"]["template"]).map((el) => {
|
|
||||||
if(element["data"]["node"]["template"][el].input_types && element["data"]["node"]["template"][el].input_types.length > 0){
|
|
||||||
element["data"]["node"]["template"][el].input_types.map((n) => {
|
|
||||||
resultFiltered.push({
|
|
||||||
family: "custom_components",
|
|
||||||
type: n,
|
|
||||||
component: element["data"]["node"]["display_name"],
|
|
||||||
})
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
|
groupedResult[family] = { family, type, component };
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return resultFiltered;
|
|
||||||
}
|
|
||||||
|
|
||||||
else{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const result = Object.values(groupedResult);
|
||||||
|
|
||||||
|
if (left === false) {
|
||||||
|
let resultFiltered = [];
|
||||||
|
flow.forEach((element) => {
|
||||||
|
Object.keys(element["data"]["node"]["template"]).map((el) => {
|
||||||
|
if (
|
||||||
|
element["data"]["node"]["template"][el].input_types &&
|
||||||
|
element["data"]["node"]["template"][el].input_types.length > 0
|
||||||
|
) {
|
||||||
|
element["data"]["node"]["template"][el].input_types.map((n) => {
|
||||||
|
resultFiltered.push({
|
||||||
|
family: "custom_components",
|
||||||
|
type: n,
|
||||||
|
component: element["data"]["node"]["display_name"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return resultFiltered;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildInputs(tabsState, id) {
|
export function buildInputs(tabsState, id) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue