Skip to content

Commit

Permalink
adapt filter to country, VM condition for VM & classroom
Browse files Browse the repository at this point in the history
  • Loading branch information
MelissaOlas committed Sep 10, 2024
1 parent c8ff1a2 commit e05e135
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 0 additions & 2 deletions server/controllers/analytic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ analyticController.router.post(
AppDataSource.getRepository(User).createQueryBuilder('user').select('user.firstlogin').where({ id: data.userId }).getRawOne(),
]);

console.log('User Phase in analytics', userPhase);

if (sessionCount === 0 && data.event === 'pageview' && data.params?.isInitial) {
const session = new AnalyticSession();
session.id = data.sessionId;
Expand Down
20 changes: 15 additions & 5 deletions src/components/admin/dashboard-statistics/ClassroomStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,27 @@ const ClassroomStats = () => {
const pelicoMessage = 'Merci de sélectionner une classe pour analyser ses statistiques ';

const countriesMap = mockClassroomsStats.map((country) => country.classroomCountryCode);
const countries = [...new Set(countriesMap)]; // avoid duplicates
const countries = [...new Set(countriesMap)];

const handleCountryChange = (country: string) => {
setSelectedCountry(country);
setSelectedVillage('');
setSelectedClassroom('');
};
const villagesMap = mockClassroomsStats.map((village) => village.villageName);

const villagesMap = mockClassroomsStats.filter((village) => village.classroomCountryCode === selectedCountry).map((village) => village.villageName);
const villages = [...new Set(villagesMap)];

const handleVillageChange = (village: string) => {
setSelectedVillage(village);
setSelectedClassroom('');
};
const classroomsMap = mockClassroomsStats.map((classroom) => classroom.classroomId);

const classroomsMap = mockClassroomsStats
.filter((classroom) => classroom.villageName === selectedVillage)
.map((classroom) => classroom.classroomId);
const classrooms = [...new Set(classroomsMap)];

const handleClassroomChange = (classroom: string) => {
setSelectedClassroom(classroom);
};
Expand All @@ -40,10 +50,10 @@ const ClassroomStats = () => {
<div className={styles.countryFilter}>
<CountriesDropdown countries={countries} onCountryChange={handleCountryChange} />
</div>
<div className={'styles.countryFilter'}>
<div className={styles.countryFilter}>
<VillageDropdown villages={villages} onVillageChange={handleVillageChange} />
</div>
<div className={'styles.countryFilter'}>
<div className={styles.countryFilter}>
<ClassroomDropdown classrooms={classrooms} onClassroomChange={handleClassroomChange} />
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/components/admin/dashboard-statistics/VillageStats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const VillageStats = () => {

const countriesMap = mockClassroomsStats.map((country) => country.classroomCountryCode);
const countries = [...new Set(countriesMap)]; // avoid duplicates

const handleCountryChange = (country: string) => {
setSelectedCountry(country);
};
const villagesMap = mockClassroomsStats.map((village) => village.villageName);

const villagesMap = mockClassroomsStats.filter((village) => village.classroomCountryCode === selectedCountry).map((village) => village.villageName);
const villages = [...new Set(villagesMap)];

const handleVillageChange = (village: string) => {
setSelectedVillage(village);
};
Expand All @@ -33,7 +36,7 @@ const VillageStats = () => {
<div className={styles.countryFilter}>
<CountriesDropdown countries={countries} onCountryChange={handleCountryChange} />
</div>
<div className={'styles.countryFilter'}>
<div className={styles.countryFilter}>
<VillageDropdown villages={villages} onVillageChange={handleVillageChange} />
</div>
</div>
Expand Down

0 comments on commit e05e135

Please sign in to comment.