Refactor component attributes and add is_composition flag
This commit is contained in:
parent
9966b4a8dc
commit
17dee05b78
3 changed files with 12 additions and 1 deletions
|
|
@ -20,7 +20,9 @@ class ComponentFunctionEntrypointNameNullError(HTTPException):
|
||||||
|
|
||||||
class Component:
|
class Component:
|
||||||
ERROR_CODE_NULL: ClassVar[str] = "Python code must be provided."
|
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
|
code: Optional[str] = None
|
||||||
_function_entrypoint_name: str = "build"
|
_function_entrypoint_name: str = "build"
|
||||||
|
|
@ -67,6 +69,10 @@ class Component:
|
||||||
|
|
||||||
return str(value) if value else ""
|
return str(value) if value else ""
|
||||||
|
|
||||||
|
def getattr_return_bool(self, value):
|
||||||
|
if isinstance(value, bool):
|
||||||
|
return value
|
||||||
|
|
||||||
def build_template_config(self) -> dict:
|
def build_template_config(self) -> dict:
|
||||||
if not self.code:
|
if not self.code:
|
||||||
return {}
|
return {}
|
||||||
|
|
@ -80,6 +86,7 @@ class Component:
|
||||||
"beta": self.getattr_return_str,
|
"beta": self.getattr_return_str,
|
||||||
"documentation": self.getattr_return_str,
|
"documentation": self.getattr_return_str,
|
||||||
"icon": self.validate_icon,
|
"icon": self.validate_icon,
|
||||||
|
"is_composition": self.getattr_return_bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
for attribute, func in attributes_func_mapping.items():
|
for attribute, func in attributes_func_mapping.items():
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ class CustomComponent(Component):
|
||||||
"""The field configuration of the component. Defaults to an empty dictionary."""
|
"""The field configuration of the component. Defaults to an empty dictionary."""
|
||||||
field_order: Optional[List[str]] = None
|
field_order: Optional[List[str]] = None
|
||||||
"""The field order of the component. Defaults to an empty list."""
|
"""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"
|
code_class_base_inheritance: ClassVar[str] = "CustomComponent"
|
||||||
function_entrypoint_name: ClassVar[str] = "build"
|
function_entrypoint_name: ClassVar[str] = "build"
|
||||||
function: Optional[Callable] = None
|
function: Optional[Callable] = None
|
||||||
|
|
|
||||||
|
|
@ -270,6 +270,7 @@ def sanitize_template_config(template_config):
|
||||||
"documentation",
|
"documentation",
|
||||||
"output_types",
|
"output_types",
|
||||||
"icon",
|
"icon",
|
||||||
|
"is_composition",
|
||||||
}
|
}
|
||||||
for key in template_config.copy():
|
for key in template_config.copy():
|
||||||
if key not in attributes:
|
if key not in attributes:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue