Refactor component name determination logic in directory_reader.py
This commit is contained in:
parent
dfae41cd45
commit
f01d8cf046
3 changed files with 10 additions and 8 deletions
|
|
@ -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 "",
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue