Skip to content

Commit

Permalink
Mapping comments updating count after making new comment
Browse files Browse the repository at this point in the history
  • Loading branch information
yelenacox committed Dec 9, 2024
1 parent 8d5a9e4 commit dc4ffe6
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 71 deletions.
17 changes: 10 additions & 7 deletions src/components/Manager/MappingsFunctions/AssignMappings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ export const AssignMappings = ({
editor: user.email,
};

fetch(`${vocabUrl}/Terminology/${terminology.id}/mapping/${mappingProp}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(mappingsDTO),
})
fetch(
`${vocabUrl}/Terminology/${terminology.id}/mapping/${mappingProp}?user_input=true&user=${user?.email}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(mappingsDTO),
}
)
.then(res => {
if (res.ok) {
return res.json();
Expand Down
21 changes: 20 additions & 1 deletion src/components/Manager/MappingsFunctions/MappingComments.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { useContext, useEffect, useState } from 'react';
import { myContext } from '../../../App';
import { MappingContext } from '../../../Contexts/MappingContext';
import { ModalSpinner } from '../Spinner';
import { getById } from '../FetchManager';

export const MappingComments = ({
mappingCode,
mappingDisplay,
variableMappings,
setComment,
idProp,
setMapping,
}) => {
const [form] = Form.useForm();
const { vocabUrl, user } = useContext(myContext);
Expand Down Expand Up @@ -91,7 +93,24 @@ export const MappingComments = ({
});
}
return error;
});
})
.then(() =>
getById(
vocabUrl,
'Terminology',
`${idProp}/mapping?user_input=True&user=${user?.email}`
)
.then(data => setMapping(data.codes))
.catch(error => {
if (error) {
notification.error({
message: 'Error',
description: 'An error occurred loading mappings.',
});
}
return error;
})
);
};

const formattedDate = dateString => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Manager/MappingsFunctions/MappingVotes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const mappingVotes = (
getById(
vocabUrl,
'Terminology',
`${terminologyId}/mapping?user_input=True`
`${terminologyId}/mapping?user_input=True&user=${user?.email}`
)
.then(data => setMapping(data.codes))
.catch(error => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const AssignMappingsViaButton = ({
};

fetch(
`${vocabUrl}/Terminology/${terminology.id}/mapping/${assignMappingsViaButton.code}`,
`${vocabUrl}/Terminology/${terminology.id}/mapping/${assignMappingsViaButton.code}?user_input=true&user=${user?.email}`,
{
method: 'PUT',
headers: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Projects/Terminologies/EditMappingModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const EditMappingsModal = ({
editor: user.email,
};
fetch(
`${vocabUrl}/Terminology/${terminologyId}/mapping/${editMappings.code}?user_input=true`,
`${vocabUrl}/Terminology/${terminologyId}/mapping/${editMappings.code}?user_input=true&user=${user?.email}`,
{
method: 'PUT',
headers: {
Expand Down Expand Up @@ -208,7 +208,7 @@ export const EditMappingsModal = ({
};

fetch(
`${vocabUrl}/Terminology/${terminologyId}/mapping/${editMappings.code}?user_input=true`,
`${vocabUrl}/Terminology/${terminologyId}/mapping/${editMappings.code}?user_input=true&user=${user?.email}`,
{
method: 'PUT',
headers: {
Expand Down
162 changes: 103 additions & 59 deletions src/components/Projects/Terminologies/Terminology.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
Tooltip,
} from 'antd';
import {
CaretDownOutlined,
CaretUpOutlined,
CloseCircleOutlined,
DownOutlined,
MessageOutlined,
Expand Down Expand Up @@ -91,13 +93,16 @@ export const Terminology = () => {
editor: user.email,
};

fetch(`${vocabUrl}/Terminology/${terminologyId}/mapping/${mappingCode}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(mappingsDTO),
})
fetch(
`${vocabUrl}/Terminology/${terminologyId}/mapping/${mappingCode}?user_input=true&user=${user?.email}`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(mappingsDTO),
}
)
.then(res => {
if (res.ok) {
return res.json();
Expand Down Expand Up @@ -160,6 +165,11 @@ It then shows the mappings as table data and alows the user to delete a mapping
return calculatedCount;
};

const userVote = code => {
const foundVote = code.user_input?.users_vote;
return foundVote;
};

const matchCode = variable => {
if (!mapping?.length) {
return noMapping(variable);
Expand All @@ -173,34 +183,53 @@ It then shows the mappings as table data and alows the user to delete a mapping
return variableMappings.mappings.map(code => (
<div className="mapping" key={code.code}>
<span>
<MessageOutlined
className="mapping_actions"
onClick={() =>
setComment({
code: code.code,
display: code.display,
variableMappings: variableMappings.code,
})
}
/>
<Tooltip
title={code?.user_input?.comments_count}
mouseEnterDelay={0.75}
>
<MessageOutlined
className="mapping_actions"
onClick={() =>
setComment({
code: code.code,
display: code.display,
variableMappings: variableMappings.code,
})
}
/>
</Tooltip>
</span>
<span className="mapping_votes">
<UpOutlined
className="mapping_actions"
style={{ color: 'blue' }}
onClick={() =>
mappingVotes(
variableMappings,
code,
user,
'up',
vocabUrl,
terminologyId,
notification,
setMapping
)
}
/>
{userVote(code) === 'up' ? (
<CaretUpOutlined
className="mapping_actions user_vote_icon"
style={{
color: 'blue',
cursor: 'not-allowed',
fontSize: '1rem',
}}
/>
) : (
<UpOutlined
className="mapping_actions"
style={{
color: 'blue',
}}
onClick={() =>
userVote(code) !== 'up' &&
mappingVotes(
variableMappings,
code,
user,
'up',
vocabUrl,
terminologyId,
notification,
setMapping
)
}
/>
)}
<Tooltip
title={`up: ${code.user_input?.votes_count.up},
down: ${code.user_input?.votes_count.down}`}
Expand All @@ -218,22 +247,36 @@ It then shows the mappings as table data and alows the user to delete a mapping
{votesCount(code)}
</span>
</Tooltip>
<DownOutlined
className="mapping_actions"
style={{ color: 'green' }}
onClick={() =>
mappingVotes(
variableMappings,
code,
user,
'down',
vocabUrl,
terminologyId,
notification,
setMapping
)
}
/>
{userVote(code) === 'down' ? (
<CaretDownOutlined
className="mapping_actions user_vote_icon"
style={{
color: 'green',
cursor: 'not-allowed',
fontSize: '1rem',
}}
/>
) : (
<DownOutlined
className="mapping_actions"
style={{
color: 'green',
}}
onClick={() =>
userVote(code) !== 'down' &&
mappingVotes(
variableMappings,
code,
user,
'down',
vocabUrl,
terminologyId,
notification,
setMapping
)
}
/>
)}
</span>
<span className="mapping-display">
<Tooltip
Expand Down Expand Up @@ -325,18 +368,18 @@ It then shows the mappings as table data and alows the user to delete a mapping
getById(
vocabUrl,
'Terminology',
`${terminologyId}/mapping?user_input=True+user=${user?.email}`
`${terminologyId}/mapping?user_input=True&user=${user?.email}`
)
.then(data => setMapping(data.codes))
// .catch(error => {
// if (error) {
// notification.error({
// message: 'Error',
// description: 'An error occurred loading mappings.',
// });
// }
// return error;
// })
.catch(error => {
if (error) {
notification.error({
message: 'Error',
description: 'An error occurred loading mappings.',
});
}
return error;
})
.then(() =>
getById(
vocabUrl,
Expand Down Expand Up @@ -559,6 +602,7 @@ It then shows the mappings as table data and alows the user to delete a mapping
variableMappings={comment?.variableMappings}
setComment={setComment}
idProp={terminologyId}
setMapping={setMapping}
/>
</div>
)}
Expand Down

0 comments on commit dc4ffe6

Please sign in to comment.