Skip to content

Commit

Permalink
Make editable fields easier to edit and group provenance as one block.
Browse files Browse the repository at this point in the history
  • Loading branch information
uittenbroekrobbert committed Feb 4, 2025
1 parent 3f76ac9 commit dddc765
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 92 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ jobs:
deploy:
runs-on: ubuntu-latest
needs: [build]
if: ${{ github.event_name == 'push' && !github.event.act}}
permissions:
actions: write
steps:
Expand All @@ -327,7 +326,11 @@ jobs:

- name: Trigger deployment
run: |
gh workflow run deploy.yml -f image_tag=${{ fromJSON(steps.meta.outputs.json).tags[0] }} -f environment=production
if [ "${{ github.event_name }}" == "push" ]; then
gh workflow run deploy.yml -f image_tag=${{ fromJSON(steps.meta.outputs.json).tags[0] }} -f environment=production
else
gh workflow run deploy.yml -f image_tag=${{ fromJSON(steps.meta.outputs.json).tags[0] }} -f environment=sandbox
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
3 changes: 2 additions & 1 deletion amt/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from starlette.background import BackgroundTask
from starlette.templating import _TemplateResponse # pyright: ignore [reportPrivateUsage]

from amt.api.editable import is_editable_resource
from amt.api.editable import is_editable_resource, is_parent_editable
from amt.api.editable_util import replace_digits_in_brackets, resolve_resource_list_path
from amt.api.http_browser_caching import url_for_cache
from amt.api.localizable import LocalizableEnum
Expand Down Expand Up @@ -168,6 +168,7 @@ def hasattr_jinja(obj: object, attributes: str) -> bool:
templates.env.globals.update(permission=permission) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(hasattr=hasattr_jinja) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(is_path_with_list=is_path_with_list) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(is_parent_editable=is_parent_editable) # pyright: ignore [reportUnknownMemberType]
templates.env.globals.update(resolve_resource_list_path=resolve_resource_list_path) # pyright: ignore [reportUnknownMemberType]
templates.env.tests["permission"] = permission # pyright: ignore [reportUnknownMemberType]
templates.env.add_extension("jinja2_base64_filters.Base64Filters") # pyright: ignore [reportUnknownMemberType]
41 changes: 28 additions & 13 deletions amt/api/editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ class Editables:
validator=EditableValidatorMinMaxLength(min_length=3, max_length=100),
)

ALGORITHM_EDITABLE_AUTHOR = Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance/author",
implementation_type=WebFormFieldImplementationType.TEXT,
)

ALGORITHM_EDITABLE_SYSTEMCARD_OWNERS = Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/owners[*]",
implementation_type=WebFormFieldImplementationType.PARENT,
Expand Down Expand Up @@ -145,14 +140,23 @@ class Editables:
)
ALGORITHM_EDITABLE_LIFECYCLE.add_bidirectional_couple(ALGORITHM_EDITABLE_SYSTEMCARD_STATUS)

ALGORITHM_EDITABLE_PROVENANCE_GIT_COMMIT_HASH = Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance/git_commit_hash",
implementation_type=WebFormFieldImplementationType.TEXT,
)

ALGORITHM_EDITABLE_PROVENANCE_URI = Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance/uri",
implementation_type=WebFormFieldImplementationType.TEXT,
ALGORITHM_EDITABLE_PROVENANCE = Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance",
implementation_type=WebFormFieldImplementationType.PARENT,
children=[
Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance/author",
implementation_type=WebFormFieldImplementationType.TEXT,
),
Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance/git_commit_hash",
implementation_type=WebFormFieldImplementationType.TEXT,
),
Editable(
full_resource_path="algorithm/{algorithm_id}/system_card/provenance/uri",
implementation_type=WebFormFieldImplementationType.TEXT,
),
],
)

ALGORITHM_EDITABLE_VERSION = Editable(
Expand Down Expand Up @@ -546,3 +550,14 @@ def set_path(obj: dict[str, Any] | object, path: str, value: typing.Any) -> None

def is_editable_resource(full_resource_path: str, editables: dict[str, ResolvedEditable]) -> bool:
return editables.get(replace_digits_in_brackets(full_resource_path), None) is not None


def is_parent_editable(editables: dict[str, ResolvedEditable], full_resource_path: str) -> bool:
full_resource_path = replace_digits_in_brackets(full_resource_path)
editable = editables.get(full_resource_path)
if editable is None:
print(full_resource_path + " : " + "false, no match")
return False
result = editable.implementation_type == WebFormFieldImplementationType.PARENT
print(full_resource_path + " : " + str(result))
return result
4 changes: 3 additions & 1 deletion amt/api/editable_enforcers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ async def enforce(self, **kwargs: Any) -> None: # noqa: ANN401
class EditableEnforcerForOrganizationInAlgorithm(EditableEnforcer):
async def enforce(self, **kwargs: Any) -> None: # noqa: ANN401
organization = await kwargs["organizations_service"].find_by_id_and_user_id(
organization_id=int(kwargs["new_value"]), user_id=kwargs["user_id"]
# TODO: using kwargs and new_values is 'a lot of assumptions' that a value is available under this key
organization_id=int(kwargs["new_values"]["organization"]),
user_id=kwargs["user_id"],
)
if organization is None:
raise AMTAuthorizationError()
11 changes: 9 additions & 2 deletions amt/api/routes/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,13 @@ async def get_algorithm_details(
request,
)

context["breadcrumbs"] = breadcrumbs
context["base_href"] = f"/algorithm/{algorithm_id}"
context.update(
{
"breadcrumbs": breadcrumbs,
"base_href": f"/algorithm/{algorithm_id}",
"editables": get_resolved_editables(context_variables={"algorithm_id": algorithm_id}),
}
)

return templates.TemplateResponse(request, "algorithms/details_info.html.j2", context)

Expand Down Expand Up @@ -429,6 +434,7 @@ async def get_algorithm_cancel(
"resource_object": editable.resource_object,
"full_resource_path": full_resource_path,
"editable_object": editable,
"editables": get_resolved_editables(context_variables={"algorithm_id": algorithm_id}),
}

return templates.TemplateResponse(request, "parts/view_cell.html.j2", context)
Expand Down Expand Up @@ -479,6 +485,7 @@ async def get_algorithm_update(
"resource_object": editable.resource_object,
"full_resource_path": full_resource_path,
"editable_object": editable,
"editables": get_resolved_editables(context_variables={"algorithm_id": algorithm_id}),
}

return templates.TemplateResponse(request, "parts/view_cell.html.j2", context)
Expand Down
6 changes: 6 additions & 0 deletions amt/api/routes/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from amt.api.editable import (
Editables,
get_enriched_resolved_editable,
get_resolved_editables,
save_editable,
)
from amt.api.editable_classes import EditModes, ResolvedEditable
Expand Down Expand Up @@ -186,6 +187,7 @@ async def get_by_slug(
"organization_id": organization.id,
"tab_items": tab_items,
"breadcrumbs": breadcrumbs,
"editables": get_resolved_editables(context_variables={"organization_id": organization.id}),
}
return templates.TemplateResponse(request, "organizations/home.html.j2", context)

Expand Down Expand Up @@ -267,6 +269,7 @@ async def get_organization_cancel(
"resource_object": None, # TODO: this should become an optional parameter in the Jinja template
"full_resource_path": full_resource_path,
"editable_object": editable,
"editables": get_resolved_editables(context_variables={"organization_id": organization.id}),
}

return templates.TemplateResponse(request, "parts/view_cell.html.j2", context)
Expand Down Expand Up @@ -319,6 +322,7 @@ async def get_organization_update(
"resource_object": None,
"full_resource_path": full_resource_path,
"editable_object": editable,
"editables": get_resolved_editables(context_variables={"organization_id": organization.id}),
}

# TODO: add a 'next action' to editable for f.e. redirect options, THIS IS A HACK
Expand Down Expand Up @@ -455,6 +459,8 @@ async def get_members(
)

filters["organization-id"] = str(organization.id)
if "name" not in sort_by:
sort_by["name"] = "ascending"
members = await users_service.find_all(search=search, sort=sort_by, filters=filters)

context: dict[str, Any] = {
Expand Down
3 changes: 3 additions & 0 deletions amt/core/exception_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ async def general_exception_handler(request: Request, exc: Exception) -> HTMLRes
message = exc.errors()
for err in message:
err["msg"] = translate_pydantic_exception(err, translations)
# Errors should be handled in appropriate "containers",
# so we always want to replace to content and not the container
response_headers["HX-Reswap"] = "innerHTML"

status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
if isinstance(exc, StarletteHTTPException):
Expand Down
12 changes: 4 additions & 8 deletions amt/locale/base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ msgid "measure executed"
msgstr ""

#: amt/site/templates/algorithms/details_compliance.html.j2:69
#: amt/site/templates/macros/editable.html.j2:67
#: amt/site/templates/macros/editable.html.j2:72
#: amt/site/templates/macros/editable.html.j2:68
#: amt/site/templates/macros/editable.html.j2:73
#: amt/site/templates/macros/tasks.html.j2:82
msgid "Edit"
msgstr ""
Expand Down Expand Up @@ -464,12 +464,12 @@ msgid "Read more on the algoritmekader"
msgstr ""

#: amt/site/templates/algorithms/details_measure_modal.html.j2:64
#: amt/site/templates/macros/editable.html.j2:174
#: amt/site/templates/macros/editable.html.j2:175
msgid "Save"
msgstr ""

#: amt/site/templates/algorithms/details_measure_modal.html.j2:68
#: amt/site/templates/macros/editable.html.j2:179
#: amt/site/templates/macros/editable.html.j2:180
#: amt/site/templates/organizations/parts/add_members_modal.html.j2:26
msgid "Cancel"
msgstr ""
Expand Down Expand Up @@ -689,10 +689,6 @@ msgstr ""
msgid "Search"
msgstr ""

#: amt/site/templates/organizations/parts/members_results.html.j2:37
msgid "Find member..."
msgstr ""

#: amt/site/templates/organizations/parts/members_results.html.j2:66
#, python-format
msgid ""
Expand Down
Binary file modified amt/locale/en_US/LC_MESSAGES/messages.mo
Binary file not shown.
16 changes: 6 additions & 10 deletions amt/locale/en_US/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ msgid "measure executed"
msgstr ""

#: amt/site/templates/algorithms/details_compliance.html.j2:69
#: amt/site/templates/macros/editable.html.j2:67
#: amt/site/templates/macros/editable.html.j2:72
#: amt/site/templates/macros/editable.html.j2:68
#: amt/site/templates/macros/editable.html.j2:73
#: amt/site/templates/macros/tasks.html.j2:82
msgid "Edit"
msgstr ""
Expand Down Expand Up @@ -465,12 +465,12 @@ msgid "Read more on the algoritmekader"
msgstr ""

#: amt/site/templates/algorithms/details_measure_modal.html.j2:64
#: amt/site/templates/macros/editable.html.j2:174
#: amt/site/templates/macros/editable.html.j2:175
msgid "Save"
msgstr ""

#: amt/site/templates/algorithms/details_measure_modal.html.j2:68
#: amt/site/templates/macros/editable.html.j2:179
#: amt/site/templates/macros/editable.html.j2:180
#: amt/site/templates/organizations/parts/add_members_modal.html.j2:26
msgid "Cancel"
msgstr ""
Expand Down Expand Up @@ -690,12 +690,8 @@ msgstr ""
msgid "Search"
msgstr ""

#: amt/site/templates/organizations/parts/members_results.html.j2:37
msgid "Find member..."
msgstr ""

#: amt/site/templates/organizations/parts/members_results.html.j2:66
#, fuzzy, python-format
#, python-format
msgid ""
"%(members_length)s result\n"
" "
Expand Down Expand Up @@ -724,7 +720,7 @@ msgid "Organisation Type"
msgstr ""

#: amt/site/templates/organizations/parts/overview_results.html.j2:80
#, fuzzy, python-format
#, python-format
msgid ""
"%(organizations_length)s result\n"
" "
Expand Down
Binary file modified amt/locale/nl_NL/LC_MESSAGES/messages.mo
Binary file not shown.
14 changes: 5 additions & 9 deletions amt/locale/nl_NL/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ msgid "measure executed"
msgstr "maatregelen uitgevoerd"

#: amt/site/templates/algorithms/details_compliance.html.j2:69
#: amt/site/templates/macros/editable.html.j2:67
#: amt/site/templates/macros/editable.html.j2:72
#: amt/site/templates/macros/editable.html.j2:68
#: amt/site/templates/macros/editable.html.j2:73
#: amt/site/templates/macros/tasks.html.j2:82
msgid "Edit"
msgstr "Bewerk"
Expand Down Expand Up @@ -484,12 +484,12 @@ msgid "Read more on the algoritmekader"
msgstr "Lees meer op het algoritmekader"

#: amt/site/templates/algorithms/details_measure_modal.html.j2:64
#: amt/site/templates/macros/editable.html.j2:174
#: amt/site/templates/macros/editable.html.j2:175
msgid "Save"
msgstr "Opslaan"

#: amt/site/templates/algorithms/details_measure_modal.html.j2:68
#: amt/site/templates/macros/editable.html.j2:179
#: amt/site/templates/macros/editable.html.j2:180
#: amt/site/templates/organizations/parts/add_members_modal.html.j2:26
msgid "Cancel"
msgstr "Annuleren"
Expand Down Expand Up @@ -712,10 +712,6 @@ msgstr "Voeg personen toe"
msgid "Search"
msgstr "Zoek"

#: amt/site/templates/organizations/parts/members_results.html.j2:37
msgid "Find member..."
msgstr "Voeg personen toe"

#: amt/site/templates/organizations/parts/members_results.html.j2:66
#, python-format
msgid ""
Expand Down Expand Up @@ -912,5 +908,5 @@ msgstr "Resultaten voor"

#: amt/site/templates/parts/tasks_search.html.j2:50
msgid "Assignee"
msgstr "Verantwoordelijke"
msgstr "Toegewezen aan"

6 changes: 5 additions & 1 deletion amt/models/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum
from typing import Any, TypeVar

from sqlalchemy import ForeignKey, String, func
from sqlalchemy import ForeignKey, String, func, orm
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.types import JSON
Expand Down Expand Up @@ -72,6 +72,10 @@ def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: ANN401
if system_card is not None:
self.system_card = system_card

@orm.reconstructor # pyright: ignore[reportUnknownMemberType]
def init_on_load(self) -> None:
self._system_card: AlgorithmSystemCard | None = None

@property
def system_card(self) -> AlgorithmSystemCard:
if not hasattr(self, "_system_card"):
Expand Down
10 changes: 9 additions & 1 deletion amt/site/static/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ main {
background-color: var(--rvo-color-lichtblauw-150);
border-radius: 10px;
height: calc(100% - 30px); /* todo (robbert): this is a display hack */
padding: 0.01px; /* this is an avoid margin collapse hack */
padding-top: 5px;
}

.progress-card-container {
Expand Down Expand Up @@ -492,4 +492,12 @@ main {
}
}

.amt-editable-block:not(:has(form)) {
&:hover {
background-color: var(--rvo-color-grijs-100);
box-shadow: 0 0 5px 5px var(--rvo-color-grijs-100);
cursor: pointer;
}
}

/* stylelint-enable */
Loading

0 comments on commit dddc765

Please sign in to comment.