Skip to content

fix social mentions styling and added new type param#129

Merged
emlimlf merged 3 commits intomainfrom
improvement/social-mentions
Mar 25, 2025
Merged

fix social mentions styling and added new type param#129
emlimlf merged 3 commits intomainfrom
improvement/social-mentions

Conversation

@emlimlf
Copy link
Copy Markdown
Collaborator

@emlimlf emlimlf commented Mar 25, 2025

In this PR

  • Added the social mentions widget to popularity with mock data
  • Fix styling and chart colors to be inline with the designs

Ticket

INS-93

Summary by CodeRabbit

  • New Features

    • Launched a dedicated Social Mentions section on the project popularity page, featuring clear descriptions and a “Learn More” link.
    • Introduced dynamic chart displays that automatically switch between bar and line visuals based on the selected tab.
    • Enhanced the user experience with a skeleton loading state during data fetches.
  • Style

    • Updated the design palette with a new yellow accent for a fresh look.

Signed-off-by: Efren Lim <elim@linuxfoundation.org>
Copilot AI review requested due to automatic review settings March 25, 2025 06:44
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2025

Walkthrough

This PR implements updates to the social mentions feature across both the frontend and backend. The social mentions component now displays updated text, a "Learn more" link, and a skeleton loading state during data fetching. It features dynamic chart rendering that switches between line and bar charts based on a renamed active tab and computed granularity values. The popularity view integrates the social mentions section with updated side navigation and imports. On the backend, the API endpoint now uses a dynamic granularity and type parameter, and mocks have standardized date property names. Additionally, a new color entry is added to the global styles.

Changes

File(s) Change Summary
frontend/app/components/modules/project/components/popularity/social-mentions.vue Updated presentation and logic of social mentions UI: modified descriptive text, added a "Learn more" link, introduced a skeleton loader, encapsulated chart rendering into lfx-project-load-state, and implemented dynamic chart configuration with new computed granularity and series properties.
frontend/app/components/modules/project/views/popularity.vue Integrated social mentions as a new section by adding <lfx-scroll-view id="social-mentions"> and a corresponding side navigation item; uncommented and imported the LfxProjectSocialMentions component.
frontend/app/config/styles/colors.ts Added a new color, yellow: '#FFD6A7', to the lfxColors object along with a TODO comment for alias verification.
frontend/server/api/project/[slug]/popularity/social-mentions.get.ts Replaced the static interval parameter with dynamic granularity and type parameters; updated conditional logic to select between allTime and newMentions data based on the new query parameters.
frontend/server/mocks/social-mentions.mock.ts Renamed date-related properties uniformly: dateFrom/periodFrom to startDate and dateTo/periodTo to endDate across all objects for consistency.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant C as Social Mentions Component
    participant L as Load State Manager
    participant API as Social Mentions API
    participant Chart as Chart Renderer

    U->>C: Navigate to Social Mentions section
    C->>L: Display skeleton loading state
    C->>API: Request social mentions data (granularity, type)
    API-->>C: Return data (cumulative or new mentions)
    C->>Chart: Supply data and computed chart configuration
    Chart-->>C: Render appropriate chart (line/bar)
    C->>U: Update UI with social mentions summary and chart
Loading

Possibly related PRs


🪧 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 plan to trigger planning for file edits and PR creation.
  • @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
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request fixes the social mentions widget by updating the styling, chart colors, and introduces a new parameter for type filtering (cumulative vs new mentions). Key changes include:

  • Adding a yellow color alias in the color configuration.
  • Updating the API and UI to support a new type parameter, changing the condition from 'all-time' to 'cumulative'.
  • Adjusting the social mentions widget component and view to match the new design and functionality.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
frontend/app/config/styles/colors.ts Added a new yellow color alias with a TODO comment.
frontend/server/api/project/[slug]/popularity/social-mentions.get.ts Updated query parameters (granularity and type) and condition logic to use 'cumulative'.
frontend/server/mocks/social-mentions.mock.ts Renamed date fields for consistency (from dateFrom/dateTo to startDate/endDate).
frontend/app/components/modules/project/components/popularity/social-mentions.vue Updated UI styling, error handling, and chart configuration for social mentions.
frontend/app/components/modules/project/views/popularity.vue Integrated the social mentions widget into the project view.
Comments suppressed due to low confidence (1)

