Skip to content
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

Stojanovic/fe 237 support moving record from one community to another UI #108

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
7 changes: 5 additions & 2 deletions oarepo_requests/resolvers/interface.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from __future__ import annotations

from typing import Any, TYPE_CHECKING
import logging
from typing import TYPE_CHECKING, Any

from invenio_pidstore.errors import PersistentIdentifierError

from oarepo_requests.resolvers.ui import resolve
import logging

if TYPE_CHECKING:
from invenio_requests.records import Request
log = logging.getLogger(__name__)


# todo consider - we are not using this strictly in the ui context - so how should we separate these things in the future
def resolve_entity(entity: str, obj: Request, ctx: dict[str, Any]) -> dict:
"""Resolve the entity and put it into the context cache.
Expand Down Expand Up @@ -42,6 +44,7 @@ def resolve_entity(entity: str, obj: Request, ctx: dict[str, Any]) -> dict:


def entity_context_key(reference_dict: dict) -> str:
"""Create a key for the entity context cache."""
return "entity:" + ":".join(
f"{x[0]}:{x[1]}" for x in sorted(reference_dict.items())
)
6 changes: 2 additions & 4 deletions oarepo_requests/resolvers/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ def resolve(identity: Identity, reference: dict[str, str]) -> UIResolvedReferenc

entity_resolvers = current_oarepo_requests.entity_reference_ui_resolvers

if reference_type == 'multiple':
if reference_type == "multiple":
# TODO(mirekys): add test coverage
resolved = []
reference_values_list = list(json.loads(reference_value))

for reference_values_item in reference_values_list:
for key, value in reference_values_item.items():
resolved.append(entity_resolvers[key].resolve_one(
identity, value
))
resolved.append(entity_resolvers[key].resolve_one(identity, value))
elif reference_type in entity_resolvers:
resolved = entity_resolvers[reference_type].resolve_one(
identity, reference_value
Expand Down
17 changes: 17 additions & 0 deletions oarepo_requests/resources/draft/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

from __future__ import annotations

import importlib_metadata

from oarepo_requests.resources.record.config import RecordRequestsResourceConfig


Expand All @@ -20,3 +22,18 @@ class DraftRecordRequestsResourceConfig(RecordRequestsResourceConfig):
"list-requests-draft": "/<pid_value>/draft/requests",
"request-type-draft": "/<pid_value>/draft/requests/<request_type>",
}

@property
def error_handlers(self) -> dict:
"""Return error handlers loaded dynamically from entry points."""
parent_handlers = (
super().error_handlers if hasattr(super(), "error_handlers") else {}
)
handlers = parent_handlers.copy() if parent_handlers else {}

for entry_point in importlib_metadata.entry_points(
group="invenio.documents.error_handlers"
mirekys marked this conversation as resolved.
Show resolved Hide resolved
):
exception_class, handler = entry_point.load()()
handlers[exception_class] = handler
return handlers
1 change: 0 additions & 1 deletion oarepo_requests/services/oarepo/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ def create(

if data is None:
data = {}

if hasattr(type_, "can_create"):
error = type_.can_create(identity, data, receiver, topic, creator)
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export const requestButtonsDefaultIconConfig = {
edit_published_record: { icon: "pencil", labelPosition: "left" },
assign_doi: { icon: "address card", labelPosition: "left" },
created: { icon: "paper plane", labelPosition: "left" },
initiate_community_migration: { icon: "exchange", labelPosition: "left" },
Ducica marked this conversation as resolved.
Show resolved Hide resolved
confirm_community_migration: { icon: "exchange", labelPosition: "left" },
secondary_community_submission: { icon: "users", labelPosition: "left" },
remove_secondary_community: { icon: "remove", labelPosition: "left" },
submitted: { icon: "clock", labelPosition: "left" },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,24 @@ import ReactDOM from "react-dom";
import { RecordRequests } from "./components";
import { encodeUnicodeBase64 } from "@js/oarepo_ui";
import { i18next } from "@translations/oarepo_requests_ui/i18next";
import { setIn } from "formik";

const recordRequestsAppDiv = document.getElementById("record-requests");

if (recordRequestsAppDiv) {
const record = JSON.parse(recordRequestsAppDiv.dataset.record);

const onActionError = ({ e, formik, modalControl }) => {
if (e?.response?.data?.errors) {
if (
e?.response?.data?.error_type === "cf_validation_error" &&
e?.response?.data?.errors
) {
let errorsObj = {};
for (const error of e.response.data.errors) {
errorsObj = setIn(errorsObj, error.field, error.messages.join(" "));
}
formik?.setErrors(errorsObj);
} else if (e?.response?.data?.errors) {
const errorData = e.response.data;
const jsonErrors = JSON.stringify(errorData);
const base64EncodedErrors = encodeUnicodeBase64(jsonErrors);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
.ui.modal {
&.requests-request-modal {
.actions {
position: relative;
z-index: -1;
}
.field {
margin-bottom: 1rem !important;
}
Expand Down
Loading