Skip to content

Commit

Permalink
Fix capital errors (langflow-ai#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielluiz committed Nov 1, 2023
2 parents bf01680 + 66cbeb8 commit cbe27f8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 33 deletions.
28 changes: 9 additions & 19 deletions src/frontend/src/CustomNodes/GenericNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
scapedJSONStringfy,
} from "../../utils/reactflowUtils";
import { nodeColors, nodeIconsLucide } from "../../utils/styleUtils";
import { classNames, toTitleCase } from "../../utils/utils";
import { classNames, getFieldTitle } from "../../utils/utils";
import ParameterComponent from "./components/parameterComponent";

export default function GenericNode({
Expand Down Expand Up @@ -239,15 +239,10 @@ export default function GenericNode({
] ??
nodeColors.unknown
}
title={
data.node?.template[templateField].display_name
? data.node.template[templateField].display_name
: data.node?.template[templateField].name
? toTitleCase(
data.node.template[templateField].name
)
: toTitleCase(templateField)
}
title={getFieldTitle(
data.node?.template!,
templateField
)}
info={data.node?.template[templateField].info}
name={templateField}
tooltipTitle={
Expand Down Expand Up @@ -448,15 +443,10 @@ export default function GenericNode({
] ??
nodeColors.unknown
}
title={
data.node?.template[templateField].display_name
? data.node.template[templateField].display_name
: data.node?.template[templateField].name
? toTitleCase(
data.node.template[templateField].name
)
: toTitleCase(templateField)
}
title={getFieldTitle(
data.node?.template!,
templateField
)}
info={data.node?.template[templateField].info}
name={templateField}
tooltipTitle={
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/types/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export type TemplateVariableType = {
dynamic?: boolean;
proxy?: { id: string; field: string };
input_types?: Array<string>;
display_name?: string;
name?: string;
[key: string]: any;
};
export type sendAllProps = {
Expand Down
20 changes: 7 additions & 13 deletions src/frontend/src/utils/reactflowUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
unselectAllNodesType,
updateEdgesHandleIdsType,
} from "../types/utils/reactflowUtils";
import { toNormalCase, toTitleCase } from "./utils";
const uid = new ShortUniqueId({ length: 5 });
import { getFieldTitle } from "./utils";

export function cleanEdges({
flow: { edges, nodes },
Expand Down Expand Up @@ -240,11 +239,7 @@ export function validateNode(node: NodeType, edges: Edge[]): Array<string> {
node.id
)
) {
errors.push(
`${type} is missing ${
template.display_name || toNormalCase(template[t].name)
}.`
);
errors.push(`${type} is missing ${getFieldTitle(template, t)}.`);
} else if (
template[t].type === "dict" &&
template[t].required &&
Expand All @@ -255,15 +250,14 @@ export function validateNode(node: NodeType, edges: Edge[]): Array<string> {
) {
if (hasDuplicateKeys(template[t].value))
errors.push(
`${type} (${
template.display_name || template[t].name
}) contains duplicate keys with the same values.`
`${type} (${getFieldTitle(
template,
t
)}) contains duplicate keys with the same values.`
);
if (hasEmptyKey(template[t].value))
errors.push(
`${type} (${
template.display_name || template[t].name
}) field must not be empty.`
`${type} (${getFieldTitle(template, t)}) field must not be empty.`
);
}
return errors;
Expand Down
17 changes: 16 additions & 1 deletion src/frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import clsx, { ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
import { ADJECTIVES, DESCRIPTIONS, NOUNS } from "../flow_constants";
import { APIDataType, TemplateVariableType } from "../types/api";
import {
APIDataType,
APITemplateType,
TemplateVariableType,
} from "../types/api";
import {
IVarHighlightType,
groupedObjType,
Expand Down Expand Up @@ -550,3 +554,14 @@ export function tabsArray(codes: string[], method: number) {
},
];
}

export function getFieldTitle(
template: APITemplateType,
templateField: string
): string {
return template[templateField].display_name
? template[templateField].display_name!
: template[templateField].name
? toTitleCase(template[templateField].name!)
: toTitleCase(templateField);
}

0 comments on commit cbe27f8

Please sign in to comment.