Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(apps/analytics): make sure that analytics pages do not break for empty courses #4407

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WeekdayActivityAnalytics } from '@klicker-uzh/graphql/dist/ops'
import { H2 } from '@uzh-bf/design-system'
import { H2, UserNotification } from '@uzh-bf/design-system'
import { useTranslations } from 'next-intl'
import {
Bar,
Expand Down Expand Up @@ -49,34 +49,50 @@ function DailyActivityPlot({
},
]

const noActivity =
activeDays.monday === 0 &&
activeDays.tuesday === 0 &&
activeDays.wednesday === 0 &&
activeDays.thursday === 0 &&
activeDays.friday === 0 &&
activeDays.saturday === 0 &&
activeDays.sunday === 0

return (
<div className="border-uzh-grey-80 rounded-xl border border-solid p-3">
<H2>{t('manage.analytics.dailyActivity')}</H2>
<ResponsiveContainer width="100%" height={300}>
<BarChart layout="vertical" data={barChartData}>
<XAxis
type="number"
tickFormatter={(value) => `${value.toFixed(0)}%`}
label={{
value: t('manage.analytics.percentageOfStudents'),
dy: 12,
}}
height={40}
/>
<YAxis type="category" dataKey="weekday" width={80} />
<Tooltip
formatter={(value) => [
`${(value as number).toFixed(2)} %`,
t('manage.analytics.activeStudents'),
]}
contentStyle={{
borderRadius: '8px',
padding: '8px',
}}
/>
<Bar dataKey="value" fill="#8884d8" />
</BarChart>
</ResponsiveContainer>
{!noActivity ? (
<ResponsiveContainer width="100%" height={300}>
<BarChart layout="vertical" data={barChartData}>
<XAxis
type="number"
tickFormatter={(value) => `${value.toFixed(0)}%`}
label={{
value: t('manage.analytics.percentageOfStudents'),
dy: 12,
}}
height={40}
/>
<YAxis type="category" dataKey="weekday" width={80} />
<Tooltip
formatter={(value) => [
`${(value as number).toFixed(2)} %`,
t('manage.analytics.activeStudents'),
]}
contentStyle={{
borderRadius: '8px',
padding: '8px',
}}
/>
<Bar dataKey="value" fill="#8884d8" />
</BarChart>
</ResponsiveContainer>
) : (
<UserNotification
message={t('manage.analytics.noActivityDistributionData')}
type="info"
/>
)}
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ParticipantActivityTimestamp } from '@klicker-uzh/graphql/dist/ops'
import { H2 } from '@uzh-bf/design-system'
import { H2, UserNotification } from '@uzh-bf/design-system'
import { useTranslations } from 'next-intl'
import ActivityTimeSeriesPlot from './ActivityTimeSeriesPlot'

Expand All @@ -15,24 +15,31 @@ function DailyActivityTimeSeries({
return (
<div className="border-uzh-grey-80 rounded-xl border border-solid p-3">
<H2>{t('manage.analytics.dailyStudentActivity')}</H2>
<div className="flex w-full flex-col gap-3 lg:flex-row">
<ActivityTimeSeriesPlot
activityData={activity.map((item) => {
const date = new Date(item.date)
return {
date: date
.toLocaleDateString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
})
.replace(/\//g, '-'),
activeParticipants:
(item.activeParticipants / courseParticipants) * 100,
}
})}
{activity.length > 0 ? (
<div className="flex w-full flex-col gap-3 lg:flex-row">
<ActivityTimeSeriesPlot
activityData={activity.map((item) => {
const date = new Date(item.date)
return {
date: date
.toLocaleDateString('en-GB', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
})
.replace(/\//g, '-'),
activeParticipants:
(item.activeParticipants / courseParticipants) * 100,
}
})}
/>
</div>
) : (
<UserNotification
message={t('manage.analytics.noDailyActivityData')}
type="info"
/>
</div>
)}
</div>
)
}
Expand Down
Loading
Loading