Skip to content

Commit

Permalink
✨ webapi: new descriptionUI flag to render service a single page UI (
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Sep 3, 2024
1 parent 0297b24 commit 7550a9c
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class Config:
"name": "sleeper",
"thumbnail": None,
"description": "A service which awaits for time to pass, two times.",
"description_ui": True,
"classifiers": [],
"quality": {},
"accessRights": {"1": {"execute": True, "write": False}},
Expand Down Expand Up @@ -221,6 +222,8 @@ class ServiceGetV2(BaseModel):
thumbnail: HttpUrl | None = None
description: str

description_ui: bool = False

version_display: str | None = None

service_type: ServiceType = Field(default=..., alias="type")
Expand Down Expand Up @@ -317,6 +320,7 @@ class ServiceUpdateV2(BaseModel):
thumbnail: HttpUrl | None = None

description: str | None = None
description_ui: bool = False
version_display: str | None = None

deprecated: datetime | None = None
Expand Down
5 changes: 5 additions & 0 deletions packages/models-library/src/models_library/services_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ class ServiceBaseDisplay(BaseModel):
"The mother of all nodes, makes your numbers shine!",
],
)
description_ui: bool = Field(
default=False,
description="A flag to enable the `description` to be presented as a single web page (=true) or in another structured format (default=false).",
)

version_display: str | None = Field(
None,
description="A user-friendly or marketing name for the release."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ServiceMetaDataEditable(ServiceBaseDisplay):
name: str | None # type: ignore[assignment]
thumbnail: HttpUrl | None
description: str | None # type: ignore[assignment]
description_ui: bool = False
version_display: str | None = None

# Below fields only in the database ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class Config:
{
**_EXAMPLE_W_BOOT_OPTIONS_AND_NO_DISPLAY_ORDER,
"version_display": "Matterhorn Release",
"description_ui": True,
"release_date": "2024-05-31T13:45:30",
},
]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""new description_ui column
Revision ID: 926c3eb2254e
Revises: feca36c8e18f
Create Date: 2024-09-02 21:25:06.042365+00:00
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "926c3eb2254e"
down_revision = "feca36c8e18f"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"services_meta_data",
sa.Column(
"description_ui",
sa.Boolean(),
server_default=sa.text("false"),
nullable=False,
),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("services_meta_data", "description_ui")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
from sqlalchemy.sql import expression

from .base import metadata

