Refactor code to improve performance and readability
This commit is contained in:
parent
5a5a5bba55
commit
b83ffc87b2
1 changed files with 43 additions and 58 deletions
|
|
@ -138,8 +138,9 @@ export default function GenericNode({
|
||||||
const iconColor = nodeColors[types[data.type]];
|
const iconColor = nodeColors[types[data.type]];
|
||||||
const iconName =
|
const iconName =
|
||||||
iconElement || (data.node?.flow ? "group_components" : name);
|
iconElement || (data.node?.flow ? "group_components" : name);
|
||||||
const iconClassName = `generic-node-icon ${!showNode ? " absolute inset-x-6 h-12 w-12 " : ""
|
const iconClassName = `generic-node-icon ${
|
||||||
}`;
|
!showNode ? " absolute inset-x-6 h-12 w-12 " : ""
|
||||||
|
}`;
|
||||||
if (iconElement && isEmoji) {
|
if (iconElement && isEmoji) {
|
||||||
return nodeIconFragment(iconElement);
|
return nodeIconFragment(iconElement);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -267,7 +268,7 @@ export default function GenericNode({
|
||||||
numberOfHandles={handles}
|
numberOfHandles={handles}
|
||||||
showNode={showNode}
|
showNode={showNode}
|
||||||
openAdvancedModal={false}
|
openAdvancedModal={false}
|
||||||
onCloseAdvancedModal={() => { }}
|
onCloseAdvancedModal={() => {}}
|
||||||
selected={selected}
|
selected={selected}
|
||||||
></NodeToolbarComponent>
|
></NodeToolbarComponent>
|
||||||
</NodeToolbar>
|
</NodeToolbar>
|
||||||
|
|
@ -389,28 +390,13 @@ export default function GenericNode({
|
||||||
})}
|
})}
|
||||||
data={data}
|
data={data}
|
||||||
color={
|
color={
|
||||||
data.node?.template[templateField].input_types &&
|
nodeColors[
|
||||||
data.node?.template[templateField].input_types!
|
|
||||||
.length > 0
|
|
||||||
? nodeColors[
|
|
||||||
data.node?.template[templateField]
|
|
||||||
.input_types![data.node?.template[templateField]
|
|
||||||
.input_types!.length - 1]
|
|
||||||
] ??
|
|
||||||
nodeColors[
|
|
||||||
types[
|
|
||||||
data.node?.template[templateField]
|
|
||||||
.input_types![data.node?.template[templateField]
|
|
||||||
.input_types!.length - 1]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
: nodeColors[
|
|
||||||
data.node?.template[templateField].type!
|
|
||||||
] ??
|
|
||||||
nodeColors[
|
|
||||||
types[data.node?.template[templateField].type!]
|
types[data.node?.template[templateField].type!]
|
||||||
] ??
|
] ??
|
||||||
nodeColors.unknown
|
nodeColors[
|
||||||
|
data.node?.template[templateField].type!
|
||||||
|
] ??
|
||||||
|
nodeColors.unknown
|
||||||
}
|
}
|
||||||
title={getFieldTitle(
|
title={getFieldTitle(
|
||||||
data.node?.template!,
|
data.node?.template!,
|
||||||
|
|
@ -454,7 +440,7 @@ export default function GenericNode({
|
||||||
color={nodeColors[types[data.type]] ?? nodeColors.unknown}
|
color={nodeColors[types[data.type]] ?? nodeColors.unknown}
|
||||||
title={
|
title={
|
||||||
data.node?.output_types &&
|
data.node?.output_types &&
|
||||||
data.node.output_types.length > 0
|
data.node.output_types.length > 0
|
||||||
? data.node.output_types.join(" | ")
|
? data.node.output_types.join(" | ")
|
||||||
: data.type
|
: data.type
|
||||||
}
|
}
|
||||||
|
|
@ -475,6 +461,12 @@ export default function GenericNode({
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
className={"group h-9 px-1.5"}
|
className={"group h-9 px-1.5"}
|
||||||
|
onClick={() => {
|
||||||
|
if (buildStatus === BuildStatus.BUILDING || isBuilding)
|
||||||
|
return;
|
||||||
|
setValidationStatus(null);
|
||||||
|
buildFlow({ nodeId: data.id });
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
<ShadTooltip
|
<ShadTooltip
|
||||||
|
|
@ -487,22 +479,17 @@ export default function GenericNode({
|
||||||
<div className="max-h-96 overflow-auto">
|
<div className="max-h-96 overflow-auto">
|
||||||
{typeof validationStatus.params === "string"
|
{typeof validationStatus.params === "string"
|
||||||
? `${durationString}\n${validationStatus.params}`
|
? `${durationString}\n${validationStatus.params}`
|
||||||
.split("\n")
|
.split("\n")
|
||||||
.map((line, index) => (
|
.map((line, index) => (
|
||||||
<div key={index}>{line}</div>
|
<div key={index}>{line}</div>
|
||||||
))
|
))
|
||||||
: durationString}
|
: durationString}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
side="bottom"
|
side="bottom"
|
||||||
>
|
>
|
||||||
<div onClick={() => {
|
<div className="generic-node-status-position flex items-center justify-center">
|
||||||
if (buildStatus === BuildStatus.BUILDING || isBuilding)
|
|
||||||
return;
|
|
||||||
setValidationStatus(null);
|
|
||||||
buildFlow({ nodeId: data.id });
|
|
||||||
}} className="generic-node-status-position flex items-center justify-center">
|
|
||||||
{renderIconStatus(buildStatus, validationStatus)}
|
{renderIconStatus(buildStatus, validationStatus)}
|
||||||
</div>
|
</div>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
|
|
@ -582,7 +569,7 @@ export default function GenericNode({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{(data.node?.description === "" || !data.node?.description) &&
|
{(data.node?.description === "" || !data.node?.description) &&
|
||||||
nameEditable
|
nameEditable
|
||||||
? "Double Click to Edit Description"
|
? "Double Click to Edit Description"
|
||||||
: data.node?.description}
|
: data.node?.description}
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -603,7 +590,7 @@ export default function GenericNode({
|
||||||
.map((templateField: string, idx) => (
|
.map((templateField: string, idx) => (
|
||||||
<div key={idx}>
|
<div key={idx}>
|
||||||
{data.node!.template[templateField].show &&
|
{data.node!.template[templateField].show &&
|
||||||
!data.node!.template[templateField].advanced ? (
|
!data.node!.template[templateField].advanced ? (
|
||||||
<ParameterComponent
|
<ParameterComponent
|
||||||
index={idx.toString()}
|
index={idx.toString()}
|
||||||
key={scapedJSONStringfy({
|
key={scapedJSONStringfy({
|
||||||
|
|
@ -617,27 +604,25 @@ export default function GenericNode({
|
||||||
data={data}
|
data={data}
|
||||||
color={
|
color={
|
||||||
data.node?.template[templateField].input_types &&
|
data.node?.template[templateField].input_types &&
|
||||||
data.node?.template[templateField].input_types!
|
data.node?.template[templateField].input_types!
|
||||||
.length > 0
|
.length > 0
|
||||||
? nodeColors[
|
? nodeColors[
|
||||||
data.node?.template[templateField]
|
data.node?.template[templateField]
|
||||||
.input_types![data.node?.template[templateField]
|
.input_types![0]
|
||||||
.input_types!.length - 1]
|
] ??
|
||||||
] ??
|
nodeColors[
|
||||||
nodeColors[
|
types[
|
||||||
types[
|
data.node?.template[templateField]
|
||||||
data.node?.template[templateField]
|
.input_types![0]
|
||||||
.input_types![data.node?.template[templateField]
|
]
|
||||||
.input_types!.length - 1]
|
]
|
||||||
]
|
|
||||||
]
|
|
||||||
: nodeColors[
|
: nodeColors[
|
||||||
data.node?.template[templateField].type!
|
data.node?.template[templateField].type!
|
||||||
] ??
|
] ??
|
||||||
nodeColors[
|
nodeColors[
|
||||||
types[data.node?.template[templateField].type!]
|
types[data.node?.template[templateField].type!]
|
||||||
] ??
|
] ??
|
||||||
nodeColors.unknown
|
nodeColors.unknown
|
||||||
}
|
}
|
||||||
title={getFieldTitle(
|
title={getFieldTitle(
|
||||||
data.node?.template!,
|
data.node?.template!,
|
||||||
|
|
@ -689,9 +674,9 @@ export default function GenericNode({
|
||||||
data={data}
|
data={data}
|
||||||
color={
|
color={
|
||||||
(data.node?.output_types &&
|
(data.node?.output_types &&
|
||||||
data.node.output_types.length > 0
|
data.node.output_types.length > 0
|
||||||
? nodeColors[data.node.output_types[0]] ??
|
? nodeColors[data.node.output_types[0]] ??
|
||||||
nodeColors[types[data.node.output_types[0]]]
|
nodeColors[types[data.node.output_types[0]]]
|
||||||
: nodeColors[types[data.type]]) ?? nodeColors.unknown
|
: nodeColors[types[data.type]]) ?? nodeColors.unknown
|
||||||
}
|
}
|
||||||
title={
|
title={
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue