Skip to content

Commit

Permalink
Merge pull request #108 from oarepo/stojanovic/fe-237-support-moving-…
Browse files Browse the repository at this point in the history
…record-from-one-community-to-another-ui

Stojanovic/fe 237 support moving record from one community to another UI
  • Loading branch information
mesemus authored Feb 14, 2025
2 parents b853b33 + 1844b47 commit a608c57
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 21 deletions.
1 change: 1 addition & 0 deletions oarepo_requests/resolvers/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,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())
)
16 changes: 16 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,17 @@ 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:
"""Get error handlers."""
entrypoint_error_handlers = {}
for x in importlib_metadata.entry_points(
group="oarepo_requests.error_handlers"
):
entrypoint_error_handlers.update(x.load())
for x in importlib_metadata.entry_points(
group="oarepo_requests.draft.error_handlers"
):
entrypoint_error_handlers.update(x.load())
return entrypoint_error_handlers
15 changes: 15 additions & 0 deletions oarepo_requests/resources/events/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import importlib_metadata
import marshmallow as ma
from flask_resources import ResponseHandler
from invenio_records_resources.services.base.config import ConfiguratorMixin
Expand Down Expand Up @@ -52,3 +53,17 @@ def response_handlers(self) -> dict[str, ResponseHandler]:
),
**super().response_handlers,
}

@property
def error_handlers(self) -> dict:
"""Get error handlers."""
entrypoint_error_handlers = {}
for x in importlib_metadata.entry_points(
group="oarepo_requests.error_handlers"
):
entrypoint_error_handlers.update(x.load())
for x in importlib_metadata.entry_points(
group="oarepo_requests.events.error_handlers"
):
entrypoint_error_handlers.update(x.load())
return entrypoint_error_handlers
15 changes: 15 additions & 0 deletions oarepo_requests/resources/oarepo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import importlib_metadata
from flask_resources import ResponseHandler
from invenio_records_resources.services.base.config import ConfiguratorMixin
from invenio_requests.resources import RequestsResourceConfig
Expand Down Expand Up @@ -37,3 +38,17 @@ def response_handlers(self) -> dict[str, ResponseHandler]:
),
**super().response_handlers,
}

@property
def error_handlers(self) -> dict:
"""Get error handlers."""
entrypoint_error_handlers = {}
for x in importlib_metadata.entry_points(
group="oarepo_requests.error_handlers"
):
entrypoint_error_handlers.update(x.load())
for x in importlib_metadata.entry_points(
group="oarepo_requests.extended.error_handlers"
):
entrypoint_error_handlers.update(x.load())
return entrypoint_error_handlers
15 changes: 15 additions & 0 deletions oarepo_requests/resources/record/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from __future__ import annotations

import importlib_metadata
import marshmallow as ma
from flask_resources import JSONSerializer, ResponseHandler
from invenio_records_resources.resources import RecordResourceConfig
Expand Down Expand Up @@ -45,3 +46,17 @@ def response_handlers(self) -> dict[str, ResponseHandler]:
),
"application/json": ResponseHandler(JSONSerializer(), headers=etag_headers),
}

@property
def error_handlers(self) -> dict:
"""Get error handlers."""
entrypoint_error_handlers = {}
for x in importlib_metadata.entry_points(
group="oarepo_requests.error_handlers"
):
entrypoint_error_handlers.update(x.load())
for x in importlib_metadata.entry_points(
group="oarepo_requests.record.error_handlers"
):
entrypoint_error_handlers.update(x.load())
return entrypoint_error_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 @@ -61,6 +61,7 @@ const DirectCreateAndSubmit = ({
loading={isLoading}
disabled={isMutating > 0}
onClick={() => handleClick()}
labelPosition="left"
{...buttonIconProps}
/>
{isError && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const CreateRequestButton = ({
const { dangerous, has_form: hasForm } = requestType;
const needsDialog = dangerous || hasForm;

if (!hasForm && dangerous) {
if (!hasForm) {
return (
<DirectCreateAndSubmit
requestType={requestType}
Expand All @@ -23,16 +23,6 @@ export const CreateRequestButton = ({
);
}

if (!hasForm && !dangerous) {
return (
<DirectCreateAndSubmit
requestType={requestType}
requireConfirmation={false}
isMutating={isMutating}
/>
);
}

if (needsDialog) {
return (
<RequestModal
Expand All @@ -46,6 +36,7 @@ export const CreateRequestButton = ({
title={header}
content={header}
disabled={isMutating > 0}
labelPosition="left"
{...buttonIconProps}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ import { OverridableContext, overrideStore } from "react-overridable";
const overriddenComponents = overrideStore.getAll();

export const requestButtonsDefaultIconConfig = {
delete_published_record: { icon: "trash", labelPosition: "left" },
publish_draft: { icon: "upload", labelPosition: "left" },
new_version: { icon: "tag", labelPosition: "left" },
edit_published_record: { icon: "pencil", labelPosition: "left" },
assign_doi: { icon: "address card", labelPosition: "left" },
created: { icon: "paper plane", labelPosition: "left" },
submitted: { icon: "clock", labelPosition: "left" },
delete_published_record: { icon: "trash" },
publish_draft: { icon: "upload" },
new_version: { icon: "tag" },
edit_published_record: { icon: "pencil" },
assign_doi: { icon: "address card" },
created: { icon: "paper plane" },
initiate_community_migration: { icon: "exchange" },
confirm_community_migration: { icon: "exchange" },
secondary_community_submission: { icon: "users" },
remove_secondary_community: { icon: "remove" },
submitted: { icon: "clock" },
};

const queryClient = new QueryClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const RequestList = ({ requests }) => {
title={header}
content={header}
disabled={isMutating > 0}
labelPosition="left"
{...buttonIconProps}
/>
}
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-requests
version = 2.3.15
version = 2.3.16
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit a608c57

Please sign in to comment.