Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | 27x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 9x 9x 9x 32x 2x 24x 24x 720x 2x 2x 2x 24x 24x 720x 720x 720x 9x 8x 8x 9x 8x 8x 9x 8x 8x 9x 8x 8x 8x 2x 9x 9x 9x 9x | <template>
<div class="admin-growth-panel">
<ErrorAlert
v-if="adminStore.growthError"
:title="t('common.error')"
:message="adminStore.growthError"
/>
<LoadingSpinner v-if="adminStore.growthLoading && !adminStore.growth" />
<template v-else-if="adminStore.growth">
<div class="row g-3 mb-4">
<div class="col-6 col-md-3">
<div class="stat-card">
<div class="stat-value">{{ formatCount(adminStore.growth.totals.users) }}</div>
<div class="stat-label">{{ t('admin.totalUsers') }}</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="stat-card">
<div class="stat-value">{{ formatCount(adminStore.growth.totals.flows) }}</div>
<div class="stat-label">{{ t('admin.totalFlows') }}</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="stat-card">
<div class="stat-value">{{ formatCount(adminStore.growth.totals.entities) }}</div>
<div class="stat-label">{{ t('admin.totalEntities') }}</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="stat-card">
<div class="stat-value">{{ formatCount(adminStore.growth.totals.items) }}</div>
<div class="stat-label">{{ t('admin.totalItems') }}</div>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-12 col-lg-4">
<h5>{{ t('admin.usersTrend') }}</h5>
<div class="chart-wrapper" data-testid="signups-chart">
<Bar :data="usersChartData" :options="trendChartOptions" />
</div>
</div>
<div class="col-12 col-lg-4">
<h5>{{ t('admin.flowsTrend') }}</h5>
<div class="chart-wrapper" data-testid="flows-chart">
<Bar :data="flowsChartData" :options="trendChartOptions" />
</div>
</div>
<div class="col-12 col-lg-4">
<h5>{{ t('admin.entitiesTrend') }}</h5>
<div class="chart-wrapper" data-testid="entities-chart">
<Bar :data="entitiesChartData" :options="trendChartOptions" />
</div>
</div>
</div>
<div class="row g-4 mt-1">
<div class="col-12 col-lg-4">
<h5>{{ t('admin.activeUsersTrend') }}</h5>
<div class="chart-wrapper" data-testid="active-users-chart">
<Bar :data="activeUsersChartData" :options="chartOptions" />
</div>
</div>
</div>
</template>
</div>
</template>
<script setup lang="ts">
// @implements UC-ADMIN-002.1
import { computed, onMounted } from 'vue'
import { Bar } from 'vue-chartjs'
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
BarElement,
LineController,
LineElement,
PointElement,
Tooltip,
Legend,
type ChartData,
type LegendItem
} from 'chart.js'
import { useAdminStore } from '@/stores/admin'
import { useUILanguage } from '@/composables/useUILanguage'
import ErrorAlert from '@/components/ErrorAlert.vue'
import LoadingSpinner from '@/components/LoadingSpinner.vue'
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
LineController,
LineElement,
PointElement,
Tooltip,
Legend
)
const adminStore = useAdminStore()
const { t } = useUILanguage()
function formatCount(value: number | null): string {
return value === null ? '—' : value.toLocaleString()
}
const DAY_MS = 24 * 60 * 60 * 1000
/**
* The API only returns the days that had activity, so plotting its keys as-is
* squeezes the chart down to those days (a single bar when only one day had any).
* Every UTC day of the window gets a slot instead, with 0 when nothing happened.
* The window ends today: the API's oldest, partial day falls outside it.
*/
function lastUtcDays(count: number): string[] {
const today = Date.now()
return Array.from({ length: count }, (_, index) =>
new Date(today - (count - 1 - index) * DAY_MS).toISOString().slice(0, 10)
)
}
const CREATED_COLOR = '#689909'
// Validated against CREATED_COLOR for color-blind readers, unlike a red
const DELETED_COLOR = '#c2478f'
const TOTAL_COLOR = '#4f78d8'
interface TrendSeries {
createdLabel: string
deletedLabel: string
created: Record<string, number>
deleted: Record<string, number>
total: Record<string, number>
}
/**
* Creations and deletions as bars on the left axis, the total as a line on the
* right one: it is usually far larger, and would flatten the bars on a shared
* scale. A day without a total stays empty rather than 0, since none was recorded.
*/
function buildTrendChartData({ createdLabel, deletedLabel, created, deleted, total }: TrendSeries) {
const days = lastUtcDays(adminStore.growth?.trend.days ?? 30)
return {
labels: days,
datasets: [
{
label: createdLabel,
data: days.map((day) => created[day] ?? 0),
backgroundColor: CREATED_COLOR,
yAxisID: 'y',
order: 2
},
{
label: deletedLabel,
data: days.map((day) => deleted[day] ?? 0),
backgroundColor: DELETED_COLOR,
yAxisID: 'y',
order: 2
},
{
type: 'line',
label: t('admin.trendTotal'),
data: days.map((day) => total[day] ?? null),
borderColor: TOTAL_COLOR,
backgroundColor: TOTAL_COLOR,
borderWidth: 2,
pointRadius: 2,
spanGaps: true,
yAxisID: 'y1',
order: 1
}
]
// vue-chartjs's Bar is typed for bar datasets only; Chart.js itself handles the mix
} as unknown as ChartData<'bar'>
}
const usersChartData = computed(() => {
const trend = adminStore.growth?.trend
return buildTrendChartData({
createdLabel: t('admin.trendSignups'),
deletedLabel: t('admin.trendAccountsDeleted'),
created: trend?.signupsByDay ?? {},
deleted: trend?.usersDeletedByDay ?? {},
total: trend?.totalUsersByDay ?? {}
})
})
const flowsChartData = computed(() => {
const trend = adminStore.growth?.trend
return buildTrendChartData({
createdLabel: t('admin.trendCreated'),
deletedLabel: t('admin.trendDeleted'),
created: trend?.flowsCreatedByDay ?? {},
deleted: trend?.flowsDeletedByDay ?? {},
total: trend?.totalFlowsByDay ?? {}
})
})
const entitiesChartData = computed(() => {
const trend = adminStore.growth?.trend
return buildTrendChartData({
createdLabel: t('admin.trendCreated'),
deletedLabel: t('admin.trendDeleted'),
created: trend?.entitiesCreatedByDay ?? {},
deleted: trend?.entitiesDeletedByDay ?? {},
total: trend?.totalEntitiesByDay ?? {}
})
})
const activeUsersChartData = computed(() => {
const byMonth = adminStore.growth?.trend.activeUsersByMonth ?? {}
const months = Object.keys(byMonth).sort()
return {
labels: months,
datasets: [
{
label: t('admin.activeUsersTrend'),
data: months.map((month) => byMonth[month]),
backgroundColor: '#689909'
}
]
}
})
const chartOptions = {
responsive: true,
maintainAspectRatio: false,
scales: { y: { beginAtZero: true, ticks: { precision: 0 } } }
}
const trendChartOptions = computed(() => ({
responsive: true,
maintainAspectRatio: false,
interaction: { mode: 'index' as const, intersect: false },
plugins: {
legend: {
// `order` puts the line above the bars, but would also list it first here
labels: {
boxWidth: 12,
sort: (a: LegendItem, b: LegendItem) => a.datasetIndex! - b.datasetIndex!
}
}
},
scales: {
y: {
beginAtZero: true,
ticks: { precision: 0 },
title: { display: true, text: t('admin.trendPerDay') }
},
y1: {
position: 'right' as const,
beginAtZero: true,
ticks: { precision: 0 },
grid: { drawOnChartArea: false },
title: { display: true, text: t('admin.trendTotal') }
}
}
}))
onMounted(() => {
adminStore.fetchGrowthAnalytics()
})
</script>
<style scoped>
.stat-card {
background: var(--bs-body-bg);
border: 1px solid var(--bs-border-color);
border-radius: 0.5rem;
padding: 1rem;
text-align: center;
}
.stat-value {
font-size: 1.75rem;
font-weight: 700;
color: #689909;
}
.stat-label {
font-size: 0.85rem;
color: var(--bs-secondary-color);
text-transform: uppercase;
letter-spacing: 0.03em;
}
.chart-wrapper {
height: 260px;
}
</style>
|