Refactor component name determination logic in directory_reader.py

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-07 14:23:21 -03:00
commit f01d8cf046
3 changed files with 10 additions and 8 deletions

View file

@ -256,7 +256,7 @@ class DirectoryReader:
output_types = [component_name_camelcase]
component_info = {
"name": "CustomComponent",
"name": component_name_camelcase,
"output_types": output_types,
"file": filename,
"code": result_content if validation_result else "",

View file

@ -124,12 +124,13 @@ def get_new_key(dictionary, original_key):
def determine_component_name(component):
"""Determine the name of the component."""
component_output_types = component["output_types"]
if len(component_output_types) == 1:
return component_output_types[0]
else:
file_name = component.get("file").split(".")[0]
return "".join(word.capitalize() for word in file_name.split("_")) if "_" in file_name else file_name
# component_output_types = component["output_types"]
# if len(component_output_types) == 1:
# return component_output_types[0]
# else:
# file_name = component.get("file").split(".")[0]
# return "".join(word.capitalize() for word in file_name.split("_")) if "_" in file_name else file_name
return component["name"]
def build_menu_items(menu_item):
@ -143,3 +144,4 @@ def build_menu_items(menu_item):
logger.error(f"Error loading Component: {component['output_types']}")
logger.exception(f"Error while building custom component {component['output_types']}: {exc}")
return menu_items
return menu_items

View file

@ -366,7 +366,7 @@ def sanitize_field_config(field_config: Dict):
def build_component(component):
"""Build a single component."""
logger.debug(f"Building component: {component.get('name'), component.get('output_types')}")
component_name = determine_component_name(component)
component_template = create_component_template(component)
logger.debug(f"Building component: {component_name, component.get('output_types')}")
return component_name, component_template