Skip to content

SSR for overview instead of hook, SWR for tables - #142

Merged
Marfuen merged 1 commit into
mainfrom
mariano/cleanup
Mar 18, 2025
Merged

Marfuen merged 1 commit into
mainfrom
mariano/cleanup

Conversation

@Marfuen

@Marfuen Marfuen commented Mar 18, 2025 •

Copy link
Copy Markdown
Contributor

…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

    • Enhanced session validation and error handling on the dashboard for improved feedback.
    • Introduced a dedicated loading state with a skeleton view for smoother transitions during data retrieval.
  • Refactor

    • Streamlined the data flow by directly passing evidence information to the dashboard, eliminating redundant loading and error checks.
    • Updated chart components to work seamlessly with the reorganized data structure.
  • Chores

    • Reorganized internal module structure for more efficient management.

…nceDashboard hook with direct data fetching, and enhance error handling. Introduce new data structure for evidence dashboard and remove obsolete action file.
@vercel

vercel Bot commented Mar 18, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 3:56pm
comp-portal ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 18, 2025 3:56pm

@coderabbitai

coderabbitai Bot commented Mar 18, 2025 •

Copy link
Copy Markdown

Walkthrough

This 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

File(s) Change Summary
apps/app/src/app/[locale]/.../actions/getEvidenceDashboard.ts
apps/app/src/app/[locale]/.../hooks/useEvidenceDashboard.ts
Removed the server-side evidence fetching function and the custom hook for managing dashboard data.
apps/app/src/app/[locale]/.../AssigneeBarChart.tsx
apps/app/src/app/[locale]/.../DepartmentBarChart.tsx
apps/app/src/app/[locale]/.../FrameworkBarChart.tsx
apps/app/src/app/[locale]/.../hooks/useAssigneeData.ts
apps/app/src/app/[locale]/.../hooks/useEvidenceData.ts
apps/app/src/app/[locale]/.../hooks/useFrameworkData.ts
Updated the import source for the EvidenceWithStatus type from ../../actions/getEvidenceDashboard to ../../data/getEvidenceDashboard; removed an unused React import in DepartmentBarChart.
apps/app/src/app/[locale]/.../AssigneeChartRow.tsx Reordered import statements and constants without altering functionality.
apps/app/src/app/[locale]/.../EvidenceOverview.tsx Refactored the component to accept an evidence prop, removing the hook-based data fetching and associated loading/error states.
apps/app/src/app/[locale]/.../data/getEvidenceDashboard.ts New file added defining types and a caching-enabled function to fetch and organize evidence dashboard data with grouping logic.
apps/app/src/app/[locale]/.../page.tsx Converted EvidenceOverviewPage into an asynchronous function that performs session validation, fetches evidence data, and renders appropriate components based on success or error.
apps/app/src/app/[locale]/.../loading.tsx New Loading component that renders the EvidenceOverviewSkeleton for a loading state.
apps/app/src/lib/errors.ts Introduced an AppError class and appErrors constant to standardize error handling across the application.

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
Loading

Possibly related PRs

  • fix evidence statuses across app #80: Introduced new logic for handling organization evidence; directly relates to the removal and replacement of the old evidence fetching function and types.

Poem

I'm a rabbit with a joyful beat,
Hoping through code with nimble feet.
Old hooks are gone, new data's in play,
Clean imports and functions lead the way.
Hopping high in fields of code so bright –
Bug-free dreams all through the night! 🐰✨

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Marfuen Marfuen changed the title Refactor evidence overview: implement loading state, replace useEvide… SSR for overview instead of hook, SWR for tables Mar 18, 2025
@Marfuen
Marfuen merged commit 8278061 into main Mar 18, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
apps/app/src/lib/errors.ts (1)

1-10: Good implementation of standardized error handling

The AppError class 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 status parameter 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/catch block 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

📥 Commits

Reviewing files that changed from the base of the PR and between 57932bf and 005d276.

⛔ Files ignored due to path filters (1)
  • yarn.lock is 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 EvidenceOverviewSkeleton component. 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 structure

The import path for EvidenceWithStatus has been properly updated to reflect the new data organization from actions to data directory, which aligns with the PR objective of replacing the useEvidenceDashboard hook with direct data fetching.

apps/app/src/lib/errors.ts (1)

12-17: Well-defined error constants

The appErrors constants 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 improved

The reordering of imports improves code organization and readability without affecting functionality. The STATUS_PRIORITY is 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 refactoring

The import path for EvidenceWithStatus has 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 correctly

The import path for EvidenceWithStatus has 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 correctly

The import path for EvidenceWithStatus has 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 correctly

The import path for EvidenceWithStatus has 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/getEvidenceDashboard aligns 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 organizationId guard 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 EvidenceDashboardData type and referencing the new chart components is consistent with the updated architecture. No issues found here.


12-16: Enhanced component signature.

Accepting the evidence prop 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, and unassigned improves 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 EvidenceStatus as a string literal type and creating EvidenceWithStatus with the optional assigneeEmail field is clean and extends the base type appropriately.


13-25: Well-structured interface for dashboard data.

Encompassing grouped evidence fields and status counts in EvidenceDashboardData helps standardize how the rest of the app interacts with the dashboard’s data.


32-83: Comprehensive fetching and initialization.

The query against organizationEvidence and 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 frameworkId if 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.

This branch was successfully deployed

2 active deployments
Preview – app — 005d2763 Deployed Mar 18, 2025 by vercel[bot]
Preview – comp-portal — 005d2763 Deployed Mar 18, 2025 by vercel[bot]
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.

1 participant