Refactor component attributes and add is_composition flag

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-20 21:33:41 -03:00
commit 17dee05b78
3 changed files with 12 additions and 1 deletions

View file

@ -20,7 +20,9 @@ class ComponentFunctionEntrypointNameNullError(HTTPException):
class Component:
ERROR_CODE_NULL: ClassVar[str] = "Python code must be provided."
ERROR_FUNCTION_ENTRYPOINT_NAME_NULL: ClassVar[str] = "The name of the entrypoint function must be provided."
ERROR_FUNCTION_ENTRYPOINT_NAME_NULL: ClassVar[str] = (
"The name of the entrypoint function must be provided."
)
code: Optional[str] = None
_function_entrypoint_name: str = "build"
@ -67,6 +69,10 @@ class Component:
return str(value) if value else ""
def getattr_return_bool(self, value):
if isinstance(value, bool):
return value
def build_template_config(self) -> dict:
if not self.code:
return {}
@ -80,6 +86,7 @@ class Component:
"beta": self.getattr_return_str,
"documentation": self.getattr_return_str,
"icon": self.validate_icon,
"is_composition": self.getattr_return_bool,
}
for attribute, func in attributes_func_mapping.items():

View file

@ -35,6 +35,9 @@ class CustomComponent(Component):
"""The field configuration of the component. Defaults to an empty dictionary."""
field_order: Optional[List[str]] = None
"""The field order of the component. Defaults to an empty list."""
is_composition: Optional[bool] = None
"""Whether the component is used for composition.
This affects the style of the edge connecting the component to the next component. Defaults to None."""
code_class_base_inheritance: ClassVar[str] = "CustomComponent"
function_entrypoint_name: ClassVar[str] = "build"
function: Optional[Callable] = None

View file

@ -270,6 +270,7 @@ def sanitize_template_config(template_config):
"documentation",
"output_types",
"icon",
"is_composition",
}
for key in template_config.copy():
if key not in attributes: