Skip to content

Webactions: Add group labels #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 35 additions & 16 deletions server/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@

IDENTIFIER_PREFIX = "application.launch."

_manifest_fields = getattr(SimpleActionManifest, "__fields__", None)
if _manifest_fields is None:
_manifest_fields = getattr(SimpleActionManifest, "model_fields", set)()
# Backwards compatibility for AYON server older than 1.8.0
_GROUP_LABEL_AVAILABLE = "group_label" in _manifest_fields


def _sort_getter(item):
return item["group_label"], item["variant_label"]


def get_items_for_app_groups(groups):
label_by_name = {}
icon_by_name = {}
items = []
for group in groups:
group_name = group["name"]
group_label = group.get(
Expand All @@ -43,18 +52,29 @@ def get_items_for_app_groups(groups):
continue
variant_label = variant["label"] or variant_name
full_name = f"{group_name}/{variant_name}"
full_label = f"{group_label} {variant_label}"
label_by_name[full_name] = full_label
icon_by_name[full_name] = icon

return [
{
"value": full_name,
"label": label_by_name[full_name],
"icon": icon_by_name[full_name],
items.append({
"value": full_name,
"group_label": group_label,
"variant_label": variant_label,
"icon": icon,
})

items.sort(key=_sort_getter)
return items


def _prepare_label_kwargs(item):
group_label = item["group_label"]
variant_label = item["variant_label"]
if _GROUP_LABEL_AVAILABLE:
return {
"label": variant_label,
"group_label": group_label,
}
for full_name in sorted(label_by_name)
]

return {
"label": f"{group_label} {variant_label}",
}


async def _get_action_manifests_with_attributes(app_groups, project_entity):
Expand All @@ -66,11 +86,10 @@ async def _get_action_manifests_with_attributes(app_groups, project_entity):
app_full_name = item["value"]
if app_full_name not in project_apps:
continue

output.append(
SimpleActionManifest(
identifier=f"{IDENTIFIER_PREFIX}{app_full_name}",
label=item["label"],
**_prepare_label_kwargs(item),
category="Applications",
icon=item["icon"],
order=100,
Expand Down Expand Up @@ -166,7 +185,7 @@ async def get_action_manifests(addon, project_name, variant):
output.append(
SimpleActionManifest(
identifier=f"{IDENTIFIER_PREFIX}{app_name}",
label=app_item["label"],
**_prepare_label_kwargs(app_item),
category="Applications",
icon=app_item["icon"],
order=100,
Expand Down
Loading