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

Added word limit to abstract fields #219

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion src/components/FormComponents/BilingualTextInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const BilingualTextInput = ({
multiline,
disabled,
error,
errorMessages,
translationButonDisabled = false,
}) => {
const { translate } = useContext(UserContext);
Expand Down Expand Up @@ -58,7 +59,8 @@ const BilingualTextInput = ({
}}
multiline={multiline}
disabled={disabled}
error={Boolean(error)}
error={errorMessages !== undefined ? errorMessages?.[lang] !== '' : error}
helperText={errorMessages?.[lang]}
/>
{i === 0 && !translationButonDisabled && (
<Tooltip
Expand Down
20 changes: 18 additions & 2 deletions src/components/Tabs/IdentificationTab.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, {useState} from "react";
import { Paper, TextField, Grid, IconButton, Tooltip } from "@material-ui/core";
import { useParams } from "react-router-dom";
import { OpenInNew, Update } from "@material-ui/icons";
Expand Down Expand Up @@ -31,11 +31,13 @@ const IdentificationTab = ({
projects,
}) => {
const { language, region } = useParams();
const [errorMessages, setErrorMessages] = useState({en: "", fr: ""});
const regionInfo = regions[region];
const doiIsValid = Boolean(
!record.datasetIdentifier || doiRegexp.test(record.datasetIdentifier)
);
const languageUpperCase = language.toUpperCase();
const abstractWordLimit = 5

const CatalogueLink = ({ lang }) => (
<a
Expand All @@ -55,6 +57,7 @@ const IdentificationTab = ({
)
);


return (
<div>
<Paper style={paperClass}>
Expand Down Expand Up @@ -240,7 +243,20 @@ const IdentificationTab = ({

<BilingualTextInput
value={record.abstract}
onChange={handleUpdateRecord("abstract")}
onChange={(dataEvent) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@n-a-t-e This logic seems close, but fields still accept input above the limit - as the payload for each language carries all languages. Does splitting the warnings like this make sense?

let newErrorObj = {...errorMessages}
// eslint-disable-next-line no-restricted-syntax
for (const [key, abstract] of Object.entries(dataEvent.target.value)){
if (abstract.split(" ").length > abstractWordLimit){
newErrorObj = {...newErrorObj, [key]: `${abstractWordLimit} word limit.`}
} else {
newErrorObj = {...newErrorObj, [key]: ``}
handleUpdateRecord("abstract")(dataEvent)
}
}
setErrorMessages(newErrorObj)
}}
errorMessages={errorMessages}
disabled={disabled}
multiline
/>
Expand Down