Skip to content

Conversation

@Jagath-P
Copy link
Contributor

@Jagath-P Jagath-P commented Nov 2, 2025


name: " Pull Request"
about: Propose and submit changes to the project for review
title: "PR: Updated the feedback stats section "
labels: ""
assignees: harshitap1305, sakshi1755

Related Issue


Changes Introduced

  • Added: getCurrentTenureRange.js in frontend/src/utils
  • Fixed: minor change to useFeedback.js
  • Updated: updated the FeedbackStats.jsx
  • Removed: none

Screenshots / Video (if applicable)

now
image

@harshitap1305 for review

💬 Additional Notes

  • [Add any other context or information here.]

Summary by CodeRabbit

  • New Features

    • Feedback statistics dashboard now shows total feedbacks, pending count, resolved submissions, recent activity (last 30 days, bounded by tenure), and average rating.
  • Refactor

    • Internal data fetching and date-range logic reorganized for clearer tenure-based filtering and more reliable stats.

@vercel
Copy link

vercel bot commented Nov 2, 2025

@Jagath-P is attempting to deploy a commit to the openlake's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link

coderabbitai bot commented Nov 2, 2025

Walkthrough

Implements a tenure-aware FeedbackStats component, adds getCurrentTenureRange utility, refactors fetch logic in useFeedback into a named function, and applies a minor formatting change to FeedbackForm without functional impact.

Changes

Cohort / File(s) Change Summary
Feedback stats & form
frontend/src/Components/Feedback/FeedbackStats.jsx, frontend/src/Components/Feedback/FeedbackForm.jsx
FeedbackStats.jsx: New full implementation that reads feedback via useFeedback, obtains tenure via getCurrentTenureRange, computes metrics (total, pending, resolved, recent (30d), avg rating) and renders them. FeedbackForm.jsx: non-functional reformat of a Select value expression and removal of a stray blank line.
Hook refactor
frontend/src/hooks/useFeedback.js
Extracted fetchFeedback into a named function declared inside the hook body and invoked from useEffect; preserves behavior (API call, sort by created_at desc, state updates, error logging, loading state).
New utility
frontend/src/utils/getCurrentTenureRange.js
Added getCurrentTenureRange() that computes current fiscal/tenure startDate and endDate (Apr 1–Mar 31 semantics with Jan–Mar mapping to previous tenure) and returns { startDate, endDate, tenureYearString }; exported via module.exports.

Sequence Diagram(s)

sequenceDiagram
    participant Stats as FeedbackStats
    participant Context as AdminContext
    participant Tenure as getCurrentTenureRange
    participant Hook as useFeedback
    participant API as Backend API

    Stats->>Context: useContext() (get role/admin flag)
    Stats->>Tenure: getCurrentTenureRange()
    Tenure-->>Stats: { startDate, endDate, tenureYearString }
    Stats->>Hook: useFeedback()
    Hook->>API: fetchFeedback() (named fn)
    API-->>Hook: feedback[]
    Hook-->>Stats: feedback, loading, error
    Stats->>Stats: filter by start/end dates, compute total, pending, resolved, recent(30d), avg rating
    Stats->>Stats: render stats block
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Attention points:

  • Verify tenure boundaries and timezone effects in getCurrentTenureRange.
  • Confirm filtering in FeedbackStats correctly clamps recent (30d) to tenure start when needed.
  • Ensure useFeedback extraction preserved error/loading behavior and sorting semantics.
  • Quick UI check for any JSX attribute typos (e.g., className) in FeedbackStats and FeedbackForm.

Poem

