fix(dashboard): hide endpoint paths in recent activity UI

This commit is contained in:
Stalin
2026-04-19 18:03:24 +05:30
parent 9115fc5ffd
commit 353a2dfc3b
5 changed files with 95 additions and 15 deletions
+38 -10
View File
@@ -377,25 +377,53 @@ def get_recent_activity():
if not any(segment in path for segment in ["/api/quizzes", "/api/exam", "/api/coding", "/api/courses", "/api/auth"]): if not any(segment in path for segment in ["/api/quizzes", "/api/exam", "/api/coding", "/api/courses", "/api/auth"]):
continue continue
if any(noise in path for noise in ["/api/auth/verify-token", "/api/health"]):
continue
log_type = "activity" log_type = "activity"
title = f"{method} {path}" title = "Learning activity"
description = f"API activity on {path}" description = "Activity recorded"
if "/api/quizzes" in path: if "/api/quizzes" in path:
log_type = "quiz" log_type = "quiz"
title = "Quiz activity" if "/join-room" in path:
description = f"{method} {path}" title = "Joined quiz room"
description = "Entered a live quiz room"
elif "/submit-answer" in path or "/submit" in path:
title = "Attempted quiz question"
description = "Submitted a quiz answer"
else:
title = "Quiz activity"
description = "Interacted with quizzes"
elif "/api/exam" in path or "/api/coding" in path: elif "/api/exam" in path or "/api/coding" in path:
log_type = "coding" log_type = "coding"
title = "Coding activity" if "/join-exam" in path:
description = f"{method} {path}" title = "Joined coding exam"
description = "Entered a coding exam"
elif "/submit" in path:
title = "Submitted coding solution"
description = "Submitted code for evaluation"
else:
title = "Coding activity"
description = "Interacted with coding workspace"
elif "/api/courses" in path: elif "/api/courses" in path:
log_type = "course" log_type = "course"
title = "Course activity" if "/activity" in path:
description = f"{method} {path}" title = "Course activity"
description = "Visited or started a course lesson"
elif "/complete" in path:
title = "Completed lesson"
description = "Marked lesson as completed"
else:
title = "Course activity"
description = "Viewed course content"
elif "/api/auth" in path: elif "/api/auth" in path:
log_type = "auth_login" log_type = "auth_login"
title = "Authentication activity" if "/login" in path or "/verify" in path:
description = f"{method} {path}" title = "Authentication activity"
description = "Signed in to account"
else:
title = "Account activity"
description = "Authentication event recorded"
activities.append({ activities.append({
"id": str(item.get("_id", uuid.uuid4())), "id": str(item.get("_id", uuid.uuid4())),
+1 -1
View File
@@ -27,7 +27,7 @@ export default function JoinExam() {
setLoading(true) setLoading(true)
try { try {
const token = localStorage.getItem("openlearnx_jwt_token") const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token")
const storedUserRaw = localStorage.getItem("openlearnx_user") const storedUserRaw = localStorage.getItem("openlearnx_user")
const storedUser = storedUserRaw ? JSON.parse(storedUserRaw) : null const storedUser = storedUserRaw ? JSON.parse(storedUserRaw) : null
+2 -2
View File
@@ -64,7 +64,7 @@ export default function CoursePage() {
const logCourseActivity = async (action: "view" | "start" | "lesson_view", lessonId?: string) => { const logCourseActivity = async (action: "view" | "start" | "lesson_view", lessonId?: string) => {
try { try {
const token = localStorage.getItem("openlearnx_jwt_token") const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token")
await fetch(`http://127.0.0.1:5000/api/courses/${courseId}/activity`, { await fetch(`http://127.0.0.1:5000/api/courses/${courseId}/activity`, {
method: "POST", method: "POST",
headers: { headers: {
@@ -242,7 +242,7 @@ export default function CoursePage() {
const markComplete = async () => { const markComplete = async () => {
try { try {
const token = localStorage.getItem("openlearnx_jwt_token") const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token")
if (selectedLessonId) { if (selectedLessonId) {
await fetch(`http://127.0.0.1:5000/api/courses/${courseId}/lessons/${selectedLessonId}/complete`, { await fetch(`http://127.0.0.1:5000/api/courses/${courseId}/lessons/${selectedLessonId}/complete`, {
method: "POST", method: "POST",
+53 -1
View File
@@ -155,7 +155,59 @@ export default function DashboardPage() {
return fakeMarkers.some((marker) => text.includes(marker)) return fakeMarkers.some((marker) => text.includes(marker))
} }
const realActivities = recentActivity.filter((item) => !isPlaceholderActivity(item)) const isEndpointText = (value: string) => /^(get|post|put|patch|delete)\s+\/api\//i.test(String(value || "").trim())
const normalizeActivityForUI = (item: ActivityData): ActivityData | null => {
const rawTitle = String(item.title || "")
const rawDescription = String(item.description || "")
const lower = `${rawTitle} ${rawDescription}`.toLowerCase()
if (lower.includes("/api/auth/verify-token")) {
return null
}
let title = rawTitle
let description = rawDescription
if (isEndpointText(rawTitle) || isEndpointText(rawDescription)) {
if (lower.includes("/api/quizzes") && lower.includes("join-room")) {
title = "Joined quiz room"
description = "Entered a live quiz room"
} else if (lower.includes("/api/quizzes") && (lower.includes("submit-answer") || lower.includes("/submit"))) {
title = "Attempted quiz question"
description = "Submitted a quiz answer"
} else if ((lower.includes("/api/exam") || lower.includes("/api/coding")) && lower.includes("join-exam")) {
title = "Joined coding exam"
description = "Entered a coding exam"
} else if ((lower.includes("/api/exam") || lower.includes("/api/coding")) && lower.includes("submit")) {
title = "Submitted coding solution"
description = "Submitted code for evaluation"
} else if (lower.includes("/api/courses") && lower.includes("complete")) {
title = "Completed lesson"
description = "Marked lesson as completed"
} else if (lower.includes("/api/courses")) {
title = "Course activity"
description = "Viewed or continued course learning"
} else if (lower.includes("/api/auth")) {
title = "Authentication activity"
description = "Signed in to account"
} else {
title = "Learning activity"
description = "Activity recorded"
}
}
return {
...item,
title,
description,
}
}
const realActivities = recentActivity
.map((item) => normalizeActivityForUI(item))
.filter((item): item is ActivityData => Boolean(item))
.filter((item) => !isPlaceholderActivity(item))
const visibleActivities = showAllActivities ? realActivities : realActivities.slice(0, 6) const visibleActivities = showAllActivities ? realActivities : realActivities.slice(0, 6)
const handleProfileUpdate = async () => { const handleProfileUpdate = async () => {
+1 -1
View File
@@ -49,7 +49,7 @@ export default function QuizJoinPage() {
setLoading(true) setLoading(true)
try { try {
const token = localStorage.getItem("openlearnx_jwt_token") const token = localStorage.getItem("openlearnx_jwt_token") || localStorage.getItem("openlearnx_token")
const storedUserRaw = localStorage.getItem("openlearnx_user") const storedUserRaw = localStorage.getItem("openlearnx_user")
const storedUser = storedUserRaw ? JSON.parse(storedUserRaw) : null const storedUser = storedUserRaw ? JSON.parse(storedUserRaw) : null