diff --git a/src/models/Grant.js b/src/models/Grant.js
index caf05edb..36d7e19d 100644
--- a/src/models/Grant.js
+++ b/src/models/Grant.js
@@ -34,70 +34,67 @@ export default class Grant extends Model {
}
function GrantsFilters({ filter }) {
- const setFilterFields = filter.setFilter
- const [year, setYear] = useState(0)
- const [status, setStatus] = useState('all')
- const currentYear = new Date().getFullYear()
- const startYear = 2007
- const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)
-
+ const setFilterFields = filter.setFilter;
+ const [selectedOption, setSelectedOption] = useState('all');
+ const currentYear = new Date().getFullYear();
+ const startYear = 2007;
+ const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i);
+
+ const options = [
+ { value: 'all', label: 'Tutti' },
+ { value: 'active', label: 'Attivi' },
+ { value: 'inactive', label: 'Non attivi' },
+ ...years.map(year => ({ value: year.toString(), label: year.toString() })),
+ ];
+
return (
- <>
-
);
}
\ No newline at end of file
diff --git a/src/models/Group.js b/src/models/Group.js
index ed65b386..38badafa 100644
--- a/src/models/Group.js
+++ b/src/models/Group.js
@@ -29,70 +29,67 @@ export default class Group extends Model {
}
function GroupsFilters({ filter }) {
- const setFilterFields = filter.setFilter
- const [year, setYear] = useState(0)
- const [status, setStatus] = useState('all')
- const currentYear = new Date().getFullYear()
- const startYear = 2007
- const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)
-
+ const setFilterFields = filter.setFilter;
+ const [selectedOption, setSelectedOption] = useState('all');
+ const currentYear = new Date().getFullYear();
+ const startYear = 2018;
+ const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i);
+
+ const options = [
+ { value: 'all', label: 'Tutti' },
+ { value: 'active', label: 'Attivi' },
+ { value: 'inactive', label: 'Non attivi' },
+ ...years.map(year => ({ value: year.toString(), label: year.toString() })),
+ ];
+
return (
- <>
- {
- const year = parseInt(evt.target.value);
- setYear(year);
- if (year) {
- setFilterFields(prev => ({
- ...prev,
+ {
+ const value = evt.target.value;
+ setSelectedOption(value);
+
+ if (value === 'all') {
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
+ return rest;
+ });
+ } else if (value === 'active') {
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
+ return {
+ ...rest,
+ endDate__gte_or_null: 'today',
+ };
+ });
+ } else if (value === 'inactive') {
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
+ return {
+ ...rest,
+ endDate__lt: 'today',
+ };
+ });
+ } else {
+ const year = parseInt(value);
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
+ return {
+ ...rest,
startDate__lt_or_null: `${year + 1}-01-01`,
endDate__gte_or_null: `${year}-01-01`,
- }));
- } else {
- setFilterFields(prev => {
- const { startDate__lt_or_null, endDate__gte_or_null, ...rest } = prev;
- return rest;
- });
- }
- }}
- >
-
- {years.map(y => )}
-
- {
- const status = evt.target.value;
- setStatus(status);
- setFilterFields(prev => {
- const { endDate__gte_or_null, endDate__lt, ...rest } = prev;
-
- if (status === 'active') {
- return {
- ...rest,
- endDate__gte_or_null: 'today',
- };
- } else if (status === 'inactive') {
- return {
- ...rest,
- endDate__lt: 'today',
- };
- } else {
- return rest;
- }
+ };
});
- }}
- >
-
-
-
-
- >
+ }
+ }}
+ >
+ {options.map(option => (
+
+ ))}
+
);
}
\ No newline at end of file
diff --git a/src/models/Staff.js b/src/models/Staff.js
index ae61265b..41031763 100644
--- a/src/models/Staff.js
+++ b/src/models/Staff.js
@@ -33,70 +33,69 @@ export default class Staff extends Model {
function StaffsFilters({ filter }) {
const setFilterFields = filter.setFilter
- const [year, setYear] = useState(0)
- const [status, setStatus] = useState('all')
+ const [selectedOption, setSelectedOption] = useState('all');
const [qualification, setQualification] = useState('')
const currentYear = new Date().getFullYear()
- const startYear = 2007
+ const startYear = 2011
const years = Array.from({ length: currentYear - startYear + 1 }, (_, i) => currentYear - i)
const qualificationOptions = ['PO', 'PA', 'RTDb', 'RTDa', 'RIC', 'Assegnista', 'Dottorando', 'PTA', 'Professore Emerito', 'Collaboratore', 'Docente Esterno', 'Dottorando Esterno', 'Personale in quiescenza', 'ex Docente']
+ const options = [
+ { value: 'all', label: 'Tutti' },
+ { value: 'active', label: 'Attivi' },
+ { value: 'inactive', label: 'Non attivi' },
+ ...years.map(year => ({ value: year.toString(), label: year.toString() })),
+ ];
+
return (
<>
{
- const year = parseInt(evt.target.value);
- setYear(year);
- if (year) {
- setFilterFields(prev => ({
- ...prev,
- startDate__lt_or_null: `${year + 1}-01-01`,
- endDate__gte_or_null: `${year}-01-01`,
- }));
- } else {
+ const value = evt.target.value;
+ setSelectedOption(value);
+
+ if (value === 'all') {
setFilterFields(prev => {
- const { startDate__lt_or_null, endDate__gte_or_null, ...rest } = prev;
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return rest;
});
- }
- }}
- >
-
- {years.map(y => )}
-
- {
- const status = evt.target.value;
- setStatus(status);
- setFilterFields(prev => {
- const { endDate__gte_or_null, endDate__lt, ...rest } = prev;
-
- if (status === 'active') {
+ } else if (value === 'active') {
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__gte_or_null: 'today',
};
- } else if (status === 'inactive') {
+ });
+ } else if (value === 'inactive') {
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
return {
...rest,
endDate__lt: 'today',
};
- } else {
- return rest;
- }
- });
+ });
+ } else {
+ const year = parseInt(value);
+ setFilterFields(prev => {
+ const { startDate__lt_or_null, endDate__gte_or_null, endDate__lt, ...rest } = prev;
+ return {
+ ...rest,
+ startDate__lt_or_null: `${year + 1}-01-01`,
+ endDate__gte_or_null: `${year}-01-01`,
+ };
+ });
+ }
}}
>
-
-
-
+ {options.map(option => (
+
+ ))}
currentYear - i)
return <>