Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/NIH-NCPI/map-dragon into mh…
Browse files Browse the repository at this point in the history
…f/FD-1542
  • Loading branch information
mhigbyflowers committed Dec 11, 2024
2 parents 0ae4c72 + dfbe0b2 commit 9529528
Show file tree
Hide file tree
Showing 19 changed files with 600 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ env:

PROJECT_ID: ${{ secrets.PROJECT_ID }}
REGION: ${{ secrets.REGION_LOC_1 }}
SERVICE: 'map-dragon'
SERVICE: 'mapdragon'
IMAGE_NAME: 'map-dragon_img'
GCP_CREDENTIALS: ${{ secrets.GCP_CREDENTIALS }}

Expand Down
3 changes: 1 addition & 2 deletions src/AppRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ export const AppRouter = () => {
const { user, vocabUrl } = useContext(myContext);
const isLoggedIn = () => {
const storedUser = localStorage.getItem('user');

if (storedUser) {
return true;
} else {
return false;
}
};

return (
<BrowserRouter>
<Routes>
Expand Down
9 changes: 9 additions & 0 deletions src/Contexts/MappingContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export function MappingContextRoot() {
const [relationshipOptions, setRelationshipOptions] = useState([]);
const [idsForSelect, setIdsForSelect] = useState([]);
const [showOptions, setShowOptions] = useState(false);
const [voteCount, setVoteCount] = useState(0);
const [mappingComments, setMappingComments] = useState([]);
const [comment, setComment] = useState(false);

const context = {
editMappings,
Expand All @@ -42,6 +45,12 @@ export function MappingContextRoot() {
setIdsForSelect,
showOptions,
setShowOptions,
voteCount,
setVoteCount,
mappingComments,
setMappingComments,
comment,
setComment,
};

return (
Expand Down
17 changes: 10 additions & 7 deletions src/components/Manager/MappingsFunctions/AssignMappings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,16 @@ export const AssignMappings = ({
mappings: selectedMappings,
};

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
17 changes: 1 addition & 16 deletions src/components/Manager/MappingsFunctions/FilterOntology.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,6 @@ export const FilterOntology = ({
}
};

const selectedOntDisplay = (ont, i) => {
return (
<>
<div key={i} className="modal_search_result">
<div>
<div className="modal_term_ontology">
<div>{ont?.curie}</div>
</div>
<div>{ont?.ontology_title}</div>
</div>
</div>
</>
);
};

const checkBoxDisplay = (ont, i) => {
return (
<>
Expand Down Expand Up @@ -211,7 +196,7 @@ export const FilterOntology = ({
value={selected}
onChange={e => onCheckboxChange(e, selected)}
>
{selectedOntDisplay(selected, i)}
{checkBoxDisplay(selected, i)}
</Checkbox>
))}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Manager/MappingsFunctions/GetMappingsModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const GetMappingsModal = ({
setLoading(true);
console.log(user);
fetch(
`${vocabUrl}/${componentString}/${component.id}/mapping/${mappingProp}`,
`${vocabUrl}/${componentString}/${component.id}/mapping/${mappingProp}?user_input=true&user=${user?.email}`,
{
method: 'PUT',
headers: {
Expand Down Expand Up @@ -341,7 +341,7 @@ export const GetMappingsModal = ({
<MappingRelationship mapping={d} />
</div>
</div>
<div>{ellipsisString(d?.description[0], '100')}</div>
<div>{ellipsisString(d?.description?.[0], '100')}</div>
</div>
</div>
</>
Expand Down
198 changes: 198 additions & 0 deletions src/components/Manager/MappingsFunctions/MappingComments.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import { Button, Form, Input, Modal, notification } from 'antd';
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);
const { mappingComments, setMappingComments } = useContext(MappingContext);
const [loading, setLoading] = useState(false);
const { TextArea } = Input;

const onClose = () => {
setComment(null);
setMappingComments([]);
};

useEffect(() => {
if (!!mappingCode) {
getComments();
}
}, [mappingCode]);

const getComments = () => {
setLoading(true);
return fetch(
`${vocabUrl}/Terminology/${idProp}/user_input/${variableMappings}/mapping/${mappingCode}/mapping_conversations`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
)
.then(res => {
if (res.ok) {
return res.json();
} else {
throw new Error('An unknown error occurred.');
}
})
.then(data => setMappingComments(data?.mapping_conversations))
.catch(error => {
if (error) {
notification.error({
message: 'Error',
description: 'An error occurred saving the comment.',
});
}
return error;
})
.finally(() => setLoading(false));
};

const onFinish = values => {
const mappingCommentDTO = {
editor: user?.email,
note: values.comment,
};

return fetch(
`${vocabUrl}/Terminology/${idProp}/user_input/${variableMappings}/mapping/${mappingCode}/mapping_conversations`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(mappingCommentDTO),
}
)
.then(res => {
if (res.ok) {
return res.json();
} else {
throw new Error('An unknown error occurred.');
}
})
.then(data => setMappingComments(data?.mapping_conversations))
.catch(error => {
if (error) {
notification.error({
message: 'Error',
description: 'An error occurred saving the comment.',
});
}
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 => {
const date = new Date(dateString);

return date.toLocaleString('en-US', {
month: 'short',
day: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: true,
});
};

const commentDisplay = (mc, i) => {
return (
<div key={i} className="comment_container">
<div className="comment_note">{mc.note}</div>
<div className="comment_date_user">
<div>{formattedDate(mc.date)}</div>
<div>{mc.user_id}</div>
</div>
</div>
);
};

return (
<>
<Modal
open={!!mappingCode}
width={'70%'}
styles={{
body: {
minHeight: '60vh',
maxHeight: '60vh',
overflowY: 'auto',
},
}}
footer={[<Button onClick={onClose}>Close</Button>]}
maskClosable={false}
closeIcon={false}
destroyOnClose={true}
>
<span className="comment_code_display">{variableMappings}: </span>
{mappingDisplay ? mappingDisplay : mappingCode}
<Form
form={form}
layout="inline"
onFinish={() => {
form.validateFields().then(values => {
onFinish(values);
form.resetFields();
});
}}
preserve={false}
>
<Form.Item name="comment">
<TextArea
rows={1}
style={{
width: 500,
resize: 'vertical',
}}
showCount
maxLength={1000}
autoFocus
className="comment_textarea"
/>
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit">
Comment
</Button>
</Form.Item>
</Form>
{loading ? (
<ModalSpinner />
) : (
mappingComments?.map((mc, i) => commentDisplay(mc, i))
)}
</Modal>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const MappingRelationship = ({ mapping }) => {
style={{
width: 120,
}}
placeholder="Quality"
placeholder="Relationship"
popupMatchSelectWidth={false}
allowClear
value={idsForSelect[mapping.obo_id || mapping.code]}
Expand Down
61 changes: 61 additions & 0 deletions src/components/Manager/MappingsFunctions/MappingVotes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { getById } from '../FetchManager';

export const mappingVotes = (
variableMappings,
code,
user,
vote,
vocabUrl,
terminologyId,
notification,
setMapping
) => {
const mappingVoteDTO = {
editor: user?.email,
vote: vote,
};

return fetch(
`${vocabUrl}/Terminology/${terminologyId}/user_input/${variableMappings?.code}/mapping/${code?.code}/mapping_votes`,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(mappingVoteDTO),
}
)
.then(res => {
if (res.ok) {
return res.json();
} else {
throw new Error('An unknown error occurred.');
}
})
.catch(error => {
if (error) {
notification.error({
message: 'Error',
description: 'An error occurred saving the vote.',
});
}
return error;
})
.then(() =>
getById(
vocabUrl,
'Terminology',
`${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;
})
);
};
Loading

0 comments on commit 9529528

Please sign in to comment.