Commit 5a7e8359 authored by TJHeeringa's avatar TJHeeringa

Finished Matchings

parent 4454e109
......@@ -144,11 +144,12 @@ const EnhancedTable = ({headers, filterProperties, rows, ...props}) => {
setAllSelected(newAllSelected);
};
const handleDelete = () => {
const handleDelete = () => {
let deleted_rows = rows.filter(row=>selected.includes(row.slug));
let new_rows = rows.filter(row=>!selected.includes(row.slug));
setAllSelected(false);
setSelected([]);
props.onDelete(new_rows);
props.onDelete(deleted_rows, new_rows);
};
const handleChangePage = (event, newPage) => {
......
......@@ -11,6 +11,7 @@ import 'react-table/react-table.css';
import EnhancedTable from "App/Components/Tables/EnhancedTable";
import ExtremeTable from "App/Components/Tables/ExtremeTable";
import { useAlertHandler } from "App/Contexts/AlertHandler";
import { Helper } from "App/Helper";
const useStyles = makeStyles(theme => ({
......@@ -138,39 +139,44 @@ const Matchings = (props) => {
console.log(Object.keys(selectedLeft).length > 0, Object.keys(selectedRight).length > 0, selectedLeft === selectedRight);
console.log("Now the handler should show up.")
} else {
console.log(selectedLeft, selectedRight);
console.log('association', props.association);
let match = {
slug: selectedLeft.slug,
left_name: selectedLeft.given_name,
left_slug: selectedLeft.slug,
right_name: selectedRight.given_name,
right_slug: selectedRight.slug,
association: props.association.url,
left_profile: selectedLeft.url,
right_profile: selectedRight.url,
};
let slugs = matchSlugs.concat([match.left_slug, match.right_slug]);
setMatches(matches.concat(match));
setLeft({});
setRight({});
setMatchSlugs(slugs);
Helper.api_call(process.env.REACT_APP_API_URL + "/matchings", "POST", match, 'json',
(created_match)=>{
let slugs = matchSlugs.concat([created_match.left_slug, created_match.right_slug]);
setMatches(matches.concat(created_match));
setMatchSlugs(slugs);
setLeft({});
setRight({});
},
()=>alertHandler.handleAlertHandler('red', 'Creation of matching failed.')
);
}
};
const onDelete = (new_matches) => {
let left_slugs = new_matches.map(match=>match.left_slug);
let right_slugs = new_matches.map(match=>match.right_slug);
const onDelete = (to_be_deleted_matches, remaining_matches) => {
let deleted_matches = [];
to_be_deleted_matches.map(match=>
Helper.api_call(process.env.REACT_APP_API_URL + "/matchings", "POST", match, 'json',
()=>{deleted_matches.push(match)},
()=>{
alertHandler.handleAlertHandler('red', 'Deletion of match between ' + match.left_name + ' and ' + match.left_name + ' failed.');
remaining_matches.push(match)
}
)
);
let left_slugs = remaining_matches.map(match=>match.left_slug);
let right_slugs = remaining_matches.map(match=>match.right_slug);
let slugs = left_slugs.concat(right_slugs);
setMatches(new_matches);
setMatches(remaining_matches);
setMatchSlugs(slugs);
};
// const postGroupMembership = (group_membership) => {
// Helper.api_call(
// process.env.REACT_APP_API_URL + "/group_memberships/",
// "POST",
// group_membership,
// 'json',
// );
// };
const rows = (loadingMembers || loadingMembertypes) ? [{}] : morphDataToMemberProfiles(members, membertypes).filter(row=>!matchSlugs.includes(row.slug));
const headers = loadingDataFields ? morphDataToHeaders([]) : morphDataToHeaders(data_fields);
......@@ -203,7 +209,7 @@ const Matchings = (props) => {
headers={['name', 'name']}
rows={matches}
filterProperties={['left_name', 'right_name']}
onDelete={(new_matches)=>onDelete(new_matches)}
onDelete={onDelete}
/>
}
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment