fix: Add TableNodeComponent and set default formatter type (#3382)

* feat: Add TableNodeComponent for rendering table data in ParameterRenderComponent

* refactor: Set default formatter type for columns in FormatColumns function

* [autofix.ci] apply automated fixes

* refactor: Improve object rendering in ObjectRender component

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
anovazzi1 2024-08-16 11:47:44 -03:00 • committed by GitHub
commit 26bc6bc645
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 33 additions and 13 deletions

View file

@ -7,12 +7,20 @@ export default function ObjectRender({
object: any; object: any;
setValue?: (value: any) => void; setValue?: (value: any) => void;
}): JSX.Element { }): JSX.Element {
let preview = let newObject = object;
object === null || object === undefined ? "‎" : JSON.stringify(object); if (typeof object === "string") {
if (object === null || object === undefined) { try {
newObject = JSON.parse(object);
} catch (e) {
newObject = object;
} }
}
let preview =
newObject === null || newObject === undefined
? "‎"
: JSON.stringify(newObject);
return ( return (
<DictAreaModal onChange={setValue} value={object ?? {}}> <DictAreaModal onChange={setValue} value={newObject ?? {}}>
<div className="flex h-full w-full items-center align-middle transition-all"> <div className="flex h-full w-full items-center align-middle transition-all">
<div className="truncate">{preview}</div> <div className="truncate">{preview}</div>
</div> </div>

View file

@ -2,6 +2,7 @@ import { handleOnNewValueType } from "@/CustomNodes/hooks/use-handle-new-value";
import { TEXT_FIELD_TYPES } from "@/constants/constants"; import { TEXT_FIELD_TYPES } from "@/constants/constants";
import { APIClassType, InputFieldType } from "@/types/api"; import { APIClassType, InputFieldType } from "@/types/api";
import { useMemo } from "react"; import { useMemo } from "react";
import TableNodeComponent from "../TableNodeComponent";
import CodeAreaComponent from "../codeAreaComponent"; import CodeAreaComponent from "../codeAreaComponent";
import DictComponent from "../dictComponent"; import DictComponent from "../dictComponent";
import FloatComponent from "../floatComponent"; import FloatComponent from "../floatComponent";
@ -146,6 +147,14 @@ export function ParameterRenderComponent({
/> />
) : templateData.type === "Any" ? ( ) : templateData.type === "Any" ? (
<>-</> <>-</>
) : templateData.type === "table" ? (
<TableNodeComponent
description={templateData.info || "Add or edit data"}
columns={templateData?.table_schema?.columns}
onChange={onChange}
tableTitle={templateData?.display_name ?? "Table"}
value={templateValue}
/>
) : ( ) : (
String(templateValue) String(templateValue)
)} )}

View file

@ -646,6 +646,7 @@ export const LANGFLOW_SUPPORTED_TYPES = new Set([
"int", "int",
"dict", "dict",
"NestedDict", "NestedDict",
"table",
]); ]);
export const priorityFields = new Set(["code", "template"]); export const priorityFields = new Set(["code", "template"]);

View file

@ -77,6 +77,7 @@ export type InputFieldType = {
refresh_button?: boolean; refresh_button?: boolean;
refresh_button_text?: string; refresh_button_text?: string;
combobox?: boolean; combobox?: boolean;
info?: string;
[key: string]: any; [key: string]: any;
}; };

View file

@ -502,7 +502,9 @@ export function FormatColumns(columns: ColumnField[]): ColDef<any>[] {
sortable: col.sortable, sortable: col.sortable,
filter: col.filterable, filter: col.filterable,
}; };
if (col.formatter) { if (!col.formatter) {
col.formatter = FormatterType.text;
}
if (basic_types.has(col.formatter)) { if (basic_types.has(col.formatter)) {
newCol.cellDataType = col.formatter; newCol.cellDataType = col.formatter;
} else { } else {
@ -511,7 +513,6 @@ export function FormatColumns(columns: ColumnField[]): ColDef<any>[] {
}; };
newCol.cellRenderer = TableAutoCellRender; newCol.cellRenderer = TableAutoCellRender;
} }
}
return newCol; return newCol;
}); });