Skip to content

Commit

Permalink
Merge pull request #104 from oarepo/mirekys/be-607-fix-multiple-reque…
Browse files Browse the repository at this point in the history
…st-receivers-rendering

fix(receiver): fix multi-receiver labels
  • Loading branch information
mirekys authored Dec 19, 2024
2 parents e87348a + 43fab64 commit 676561b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
14 changes: 13 additions & 1 deletion oarepo_requests/resolvers/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import abc
import contextlib
import copy
import json
from typing import TYPE_CHECKING, Any, TypedDict, cast, override

from flask import request
Expand Down Expand Up @@ -62,7 +63,18 @@ def resolve(identity: Identity, reference: dict[str, str]) -> UIResolvedReferenc
return cache[(reference_type, reference_value)]

entity_resolvers = current_oarepo_requests.entity_reference_ui_resolvers
if reference_type in entity_resolvers:

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
))
elif reference_type in entity_resolvers:
resolved = entity_resolvers[reference_type].resolve_one(
identity, reference_value
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { i18next } from "@translations/oarepo_requests_ui/i18next";
import { Icon, List } from "semantic-ui-react";
import _has from "lodash/has";
import _truncate from "lodash/truncate";
import _isArray from "lodash/isArray";
import { getRequestStatusIcon } from "@js/oarepo_requests_common";
import PropTypes from "prop-types";

Expand Down Expand Up @@ -31,15 +32,16 @@ export const SideRequestInfo = ({ request }) => {
</List.Content>
</List.Item>
)}
{request?.receiver && (
{(request?.receiver &&
!_isArray(request.receiver)) ? (
<List.Item>
<List.Header as="h3">{i18next.t("Receiver")}</List.Header>
<List.Content>
<Icon name="mail outline" />
<span>
{_has(request, "links.receiver.self_html") ? (
{_has(request, "links.receiver_html") ? (
<a
href={request.links.receiver.self_html}
href={request.links.receiver_html}
target="_blank"
rel="noreferrer"
>
Expand All @@ -50,8 +52,32 @@ export const SideRequestInfo = ({ request }) => {
)}
</span>
</List.Content>
</List.Item>) : (_isArray(request.receiver)) && (
<List.Item>
<List.Header as="h3">{i18next.t("Receiver")}</List.Header>
<List.Content>
<Icon name="mail outline" />
{request.receiver.map((receiverItem, index) => (
<span key={receiverItem.label}>
{receiverItem.links.self_html ? (
<a
href={receiverItem.links.self_html}
target="_blank"
rel="noreferrer"
>
{receiverItem.label}
</a>
) : (
receiverItem.label
)}
{ request.receiver.length - 1 !== index && ', ' }
</span>

))}
</List.Content>
</List.Item>
)}
)
}
<List.Item>
<List.Header as="h3">{i18next.t("Status")}</List.Header>
<List.Content>
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.13
version = 2.3.14
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down

0 comments on commit 676561b

Please sign in to comment.