🐰 I hopped through code, my whiskers bright,
I fetched the stats by day and night,
Tenure ranges neatly found,
Counts and averages all around,
A carrot-coded cheer — well done, delight! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The pull request includes changes to FeedbackForm.jsx that are cosmetic and unrelated to the feedback statistics feature requirements in issue #175. These changes consist of removing a stray blank line and reformatting a Select value expression without any functional changes. While minimal, these modifications fall outside the scope of implementing the Feedback Statistics Card feature and appear to be incidental formatting adjustments. The useFeedback.js refactoring, while somewhat tangential, can be reasonably considered a supporting change necessary for proper hook functionality with the new FeedbackStats component.
Description Check ⚠️ Warning The pull request description covers some required sections from the template, including the Related Issue (Closes #175), Changes Introduced (Added, Fixed, Updated, Removed), and Screenshots. However, it is missing critical sections such as "Why This Change?" which should explain the problem, solution, and impact, as well as the Testing section (with no test cases documented) and the Checklist section. The description also provides minimal context about the motivation and implementation approach, relying instead on a screenshot to convey the change.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "[SPRINT-M25] feature: added feedback stats" directly and clearly describes the main change in the changeset. It is concise, specific, and avoids generic terminology. The title accurately captures the primary objective of implementing the feedback statistics feature, which aligns with the substantial refactoring of the FeedbackStats component and the addition of the getCurrentTenureRange utility function.
Linked Issues Check ✅ Passed The code changes successfully implement all requirements from issue #175. The FeedbackStats component now displays all required statistics: total feedbacks, pending feedbacks, total resolved feedbacks, recent feedbacks from the last 30 days, and average rating [#175]. The new getCurrentTenureRange utility function computes the fiscal tenure range as required, and FeedbackStats filters feedback data to the current tenure range only using startDate and endDate from this function [#175]. The useFeedback hook refactoring provides a supporting improvement that enables these components to function properly [#175].
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0dd13ab and 9e4aea9.

📒 Files selected for processing (1)
  • frontend/src/Components/Feedback/FeedbackStats.jsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/Components/Feedback/FeedbackStats.jsx

Comment @coderabbitai help to get the list of available commands and usage tips.

@Jagath-P Jagath-P changed the title added feedback stats [SPRINT-M25] feature: added feedback stats Nov 2, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (6)
frontend/src/Components/Feedback/FeedbackStats.jsx (4)

2-2: Remove unused import.

useState is imported but never used in this component.

Apply this diff:

-import { useState, useContext } from "react";
+import { useContext } from "react";

7-15: Remove unused destructured values.

Many values are destructured from useFeedback() but never used: loading, activeTab, setActiveTab, statusFilter, setStatusFilter, and markAsResolved. Only filteredFeedbacks is actually utilized.

Apply this diff:

-  const {
-    loading,
-    activeTab,
-    setActiveTab,
-    statusFilter,
-    setStatusFilter,
-    filteredFeedbacks,
-    markAsResolved,
-  } = useFeedback();
+  const { filteredFeedbacks } = useFeedback();

16-16: Remove unused variable from destructuring.

tenureYearString is destructured but never used in the component.

Apply this diff:

-  const { startDate, endDate, tenureYearString } = getCurrentTenureRange();
+  const { startDate, endDate } = getCurrentTenureRange();

21-22: Remove unused isStudent computation.

The isStudent flag is computed but never used in the component. If this is for future functionality, consider adding it when needed.

Apply this diff to remove the unused code:

-  const { isUserLoggedIn } = useContext(AdminContext);
-  const isStudent = isUserLoggedIn?.role === "STUDENT";
-
frontend/src/utils/getCurrentTenureRange.js (2)

19-19: Use ES6 export syntax for consistency.

The file uses CommonJS module.exports while the rest of the frontend codebase uses ES6 import/export syntax. Although most bundlers handle this, maintaining consistency improves code clarity.

Apply this diff:

-module.exports = getCurrentTenureRange;
+export default getCurrentTenureRange;

1-17: Note: Code duplication with backend utility.

The relevant code snippets show that backend/utils/getTenureRange.js contains nearly identical logic. While some duplication between frontend and backend is acceptable (separate environments), consider whether this logic could be shared via a common package or if the calculation should be performed server-side and exposed via API to ensure consistency.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4d1d2e0 and 0dd13ab.

📒 Files selected for processing (4)
  • frontend/src/Components/Feedback/FeedbackForm.jsx (1 hunks)
  • frontend/src/Components/Feedback/FeedbackStats.jsx (1 hunks)
  • frontend/src/hooks/useFeedback.js (1 hunks)
  • frontend/src/utils/getCurrentTenureRange.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
frontend/src/hooks/useFeedback.js (1)
frontend/src/utils/api.js (1)
  • api (2-5)
frontend/src/Components/Feedback/FeedbackForm.jsx (1)
frontend/src/hooks/useFeedback.js (2)
  • filteredTargets (86-86)
  • formData (87-94)
frontend/src/Components/Feedback/FeedbackStats.jsx (2)
frontend/src/hooks/useFeedback.js (5)
  • useFeedback (8-77)
  • useFeedback (8-77)
  • filteredFeedbacks (35-44)
  • useContext (13-13)
  • useContext (95-95)
frontend/src/utils/getCurrentTenureRange.js (3)
  • getCurrentTenureRange (1-17)
  • startDate (6-6)
  • now (2-2)
frontend/src/utils/getCurrentTenureRange.js (2)
frontend/src/Components/Feedback/FeedbackStats.jsx (1)
  • getCurrentTenureRange (16-16)
backend/utils/getTenureRange.js (1)
  • now (1-17)
🔇 Additional comments (3)
frontend/src/Components/Feedback/FeedbackForm.jsx (1)

118-122: LGTM! Formatting improves readability.

The multi-line formatting of the Select value expression enhances code readability without changing the logic.

frontend/src/utils/getCurrentTenureRange.js (1)

1-17: Logic looks correct for April-March fiscal year.

The tenure range calculation correctly handles the 3-month cutoff (January-March) and computes the appropriate start and end dates for an April 1 to March 31 tenure period.

frontend/src/hooks/useFeedback.js (1)

15-27: LGTM! Good refactoring.

Extracting fetchFeedback as a named function improves code organization and reusability while preserving the original behavior (API call, sorting, error handling, and loading state management).

@harshitap1305
Copy link
Member

@Jagath-P pls make changes suggested by coderabbit

@harshitap1305 harshitap1305 merged commit 5b212fb into OpenLake:main Nov 3, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(backend-frontend): Implement Feedback Statistics Card

2 participants