Skip to content

Improvement/active days#53

Merged
emlimlf merged 4 commits intomainfrom
improvement/active-days
Feb 27, 2025
Merged

Improvement/active days#53
emlimlf merged 4 commits intomainfrom
improvement/active-days

Conversation

@emlimlf
Copy link
Copy Markdown
Collaborator

@emlimlf emlimlf commented Feb 26, 2025

In this PR

  • Added active days widget using mock data
  • Added git add . command after lint fixing
  • Moved incorrectly placed popularity api to the correct folder
  • Added logic checks to other widgets to prevent it from throwing error on SSR

Ticket

INS-116

Summary by CodeRabbit

  • New Features

    • Introduced an active days dashboard showing detailed contribution summaries and average daily contributions with an integrated heatmap visualization.
  • UI Enhancements

    • Improved project analytics displays—including pull requests, forks, stars, and various mentions—to ensure metrics appear only when complete and valid.
  • Chart Enhancements

    • Refined heatmap configurations with updated layout, color gradients, and styling for a clearer and more visually appealing presentation.

Signed-off-by: Efren Lim <elim@linuxfoundation.org>
Signed-off-by: Efren Lim <elim@linuxfoundation.org>
Signed-off-by: Efren Lim <elim@linuxfoundation.org>
@emlimlf emlimlf requested a review from gaspergrom February 26, 2025 06:36
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 26, 2025

Walkthrough

This pull request introduces several code enhancements across the frontend and server. In the pre-commit hook, an extra command is added to automatically stage changes fixed by linting. The active-days component now fetches data via an API with corresponding computed properties and a new TypeScript interface, while other Vue components have updates for conditional rendering and type safety. Chart configuration files have been improved for heatmap display, including new helper functions and type extensions. Additionally, a new API endpoint and mock data file for active days have been added.

Changes

File(s) Change Summary
frontend/.husky/pre-commit Added git add . command after linting and TypeScript checks to automatically stage fixes.
frontend/.../development/active-days.vue
frontend/.../development/types/active-days.types.ts
Introduced active days functionality: API data fetching via useFetch, new computed properties (activeDays, summary, chartData, categoryData), and a new ActiveDays interface.
frontend/.../development/pull-requests.vue Updated conditional rendering with v-if and enhanced computed properties using optional chaining for safer data handling.
frontend/.../popularity/{forks.vue, stars.vue} Modified computed property types and conditional rendering to check for both status and defined summary values.
frontend/.../popularity/{github-mentions.vue, press-mentions.vue, social-mentions.vue} Revised API endpoints to use the /api/projects/popularity/ routes instead of the old contributor-based paths.
frontend/app/components/uikit/chart/{configs/heat-map.chart.ts, helpers/chart-helpers.ts, types/ChartTypes.ts} Enhanced heat map chart configuration with added grid settings and axis adjustments; added convertToCategoryData and extended ChartSeries to include the heatmap type.
frontend/server/api/projects/development/active-days.get.ts
frontend/server/mocks/active-days.mock.ts
Added a new API endpoint and corresponding mock data file to serve active days information.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer
    participant Hook as Pre-commit Hook
    participant Git as Git

    Dev->>Hook: Initiate commit
    Hook->>Hook: Run linting and TypeScript checks (pnpm lint:fix)
    Hook->>Git: Execute `git add .` to stage fixed files
    Git-->>Dev: Proceed with commit if checks pass
Loading
sequenceDiagram
    participant Comp as ActiveDays.vue
    participant API as Active-Days API Endpoint
    participant Mock as activeDays.mock

    Comp->>API: Request active days data (with query parameters)
    API->>Mock: Retrieve mock data
    Mock-->>API: Return active days data
    API-->>Comp: Deliver data
    alt Successful fetch
        Comp->>Comp: Update computed properties and render chart
    else Error occurs
        Comp->>Toast: Trigger error toast notification
    end
Loading

Possibly related PRs

  • LF-Engineering/lfx-insights-ui#4587: Enhancements in the active-days component with new computed properties and data handling align closely with the changes introduced.
  • added husky #11: Modifications to the pre-commit hook, including the addition of git add ., suggest a strong code-level connection.
  • added heatmap chart and sample #19: Updates to both the active-days component and heat map chart configurations demonstrate similar patterns of data fetching and visualization improvements.

Suggested reviewers

  • gaspergrom

Poem

I’m a rabbit hopping through lines of code,
Celebrating commits on an energetic road.
With hooks that stage and charts that shine,
Each active day’s a data design.
Leaping over bugs with a joyful cheer,
My whiskers twitch for every update here!
🐰💻 Happy coding, my dears!

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

Copy link
Copy Markdown

@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: 2

🔭 Outside diff range comments (1)
frontend/app/components/modules/project/components/popularity/stars.vue (1)

109-109: 🛠️ Refactor suggestion

Error message doesn't match component purpose

The error message mentions "active contributors" but this component displays "Stars" data.

Update the error message to correctly reflect the component's purpose:

-      `Error fetching active contributors: ${error.value?.statusMessage}`,
+      `Error fetching stars data: ${error.value?.statusMessage}`,
🧹 Nitpick comments (5)
frontend/.husky/pre-commit (1)

6-6: Consider using a more targeted git add command.

While adding git add . after linting fixes is a common practice to automatically stage changes made by the linter, this command stages ALL changes in the working directory, which might include unrelated files or changes that weren't intended to be committed yet.

A more targeted approach would be:

-    git add .
+    git add -u

Using git add -u will only stage modifications to already tracked files, reducing the risk of accidentally committing unintended changes.

frontend/app/components/uikit/chart/configs/heat-map.chart.ts (1)

29-30: Update xAxis configuration for better positioning.

The offset addition is good, but you should make a decision on boundaryGap rather than leaving it commented.

-// boundaryGap: true,
+boundaryGap: false, // Disabled to allow cells to align properly with axes
frontend/app/components/modules/project/components/development/active-days.vue (3)

6-9: Improve sentence structure for clarity.
You could rewrite this sentence to be more grammatically complete, for example:

-Active contributor is an individual performing tasks such as commits,
-issues, or pull requests during the selected time period.
+An active contributor is an individual performing tasks such as commits,
+issues, or pull requests during the selected time period.

12-25: Avoid redundant condition check for status === 'success'.
Since lines 12-25 are already guarded by v-if="status === 'success'", the nested check on line 21 is redundant and can be removed to simplify the template.

-<span v-if="status === 'success'" class="text-xl">
+<span class="text-xl">

104-107: Correct the error message to align with active-days data.
The toast references “social mentions” instead of “active-days.” Update it to maintain consistency and clarity:

-`Error fetching social mentions: ${error.value?.statusMessage}`
+`Error fetching active days: ${error.value?.statusMessage}`
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c253345 and 2efbadf.

📒 Files selected for processing (14)
  • frontend/.husky/pre-commit (1 hunks)
  • frontend/app/components/modules/project/components/development/active-days.vue (1 hunks)
  • frontend/app/components/modules/project/components/development/pull-requests.vue (3 hunks)
  • frontend/app/components/modules/project/components/development/types/active-days.types.ts (1 hunks)
  • frontend/app/components/modules/project/components/popularity/forks.vue (2 hunks)
  • frontend/app/components/modules/project/components/popularity/github-mentions.vue (1 hunks)
  • frontend/app/components/modules/project/components/popularity/press-mentions.vue (1 hunks)
  • frontend/app/components/modules/project/components/popularity/social-mentions.vue (1 hunks)
  • frontend/app/components/modules/project/components/popularity/stars.vue (2 hunks)
  • frontend/app/components/uikit/chart/configs/heat-map.chart.ts (5 hunks)
  • frontend/app/components/uikit/chart/helpers/chart-helpers.ts (2 hunks)
  • frontend/app/components/uikit/chart/types/ChartTypes.ts (1 hunks)
  • frontend/server/api/projects/development/active-days.get.ts (1 hunks)
  • frontend/server/mocks/active-days.mock.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • frontend/server/mocks/active-days.mock.ts
🔇 Additional comments (20)
frontend/app/components/modules/project/components/popularity/press-mentions.vue (1)

64-64: API endpoint path correctly relocated.

The press mentions API was moved from the 'contributors' category to the 'popularity' category, which is a more logical categorization for this data.

