🐛 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:
Cristhian Zanforlin Lousa 2023-07-24 15:10:55 -03:00
commit 891abae528
2 changed files with 142 additions and 35 deletions

View file

@ -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,46 +100,48 @@ 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); refNumberComponents.current = groupedObj[0]?.type?.length;
console.log("left", left);
console.log("data.type", data.type); refHtml.current = groupedObj.map((item, i) => {
console.log("flows", flows);
const groupedObj = groupByFamily(myData, tooltipTitle, left, data.type);
refNumberComponents.current = groupedObj[0]?.type?.length; const Icon: any = nodeIconsLucide[item.family];
refHtml.current = groupedObj.map((item, i) => { return (
const Icon: any = nodeIconsLucide[item.family]; <span
key={getRandomKeyByssmm() + item.family + i}
return ( className={classNames(
<span i > 0 ? "mt-2 flex items-center" : "flex items-center"
key={getRandomKeyByssmm() + item.family + i} )}
className={classNames(
i > 0 ? "mt-2 flex items-center" : "flex items-center"
)}
>
<div
className="h-5 w-5"
style={{
color: nodeColors[item.family],
}}
> >
<Icon <div
className="h-5 w-5" className="h-5 w-5"
strokeWidth={1.5}
style={{ style={{
color: nodeColors[item.family] ?? nodeColors.unknown, color: nodeColors[item.family],
}} }}
/> >
</div> <Icon
<span className="ps-2 text-xs text-foreground"> className="h-5 w-5"
{nodeNames[item.family] ?? ""}{" "} strokeWidth={1.5}
style={{
color: nodeColors[item.family] ?? nodeColors.unknown,
}}
/>
</div>
<span className="ps-2 text-xs text-foreground">
{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}

View file

@ -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] &&