Commit ee683de0 authored by Imane Misrar's avatar Imane Misrar
Browse files

feat(Filter/FilterService) : add front feature to filter only open destinations

Relates to #148
parent 65bcecc7
......@@ -6,6 +6,9 @@ import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
import Typography from "@material-ui/core/Typography";
import uuid from "uuid/v4";
import { makeStyles } from "@material-ui/styles";
import { Checkbox } from "@material-ui/core";
import FormControl from "@material-ui/core/FormControl";
import FormControlLabel from "@material-ui/core/FormControlLabel";
import DownshiftMultiple from "../common/DownshiftMultiple";
import useGlobalState from "../../hooks/useGlobalState";
import FilterService from "../../services/FilterService";
......@@ -54,18 +57,24 @@ function Filter() {
[]
);
const [onlyOpenDestinations, setOnlyOpenDestinations] = useGlobalState(
"filter-only-open-destinations",
false
);
useEffect(() => {
const selectedUniversities = FilterService.getSelection(
countries,
semesters,
majorMinors
majorMinors,
onlyOpenDestinations
);
const hasSelection = [countries, semesters, majorMinors].some(
arr => arr.length !== 0
);
const hasSelection =
[countries, semesters, majorMinors].some(arr => arr.length !== 0) ||
onlyOpenDestinations === true;
saveSelectedUniversities(hasSelection ? selectedUniversities : null);
}, [countries, semesters, majorMinors]);
}, [countries, semesters, majorMinors, onlyOpenDestinations]);
const {
countriesOptions,
......@@ -132,6 +141,23 @@ function Filter() {
effectués sont pris en compte.
</Typography>
</div>
<div className={classes.input}>
<FormControl>
<FormControlLabel
control={
<Checkbox
color="primary"
checked={onlyOpenDestinations}
onChange={() =>
setOnlyOpenDestinations(!onlyOpenDestinations)
}
/>
}
label="Filtrer par destinations disponibles actuellement"
labelPlacement="end"
/>
</FormControl>
</div>
</ExpansionPanelDetails>
</ExpansionPanel>
);
......
......@@ -134,7 +134,8 @@ class FilterService {
getSelection(
selectedCountriesCode = [],
selectedSemesters = [],
selectedMajorMinors = []
selectedMajorMinors = [],
selectOnlyOpenDestinations = false
) {
let possible =
selectedCountriesCode.length === 0
......@@ -175,6 +176,12 @@ class FilterService {
});
}
if (selectOnlyOpenDestinations) {
possible = possible.filter(
univ => univ.denormalized_infos.id_destination_open === true
);
}
return possible.map(univ => univ.id);
}
}
......
Supports Markdown
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