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

scroll container + back button fix #95

Merged
merged 3 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from "react";
import React, { useEffect, useRef } from "react";
import PropTypes from "prop-types";
import { useFormConfig, goBack } from "@js/oarepo_ui";
import { useFormikContext, getIn } from "formik";
Expand Down Expand Up @@ -38,6 +38,7 @@ export const GenericCommunityMessage = () => (

export const CommunitySelector = ({ fieldPath }) => {
const { values, setFieldValue } = useFormikContext();
const lastSelectedCommunity = useRef(null);
const {
formConfig: {
allowed_communities,
Expand All @@ -50,75 +51,93 @@ export const CommunitySelector = ({ fieldPath }) => {
if (!values.id) {
if (preselected_community) {
setFieldValue(fieldPath, preselected_community.id);
lastSelectedCommunity.current = preselected_community.id;
} else if (allowed_communities.length === 1) {
setFieldValue(fieldPath, allowed_communities[0].id);
lastSelectedCommunity.current = allowed_communities[0].id;
}
mirekys marked this conversation as resolved.
Show resolved Hide resolved
}
}, []);

const handleClick = (id) => {
setFieldValue(fieldPath, id);
lastSelectedCommunity.current = id;
};
mirekys marked this conversation as resolved.
Show resolved Hide resolved
return (
!values.id && (
<Modal open={!selectedCommunity}>
<Modal
open={!selectedCommunity}
className="communities community-selection-modal"
>
<Modal.Header>{i18next.t("Community selection")}</Modal.Header>
<Modal.Content>
<React.Fragment>
{allowed_communities.length > 1 && (
<React.Fragment>
<p>
{i18next.t(
"Please select community in which your work will be published:"
)}
</p>
<List selection>
{allowed_communities.map((c) => (
<CommunityItem
key={c.id}
community={c}
handleClick={handleClick}
renderLinks={false}
/>
))}
</List>
</React.Fragment>
)}
{allowed_communities.length === 0 && (
<React.Fragment>
<GenericCommunityMessage />{" "}
<span>
{i18next.t(
"If you are certain that you wish to proceed with the generic community, please click on it below."
)}
</span>
<List selection>
{allowed_communities.length > 1 && (
<div className="communities communities-list-scroll-container">
<p>
{i18next.t(
"Please select community in which your work will be published:"
)}
</p>
<List selection>
{allowed_communities.map((c) => (
<CommunityItem
community={generic_community}
key={c.id}
community={c}
handleClick={handleClick}
renderLinks={false}
/>
</List>
</React.Fragment>
)}
<Message>
<Icon name="info circle" className="text size large" />
))}
</List>
</div>
)}
{allowed_communities.length === 0 && (
<React.Fragment>
<GenericCommunityMessage />{" "}
<span>
{i18next.t("All records must belong to a community.")}
{i18next.t(
"If you are certain that you wish to proceed with the generic community, please click on it below."
)}
</span>
</Message>
</React.Fragment>
<List selection>
<CommunityItem
community={generic_community}
handleClick={handleClick}
renderLinks={false}
/>
</List>
</React.Fragment>
)}
<Message>
<Icon name="info circle" className="text size large" />
<span>{i18next.t("All records must belong to a community.")}</span>
</Message>
</Modal.Content>
<Modal.Actions className="flex">
<Button
type="button"
className="ml-0"
icon
labelPosition="left"
onClick={() => goBack()}
>
<Icon name="arrow alternate circle left outline" />
{i18next.t("Go back")}
</Button>
{lastSelectedCommunity.current ? (
<Button
type="button"
className="ml-0"
icon
labelPosition="left"
onClick={() =>
setFieldValue(fieldPath, lastSelectedCommunity.current)
}
mirekys marked this conversation as resolved.
Show resolved Hide resolved
>
<Icon name="arrow alternate circle left outline" />
{i18next.t("Go back")}
</Button>
) : (
<Button
type="button"
className="ml-0"
icon
labelPosition="left"
onClick={() => goBack()}
>
<Icon name="arrow alternate circle left outline" />
{i18next.t("Go back")}
</Button>
)}
</Modal.Actions>
</Modal>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
}
}
}
&.communities.community-selection-modal {
.communities.communities-list-scroll-container {
max-height: 50vh;
overflow-y: auto;
}
}
}
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-communities
version = 5.1.3
version = 5.1.4
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down
Loading