frontend/app/components/modules/project/components/popularity/social-mentions.vue (1)

64-64: API endpoint path correctly relocated.

The social mentions API was moved from the 'contributors' category to the 'popularity' category, which is a more logical categorization for this data.

frontend/app/components/modules/project/components/development/types/active-days.types.ts (1)

1-11: Well-structured interface for active days data.

The ActiveDays interface is clearly defined with appropriate types for all properties. Good use of the shared Summary type and clear organization of the data structure needed for the active days feature.

frontend/app/components/modules/project/components/popularity/github-mentions.vue (1)

64-65: Correctly relocated API endpoint from contributors to popularity category

This change aligns the API endpoint with its actual purpose, moving it from /api/projects/contributors/github-mentions to /api/projects/popularity/github-mentions while maintaining the same functionality.

frontend/app/components/uikit/chart/types/ChartTypes.ts (1)

10-10: Added heatmap chart type to support new active days widget

The addition of the 'heatmap' type to the ChartSeries interface expands the chart capabilities to support the new active days widget mentioned in the PR objectives.

frontend/app/components/modules/project/components/popularity/stars.vue (2)

12-12: Added null check to prevent SSR errors

Good addition of the null check for the summary object. This aligns with the PR objective to "add logic checks to other widgets to prevent errors during server-side rendering (SSR)".


70-70: Improved type safety by accounting for undefined summary

Updating the type of the summary computed property to handle the possibility of undefined values prevents potential runtime errors. This change complements the template change on line 12 for better defensive programming.

frontend/app/components/uikit/chart/helpers/chart-helpers.ts (2)

6-7: Include SeriesTypes and CategoryData types in imports.

Good addition of these type references for ensuring type safety and better developer experience.


31-43: Well-implemented utility function for category data transformation.

The new convertToCategoryData function efficiently transforms chart data into the appropriate format needed for categorical charts like heatmaps. The function correctly handles possible missing values with the fallback to 0 and ensures proper integer conversion.

This function is a good abstraction that will make chart data preparation more consistent across components.

frontend/app/components/modules/project/components/development/pull-requests.vue (2)

22-23: Prevent server-side rendering errors for average velocity display.

The conditional check ensures the velocity is only displayed when data is successfully loaded, preventing potential null reference errors during SSR.


100-102: Improved null safety with optional chaining.

Good use of optional chaining to handle potential undefined values. This adds robustness against runtime errors when data is not yet available.

frontend/app/components/modules/project/components/popularity/forks.vue (2)

12-12: Enhanced conditional rendering to prevent null reference errors.

Good addition of the && summary check to ensure that the content is only rendered when summary data is available.


70-70: Improved type safety with optional chaining and union type.

Good update to the computed property type to allow for undefined values and use of optional chaining to safely access properties.

frontend/app/components/uikit/chart/configs/heat-map.chart.ts (6)

5-9: Better organization of imported types.

Good reorganization of imported types for better readability and maintainability.


21-26: Improved grid positioning for heat map.

Adding explicit grid margins improves the chart layout and provides better visual space around the heat map.


54-61: Enhanced visualization with color gradient.

Good addition of the color gradient configuration for the heat map. The progression from neutral to brand colors provides better visual distinction between different data points.


100-111: Improved styling for heat map items.

Good enhancement of the heat map cell styling with rounded corners, borders, and hover effects. This significantly improves the visual appeal and interactivity of the chart.


114-117: Better function signature formatting.

Improved code readability by breaking the function parameters into separate lines.


159-166: Improved chart axis configuration.

Good restructuring of the axis configuration code for better readability and maintainability. Using the categoryData to populate the axis data ensures proper data alignment.

frontend/app/components/modules/project/components/development/active-days.vue (1)

29-31: Verify handling of error state for chart rendering.
Currently, the chart is shown if status !== 'pending', which includes “error” status. This can lead to an empty or broken chart visualization. Consider explicitly handling the error state in the template to avoid confusion or unexpected UI behavior.

Comment on lines +1 to +28
import { activeDays } from '~~/server/mocks/active-days.mock';

