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"; ...@@ -6,6 +6,9 @@ import ExpandMoreIcon from "@material-ui/icons/ExpandMore";
import Typography from "@material-ui/core/Typography"; import Typography from "@material-ui/core/Typography";
import uuid from "uuid/v4"; import uuid from "uuid/v4";
import { makeStyles } from "@material-ui/styles"; 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 DownshiftMultiple from "../common/DownshiftMultiple";
import useGlobalState from "../../hooks/useGlobalState"; import useGlobalState from "../../hooks/useGlobalState";
import FilterService from "../../services/FilterService"; import FilterService from "../../services/FilterService";
...@@ -54,18 +57,24 @@ function Filter() { ...@@ -54,18 +57,24 @@ function Filter() {
[] []
); );
const [onlyOpenDestinations, setOnlyOpenDestinations] = useGlobalState(
"filter-only-open-destinations",
false
);
useEffect(() => { useEffect(() => {
const selectedUniversities = FilterService.getSelection( const selectedUniversities = FilterService.getSelection(
countries, countries,
semesters, semesters,
majorMinors majorMinors,
onlyOpenDestinations
); );
const hasSelection = [countries, semesters, majorMinors].some( const hasSelection =
arr => arr.length !== 0 [countries, semesters, majorMinors].some(arr => arr.length !== 0) ||
); onlyOpenDestinations === true;
saveSelectedUniversities(hasSelection ? selectedUniversities : null); saveSelectedUniversities(hasSelection ? selectedUniversities : null);
}, [countries, semesters, majorMinors]); }, [countries, semesters, majorMinors, onlyOpenDestinations]);
const { const {
countriesOptions, countriesOptions,
...@@ -132,6 +141,23 @@ function Filter() { ...@@ -132,6 +141,23 @@ function Filter() {
effectués sont pris en compte. effectués sont pris en compte.
</Typography> </Typography>
</div> </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> </ExpansionPanelDetails>
</ExpansionPanel> </ExpansionPanel>
); );
......
...@@ -80,7 +80,7 @@ class FilterService { ...@@ -80,7 +80,7 @@ class FilterService {
Object.values( Object.values(
univObj.denormalized_infos.semesters_majors_minors univObj.denormalized_infos.semesters_majors_minors
).flatMap(forSemester => Object.keys(forSemester)) ).flatMap(forSemester => Object.keys(forSemester))
) )
]; ];
} }
...@@ -134,7 +134,8 @@ class FilterService { ...@@ -134,7 +134,8 @@ class FilterService {
getSelection( getSelection(
selectedCountriesCode = [], selectedCountriesCode = [],
selectedSemesters = [], selectedSemesters = [],
selectedMajorMinors = [] selectedMajorMinors = [],
selectOnlyOpenDestinations = false
) { ) {
let possible = let possible =
selectedCountriesCode.length === 0 selectedCountriesCode.length === 0
...@@ -175,6 +176,12 @@ class FilterService { ...@@ -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); 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