From 3613497e219e04dd90f89a5921abc321b61abc85 Mon Sep 17 00:00:00 2001 From: ducica Date: Tue, 22 Oct 2024 10:49:24 +0200 Subject: [PATCH] moved community related cmps to oarepo-communities --- .../CommunitySelector/CommunityItem.jsx | 73 ---------- .../CommunitySelector/CommunitySelector.jsx | 137 ------------------ .../CommunitySelector/SelectedCommunity.jsx | 77 ---------- .../components/CommunitySelector/index.js | 3 - .../js/oarepo_ui/forms/components/index.js | 1 - .../themes/default/elements/image.overrides | 6 - 6 files changed, 297 deletions(-) delete mode 100644 oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunityItem.jsx delete mode 100644 oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunitySelector.jsx delete mode 100644 oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/SelectedCommunity.jsx delete mode 100644 oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/index.js diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunityItem.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunityItem.jsx deleted file mode 100644 index db04b39e..00000000 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunityItem.jsx +++ /dev/null @@ -1,73 +0,0 @@ -import React from "react"; -import { List, Header, Icon } from "semantic-ui-react"; -import Overridable from "react-overridable"; -import PropTypes from "prop-types"; -import { Image } from "react-invenio-forms"; - -export const CommunityItem = ({ community, handleClick, renderLinks }) => { - const { id, title, website, logo, organizations } = community; - return ( - - handleClick(id)} - className="flex align-items-center" - > -
- -
- -
- {renderLinks ? ( - { - e.stopPropagation(); - }} - href={community.links.self_html} - target="_blank" - rel="noopener noreferrer" - > - {title} - - ) : ( - title - )} -
- {website && renderLinks && ( - - - e.stopPropagation()} - href={website} - > - {website} - - - )} - {organizations && ( -
- - {organizations.map((o) => o.name).join(", ")} -
- )} -
-
-
- ); -}; - -CommunityItem.propTypes = { - community: PropTypes.object.isRequired, - handleClick: PropTypes.func, - renderLinks: PropTypes.bool, -}; - -CommunityItem.defaultProps = { - renderLinks: true, -}; diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunitySelector.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunitySelector.jsx deleted file mode 100644 index 8a1f8fa1..00000000 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/CommunitySelector.jsx +++ /dev/null @@ -1,137 +0,0 @@ -import React, { useEffect } from "react"; -import PropTypes from "prop-types"; -import { useFormConfig, goBack } from "@js/oarepo_ui"; -import { useFormikContext, getIn } from "formik"; -import { Message, Icon, Modal, List, Button } from "semantic-ui-react"; -import { Trans } from "react-i18next"; -import { i18next } from "@translations/oarepo_ui/i18next"; -import { CommunityItem } from "./CommunityItem"; - -/* TODO: get actual link for the documentation */ - -export const GenericCommunityMessage = () => ( - - You are not a member of any community. If you choose to proceed, your work - will be published in the "generic" community. We strongly recommend that you - join a community to increase the visibility of your work and to cooperate - with others more easily. You can check the available communities{" "} - e.stopPropagation()} - > - on our communities page. - {" "} - For more details on how to join a community please refer to the instructions - on{" "} - e.stopPropagation()} - > - how to join a community. - {" "} - -); - -export const CommunitySelector = ({ fieldPath }) => { - const { values, setFieldValue } = useFormikContext(); - const { - formConfig: { - allowed_communities, - preselected_community, - generic_community, - }, - } = useFormConfig(); - const selectedCommunity = getIn(values, "parent.communities.default", ""); - // TODO: ideally if the there is a preselected community, it could arrive as part of the - // empty record also, same for the case where the user has just one community, which would eliminate - // the need for this useEffect - useEffect(() => { - if (!values.id) { - if (preselected_community) { - setFieldValue(fieldPath, preselected_community.id); - } else if (allowed_communities.length === 1) { - setFieldValue(fieldPath, allowed_communities[0].id); - } - } - }, []); - const handleClick = (id) => { - setFieldValue(fieldPath, id); - }; - return ( - !values.id && ( - - {i18next.t("Community selection")} - - - {allowed_communities.length > 1 && ( - -

- {i18next.t( - "Please select community in which your work will be published:" - )} -

- - {allowed_communities.map((c) => ( - - ))} - -
- )} - {allowed_communities.length === 0 && ( - - {" "} - - {i18next.t( - "If you are certain that you wish to proceed with the generic community, please click on it below." - )} - - - - - - )} - - - - {i18next.t("All records must belong to a community.")} - - -
-
- - - -
- ) - ); -}; - -CommunitySelector.propTypes = { - fieldPath: PropTypes.string, -}; - -CommunitySelector.defaultProps = { - fieldPath: "parent.communities.default", -}; diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/SelectedCommunity.jsx b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/SelectedCommunity.jsx deleted file mode 100644 index 6bd0e880..00000000 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/SelectedCommunity.jsx +++ /dev/null @@ -1,77 +0,0 @@ -import React from "react"; -import { useFormikContext, getIn } from "formik"; -import { useFormConfig, CommunityItem } from "@js/oarepo_ui"; -import PropTypes from "prop-types"; -import { i18next } from "@translations/oarepo_ui/i18next"; -import { Message, Icon, Button, List } from "semantic-ui-react"; -import { GenericCommunityMessage } from "./CommunitySelector"; -import { Trans } from "react-i18next"; - -export const SelectedCommunity = ({ fieldPath }) => { - const { - formConfig: { - allowed_communities, - generic_community, - preselected_community, - }, - } = useFormConfig(); - const { values, setFieldValue } = useFormikContext(); - const selectedCommunityId = getIn(values, fieldPath, ""); - let selectedCommunity = allowed_communities.find( - (c) => c.id === selectedCommunityId - ); - const isGeneric = generic_community.id === selectedCommunityId; - if (isGeneric) { - selectedCommunity = generic_community; - } - const handleCommunityRemoval = () => { - setFieldValue(fieldPath, ""); - }; - return ( - - {values?.id && ( -

- {i18next.t( - "Your record will be published in the following community:" - )} -

- )} - {!values?.id && - allowed_communities.length > 1 && - !preselected_community && ( - - 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 - - to change the selection. - - )} - {selectedCommunity && ( - - - - )} - {isGeneric ? ( - - - - - ) : null} -
- ); -}; - -SelectedCommunity.propTypes = { - fieldPath: PropTypes.string, -}; - -SelectedCommunity.defaultProps = { - fieldPath: "parent.communities.default", -}; diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/index.js b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/index.js deleted file mode 100644 index 0b98d2ec..00000000 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/CommunitySelector/index.js +++ /dev/null @@ -1,3 +0,0 @@ -export * from "./SelectedCommunity.jsx"; -export * from "./CommunitySelector.jsx"; -export * from "./CommunityItem.jsx"; diff --git a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js index eaa3fa3b..f7f6b5d8 100644 --- a/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js +++ b/oarepo_ui/theme/assets/semantic-ui/js/oarepo_ui/forms/components/index.js @@ -16,4 +16,3 @@ export * from "./SaveButton"; export * from "./ConfirmationModal"; export * from "./BaseFormLayout"; export * from "./CompactFieldLabel"; -export * from "./CommunitySelector"; diff --git a/oarepo_ui/theme/assets/semantic-ui/less/oarepo_ui/themes/default/elements/image.overrides b/oarepo_ui/theme/assets/semantic-ui/less/oarepo_ui/themes/default/elements/image.overrides index e781882c..16d2d8b5 100644 --- a/oarepo_ui/theme/assets/semantic-ui/less/oarepo_ui/themes/default/elements/image.overrides +++ b/oarepo_ui/theme/assets/semantic-ui/less/oarepo_ui/themes/default/elements/image.overrides @@ -1,9 +1,3 @@ -.ui.image.community-selector-image img { - max-height: 80px; - min-width: 80px; - object-fit: contain; -} - .identifier-badge { line-height: 1.2rem; }