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]
|
output_types = [component_name_camelcase]
|
||||||
|
|
||||||
component_info = {
|
component_info = {
|
||||||
"name": "CustomComponent",
|
"name": component_name_camelcase,
|
||||||
"output_types": output_types,
|
"output_types": output_types,
|
||||||
"file": filename,
|
"file": filename,
|
||||||
"code": result_content if validation_result else "",
|
"code": result_content if validation_result else "",
|
||||||
|
|
|
||||||
|
|
@ -124,12 +124,13 @@ def get_new_key(dictionary, original_key):
|
||||||
|
|
||||||
def determine_component_name(component):
|
def determine_component_name(component):
|
||||||
"""Determine the name of the component."""
|
"""Determine the name of the component."""
|
||||||
component_output_types = component["output_types"]
|
# component_output_types = component["output_types"]
|
||||||
if len(component_output_types) == 1:
|
# if len(component_output_types) == 1:
|
||||||
return component_output_types[0]
|
# return component_output_types[0]
|
||||||
else:
|
# else:
|
||||||
file_name = component.get("file").split(".")[0]
|
# 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 "".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):
|
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.error(f"Error loading Component: {component['output_types']}")
|
||||||
logger.exception(f"Error while building custom component {component['output_types']}: {exc}")
|
logger.exception(f"Error while building custom component {component['output_types']}: {exc}")
|
||||||
return menu_items
|
return menu_items
|
||||||
|
return menu_items
|
||||||
|
|
|
||||||
|
|
@ -366,7 +366,7 @@ def sanitize_field_config(field_config: Dict):
|
||||||
|
|
||||||
def build_component(component):
|
def build_component(component):
|
||||||
"""Build a single component."""
|
"""Build a single component."""
|
||||||
logger.debug(f"Building component: {component.get('name'), component.get('output_types')}")
|
|
||||||
component_name = determine_component_name(component)
|
component_name = determine_component_name(component)
|
||||||
component_template = create_component_template(component)
|
component_template = create_component_template(component)
|
||||||
|
logger.debug(f"Building component: {component_name, component.get('output_types')}")
|
||||||
return component_name, component_template
|
return component_name, component_template
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue