SSR for overview instead of hook, SWR for tables - #142
Conversation
…nceDashboard hook with direct data fetching, and enhance error handling. Introduce new data structure for evidence dashboard and remove obsolete action file.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis PR removes the old server-side evidence fetching function and associated hook, replacing them with a new implementation in a reorganized data module. Several component files have their import paths updated accordingly, and minor import ordering adjustments were performed. The EvidenceOverview component was refactored to accept props directly and the Overview page now validates sessions and handles errors asynchronously. Additionally, new error handling and loading state components have been introduced. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant P as EvidenceOverviewPage
participant A as Auth Module
participant D as getEvidenceDashboard
U->>P: Request Evidence Overview
P->>A: Validate session
A-->>P: Return session data (with organizationId)
alt Invalid Session
P-->U: Redirect to "/"
else Valid Session
P->>D: Fetch evidence data with organizationId
D-->>P: Return evidence data or error
alt Data Retrieved
P->>U: Render EvidenceOverview with evidence prop
else Error Occurred
P->>U: Render EvidenceErrorState with error details
end
end
Possibly related PRs
Poem
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)
apps/app/src/lib/errors.ts (1)
1-10: Good implementation of standardized error handlingThe
AppErrorclass implementation provides a solid foundation for consistent error handling across the application, which supports the PR objective of enhancing error handling capabilities.Consider removing the redundant type annotation for the
statusparameter as suggested by the static analysis:constructor( public code: string, message?: string, - public status: number = 400 + public status = 400 ) {🧰 Tools
🪛 Biome (1.9.4)
[error] 5-5: This type annotation is trivially inferred from its initialization.
Safe fix: Remove the type annotation.
(lint/style/noInferrableTypes)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/page.tsx (1)
18-26: Well-structured async logic with error fallback.Wrapping the data fetching in a
try/catchblock ensures any errors during evidence retrieval are handled gracefully, rendering an appropriate error state. Consider logging the error for better visibility.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/data/getEvidenceDashboard.ts (1)
172-188: Potentially unused status counts for the first assignee.The code calculates status counts for the first assignee but doesn’t return or display them. If this is an intentional placeholder, consider removing or incorporating the counts into the final returned data.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (14)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/actions/getEvidenceDashboard.ts(0 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/AssigneeChart/AssigneeBarChart.tsx(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/AssigneeChart/AssigneeChartRow.tsx(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/DepartmentChart/DepartmentBarChart.tsx(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/EvidenceOverview.tsx(4 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/FrameworkChart/FrameworkBarChart.tsx(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/data/getEvidenceDashboard.ts(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useAssigneeData.ts(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useEvidenceDashboard.ts(0 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useEvidenceData.ts(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useFrameworkData.ts(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/loading.tsx(1 hunks)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/page.tsx(1 hunks)apps/app/src/lib/errors.ts(1 hunks)
💤 Files with no reviewable changes (2)
- apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useEvidenceDashboard.ts
- apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/actions/getEvidenceDashboard.ts
🧰 Additional context used
🧬 Code Definitions (2)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/page.tsx (2)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/data/getEvidenceDashboard.ts (1) (1)
getEvidenceDashboard(32:218)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/EvidenceOverview.tsx (1) (1)
EvidenceOverview(12:61)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/EvidenceOverview.tsx (5)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/data/getEvidenceDashboard.ts (1) (1)
EvidenceDashboardData(13:25)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/EvidenceUIStates.tsx (1) (1)
EvidenceEmptyState(85:96)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/DepartmentChart/DepartmentBarChart.tsx (1) (1)
DepartmentBarChart(18:60)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/AssigneeChart/AssigneeBarChart.tsx (1) (1)
AssigneeBarChart(18:63)apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/FrameworkChart/FrameworkBarChart.tsx (1) (1)
FrameworkBarChart(17:59)
🪛 Biome (1.9.4)
apps/app/src/lib/errors.ts
[error] 5-5: This type annotation is trivially inferred from its initialization.
Safe fix: Remove the type annotation.
(lint/style/noInferrableTypes)
🔇 Additional comments (21)
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/loading.tsx (1)
1-5: Great implementation of loading state!This new loading component follows Next.js patterns for handling loading states by leveraging the
EvidenceOverviewSkeletoncomponent. This aligns perfectly with the PR objective of implementing a loading state for the evidence overview.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/FrameworkChart/FrameworkBarChart.tsx (1)
4-6: Import path correctly updated for reorganized data structureThe import path for
EvidenceWithStatushas been properly updated to reflect the new data organization fromactionstodatadirectory, which aligns with the PR objective of replacing theuseEvidenceDashboardhook with direct data fetching.apps/app/src/lib/errors.ts (1)
12-17: Well-defined error constantsThe
appErrorsconstants provide standardized error codes that can be reused across the application, making error handling more consistent and maintainable.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/AssigneeChart/AssigneeChartRow.tsx (1)
7-11: Import organization improvedThe reordering of imports improves code organization and readability without affecting functionality. The
STATUS_PRIORITYis now correctly grouped with the related status constants, and type imports are organized more logically.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useFrameworkData.ts (1)
1-1: Import path updated correctly as part of refactoringThe import path for
EvidenceWithStatushas been updated from "../actions/getEvidenceDashboard" to "../data/getEvidenceDashboard" as part of the larger refactoring effort to replace the useEvidenceDashboard hook with direct data fetching as mentioned in the PR objectives.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/DepartmentChart/DepartmentBarChart.tsx (1)
4-4: Import path updated correctlyThe import path for
EvidenceWithStatushas been updated from "../../actions/getEvidenceDashboard" to "../../data/getEvidenceDashboard" as part of the codebase reorganization. This change aligns with the PR objectives of replacing the useEvidenceDashboard hook with direct data fetching.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useEvidenceData.ts (1)
5-5: Import path updated correctlyThe import path for
EvidenceWithStatushas been updated from "../actions/getEvidenceDashboard" to "../data/getEvidenceDashboard" as part of the codebase reorganization. This is consistent with the changes in other files and aligns with the PR objectives.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/hooks/useAssigneeData.ts (1)
3-3: Import path updated correctlyThe import path for
EvidenceWithStatushas been updated from "../actions/getEvidenceDashboard" to "../data/getEvidenceDashboard" as part of the codebase reorganization. This is consistent with the changes in other files and supports the PR's goal of replacing the useEvidenceDashboard hook with direct data fetching.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/AssigneeChart/AssigneeBarChart.tsx (1)
7-7: Looks consistent with the new data organization.Switching the import path to
../../data/getEvidenceDashboardaligns with the new approach for fetching and typing evidence data.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/page.tsx (2)
1-5: Imports support SSR-based authentication and navigation.These import statements align well with Next.js SSR usage patterns for auth checks and redirects. No issues found.
7-16: Robust session checks.The checks for a valid session and
organizationIdguard against unauthorized or incomplete user data. This helps mitigate security concerns by preventing direct access.apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/components/EvidenceOverview.tsx (5)
4-10: New imports reflect revised data modules.Adopting the reorganized
EvidenceDashboardDatatype and referencing the new chart components is consistent with the updated architecture. No issues found here.
12-16: Enhanced component signature.Accepting the
evidenceprop directly instead of using a hook clarifies data flow. This change simplifies the component’s logic and improves testability.
19-21: Graceful handling of null evidence.Displaying an empty state when no data is present prevents runtime errors and improves UX. Good approach.
23-23: Destructuring data fields enhances readability.Destructuring
byDepartment,byAssignee,byFramework, andunassignedimproves clarity and discoverability of the component’s data usage.
37-37: Chart integrations are consistent.Passing the correct data slices to each bar chart (
DepartmentBarChart,AssigneeBarChart,FrameworkBarChart) stays aligned with the new data structure. Looks good.Also applies to: 46-46, 55-55
apps/app/src/app/[locale]/(app)/(dashboard)/evidence/overview/data/getEvidenceDashboard.ts (5)
5-11: Clear status typing.Defining
EvidenceStatusas a string literal type and creatingEvidenceWithStatuswith the optionalassigneeEmailfield is clean and extends the base type appropriately.
13-25: Well-structured interface for dashboard data.Encompassing grouped evidence fields and status counts in
EvidenceDashboardDatahelps standardize how the rest of the app interacts with the dashboard’s data.
32-83: Comprehensive fetching and initialization.The query against
organizationEvidenceand subsequent null return if empty gracefully handle missing data. The approach to prepare and increment status counts per evidence record is clear.
189-202: Clear grouping by framework.Groups evidence by
frameworkIdif present. This logic is consistent with the department and assignee grouping above.
204-218: Returns a comprehensive view of evidence data.The final return object captures each grouping plus status counts. Overall this function centralizes the dashboard’s logic well.
…nceDashboard hook with direct data fetching, and enhance error handling. Introduce new data structure for evidence dashboard and remove obsolete action file.
Summary by CodeRabbit
New Features
Refactor
Chores