-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improve component structure and extract data aggregation fu…
…nctionality to custom hooks
- Loading branch information
1 parent
4adb5ca
commit 6b23edb
Showing
8 changed files
with
103 additions
and
60 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
apps/frontend-manage/src/components/analytics/overview/CourseDashboardList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
apps/frontend-manage/src/components/analytics/performance/useActivityMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { MicroLearning, PracticeQuiz } from '@klicker-uzh/graphql/dist/ops' | ||
import { useMemo } from 'react' | ||
|
||
function useActivityMap({ | ||
practiceQuizzes, | ||
microLearnings, | ||
}: { | ||
practiceQuizzes?: Pick<PracticeQuiz, 'id' | 'name'>[] | null | ||
microLearnings?: Pick<MicroLearning, 'id' | 'name'>[] | null | ||
}) { | ||
const activityNameMap = useMemo( | ||
() => ({ | ||
...(practiceQuizzes?.reduce<Record<string, string>>((acc, pq) => { | ||
acc[pq.id] = pq.name | ||
return acc | ||
}, {}) ?? {}), | ||
...(microLearnings?.reduce<Record<string, string>>((acc, ml) => { | ||
acc[ml.id] = ml.name | ||
return acc | ||
}, {}) ?? {}), | ||
}), | ||
[practiceQuizzes, microLearnings] | ||
) | ||
|
||
const allActivityIds = useMemo( | ||
() => [ | ||
...(practiceQuizzes?.map((quiz) => quiz.id) ?? []), | ||
...(microLearnings?.map((ml) => ml.id) ?? []), | ||
], | ||
[practiceQuizzes, microLearnings] | ||
) | ||
|
||
return { activityNameMap, allActivityIds } | ||
} | ||
|
||
export default useActivityMap |
46 changes: 46 additions & 0 deletions
46
...end-manage/src/components/analytics/performance/useStudentActivityPerformanceTableData.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { ParticipantActivityPerformances } from '@klicker-uzh/graphql/dist/ops' | ||
import { useTranslations } from 'next-intl' | ||
import { useMemo } from 'react' | ||
|
||
function useStudentActivityPerformanceTableData({ | ||
dataAvailable, | ||
performances, | ||
selectedActivities, | ||
}: { | ||
dataAvailable: boolean | ||
performances: ParticipantActivityPerformances[] | ||
selectedActivities: string[] | ||
}) { | ||
const t = useTranslations() | ||
|
||
return useMemo(() => { | ||
if (!dataAvailable) { | ||
return [] | ||
} | ||
|
||
// map the performances to a data structure where every selected activity entry can be | ||
// identified through a direct key - {activityId}-totalScore and {activityId}-completion | ||
return performances.map((studentPerformance) => | ||
studentPerformance.performances.reduce<Record<string, string | number>>( | ||
(acc, performance) => { | ||
if (selectedActivities.includes(performance.activityId)) { | ||
acc[`${performance.activityId}-totalScore`] = performance.totalScore | ||
acc[`${performance.activityId}-completion`] = Math.round( | ||
performance.completion * 100 | ||
) | ||
} | ||
|
||
return acc | ||
}, | ||
{ | ||
participantUsername: studentPerformance.participantUsername, | ||
participantEmail: | ||
studentPerformance.participantEmail ?? | ||
t('manage.analytics.emailMissing'), | ||
} | ||
) | ||
) | ||
}, [dataAvailable, performances, t, selectedActivities]) | ||
} | ||
|
||
export default useStudentActivityPerformanceTableData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters