feature: Improve Table customization to enhance ux on tool mode (#5216)
* refactor: Add field validation options to TableOptions * refactor: Add field validation options and trigger text/icon to TableMixin * refactor: Add field validation options and trigger text/icon to TableMixin * refactor: Add field validation options and trigger text/icon to TableMixin * update table trigger for toolmode usage * Refactor table trigger and field validation options - Updated the table trigger for toolmode usage - Added field validation options and trigger text/icon to TableMixin - Modified TableOptions to block certain actions and hide options * Refactor TableOptionsTypeAPI field names for blocking actions * Refactor TableOptions default values for blocking actions * Refactor TableOptions default values for blocking actions * Refactor TableOptions component to include tableOptions prop * Refactor table selection and pagination options * Refactor TOOL_TABLE_SCHEMA to disable sorting and filtering for the "name" and "description" fields * Refactor TableOptions to allow blocking hiding of fields * Refactor TableModal and TableNodeComponent to include support for block hiding columns * Refactor Column model to include support for different edit modes * Refactor TableOptions to include support for field parsers * Refactor TableOptions to include support for field parsers and blocking hiding of fields * Refactor TableOptions to include support for inline editing of fields * Refactor App.css to style large text inputs and text areas in AgGrid * update types * Update table modal to prevent closing the the modal while editing cell * Refactor string manipulation utilities to support parsing and transforming strings based on specified field parsers * add inline input support * Refactor TextModal component to remove close button in the footer * add field parser in context * format code * format code * Add disable_edit field to Column class * Refactor TableNodeComponent to exclude columns with disable_edit field from being editable * [autofix.ci] apply automated fixes * Fix casing in selector text for "Open table" in tableInputComponent tests --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
parent
13a468027b
commit
dffc2d51cd
17 changed files with 320 additions and 41 deletions
|
|
@ -1,3 +1,5 @@
|
|||
from langflow.schema.table import EditMode
|
||||
|
||||
TOOL_OUTPUT_NAME = "component_as_tool"
|
||||
TOOL_OUTPUT_DISPLAY_NAME = "Toolset"
|
||||
TOOLS_METADATA_INPUT_NAME = "tools_metadata"
|
||||
|
|
@ -7,11 +9,17 @@ TOOL_TABLE_SCHEMA = [
|
|||
"display_name": "Name",
|
||||
"type": "str",
|
||||
"description": "Specify the name of the output field.",
|
||||
"sortable": False,
|
||||
"filterable": False,
|
||||
"edit_mode": EditMode.INLINE,
|
||||
},
|
||||
{
|
||||
"name": "description",
|
||||
"display_name": "Description",
|
||||
"type": "str",
|
||||
"description": "Describe the purpose of the output field.",
|
||||
"sortable": False,
|
||||
"filterable": False,
|
||||
"edit_mode": EditMode.INLINE,
|
||||
},
|
||||
]
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ from langflow.schema.artifact import get_artifact_type, post_process_raw
|
|||
from langflow.schema.data import Data
|
||||
from langflow.schema.message import ErrorMessage, Message
|
||||
from langflow.schema.properties import Source
|
||||
from langflow.schema.table import FieldParserType, TableOptions
|
||||
from langflow.services.tracing.schema import Log
|
||||
from langflow.template.field.base import UNDEFINED, Input, Output
|
||||
from langflow.template.frontend_node.custom_components import ComponentFrontendNode
|
||||
|
|
@ -1183,8 +1184,22 @@ class Component(CustomComponent):
|
|||
|
||||
return TableInput(
|
||||
name=TOOLS_METADATA_INPUT_NAME,
|
||||
display_name="Tools Metadata",
|
||||
info="Use the table to configure the tools.",
|
||||
display_name="Toolset configuration",
|
||||
real_time_refresh=True,
|
||||
table_schema=TOOL_TABLE_SCHEMA,
|
||||
value=tool_data,
|
||||
trigger_icon="Hammer",
|
||||
trigger_text="Open toolset",
|
||||
table_options=TableOptions(
|
||||
block_add=True,
|
||||
block_delete=True,
|
||||
block_edit=True,
|
||||
block_sort=True,
|
||||
block_filter=True,
|
||||
block_hide=True,
|
||||
block_select=True,
|
||||
hide_options=True,
|
||||
field_parsers={"name": FieldParserType.SNAKE_CASE},
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from pydantic import (
|
|||
|
||||
from langflow.field_typing.range_spec import RangeSpec
|
||||
from langflow.inputs.validators import CoalesceBool
|
||||
from langflow.schema.table import Column, TableSchema
|
||||
from langflow.schema.table import Column, TableOptions, TableSchema
|
||||
|
||||
|
||||
class FieldTypes(str, Enum):
|
||||
|
|
@ -184,6 +184,9 @@ class SliderMixin(BaseModel):
|
|||
|
||||
class TableMixin(BaseModel):
|
||||
table_schema: TableSchema | list[Column] | None = None
|
||||
trigger_text: str = Field(default="Open table")
|
||||
trigger_icon: str = Field(default="Table")
|
||||
table_options: TableOptions | None = None
|
||||
|
||||
@field_validator("table_schema")
|
||||
@classmethod
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ class FormatterType(str, Enum):
|
|||
boolean = "boolean"
|
||||
|
||||
|
||||
class EditMode(str, Enum):
|
||||
MODAL = "modal"
|
||||
INLINE = "inline"
|
||||
|
||||
|
||||
class Column(BaseModel):
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
name: str
|
||||
|
|
@ -22,6 +27,8 @@ class Column(BaseModel):
|
|||
formatter: FormatterType | str | None = Field(default=None, alias="type")
|
||||
description: str | None = None
|
||||
default: str | None = None
|
||||
disable_edit: bool = Field(default=False)
|
||||
edit_mode: EditMode | None = Field(default=EditMode.MODAL)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def set_display_name(self):
|
||||
|
|
@ -48,3 +55,44 @@ class Column(BaseModel):
|
|||
|
||||
class TableSchema(BaseModel):
|
||||
columns: list[Column]
|
||||
|
||||
|
||||
class FieldValidatorType(str, Enum):
|
||||
"""Enum for field validation types."""
|
||||
|
||||
NO_SPACES = "no_spaces" # Prevents spaces in input
|
||||
LOWERCASE = "lowercase" # Forces lowercase
|
||||
UPPERCASE = "uppercase" # Forces uppercase
|
||||
EMAIL = "email" # Validates email format
|
||||
URL = "url" # Validates URL format
|
||||
ALPHANUMERIC = "alphanumeric" # Only letters and numbers
|
||||
NUMERIC = "numeric" # Only numbers
|
||||
ALPHA = "alpha" # Only letters
|
||||
PHONE = "phone" # Phone number format
|
||||
SLUG = "slug" # URL slug format (lowercase, hyphens)
|
||||
USERNAME = "username" # Alphanumeric with underscores
|
||||
PASSWORD = "password" # Minimum security requirements # noqa: S105
|
||||
|
||||
|
||||
class FieldParserType(str, Enum):
|
||||
"""Enum for field parser types."""
|
||||
|
||||
SNAKE_CASE = "snake_case"
|
||||
CAMEL_CASE = "camel_case"
|
||||
PASCAL_CASE = "pascal_case"
|
||||
KEBAB_CASE = "kebab_case"
|
||||
LOWERCASE = "lowercase"
|
||||
UPPERCASE = "uppercase"
|
||||
|
||||
|
||||
class TableOptions(BaseModel):
|
||||
block_add: bool = Field(default=False)
|
||||
block_delete: bool = Field(default=False)
|
||||
block_edit: bool = Field(default=False)
|
||||
block_sort: bool = Field(default=False)
|
||||
block_filter: bool = Field(default=False)
|
||||
block_hide: bool | list[str] = Field(default=False)
|
||||
block_select: bool = Field(default=False)
|
||||
hide_options: bool = Field(default=False)
|
||||
field_validators: dict[str, list[FieldValidatorType] | FieldValidatorType] | None = Field(default=None)
|
||||
field_parsers: dict[str, list[FieldParserType] | FieldParserType] | None = Field(default=None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue