feat: Add default value support for table columns (#4043)
* Add 'type', 'description', and 'default' fields to Table schema and enhance formatter validation * Add type-based mapping to formatter validator in table schema * Add default value support for new table rows in TableNodeComponent * Add optional 'description' and 'default' fields to ColumnField interface * Add default value inference for table columns in utils.ts - Initialize 'default' property for table columns to null. - Infer default value from the first row of data if available. - Adjust column formatter determination based on sample value. * Add default table input validation and update formatter logic in Column model * Add unit tests for Column class in table schema module --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
90b2c9d577
commit
65153374ed
5 changed files with 100 additions and 10 deletions
|
|
@ -1,6 +1,8 @@
|
|||
from enum import Enum
|
||||
|
||||
from pydantic import BaseModel, Field, field_validator
|
||||
from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
|
||||
|
||||
VALID_TYPES = ["date", "number", "text", "json", "integer", "int", "float", "str", "string"]
|
||||
|
||||
|
||||
class FormatterType(str, Enum):
|
||||
|
|
@ -11,19 +13,35 @@ class FormatterType(str, Enum):
|
|||
|
||||
|
||||
class Column(BaseModel):
|
||||
display_name: str
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
name: str
|
||||
display_name: str = Field(default="")
|
||||
sortable: bool = Field(default=True)
|
||||
filterable: bool = Field(default=True)
|
||||
formatter: FormatterType | str | None = None
|
||||
formatter: FormatterType | str | None = Field(default=None, alias="type")
|
||||
description: str | None = None
|
||||
default: str | None = None
|
||||
|
||||
@field_validator("formatter")
|
||||
@model_validator(mode="after")
|
||||
def set_display_name(self):
|
||||
if not self.display_name:
|
||||
self.display_name = self.name
|
||||
return self
|
||||
|
||||
@field_validator("formatter", mode="before")
|
||||
@classmethod
|
||||
def validate_formatter(cls, value):
|
||||
if value in ["integer", "int", "float"]:
|
||||
value = FormatterType.number
|
||||
if value in ["str", "string"]:
|
||||
value = FormatterType.text
|
||||
if value == "dict":
|
||||
value = FormatterType.json
|
||||
if isinstance(value, str):
|
||||
return FormatterType(value)
|
||||
if isinstance(value, FormatterType):
|
||||
return value
|
||||
msg = "Invalid formatter type"
|
||||
msg = f"Invalid formatter type: {value}. Valid types are: {FormatterType}"
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue