🐛 fix(parameterComponent): fix linting issues and add missing import
✨ feat(parameterComponent): add support for custom components in groupByFamily function ✨ feat(utils): add groupByFamilyCustom function to handle custom components in groupByFamily function
This commit is contained in:
parent
530d416735
commit
891abae528
2 changed files with 142 additions and 35 deletions
|
|
@ -27,6 +27,7 @@ import {
|
||||||
classNames,
|
classNames,
|
||||||
getRandomKeyByssmm,
|
getRandomKeyByssmm,
|
||||||
groupByFamily,
|
groupByFamily,
|
||||||
|
groupByFamilyCustom,
|
||||||
} from "../../../../utils/utils";
|
} from "../../../../utils/utils";
|
||||||
|
|
||||||
export default function ParameterComponent({
|
export default function ParameterComponent({
|
||||||
|
|
@ -99,21 +100,23 @@ export default function ParameterComponent({
|
||||||
);
|
);
|
||||||
}, [info]);
|
}, [info]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
let groupedObj = groupByFamily(myData, tooltipTitle, left, data.type, 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
console.log("mydata", myData);
|
if(groupedObj){
|
||||||
console.log("tooltipTitle", tooltipTitle);
|
|
||||||
console.log("left", left);
|
|
||||||
console.log("data.type", data.type);
|
|
||||||
console.log("flows", flows);
|
|
||||||
|
|
||||||
|
|
||||||
const groupedObj = groupByFamily(myData, tooltipTitle, left, data.type);
|
|
||||||
|
|
||||||
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 (
|
||||||
|
|
@ -138,7 +141,7 @@ export default function ParameterComponent({
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className="ps-2 text-xs text-foreground">
|
<span className="ps-2 text-xs text-foreground">
|
||||||
{nodeNames[item.family] ?? ""}{" "}
|
{item.family !== 'custom_components' ? nodeNames[item.family] : item.component ?? ""}{" "}
|
||||||
<span className="text-xs">
|
<span className="text-xs">
|
||||||
{" "}
|
{" "}
|
||||||
{item.type === "" ? "" : " - "}
|
{item.type === "" ? "" : " - "}
|
||||||
|
|
@ -155,10 +158,14 @@ export default function ParameterComponent({
|
||||||
: item.type}
|
: item.type}
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}, [tooltipTitle]);
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}, [tooltipTitle, flows.find((f) => f.id === tabId).data.nodes]);
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { IVarHighlightType } from "../types/components";
|
||||||
import { FlowType } from "../types/flow";
|
import { FlowType } from "../types/flow";
|
||||||
import { TabsState } from "../types/tabs";
|
import { TabsState } from "../types/tabs";
|
||||||
import { buildTweaks } from "./reactflowUtils";
|
import { buildTweaks } from "./reactflowUtils";
|
||||||
|
import { nodeNames } from "./styleUtils";
|
||||||
|
|
||||||
export function classNames(...classes: Array<string>) {
|
export function classNames(...classes: Array<string>) {
|
||||||
return classes.filter(Boolean).join(" ");
|
return classes.filter(Boolean).join(" ");
|
||||||
|
|
@ -88,12 +89,13 @@ export function checkUpperWords(str: string) {
|
||||||
export const isWrappedWithClass = (event: any, className: string | undefined) =>
|
export const isWrappedWithClass = (event: any, className: string | undefined) =>
|
||||||
event.target.closest(`.${className}`);
|
event.target.closest(`.${className}`);
|
||||||
|
|
||||||
export function groupByFamily(data, baseClasses, left, type) {
|
export function groupByFamily(data, baseClasses, left, type, flow) {
|
||||||
let parentOutput: string;
|
let parentOutput: string;
|
||||||
let arrOfParent: string[] = [];
|
let arrOfParent: string[] = [];
|
||||||
let arrOfType: { family: string; type: string; component: string }[] = [];
|
let arrOfType: { family: string; type: string; component: string }[] = [];
|
||||||
let arrOfLength: { length: number; type: string }[] = [];
|
let arrOfLength: { length: number; type: string }[] = [];
|
||||||
let lastType = "";
|
let lastType = "";
|
||||||
|
|
||||||
Object.keys(data).forEach((d) => {
|
Object.keys(data).forEach((d) => {
|
||||||
Object.keys(data[d]).forEach((n) => {
|
Object.keys(data[d]).forEach((n) => {
|
||||||
try {
|
try {
|
||||||
|
|
@ -203,6 +205,104 @@ export function groupByFamily(data, baseClasses, left, type) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function groupByFamilyCustom(data, baseClasses, left, type, flow) {
|
||||||
|
let arrOfParentCustom: string[] = [];
|
||||||
|
let arrOfType: { family: string; type: string; component: string }[] = [];
|
||||||
|
|
||||||
|
|
||||||
|
if (type === "CustomComponent") {
|
||||||
|
const uniqueValuesSet = new Set();
|
||||||
|
flow.forEach((element) => {
|
||||||
|
element["data"]["node"]["base_classes"].forEach((el) => {
|
||||||
|
if (!uniqueValuesSet.has(el)) {
|
||||||
|
arrOfParentCustom.push(el);
|
||||||
|
uniqueValuesSet.add(el);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (left === false) {
|
||||||
|
arrOfParentCustom.map((n) => {
|
||||||
|
try {
|
||||||
|
arrOfType.push({
|
||||||
|
family: "custom_components",
|
||||||
|
type: n,
|
||||||
|
component: nodeNames["custom_components"],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
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) => {
|
||||||
|
try {
|
||||||
|
arrOfType.push({
|
||||||
|
family: "custom_components",
|
||||||
|
type: n,
|
||||||
|
component: nodeNames["custom_components"],
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const groupedResult = {};
|
||||||
|
|
||||||
|
arrOfType.forEach((item) => {
|
||||||
|
const { family, type, component } = item;
|
||||||
|
if (groupedResult.hasOwnProperty(family)) {
|
||||||
|
if (!groupedResult[family].type.includes(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"],
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return resultFiltered;
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export function buildInputs(tabsState, id) {
|
export function buildInputs(tabsState, id) {
|
||||||
return tabsState &&
|
return tabsState &&
|
||||||
tabsState[id] &&
|
tabsState[id] &&
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue