Skip to content

Commit

Permalink
Selections sent to API after changing ontology filters
Browse files Browse the repository at this point in the history
  • Loading branch information
yelenacox committed Jan 8, 2025
1 parent a2a1779 commit 65b8756
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
15 changes: 8 additions & 7 deletions src/components/Manager/MappingsFunctions/MappingSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const MappingSearch = ({
setDisplaySelectedMappings,
selectedBoxes,
setSelectedBoxes,
existingMappings,
} = useContext(MappingContext);

let ref = useRef();
Expand Down Expand Up @@ -253,7 +254,8 @@ export const MappingSearch = ({
};

const onExistingChange = checkedValues => {
setExistingMappings(checkedValues);
const parsedValues = checkedValues.map(cv => JSON.parse(cv));
setExistingMappings(parsedValues);
};

// If the checkbox is checked, it adds the object to the selectedBoxes array
Expand Down Expand Up @@ -410,8 +412,12 @@ export const MappingSearch = ({
);
};

// Sets existingMappings to the mappings that have already been mapped to pass them to the body of the PUT call on save.
useEffect(() => {
setExistingMappings(mappingsForSearch);
}, []);
// Iterates through the array of previously selected mappings. Returns a JSON stringified object to use as default checked values separate from the search results.
const initialChecked = mappingsForSearch.map(m =>
const initialChecked = existingMappings.map(m =>
JSON.stringify({
code: m?.code,
display: m?.display,
Expand All @@ -420,11 +426,6 @@ export const MappingSearch = ({
})
);

// Sets existingMappings to the mappings that have already been mapped to pass them to the body of the PUT call on save.
useEffect(() => {
setExistingMappings(mappingsForSearch);
}, []);

// Creates a Set that excludes the mappings that have already been selected.
// Then filteres the existing mappings out of the results to only display results that have not yet been selected.
const getFilteredResults = () => {
Expand Down
30 changes: 15 additions & 15 deletions src/components/Projects/Tables/EditMappingsTableModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export const EditMappingsTableModal = ({
setDisplaySelectedMappings,
setShowOptions,
idsForSelect,
existingMappings,
selectedBoxes,
} = useContext(MappingContext);
const {
apiPreferencesCode,
Expand Down Expand Up @@ -179,27 +181,25 @@ export const EditMappingsTableModal = ({
// The existing and new mappings are JSON.parsed and combined into one mappings array to be passed into the body of the PUT call.
const editUpdatedMappings = values => {
setLoading(true);
const selectedMappings = values?.selected_mappings?.map(item => ({

const selectedMappings = selectedBoxes?.map(item => ({
code: item.code,
display: item.display,
description: item.description,
system:
item.system || systemsMatch(item.code.split(':')[0], ontologyApis),
system: systemsMatch(item.code.split(':')[0], ontologyApis),
mapping_relationship: idsForSelect[item.code],
}));
const mappingsDTO = {
mappings: [
...(values.existing_mappings?.map(v => {
const parsedMapping = JSON.parse(v);
if (idsForSelect[parsedMapping.code]) {
parsedMapping.mapping_relationship =
idsForSelect[parsedMapping.code];
}

return parsedMapping;
}) ?? []),
...(selectedMappings ?? []),
],
const preexistingMappings = existingMappings?.map(item => ({
code: item.code,
display: item.display,
description: item.description,
system: systemsMatch(item?.code?.split(':')[0], ontologyApis),
mapping_relationship: idsForSelect[item.code],
}));

const mappingsDTO = {
mappings: [...(preexistingMappings ?? []), ...(selectedMappings ?? [])],
editor: user.email,
};

Expand Down
30 changes: 14 additions & 16 deletions src/components/Projects/Terminologies/EditMappingModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const EditMappingsModal = ({
const [termMappings, setTermMappings] = useState([]);
const [options, setOptions] = useState([]);
const { vocabUrl, setSelectedKey, user } = useContext(myContext);
const { setShowOptions, idsForSelect } = useContext(MappingContext);
const { setShowOptions, idsForSelect, selectedBoxes, existingMappings } =
useContext(MappingContext);
const {
apiPreferencesCode,
setApiPreferencesCode,
Expand Down Expand Up @@ -182,27 +183,24 @@ export const EditMappingsModal = ({
// The existing and new mappings are JSON.parsed combined into one mappings array to be passed into the body of the PUT call.
const editUpdatedMappings = values => {
setLoading(true);
const selectedMappings = values?.selected_mappings?.map(item => ({
const selectedMappings = selectedBoxes?.map(item => ({
code: item.code,
display: item.display,
description: item.description,
system:
item.system || systemsMatch(item.code.split(':')[0], ontologyApis),
system: systemsMatch(item.code.split(':')[0], ontologyApis),
mapping_relationship: idsForSelect[item.code],
}));
const mappingsDTO = {
mappings: [
...(values.existing_mappings?.map(v => {
const parsedMapping = JSON.parse(v);
if (idsForSelect[parsedMapping.code]) {
parsedMapping.mapping_relationship =
idsForSelect[parsedMapping.code];
}

return parsedMapping;
}) ?? []),
...(selectedMappings ?? []),
],
const preexistingMappings = existingMappings?.map(item => ({
code: item.code,
display: item.display,
description: item.description,
system: systemsMatch(item?.code?.split(':')[0], ontologyApis),
mapping_relationship: idsForSelect[item.code],
}));

const mappingsDTO = {
mappings: [...(preexistingMappings ?? []), ...(selectedMappings ?? [])],
editor: user.email,
};

Expand Down
6 changes: 4 additions & 2 deletions src/components/Search/SearchResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const SearchResults = () => {
const { query } = useParams();
const navigate = useNavigate();
const ref = useRef();
const pageref = useRef;
const pageref = useRef();
const pageStart = page * entriesPerPage;

useEffect(() => {
Expand Down Expand Up @@ -158,7 +158,9 @@ The user is then redirected to the search page, which completes the search for t
<>
<div
key={index}
pageref={index === lastCount + 1 ? ref : undefined}
pageref={
index === lastCount + 1 ? pageref : undefined
}
className="search_result"
>
<div className="term_ontology">
Expand Down

0 comments on commit 65b8756

Please sign in to comment.