Skip to content

Commit

Permalink
update widget generator
Browse files Browse the repository at this point in the history
* convert camelcase to snake_case the widget function name
* update default params logic to be smaller
* fix bad jsdoc object value on some components
  • Loading branch information
syrk4web committed Aug 7, 2024
1 parent afabcf6 commit ea1ae91
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ui/client/dashboard/components/List/Details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import MessageUnmatch from "@components/Message/Unmatch.vue";
}]
* @param {string} details - List of details item that contains a text, disabled state, attrs and list of popovers. We can also add a disabled key to disable the item.
* @param {array} [filters=[]] - List of filters to apply on the list of items.
* @param {columns} [columns={pc: 4, tablet: 6, mobile: 12}] - Determine the position of the items in the grid system.
* @param {columns} [columns={"pc": "4", "tablet": "6", "mobile": "12"}] - Determine the position of the items in the grid system.
*/
const props = defineProps({
Expand Down
2 changes: 1 addition & 1 deletion src/ui/client/dashboard/components/List/Pairs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { computed, defineProps } from "vue";
* columns: { pc: 12, tablet: 12, mobile: 12 }
* }
* @param {array} pairs - The list of key value information. The key and value can be a translation key or a raw text.
* @param {object} [columns={pc: 12, tablet: 12, mobile: 12}] - Determine the position of the items in the grid system.
* @param {object} [columns={"pc": "12", "tablet": "12", "mobile": "12"}] - Determine the position of the items in the grid system.
*/
const props = defineProps({
Expand Down
23 changes: 17 additions & 6 deletions src/ui/client/widgets_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def get_py_title(data: str) -> str:
if "/" in title:
title = title.split("/")[-1]
# remove the extension
title = title.replace(".vue", "").lower()
title = title.replace(".vue", "")
return title


Expand Down Expand Up @@ -337,13 +337,19 @@ def convert_params(params: List[dict]) -> List[dict]:

def create_widget(title: str, desc: str, params: List[dict]):
try:
# format function title from camelCase to snake_case
f_title = sub(r"([A-Z])", r"_\1", title).lower()
# Case title start by _, remove it
if f_title.startswith("_"):
f_title = f_title[1:]

# Add indentation to desc
desc_lines = desc.split("\n")
desc_indent = []
for line in desc_lines:
desc_indent.append(f" {line}")
desc = "\n".join(desc_indent)
desc = ' """' + desc + ' """\n'
desc = ' """' + desc + '"""\n'

# Create function params with type and optional value if exists
params_str = ""
Expand Down Expand Up @@ -376,19 +382,24 @@ def create_widget(title: str, desc: str, params: List[dict]):
continue
param_name = param.get("name")
param_default = '""' if param.get("default") == "" else param.get("default")
add_keys_not_default += f""" add_key_value(data, "{param_name}", {param_name}, {param_default})\n"""
add_keys_not_default += f"""("{param_name}", {param_name}, {param_default}),"""

if add_keys_not_default:
add_keys_not_default = " # List of params that will be add only if not default value\n" + add_keys_not_default
add_keys_not_default = f"""
# List of params that will be add only if not default value
list_params = [{add_keys_not_default.rstrip(',')}]
for param in list_params:
add_key_value(data, param[0], param[1], param[2])
"""

widget_function = f"""
def {title}_widget(
def {f_title}_widget(
{params_str}
):
{desc}
{data}
{add_keys_not_default}
return {{ "type" : "{title.capitalize()}", "data" : data }}
return {{ "type" : "{title.lower().capitalize()}", "data" : data }}
"""
return widget_function

Expand Down

0 comments on commit ea1ae91

Please sign in to comment.