Skip to content

Commit d02bd45

Browse files
committed
refactor
1 parent e6438d8 commit d02bd45

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

jhub_apps/config_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from traitlets.config import SingletonConfigurable, Enum
77

8-
from jhub_apps.service.models import StartupApp, PinnedService
8+
from jhub_apps.service.models import StartupApp, AdditionalService
99

1010

1111
# jhub-app-proxy configuration constants
@@ -139,13 +139,13 @@ class JAppsConfig(SingletonConfigurable):
139139
).tag(config=True)
140140

141141
additional_services = List(
142-
trait=PydanticModelTrait(PinnedService),
142+
trait=PydanticModelTrait(AdditionalService),
143143
description="List of additional external services to display in JupyterHub UI.",
144144
default_value=[],
145145
help="""
146146
List of additional external services to display in JupyterHub's services menu.
147147
Services with pinned=True will also appear in the quick access section.
148-
Each service should be a PinnedService model instance or dict with keys:
148+
Each service should be an AdditionalService model instance or dict with keys:
149149
name (str), url (str), description (str, optional), pinned (bool, optional),
150150
thumbnail (str, optional) - can be a URL or base64-encoded data URL.
151151

jhub_apps/configuration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def install_jhub_apps(c, spawner_to_subclass, *, oauth_no_confirm=False):
102102

103103
# Add additional services from JAppsConfig
104104
if japps_config.additional_services:
105-
from jhub_apps.service_utils import pinned_service_to_service_dict
105+
from jhub_apps.service_utils import additional_service_to_service_dict
106106
additional_service_dicts = [
107-
pinned_service_to_service_dict(service)
107+
additional_service_to_service_dict(service)
108108
for service in japps_config.additional_services
109109
]
110110
c.JupyterHub.services.extend(additional_service_dicts)

jhub_apps/service/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ class StartupApp(ServerCreation):
103103
user_options: JHubAppUserOptions
104104

105105

106-
class PinnedService(BaseModel):
107-
"""Configuration for a pinned external service in JupyterHub.
106+
class AdditionalService(BaseModel):
107+
"""Configuration for an additional external service in JupyterHub.
108108
109109
These services appear in the JupyterHub UI services menu.
110+
Services with pinned=True also appear in the quick access section.
110111
"""
111112
name: str
112113
url: str

jhub_apps/service_utils.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Utilities for configuring JupyterHub services."""
22
from typing import Dict, Any, Optional
33

4-
from jhub_apps.service.models import PinnedService
4+
from jhub_apps.service.models import AdditionalService
55

66

77
def service_for_jhub_apps(
@@ -14,15 +14,16 @@ def service_for_jhub_apps(
1414
"""Create a service configuration dict for JupyterHub services.
1515
1616
This helper function creates the proper structure for external services
17-
that appear in the JupyterHub UI services menu. It validates the input
18-
using the PinnedService Pydantic model.
17+
that appear in the JupyterHub UI services menu. Services with pinned=True
18+
also appear in the quick access section. It validates the input using
19+
the AdditionalService Pydantic model.
1920
2021
Args:
2122
name: Display name of the service
2223
url: URL path for the service
2324
description: Optional description of the service
24-
pinned: Whether the service should be pinned in the UI
25-
thumbnail: Optional thumbnail URL or data URL for the service icon
25+
pinned: Whether the service should appear in the quick access section
26+
thumbnail: Optional thumbnail URL or base64-encoded data URL for the service icon
2627
2728
Returns:
2829
Dictionary with JupyterHub service configuration
@@ -40,7 +41,7 @@ def service_for_jhub_apps(
4041
... )
4142
"""
4243
# Validate inputs using Pydantic model
43-
pinned_service = PinnedService(
44+
additional_service = AdditionalService(
4445
name=name,
4546
url=url,
4647
description=description,
@@ -49,32 +50,32 @@ def service_for_jhub_apps(
4950
)
5051

5152
return {
52-
"name": pinned_service.name,
53+
"name": additional_service.name,
5354
"display": True,
5455
"info": {
55-
"name": pinned_service.name,
56-
"description": pinned_service.description,
57-
"url": pinned_service.url,
56+
"name": additional_service.name,
57+
"description": additional_service.description,
58+
"url": additional_service.url,
5859
"external": True,
59-
"pinned": pinned_service.pinned,
60-
"thumbnail": pinned_service.thumbnail,
60+
"pinned": additional_service.pinned,
61+
"thumbnail": additional_service.thumbnail,
6162
},
6263
}
6364

6465

65-
def pinned_service_to_service_dict(pinned_service: PinnedService) -> Dict[str, Any]:
66-
"""Convert a PinnedService model to a JupyterHub service dict.
66+
def additional_service_to_service_dict(additional_service: AdditionalService) -> Dict[str, Any]:
67+
"""Convert an AdditionalService model to a JupyterHub service dict.
6768
6869
Args:
69-
pinned_service: PinnedService model instance
70+
additional_service: AdditionalService model instance
7071
7172
Returns:
7273
Dictionary with JupyterHub service configuration
7374
"""
7475
return service_for_jhub_apps(
75-
name=pinned_service.name,
76-
url=pinned_service.url,
77-
description=pinned_service.description,
78-
pinned=pinned_service.pinned,
79-
thumbnail=pinned_service.thumbnail,
76+
name=additional_service.name,
77+
url=additional_service.url,
78+
description=additional_service.description,
79+
pinned=additional_service.pinned,
80+
thumbnail=additional_service.thumbnail,
8081
)

0 commit comments

Comments
 (0)