Skip to content

Commit

Permalink
Add name attribute for template tab groups
Browse files Browse the repository at this point in the history
  • Loading branch information
buehlefs committed Aug 2, 2024
1 parent a3c979e commit df414b6
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def generate_link(
else:
query_params[TEMPLATE_GROUP_QUERY_KEY] = resource.location

if resource.name:
name = resource.name
else:
name = f"Tab Group: {resource.location}"

return ApiLink(
href=url_for(
endpoint,
Expand All @@ -78,7 +83,7 @@ def generate_link(
resource_type=meta.rel_type,
resource_key=KeyGenerator.generate_key(resource, query_params=query_params),
schema=f"{url_for(API_SPEC_RESOURCE, _external=True)}#/components/schemas/{TemplateGroupSchema.schema_name()}",
name=f"Tab Group: {resource.location}",
name=name,
)


Expand Down
4 changes: 2 additions & 2 deletions qhana_plugin_registry/api/models/generators/template_tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def update_key(self, key: Dict[str, str], resource: TemplateTab) -> Dict[str, st
assert isinstance(resource, TemplateTab)
template = resource.template
assert template is not None
parent_resource = TemplateGroupRaw(template, resource.location, [])
parent_resource = TemplateGroupRaw(template, resource.location, None, [])
parent_key = KeyGenerator.generate_key(parent_resource)
key.update(parent_key)
key[TEMPLATE_TAB_ID_KEY] = str(resource.id)
Expand Down Expand Up @@ -173,7 +173,7 @@ def generate_link(
) -> Optional[ApiLink]:
template = resource.template
assert template is not None
parent_resource = TemplateGroupRaw(template, resource.location, [])
parent_resource = TemplateGroupRaw(template, resource.location, None, [])
return LinkGenerator.get_link_of(
parent_resource,
extra_relations=(UP_REL,),
Expand Down
14 changes: 12 additions & 2 deletions qhana_plugin_registry/api/models/generators/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,24 @@ def generate_api_object(

assert self_link is not None

group_locations: Set[str] = {t.location for t in resource.tabs}
group_locations: Dict[str, Optional[str]] = {
t.location: None for t in resource.tabs
}

for t in resource.tabs:
if t.group_key:
group = f"{t.location}.{t.group_key}"
if group in group_locations:
group_locations[group] = t.name

groups = (
TemplateGroupRaw(
template=resource,
location=loc,
name=name,
items=[],
)
for loc in group_locations
for loc, name in group_locations.items()
)
group_links = [l for g in groups if (l := LinkGenerator.get_link_of(g))]

Expand Down
3 changes: 2 additions & 1 deletion qhana_plugin_registry/api/models/templates_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@
# limitations under the License.

from dataclasses import dataclass
from typing import Sequence
from typing import Sequence, Optional
from ...db.models.templates import UiTemplate, TemplateTab


@dataclass
class TemplateGroupRaw:
template: UiTemplate
location: str
name: Optional[str]
items: Sequence[TemplateTab]
9 changes: 9 additions & 0 deletions qhana_plugin_registry/api/template_tabs/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,18 @@ def get(self, template_id: str, **kwargs):
resource: Union[CollectionResource, TemplateGroupRaw]

if group:
group_name = None
if "." in group:
*group_tab_group, group_key = group.split(".")
group_location = ".".join(group_tab_group)
for tab in found_template.tabs:
if tab.location == group_location and tab.group_key == group_key:
group_name = tab.name
break
resource = TemplateGroupRaw(
template=found_template,
location=group,
name=group_name,
items=tabs,
)
else:
Expand Down

0 comments on commit df414b6

Please # to comment.