/**
* Frontend expects the data to be in the following format:
* {
* summary: {
* current: number; // current value
* previous: number; // previous value
* percentageChange: number; // percentage change (return as actual percentage ex: 2.3 percent)
* changeValue: number; // change value
* periodFrom: string; // period from
* periodTo: string; // period to
* },
* avgContributions: number;
* data: {
* dateFrom: string; // ISO 8601 date string - start of the bucket. Based on the interval
* dateTo: string; // ISO 8601 date string - end of the bucket. Based on the interval
* contributions: number; // count of contributions
* }[],
* }
*/
/**
* Query params:
* - project: string
* - repository: string
* - time-period: string // This is isn't defined yet, but we'll add '90d', '1y', '5y' for now
*/
export default defineEventHandler(async () => activeDays);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Implemented new API endpoint for active days with mock data

This implements the new API endpoint for the active days widget, which was the main objective of this PR. The implementation is well-documented with clear comments about the expected data format and query parameters.

However, there's no actual implementation of query parameter handling - the function just returns the mock data regardless of the query parameters.

Consider implementing query parameter handling to ensure the endpoint behaves correctly with different parameters:

-export default defineEventHandler(async () => activeDays);
+export default defineEventHandler(async (event) => {
+  // Extract query parameters
+  const query = getQuery(event)
+  const project = query.project as string
+  const repository = query.repository as string
+  const timePeriod = query['time-period'] as string || '90d'
+  
+  // For now, just return mock data
+  // TODO: Replace with actual implementation when available
+  return activeDays;
+});

You'll need to import getQuery from h3 at the top of the file.

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +32 to +35
<div v-if="status === 'success'" class="flex flex-col gap-5">
<lfx-project-pull-request-legend-item title="Open" :delta="openSummary!" :color="chartSeries[0]!.color!" />
<lfx-project-pull-request-legend-item title="Merged" :delta="mergedSummary!" :color="chartSeries[1]!.color!" />
<lfx-project-pull-request-legend-item title="Closed" :delta="closedSummary!" :color="chartSeries[2]!.color!" />
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Ensure legend items only render with successful data, but remove non-null assertions.

The conditional rendering is good, but using non-null assertions (!) is risky. Even with the v-if guard, it would be safer to handle potential undefined values properly.

-<lfx-project-pull-request-legend-item title="Open" :delta="openSummary!" :color="chartSeries[0]!.color!" />
-<lfx-project-pull-request-legend-item title="Merged" :delta="mergedSummary!" :color="chartSeries[1]!.color!" />
-<lfx-project-pull-request-legend-item title="Closed" :delta="closedSummary!" :color="chartSeries[2]!.color!" />
+<lfx-project-pull-request-legend-item title="Open" :delta="openSummary || {}" :color="chartSeries[0]?.color || ''" />
+<lfx-project-pull-request-legend-item title="Merged" :delta="mergedSummary || {}" :color="chartSeries[1]?.color || ''" />
+<lfx-project-pull-request-legend-item title="Closed" :delta="closedSummary || {}" :color="chartSeries[2]?.color || ''" />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div v-if="status === 'success'" class="flex flex-col gap-5">
<lfx-project-pull-request-legend-item title="Open" :delta="openSummary!" :color="chartSeries[0]!.color!" />
<lfx-project-pull-request-legend-item title="Merged" :delta="mergedSummary!" :color="chartSeries[1]!.color!" />
<lfx-project-pull-request-legend-item title="Closed" :delta="closedSummary!" :color="chartSeries[2]!.color!" />
<div v-if="status === 'success'" class="flex flex-col gap-5">
<lfx-project-pull-request-legend-item title="Open" :delta="openSummary || {}" :color="chartSeries[0]?.color || ''" />
<lfx-project-pull-request-legend-item title="Merged" :delta="mergedSummary || {}" :color="chartSeries[1]?.color || ''" />
<lfx-project-pull-request-legend-item title="Closed" :delta="closedSummary || {}" :color="chartSeries[2]?.color || ''" />

@emlimlf emlimlf merged commit 17d5ea4 into main Feb 27, 2025
2 checks passed
@emlimlf emlimlf deleted the improvement/active-days branch February 27, 2025 05:36
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.

2 participants