frontend/app/components/modules/project/components/popularity/social-mentions.vue:159

  • The API documentation specifies the type parameter for new mentions as 'new', but the UI tab is using 'new-mentions'. This mismatch may lead to unexpected behavior when fetching data for new mentions.
{ label: 'New mentions by platform', value: 'new-mentions' }

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 (2)
frontend/server/api/project/[slug]/popularity/social-mentions.get.ts (1)

36-40: 🛠️ Refactor suggestion

Add validation for the type parameter

The code assumes query.type will always be either 'cumulative' or some other value but lacks validation to ensure it's one of the expected values.

Add validation for the type parameter to prevent unexpected behavior:

- if (query.type === 'cumulative') {
+ const type = ['cumulative', 'new'].includes(query.type as string) 
+   ? query.type as 'cumulative' | 'new'
+   : 'cumulative'; // Default value
+ 
+ if (type === 'cumulative') {
frontend/server/mocks/social-mentions.mock.ts (1)

148-149: ⚠️ Potential issue

Incomplete property renaming in the newMentions summary object

While most date properties have been renamed from dateFrom/dateTo to startDate/endDate, the periodFrom and periodTo properties in the newMentions.summary object were not updated consistently.

Apply this diff to maintain consistency with the renamed properties:

  summary: {
    current: 4000,
    previous: 3880,
    percentageChange: 3.1,
    changeValue: 120,
-   periodFrom: '2024-11-11T00:00:00Z',
-   periodTo: '2025-02-12T00:00:00Z'
+   startDate: '2024-11-11T00:00:00Z',
+   endDate: '2025-02-12T00:00:00Z'
  },
🧹 Nitpick comments (4)
frontend/app/config/styles/colors.ts (1)

86-87: Address the TODO comment and ensure color structure consistency

The addition of the yellow color with a TODO comment suggests this is a temporary or uncertain solution. Additionally, this single color definition is inconsistent with the structured palette approach used for other colors (which use shade levels 50-900).

Consider either:

  1. Resolving the TODO by confirming the appropriate color alias with Nuno
  2. Structuring this color consistently with other colors by using a palette object:
- // TODO: Verify with Nuno what color alias we should use
- yellow: '#FFD6A7'
+ amber: {
+   500: '#FFD6A7',
+   // Add other shades as needed
+ }
frontend/server/api/project/[slug]/popularity/social-mentions.get.ts (1)

26-28: Improve API documentation for the new parameters

The JSDoc for query parameters has been updated but lacks specific details about valid values for granularity and potential usage examples.

Enhance the documentation by providing allowed values and examples:

 * Query params:
 * - granularity: string
 * - type: 'cumulative' | 'new'
+ * Examples:
+ * - granularity: 'day', 'week', 'month', etc.
frontend/server/mocks/social-mentions.mock.ts (1)

67-74: Remove duplicate data entry

Lines 67-74 and 75-82 appear to contain duplicate data entries with identical date ranges and values.

Consider removing one of these duplicate entries to maintain cleaner mock data:

  {
    startDate: '2024-12-23T00:00:00Z',
    endDate: '2025-01-06T00:00:00Z',
    twitter: 1500,
    reddit: 1700,
    hackerNews: 1800,
    stackOverflow: 1900
  },
- {
-   startDate: '2024-12-23T00:00:00Z',
-   endDate: '2025-01-06T00:00:00Z',
-   twitter: 1500,
-   reddit: 1700,
-   hackerNews: 1800,
-   stackOverflow: 1900
- },
frontend/app/components/modules/project/components/popularity/social-mentions.vue (1)

194-194: Consider updating Stack Overflow color for better distinction

The Stack Overflow series is using lfxColors.warning[200] which might be too similar to the Hacker News color (lfxColors.warning[500]). Consider using lfxColors.yellow instead to match the legend color shown on line 65.

-    color: lfxColors.warning[200]
+    color: lfxColors.yellow
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b64fed and 5e25908.

📒 Files selected for processing (5)
  • frontend/app/components/modules/project/components/popularity/social-mentions.vue (3 hunks)
  • frontend/app/components/modules/project/views/popularity.vue (3 hunks)
  • frontend/app/config/styles/colors.ts (1 hunks)
  • frontend/server/api/project/[slug]/popularity/social-mentions.get.ts (2 hunks)
  • frontend/server/mocks/social-mentions.mock.ts (2 hunks)
🔇 Additional comments (9)
frontend/app/components/modules/project/views/popularity.vue (2)

30-35: The social mentions widget implementation looks good

The addition of the social mentions component follows the established pattern of the other sections and is properly integrated with the scroll functionality.


58-58: Clean implementation of the imports and navigation items

The import of the LfxProjectSocialMentions component and the addition of the navigation item are properly implemented.

Also applies to: 71-71

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

7-12: Good addition of dynamic project name and "Learn more" link

The updated text now provides context-specific information by using the project name, and the "Learn more" link gives users access to additional information. This makes the component more helpful and user-friendly.


16-34: Great improvement to loading state implementation

The skeleton loading state implementation is a significant UX improvement over the previous approach. Using the lfx-skeleton-state component provides better visual feedback during data loading, and checking for the existence of summary is more robust than relying on a fixed status check.


42-72: Excellent chart rendering implementation

The new chart rendering approach with lfx-project-load-state handles loading, error, and empty states much more effectively. The dynamic chart selection based on the active tab is well-implemented, and the custom legend with color indicators for each platform improves user understanding of the data.


120-128: Well-structured granularity computation

The computed properties for granularity handling are well-designed, providing excellent flexibility for different chart types and time ranges. The separation of barGranularity and lineGranularity with a unified granularity property is a clean implementation that adapts to both custom date ranges and predefined time periods.


134-135: Good update to API request parameters

Changing from a static interval to a dynamic granularity parameter and adding the type parameter based on activeTab aligns well with the backend changes and provides more flexible data fetching.


148-148: Good standardization of date property names

Updating the property name from 'date' to 'startDate' in the convertToChartData function ensures consistency with the standardized date property names in the API response.


163-206: Great chart configuration improvements

The dynamic chart type selection in chartSeries and the separate configurations for line and bar charts provide more appropriate visualizations based on the context. The implementation correctly uses the computed granularity values and ensures a consistent user experience.

Comment on lines +153 to +154
startDate: '2024-11-11T00:00:00Z',
endDate: '2024-01-31T00:00:00Z',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistent date range in mock data

There's an issue with the date range in the first entry of newMentions.data: the end date (2024-01-31) is before the start date (2024-11-11), which is logically incorrect.

Correct the date range to ensure the end date is after the start date:

  {
    startDate: '2024-11-11T00:00:00Z',
-   endDate: '2024-01-31T00:00:00Z',
+   endDate: '2024-11-30T00:00:00Z',
    twitter: 500,
    reddit: 700,
    hackerNews: 800,
    stackOverflow: 900
  },
📝 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
startDate: '2024-11-11T00:00:00Z',
endDate: '2024-01-31T00:00:00Z',
{
startDate: '2024-11-11T00:00:00Z',
endDate: '2024-11-30T00:00:00Z',
twitter: 500,
reddit: 700,
hackerNews: 800,
stackOverflow: 900
},

Comment on lines +161 to +162
startDate: '2024-02-01T00:00:00Z',
endDate: '2024-02-29T00:00:00Z',
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix year in date range

The months in this mock data appear to be sequential, but there's an inconsistency in the year. If we're starting with November 2024, then February should also be 2025, not 2024.

Correct the year in the date range:

  {
-   startDate: '2024-02-01T00:00:00Z',
-   endDate: '2024-02-29T00:00:00Z',
+   startDate: '2024-12-01T00:00:00Z',
+   endDate: '2024-12-31T00:00:00Z',
    twitter: 300,
    reddit: 500,
    hackerNews: 600,
    stackOverflow: 700
  },

This correction assumes we want consecutive months. Adjust according to the actual requirements for your mock data timeline.

📝 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
startDate: '2024-02-01T00:00:00Z',
endDate: '2024-02-29T00:00:00Z',
{
startDate: '2024-12-01T00:00:00Z',
endDate: '2024-12-31T00:00:00Z',
twitter: 300,
reddit: 500,
hackerNews: 600,
stackOverflow: 700
},

Signed-off-by: Efren Lim <elim@linuxfoundation.org>
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: 0

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

65-66: Color inconsistency between template and script.

There's a potential mismatch between the color definitions. The template uses bg-yellow for Stack Overflow, while the script uses lfxColors.warning[200].

Ensure consistency by using the same color reference:

-  <div class="w-3 h-3 bg-yellow rounded-xs" />
+  <div class="w-3 h-3 bg-warning-200 rounded-xs" />

Or alternatively update the script to use the consistent color:

-    color: lfxColors.warning[200]
+    color: lfxColors.yellow

Also applies to: 194-195

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5e25908 and 9c0685c.

📒 Files selected for processing (1)
  • frontend/app/components/modules/project/components/popularity/social-mentions.vue (3 hunks)
🔇 Additional comments (16)
frontend/app/components/modules/project/components/popularity/social-mentions.vue (16)

7-12: Clear and informative description with helpful "Learn more" link.

The updated description clearly explains what social mentions represent, using the dynamic project name through the keyword computed property. The addition of the "Learn more" link is a good practice for providing users with additional context.


16-34: Improved loading experience with skeleton state.

The skeleton loading state implementation provides better user feedback during data fetching. The conditional rendering based on summary availability is properly implemented, and the delta display logic correctly accounts for the time range selection.


42-46: Error message consistency with component purpose.

The error message now correctly refers to "social mentions" rather than "forks" as mentioned in a previous review.


48-71: Well-structured chart with appropriate legend.

The dynamic chart selection based on the active tab is well-implemented. The legend with distinct colors for different platforms enhances usability and data comprehension.


94-94: Added import for line chart configuration.

The addition of the line area chart import supports the new chart type functionality.


100-104: Required imports for new functionality.

These imports provide the necessary functionality for links, date options, data validation, and granularity definitions needed for the improved component.


107-115: Enhanced store integration with keyword computation.

The expanded destructuring of the store provides access to all required reactive properties. The computed keyword property intelligently uses the project name.


117-117: Tab renaming from 'all-time' to 'cumulative'.

The default tab has been renamed to be more descriptive of its function.


120-129: Well-implemented dynamic granularity calculations.

The computed properties for granularity selection based on time range and chart type are well-structured. The code correctly handles custom date ranges by leveraging the store's customRangeGranularity.


134-135: API parameters updated to use dynamic values.

The request parameters now use computed granularity and type values, providing more flexible and context-aware data fetching.


148-148: Chart data conversion using 'startDate' property.

The convertToChartData function now properly uses 'startDate' as the date property key.


156-157: Added empty state detection.

The isEmpty computed property helps determine when to display empty state UI, improving user experience.


159-159: Updated tab label for clarity.

The tab has been relabeled to "Mentions by platform" which better describes the content being displayed.


163-196: Dynamic chart type based on selected tab.

The chart series now dynamically changes its visualization type based on the active tab, switching between line and bar charts as appropriate. This provides different views of the data that may be better suited for different analysis needs.


197-201: Added line chart configuration.

The new computed property for line chart configuration supports the dual visualization approach, using appropriate granularity values based on the selected time range.


205-205: Bar chart configuration updated for dynamic granularity.

The bar chart configuration now correctly uses the computed barGranularity value, ensuring consistent time intervals across visualizations.

@emlimlf emlimlf merged commit 21bba50 into main Mar 25, 2025
3 checks passed
@emlimlf emlimlf deleted the improvement/social-mentions branch March 25, 2025 08:05
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.

3 participants