Skip to content

Design preview for code example voting #2810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rohitpaulk
Copy link
Member

@rohitpaulk rohitpaulk commented Apr 23, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a feedback section at the bottom of community solution cards, enabling users to upvote or downvote solutions with immediate visual confirmation.
  • Style
    • Enhanced layout and interactive button styling, including dark mode support and smooth animated transitions.
  • Refactor
    • Relocated upvote and downvote buttons from the header to the new feedback section for improved user experience.

Copy link
Contributor

coderabbitai bot commented Apr 23, 2025

"""

Walkthrough

A feedback feature was introduced to the community solution card within the course page. The upvote and downvote buttons, previously located in the card header, have been removed from there and a new feedback section component has been added at the bottom of the card. This feedback section provides interactive upvote and downvote buttons, visually reflects user actions, and displays a temporary thank-you message upon voting. The new component handles vote state and UI transitions internally, utilizing tracked properties and animated feedback.

Changes

File(s) Change Summary
app/components/course-page/course-stage-step/community-solution-card/content.hbs Renders the new <FeedbackSection> component after the unchanged file comparisons section.
app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs,
.../community-solution-card/feedback-section.ts
New feedback section component: UI for upvote/downvote, state management, animated transitions, and thank-you message.
app/components/course-page/course-stage-step/community-solution-card/header.hbs Removes (comments out) the upvote/downvote buttons from the header, indicating relocation to the card's bottom.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CommunitySolutionCard
    participant FeedbackSection

    User->>CommunitySolutionCard: Views solution card
    CommunitySolutionCard->>FeedbackSection: Renders feedback section
    User->>FeedbackSection: Clicks "Helpful" or "Not helpful"
    FeedbackSection->>FeedbackSection: Updates vote state
    FeedbackSection->>FeedbackSection: Shows "Thanks for your feedback!" (1.5s)
    FeedbackSection-->>User: Visual feedback (button highlight, message)
Loading

Poem

A rabbit hopped through code today,
Moving buttons out of the way.
Now at the bottom, feedback shines—
With up and down in tidy lines.
Click "Yes" or "No," a thank-you glows,
For helpful thoughts the user shows!
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 1fd42e4 and c4f2f92.

📒 Files selected for processing (4)
  • app/components/course-page/course-stage-step/community-solution-card/content.hbs (1 hunks)
  • app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs (1 hunks)
  • app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts (1 hunks)
  • app/components/course-page/course-stage-step/community-solution-card/header.hbs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • app/components/course-page/course-stage-step/community-solution-card/content.hbs
  • app/components/course-page/course-stage-step/community-solution-card/header.hbs
  • app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs
  • app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts

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

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 sequence diagram to generate a sequence diagram of the changes in 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.

@rohitpaulk rohitpaulk force-pushed the update-course-page-code-examples-test branch 2 times, most recently from eb19b4a to 8a5f787 Compare April 23, 2025 00:25
Copy link

github-actions bot commented Apr 23, 2025

Test Results

  1 files  ±0    1 suites  ±0   8m 19s ⏱️ -58s
624 tests ±0  576 ✅  - 3  45 💤 ±0  0 ❌ ±0  3 🔥 +3 
624 runs  ±0  573 ✅  - 6  45 💤 ±0  3 ❌ +3  3 🔥 +3 

For more details on these errors, see this check.

Results for commit c4f2f92. ± Comparison against base commit c9b1151.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Apr 23, 2025

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
579 3 576 45
View the top 3 failed test(s) by shortest run time
Chrome 135.0 Acceptance | view-badges: it renders when all badges are unearned
Stack Traces | 1.27s run time
Promise rejected during "it renders when all badges are unearned": Failed to visit URL '/badges': ChunkLoadError: Loading chunk vendors-assets__route__badges_js failed.
(error: http://localhost:7357/assets/chunk.3208a847fb0336699f6a.js)

PageObject: 'page.visit()'
  Selector: ':first'
Chrome 135.0 Acceptance | course-page | code-examples | vote: can upvote code examples
Stack Traces | 1.6s run time
Promise rejected during "can upvote code examples": Element not found.

PageObject: 'page.codeExamplesTab.solutionCards[0].upvoteButton'
  Selector: '[data-test-code-examples-tab] [data-test-community-solution-card]:eq(0) [data-test-solution-card-upvote-button]'

PageObject: 'page.codeExamplesTab.solutionCards[0].upvoteButton.hover()'
  Selector: '[data-test-code-examples-tab] [data-test-community-solution-card]:eq(0) [data-test-solution-card-upvote-button]'
Chrome 135.0 Acceptance | course-page | code-examples | vote: can downvote code examples
Stack Traces | 1.71s run time
Promise rejected during "can downvote code examples": Element not found.

PageObject: 'page.codeExamplesTab.solutionCards[0].downvoteButton'
  Selector: '[data-test-code-examples-tab] [data-test-community-solution-card]:eq(0) [data-test-solution-card-downvote-button]'

PageObject: 'page.codeExamplesTab.solutionCards[0].downvoteButton.hover()'
  Selector: '[data-test-code-examples-tab] [data-test-community-solution-card]:eq(0) [data-test-solution-card-downvote-button]'

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Copy link

codecov bot commented Apr 23, 2025

Bundle Report

Changes will increase total bundle size by 1.12kB (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
client-array-push 36.58MB 1.12kB (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: client-array-push

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/chunk.*.js 1.12kB 49.98kB 2.3%

Copy link
Contributor

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0813f20 and c16d008.

📒 Files selected for processing (4)
  • app/components/course-page/course-stage-step/community-solution-card/content.hbs (1 hunks)
  • app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs (1 hunks)
  • app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts (1 hunks)
  • app/components/course-page/course-stage-step/community-solution-card/header.hbs (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts

[warning] 23-24: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L23-L24
Added lines #L23 - L24 were not covered by tests


[warning] 26-26: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L26
Added line #L26 was not covered by tests


[warning] 29-31: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L29-L31
Added lines #L29 - L31 were not covered by tests


[warning] 38-39: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L38-L39
Added lines #L38 - L39 were not covered by tests


[warning] 41-41: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L41
Added line #L41 was not covered by tests


[warning] 44-46: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L44-L46
Added lines #L44 - L46 were not covered by tests


[warning] 50-52: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L50-L52
Added lines #L50 - L52 were not covered by tests

🔇 Additional comments (1)
app/components/course-page/course-stage-step/community-solution-card/feedback-section.hbs (1)

1-42: Feedback section UI looks good

The UI implementation for the feedback section is well designed with appropriate animations and visual state changes for different voting conditions.

{{/each}}

<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection class="pt-6 pb-3" />
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

The feedback section component is missing solution data

The feedback section component is added correctly, but it doesn't receive any data about the current solution. For the design preview this might be intentional, but for actual functionality, it should receive the solution data to record votes.

-<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection class="pt-6 pb-3" />
+<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection 
+  @solution={{@solution}} 
+  @metadata={{@metadataForUpvote}} 
+  class="pt-6 pb-3" 
+/>
📝 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
<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection class="pt-6 pb-3" />
<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection
@solution={{@solution}}
@metadata={{@metadataForUpvote}}
class="pt-6 pb-3"
/>

Comment on lines +23 to +28
{{! Remove, replace with buttons at the bottom of the card }}
{{!-- {{#unless (eq @solution.user this.authenticator.currentUser)}}
<CoursePage::CourseStageStep::CommunitySolutionCard::UpvoteButton @solution={{@solution}} @metadata={{@metadataForUpvote}} class="mr-2" />
<CoursePage::CourseStageStep::CommunitySolutionCard::DownvoteButton @solution={{@solution}} @metadata={{@metadataForDownvote}} />
<div class="w-px h-3 bg-gray-200 dark:bg-white/5 mx-2"></div>
{{/unless}}
{{/unless}} --}}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing user restriction in new feedback component

The commented-out code shows the previous implementation had a condition to only show vote buttons if the solution wasn't created by the current user. This same logic should be applied to the new feedback section component to maintain consistent behavior.

This restriction logic should either be:

  1. Implemented in the feedback-section component itself (by passing the current user)
  2. Added as a condition when rendering the component in content.hbs
// In content.hbs:
+{{#unless (eq @solution.user this.authenticator.currentUser)}}
  <CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection @solution={{@solution}} class="pt-6 pb-3" />
+{{/unless}}
📝 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
{{! Remove, replace with buttons at the bottom of the card }}
{{!-- {{#unless (eq @solution.user this.authenticator.currentUser)}}
<CoursePage::CourseStageStep::CommunitySolutionCard::UpvoteButton @solution={{@solution}} @metadata={{@metadataForUpvote}} class="mr-2" />
<CoursePage::CourseStageStep::CommunitySolutionCard::DownvoteButton @solution={{@solution}} @metadata={{@metadataForDownvote}} />
<div class="w-px h-3 bg-gray-200 dark:bg-white/5 mx-2"></div>
{{/unless}}
{{/unless}} --}}
{{!-- Only show feedback section if the solution wasn't created by the current user --}}
{{#unless (eq @solution.user this.authenticator.currentUser)}}
<CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection
@solution={{@solution}}
class="pt-6 pb-3"
/>
{{/unless}}

Comment on lines +11 to +59
export default class CommunitySolutionCardFeedbackSectionComponent extends Component<Signature> {
transition = fade;

@tracked tempHasVotedRecently = false;
@tracked tempHasUpvoted = false;
@tracked tempHasDownvoted = false;

@action
handleDownvoteButtonClick() {
// No feedback if the user is "reversing" their vote
if (this.tempHasDownvoted) {
this.tempHasDownvoted = false;
this.tempHasVotedRecently = false;

return;
}

this.flashSuccessMessageTask.perform();
this.tempHasUpvoted = false;
this.tempHasDownvoted = true;
}

@action
handleUpvoteButtonClick() {
// No feedback if the user is "reversing" their vote
if (this.tempHasUpvoted) {
this.tempHasUpvoted = false;
this.tempHasVotedRecently = false;

return;
}

this.flashSuccessMessageTask.perform();
this.tempHasDownvoted = false;
this.tempHasUpvoted = true;
}

flashSuccessMessageTask = task({ keepLatest: true }, async () => {
this.tempHasVotedRecently = true;
await timeout(1500);
this.tempHasVotedRecently = false;
});
}

declare module '@glint/environment-ember-loose/registry' {
export default interface Registry {
'CoursePage::CourseStageStep::CommunitySolutionCard::FeedbackSection': typeof CommunitySolutionCardFeedbackSectionComponent;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Missing actual vote persistence functionality

The component currently only manages temporary visual state (note the temp prefixes in variable names) but doesn't persist votes or make API calls. For a design preview this is fine, but for production functionality, it should:

  1. Accept @Solution as an argument to know which solution is being voted on
  2. Make API calls to record votes
  3. Handle loading and error states

Here's a suggested enhancement to the component interface:

interface Signature {
  Element: HTMLDivElement;
+  Args: {
+    solution: SolutionModel;
+    metadata?: Record<string, unknown>;
+  };
}

Additionally, implement actual API calls in the handlers:

@action
async handleUpvoteButtonClick() {
  // Existing logic for UI state...
  
  try {
    await this.args.solution.upvote(this.args.metadata);
    // Success handling
  } catch (error) {
    // Error handling
    this.tempHasUpvoted = false;
    this.tempHasVotedRecently = false;
  }
}
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 23-24: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L23-L24
Added lines #L23 - L24 were not covered by tests


[warning] 26-26: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L26
Added line #L26 was not covered by tests


[warning] 29-31: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L29-L31
Added lines #L29 - L31 were not covered by tests


[warning] 38-39: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L38-L39
Added lines #L38 - L39 were not covered by tests


[warning] 41-41: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L41
Added line #L41 was not covered by tests


[warning] 44-46: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L44-L46
Added lines #L44 - L46 were not covered by tests


[warning] 50-52: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L50-L52
Added lines #L50 - L52 were not covered by tests

Comment on lines +14 to +52
@tracked tempHasVotedRecently = false;
@tracked tempHasUpvoted = false;
@tracked tempHasDownvoted = false;

@action
handleDownvoteButtonClick() {
// No feedback if the user is "reversing" their vote
if (this.tempHasDownvoted) {
this.tempHasDownvoted = false;
this.tempHasVotedRecently = false;

return;
}

this.flashSuccessMessageTask.perform();
this.tempHasUpvoted = false;
this.tempHasDownvoted = true;
}

@action
handleUpvoteButtonClick() {
// No feedback if the user is "reversing" their vote
if (this.tempHasUpvoted) {
this.tempHasUpvoted = false;
this.tempHasVotedRecently = false;

return;
}

this.flashSuccessMessageTask.perform();
this.tempHasDownvoted = false;
this.tempHasUpvoted = true;
}

flashSuccessMessageTask = task({ keepLatest: true }, async () => {
this.tempHasVotedRecently = true;
await timeout(1500);
this.tempHasVotedRecently = false;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Missing test coverage for component logic

The static analysis indicates that much of the component logic is not covered by tests. Consider adding tests for:

  1. The upvote/downvote toggle functionality
  2. The success message flash behavior
  3. Edge cases like multiple rapid clicks

You can verify the current test coverage with:


🏁 Script executed:

#!/bin/bash
# Check current test coverage for feedback-section component
find tests -type f -name "*feedback-section*" -o -name "*community-solution*" | xargs cat

Length of output: 16787


Add targeted tests for flash message and rapid-click behavior

While the existing acceptance tests cover the basic upvote/downvote toggling via UI, we still need to add focused tests for the component’s internal logic:

• Test the flashSuccessMessageTask in isolation
– Verify that tempHasVotedRecently flips to true, then back to false after the 1.5 s timeout (e.g. using await settled() or ember-concurrency’s test helpers).
• Test rapid‐click edge cases
– Ensure that clicking upvote/downvote multiple times in quick succession doesn’t trigger extra flashes or leave the component in an inconsistent state.
• (If not already covered) Add a small unit/integration test for the toggle logic directly on the component, asserting initial state and flip behavior of tempHasUpvoted/tempHasDownvoted.

You can place these in a new integration test under:
  tests/integration/components/course-page/course-stage-step/community-solution-card/feedback-section-test.js

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 23-24: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L23-L24
Added lines #L23 - L24 were not covered by tests


[warning] 26-26: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L26
Added line #L26 was not covered by tests


[warning] 29-31: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L29-L31
Added lines #L29 - L31 were not covered by tests


[warning] 38-39: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L38-L39
Added lines #L38 - L39 were not covered by tests


[warning] 41-41: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L41
Added line #L41 was not covered by tests


[warning] 44-46: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L44-L46
Added lines #L44 - L46 were not covered by tests


[warning] 50-52: app/components/course-page/course-stage-step/community-solution-card/feedback-section.ts#L50-L52
Added lines #L50 - L52 were not covered by tests

refactor(feedback): increase animation duration for voting feedback
fix: improve feedback section text clarity and consistency
feat: add tooltips to feedback buttons for clarity
feat(tooltip): add delay to tooltips for improved usability
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