Skip to content

Commit

Permalink
Merge branch 'main' into mirekys/fe-247-implement-reusable-suggestion…
Browse files Browse the repository at this point in the history
…-api-query-hookcomponent
  • Loading branch information
mirekys authored Oct 8, 2024
2 parents 6401ddc + 2a46689 commit b6fd0f5
Show file tree
Hide file tree
Showing 11 changed files with 186 additions and 73 deletions.
10 changes: 7 additions & 3 deletions oarepo_ui/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Iterator

import deepmerge
from flask import abort, g, redirect, request
from flask import abort, g, redirect, request, Response
from flask_principal import PermissionDenied
from flask_resources import (
Resource,
Expand All @@ -30,6 +30,7 @@
from werkzeug.exceptions import Forbidden

from oarepo_ui.utils import dump_empty
from .signposting import response_header_signposting

from .templating.data import FieldData

Expand Down Expand Up @@ -187,6 +188,7 @@ def ui_model(self):
# helper function to avoid duplicating code between detail and preview handler
@request_read_args
@request_view_args
@response_header_signposting
def _detail(self, *, is_preview=False):
if is_preview:
api_record = self._get_record(resource_requestctx, allow_draft=is_preview)
Expand Down Expand Up @@ -258,10 +260,12 @@ def _detail(self, *, is_preview=False):
"is_preview": is_preview,
}

return current_oarepo_ui.catalog.render(
response = Response(current_oarepo_ui.catalog.render(
render_method,
**render_kwargs,
)
), mimetype="text/html", status=200)
response._api_record = api_record
return response

def detail(self):
"""Returns item detail page."""
Expand Down
30 changes: 30 additions & 0 deletions oarepo_ui/resources/signposting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from functools import wraps


def response_header_signposting(f):
"""Add signposting link to view's reponse headers.
:param headers: response headers
:type headers: dict
:return: updated response headers
:rtype: dict
"""

@wraps(f)
def inner(*args, **kwargs):
response = f(*args, **kwargs)
if response.status_code != 200:
return response
if not hasattr(response, "_api_record"):
return response

signposting_link = response._api_record.links['self']
response.headers.update(
{
"Link": f'<{signposting_link}> ; rel="linkset" ; type="application/linkset+json"', # noqa
}
)

return response

return inner
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
import React from "react";
import { List, Header } from "semantic-ui-react";
import { List, Header, Icon } from "semantic-ui-react";
import Overridable from "react-overridable";
import PropTypes from "prop-types";
import { i18next } from "@translations/oarepo_ui/i18next";
import { Image } from "react-invenio-forms";

export const CommunityItem = ({ community, handleClick }) => {
const { id, title, description, website, logo } = community;
const { id, title, website, logo, organizations } = community;
return (
<Overridable
id="record-community-selection-item"
community={community}
handleClick={handleClick}
>
<List.Item onClick={() => handleClick(id)} className="flex">
<div className="ui image community-image">
<List.Item
onClick={() => handleClick(id)}
className="flex align-items-center"
>
<div className="ui image community-selector-image">
<Image src={logo} size="tiny" rounded verticalAlign="top" />
</div>
<List.Content>
<Header size="small">{title}</Header>
{description && <p className="mb-5">{description}</p>}
{website && (
<Header size="small">
<a
onClick={(e) => e.stopPropagation()}
href={community.links.self_html}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
href={website}
>
{i18next.t("Community website")}
{title}
</a>
</Header>
{website && (
<React.Fragment>
<Icon name="linkify" />
<a
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
href={website}
>
{website}
</a>
</React.Fragment>
)}
{organizations && (
<div>
<Icon name="building outline" />
<span>{organizations.map((o) => o.name).join(", ")}</span>
</div>
)}
</List.Content>
</List.Item>
Expand All @@ -38,5 +57,5 @@ export const CommunityItem = ({ community, handleClick }) => {

CommunityItem.propTypes = {
community: PropTypes.object.isRequired,
handleClick: PropTypes.func.isRequired,
handleClick: PropTypes.func,
};
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from "react";
import { useFormikContext, getIn } from "formik";
import { useFormConfig } from "@js/oarepo_ui";
import { useFormConfig, CommunityItem } from "@js/oarepo_ui";
import PropTypes from "prop-types";
import { i18next } from "@translations/oarepo_ui/i18next";
import { Header, Message, Icon, Button } from "semantic-ui-react";
import { Message, Icon, Button, List } from "semantic-ui-react";
import { GenericCommunityMessage } from "./CommunitySelector";
import { Trans } from "react-i18next";

export const SelectedCommunity = ({ fieldPath }) => {
const {
Expand All @@ -28,57 +29,34 @@ export const SelectedCommunity = ({ fieldPath }) => {
};
return (
<React.Fragment>
{values?.id ? (
{values?.id && (
<p>
{i18next.t(
"Your record will be published in the following community:"
)}
</p>
) : (
<p>
{i18next.t(
"Your work will be saved in the following community. Please note that after saving it will not be possible to transfer it to another community."
)}
</p>
)}
<div className="flex center aligned">
<Header as="h3" className="m-0">
{/* TODO: the link is to the community landing page which is not yet ready */}
<a
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
href={selectedCommunity?.links?.self_html}
aria-label={i18next.t("Community home page")}
>
{selectedCommunity?.title}
</a>
</Header>
{!values?.id &&
allowed_communities.length > 1 &&
!preselected_community && (
{!values?.id &&
allowed_communities.length > 1 &&
!preselected_community && (
<Trans i18n={i18next}>
Your work will be saved in the following community. Please note that
after saving it will not be possible to transfer it to another
community. Click
<Button
className="rel-ml-1"
className="ml-5 mr-5"
onClick={handleCommunityRemoval}
size="mini"
>
{i18next.t("Change")}
here
</Button>
)}
</div>

<p>{selectedCommunity?.description}</p>
{selectedCommunity?.website && (
<span>
<a
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
href={selectedCommunity?.website}
>
{i18next.t("Community website.")}
</a>
</span>
to change the selection.
</Trans>
)}
{selectedCommunity && (
<List>
<CommunityItem community={selectedCommunity} />
</List>
)}
{isGeneric ? (
<Message>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.ui.image.community-image img {
.ui.image.community-selector-image img {
max-height: 80px;
min-width: 80px;
object-fit: contain;
Expand Down

Large diffs are not rendered by default.

Binary file modified oarepo_ui/translations/cs/LC_MESSAGES/messages.mo
Binary file not shown.
36 changes: 36 additions & 0 deletions oarepo_ui/translations/cs/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,39 @@ msgstr ""

msgid "Change"
msgstr "Změnit"

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:7
msgid "ORCID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:12
msgid "Scopus ID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:17
msgid "ROR profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:22
msgid "WOS Researcher ID"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:27
msgid "DOI profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:32
msgid "GND profile"
msgstr ""

msgid "change"
msgstr ""

msgid ""
"Your work will be saved in the following community. Please note that after "
"saving it will not be possible to transfer it to another community. "
"Click<1>here</1>to change the selection."
msgstr ""
"Vaše práce bude uložena v následující komunitě. Vezměte prosím na vědomí, že"
" po uložení nebude možné převést ji do jiné komunity. Klikněte<1>zde</1>pro "
"změnu výběru."
33 changes: 33 additions & 0 deletions oarepo_ui/translations/en/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -628,3 +628,36 @@ msgid ""
"If you are certain that you wish to proceed with the generic community, "
"please click on it below."
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:7
msgid "ORCID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:12
msgid "Scopus ID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:17
msgid "ROR profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:22
msgid "WOS Researcher ID"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:27
msgid "DOI profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:32
msgid "GND profile"
msgstr ""

msgid "change"
msgstr ""

msgid ""
"Your work will be saved in the following community. Please note that after "
"saving it will not be possible to transfer it to another community. "
"Click<1>here</1>to change the selection."
msgstr ""
Binary file modified oarepo_ui/translations/messages.mo
Binary file not shown.
41 changes: 27 additions & 14 deletions oarepo_ui/translations/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2024-08-26 11:34+0200\n"
"POT-Creation-Date: 2024-09-15 21:51+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand Down Expand Up @@ -77,6 +77,30 @@ msgstr ""
msgid "Edit item"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:7
msgid "ORCID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:12
msgid "Scopus ID profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:17
msgid "ROR profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:22
msgid "WOS Researcher ID"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:27
msgid "DOI profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifierBadge.jinja:32
msgid "GND profile"
msgstr ""

#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifiersAndLinks.jinja:3
#: /home/dusanst/oarepo-ui/oarepo-ui/oarepo_ui/templates/components/IdentifiersAndLinks.jinja:4
msgid "Identifiers and links"
Expand Down Expand Up @@ -248,9 +272,6 @@ msgstr ""
msgid "Remove field"
msgstr ""

msgid "Community website"
msgstr ""

msgid "Community selection"
msgstr ""

Expand All @@ -276,16 +297,8 @@ msgstr ""

msgid ""
"Your work will be saved in the following community. Please note that after "
"saving it will not be possible to transfer it to another community."
msgstr ""

msgid "Community home page"
msgstr ""

msgid "Change"
msgstr ""

msgid "Community website."
"saving it will not be possible to transfer it to another community. "
"Click<1>here</1>to change the selection."
msgstr ""

msgid "Delete"
Expand Down

0 comments on commit b6fd0f5

Please sign in to comment.