Expand Down Expand Up @@ -49,7 +50,16 @@
"description",
sa.String,
nullable=False,
doc="Markdown-compatible description (editable)",
doc="Markdown-compatible description (editable). SEE `description_ui`",
),
sa.Column(
"description_ui",
sa.Boolean,
nullable=False,
server_default=expression.false(),
doc="A flag that determines how the `description` column is rendered in the UI (editable)"
"Specifically, it indicates whether the `description` should be presented as a single web page (=true) or in another structured format (default=false)."
"This field is primarily used by the front-end of the application to decide on the presentation style of the service's metadata.",
),
sa.Column(
"thumbnail",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def random_service_meta_data(
"name": f"the-{_name}-service", # display
"description": fake.sentence(),
# optional
"description_ui": fake.pybool(),
"owner": owner_primary_gid,
"thumbnail": _pick_from([fake.image_url(), None]), # nullable
"version_display": _pick_from([f"v{_version}", None]), # nullable
Expand Down
11 changes: 11 additions & 0 deletions services/catalog/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2070,6 +2070,12 @@
"title": "Description",
"description": "human readable description of the purpose of the node"
},
"description_ui": {
"type": "boolean",
"title": "Description Ui",
"description": "A flag to enable the `description` to be presented as a single web page (=true) or in another structured format (default=false).",
"default": false
},
"version_display": {
"type": "string",
"title": "Version Display",
Expand Down Expand Up @@ -2550,6 +2556,11 @@
"type": "string",
"title": "Description"
},
"description_ui": {
"type": "boolean",
"title": "Description Ui",
"default": false
},
"version_display": {
"type": "string",
"title": "Version Display"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def list_latest_services_with_history_stmt(
users.c.email.label("owner_email"),
services_meta_data.c.name,
services_meta_data.c.description,
services_meta_data.c.description_ui,
services_meta_data.c.thumbnail,
services_meta_data.c.version_display,
services_meta_data.c.classifiers,
Expand Down Expand Up @@ -270,6 +271,7 @@ def list_latest_services_with_history_stmt(
# display
latest_query.c.name,
latest_query.c.description,
latest_query.c.description_ui,
latest_query.c.thumbnail,
latest_query.c.version_display,
# ownership
Expand Down Expand Up @@ -308,6 +310,7 @@ def list_latest_services_with_history_stmt(
latest_query.c.owner_email,
latest_query.c.name,
latest_query.c.description,
latest_query.c.description_ui,
latest_query.c.thumbnail,
latest_query.c.version_display,
latest_query.c.classifiers,
Expand Down Expand Up @@ -369,6 +372,7 @@ def get_service_stmt(
# display
services_meta_data.c.name,
services_meta_data.c.description,
services_meta_data.c.description_ui,
services_meta_data.c.thumbnail,
services_meta_data.c.version_display,
# ownership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ async def get_service_with_history(
# display
name=row.name,
description=row.description,
description_ui=row.description_ui,
thumbnail=row.thumbnail,
version_display=row.version_display,
# ownership
Expand Down Expand Up @@ -401,6 +402,7 @@ async def list_latest_services(
# display
name=r.name,
description=r.description,
description_ui=r.description_ui,
thumbnail=r.thumbnail,
version_display=r.version_display,
# ownership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Config:
"owner": 8,
"name": "sim4life",
"description": "s4l web",
"description_ui": 0,
"thumbnail": "http://thumbnailit.org/image",
"version_display": "S4L X",
"created": "2021-01-18 12:46:57.7315",
Expand Down Expand Up @@ -65,6 +66,7 @@ class ServiceWithHistoryFromDB(BaseModel):
# display
name: str
description: str
description_ui: bool
thumbnail: str | None
version_display: str | None
# ownership
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _db_to_api_model(
else None
),
description=service_db.description,
description_ui=service_db.description_ui,
version_display=service_db.version_display,
type=service_manifest.service_type,
contact=service_manifest.contact,
Expand Down
2 changes: 2 additions & 0 deletions services/catalog/tests/unit/with_dbs/test_api_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,15 @@ async def test_rpc_catalog_client(
"name": "foo",
"description": "bar",
"version_display": "this is a nice version",
"description_ui": True, # owner activates wiki view
},
)

assert updated.key == got.key
assert updated.version == got.version
assert updated.name == "foo"
assert updated.description == "bar"
assert updated.description_ui
assert updated.version_display == "this is a nice version"
assert not updated.classifiers

Expand Down
2 changes: 1 addition & 1 deletion services/web/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.42.0
0.43.0
2 changes: 1 addition & 1 deletion services/web/server/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.42.0
current_version = 0.43.0
commit = True
message = services/webserver api version: {current_version} → {new_version}
tag = False
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.2
info:
title: simcore-service-webserver
description: Main service with an interface (http-API & websockets) to the web front-end
version: 0.42.0
version: 0.43.0
servers:
- url: ''
description: webserver
Expand Down Expand Up @@ -5842,6 +5842,10 @@ components:
description:
title: Description
type: string
descriptionUi:
title: Descriptionui
type: boolean
default: false
versionDisplay:
title: Versiondisplay
type: string
Expand Down Expand Up @@ -5908,6 +5912,7 @@ components:
example:
name: sleeper
description: A service which awaits for time to pass, two times.
description_ui: true
classifiers: []
quality: {}
accessRights:
Expand Down Expand Up @@ -5986,6 +5991,10 @@ components:
description:
title: Description
type: string
descriptionUi:
title: Descriptionui
type: boolean
default: false
versionDisplay:
title: Versiondisplay
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ async def test_get_and_patch_service(
description="bar",
classifiers=None,
versionDisplay="Some nice name",
descriptionUi=True,
accessRights={1: {"execute": True, "write": True}},
)
response = await client.patch(
Expand All @@ -209,6 +210,7 @@ async def test_get_and_patch_service(
assert model.version == service_version
assert model.name == update.name
assert model.description == update.description
assert model.description_ui == update.description_ui
assert model.version_display == update.version_display
assert model.access_rights == update.access_rights

Expand Down

0 comments on commit 7550a9c

Please sign in to comment.