Skip to content
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

CC-1480: Highlight language guides in stage 2 tutorial card #2367

Merged
merged 4 commits into from
Oct 29, 2024

Conversation

andy1li
Copy link
Member

@andy1li andy1li commented Oct 29, 2024

Checklist:

  • I've thoroughly self-reviewed my changes
  • I've added tests for my changes, unless they affect admin-only areas (or are otherwise not worth testing)
  • I've verified any visual changes using Percy (add a commit with [percy] in the message to trigger)

Summary by CodeRabbit

  • New Features

    • Introduced dynamic visibility for language guides in the instructions card, enhancing user experience.
    • Added conditional rendering for language guide recommendations in the "Implement Solution" and "Read Instructions" steps.
    • Enhanced responsiveness of the course stage instructions by integrating language guide loading.
    • Updated user interface to display language-specific guidance based on the availability of language guides.
  • Bug Fixes

    • Improved state management for displaying language guides based on feature flags.
  • Documentation

    • Updated component interfaces to include new properties related to language guide visibility.

@andy1li andy1li self-assigned this Oct 29, 2024
Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The pull request introduces enhancements to the CoursePage::InstructionsCard component, specifically in the second-stage-instructions-card files. Key changes include the addition of a new attribute @shouldRecommendLanguageGuide to the ReadInstructionsStep and ImplementSolutionStep components. The SecondStageInstructionsCardComponent now includes a boolean argument for this attribute, which influences the rendering of content related to language guides. Additionally, the CourseStageInstructionsController has been updated to manage the loading of language guides based on the current course stage.

Changes

File Change Summary
app/components/course-page/course-stage-step/second-stage-instructions-card.hbs Added @shouldRecommendLanguageGuide attribute to ReadInstructionsStep and ImplementSolutionStep components.
app/components/course-page/course-stage-step/second-stage-instructions-card.ts Added shouldRecommendLanguageGuide argument to SecondStageInstructionsCardComponent signature.
app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.hbs Introduced conditional rendering based on @shouldRecommendLanguageGuide for language guide suggestions.
app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts Added shouldRecommendLanguageGuide argument to Args interface.
app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.hbs Added conditional rendering for a link to the language guide based on @shouldRecommendLanguageGuide.
app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts Added shouldRecommendLanguageGuide argument to Args interface.
app/components/course-page/course-stage-step/simple-language-guide-card.hbs Removed surrounding <div> and conditional rendering for the CoursePage::InstructionsCard.
app/components/course-page/course-stage-step/simple-language-guide-card.ts Updated languageGuide getter type and removed loadLanguageGuides method and task.
app/controllers/course/stage/instructions.ts Injected store service, updated shouldShowLanguageGuide computed property, and added loadLanguageGuides action with a task for asynchronous loading of language guides.
app/templates/course/stage/instructions.hbs Added lifecycle hooks to invoke loadLanguageGuides and passed @shouldRecommendLanguageGuide to CourseStageStep::SecondStageInstructionsCard.
tests/acceptance/course-page/attempt-course-stage-test.js Updated assertions to include the API request for fetching the language guide.
tests/acceptance/course-page/resume-course-test.js Updated expected API requests count to include the language guide fetch request.
tests/acceptance/course-page/switch-repository-test.js Added assertion for the API request related to fetching language guides.
tests/acceptance/course-page/try-other-language-test.js Updated expected API requests count to include the request for fetching the language guide.

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • rohitpaulk

Poem

🐰 In the course where knowledge grows,
Language guides now brightly show,
With hooks and flags, we pave the way,
For learners bright, both night and day.
So hop along, let’s learn and play! 🌟


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between eb8c049 and 190fca8.

📒 Files selected for processing (5)
  • app/components/course-page/course-stage-step/simple-language-guide-card.hbs (1 hunks)
  • app/components/course-page/course-stage-step/simple-language-guide-card.ts (1 hunks)
  • app/controllers/course/stage/instructions.ts (4 hunks)
  • app/templates/course/stage/instructions.hbs (3 hunks)
  • tests/acceptance/course-page/try-other-language-test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • app/components/course-page/course-stage-step/simple-language-guide-card.hbs
  • app/components/course-page/course-stage-step/simple-language-guide-card.ts
  • app/controllers/course/stage/instructions.ts
  • app/templates/course/stage/instructions.hbs
  • tests/acceptance/course-page/try-other-language-test.js

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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 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.

@andy1li andy1li force-pushed the highlight-language-guides-in-stage-2 branch from 1fc47de to 2beb262 Compare October 29, 2024 10:27
@andy1li andy1li changed the title Highlight language guides in second-stage-instructions-card CC-1480: Highlight language guides in stage 2 tutorial card Oct 29, 2024
Copy link

linear bot commented Oct 29, 2024

@andy1li andy1li force-pushed the highlight-language-guides-in-stage-2 branch from 2beb262 to f1c68fc Compare October 29, 2024 10:31
Copy link

codecov bot commented Oct 29, 2024

Bundle Report

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

Detailed changes
Bundle name Size Change
client-array-push 35.84MB 2.71kB (0.01%) ⬆️

Copy link

github-actions bot commented Oct 29, 2024

Test Results

  1 files  ±0    1 suites  ±0   6m 25s ⏱️ -13s
582 tests ±0  542 ✅ ±0  40 💤 ±0  0 ❌ ±0 
597 runs  ±0  557 ✅ ±0  40 💤 ±0  0 ❌ ±0 

Results for commit 190fca8. ± Comparison against base commit 8e2bbfe.

♻️ This comment has been updated with latest results.

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files

📢 Thoughts on this report? Let us know!

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: 3

🧹 Outside diff range and nitpick comments (2)
app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.hbs (1)

12-21: LGTM! Consider adding ARIA attributes for better accessibility.

The conditional rendering logic is well-implemented and maintains a consistent user experience. The content is clear and purposeful in both cases.

Consider adding ARIA attributes to enhance accessibility:

 {{#if @isShowingLanguageGuide}}
   The
-  <a href="#language-guide-card">{{this.currentLanguageName}} Guide</a>
+  <a href="#language-guide-card" aria-label="View {{this.currentLanguageName}} specific guide">{{this.currentLanguageName}} Guide</a>
   card, which contains
   {{this.currentLanguageName}}-specific instructions for this stage.
 {{else}}
   The
-  <LinkTo @route="course.stage.code-examples">Code Examples</LinkTo>
+  <LinkTo @route="course.stage.code-examples" aria-label="View code examples from other users">Code Examples</LinkTo>
   tab, which contains code examples from other users.
 {{/if}}
app/components/course-page/course-stage-step/second-stage-instructions-card.hbs (1)

Line range hint 1-44: Consider adding tests for language guide visibility logic.

While the PR objectives mention that tests weren't added, consider adding tests to verify:

  1. Language guide loading behavior on component initialization and course stage changes
  2. Correct propagation of isShowingLanguageGuide to child components
  3. Integration tests for the visibility toggling functionality

This would help ensure the reliability of the language guide feature.

Would you like me to help draft some test cases for these scenarios?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0a63165 and f1c68fc.

📒 Files selected for processing (6)
  • app/components/course-page/course-stage-step/second-stage-instructions-card.hbs (2 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card.ts (4 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.hbs (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.hbs (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts (1 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts

[warning] 19-19: app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts#L19
Added line #L19 was not covered by tests

app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts

[warning] 19-19: app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts#L19
Added line #L19 was not covered by tests

🔇 Additional comments (10)
app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.hbs (2)

6-12: LGTM! Clean conditional implementation.

The conditional rendering is well-structured and maintains a consistent user experience by providing appropriate guidance in both cases. The implementation aligns with the PR objective of enhancing language guide visibility.


6-12: Verify the language guide card anchor exists.

The template links to "#language-guide-card" anchor. Please ensure this anchor exists in the parent template to avoid broken navigation.

✅ Verification successful

The language guide card anchor exists in both simple and full guide templates

The "#language-guide-card" anchor is properly implemented in both variants of the language guide card:

  • simple-language-guide-card.hbs
  • language-guide-card.hbs

This ensures the anchor link in the instructions will work correctly regardless of which guide variant is rendered.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for language-guide-card id/anchor in template files
rg -t html -t hbs 'id="language-guide-card"' || rg -t html -t hbs 'name="language-guide-card"'

Length of output: 249

app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts (1)

12-12: LGTM: Clean interface extension

The addition of the required boolean flag isShowingLanguageGuide to the Args interface is well-typed and aligns with the PR's objective of enhancing language guide visibility.

app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts (2)

12-12: LGTM: Interface extension is well-typed

The addition of isShowingLanguageGuide boolean argument is properly typed and aligns with the component's purpose.


17-19: ⚠️ Potential issue

Consider safer type handling and add tests

The getter implementation has several areas for improvement:

  1. The non-null assertion (!) assumes language is always defined, which might not be true
  2. The method lacks test coverage
  3. Missing documentation explaining the getter's purpose

Here's a safer implementation:

+ /**
+  * Returns the name of the repository's programming language
+  * @throws Error if language is not set
+  */
 get currentLanguageName(): string {
-  return this.args.repository.language!.name;
+  if (!this.args.repository.language) {
+    throw new Error('Repository language is not set');
+  }
+  return this.args.repository.language.name;
 }

Let's verify if language can be undefined:

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 19-19: app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts#L19
Added line #L19 was not covered by tests

app/components/course-page/course-stage-step/second-stage-instructions-card.hbs (3)

27-27: LGTM: Clean integration of language guide visibility.

The @isShowingLanguageGuide prop is well-named and consistently integrated with existing props.


34-34: LGTM: Consistent implementation across components.

The @isShowingLanguageGuide prop is consistently implemented across both step components.


5-6: Verify duplicate loading prevention in loadLanguageGuides.

The component uses both did-insert and did-update hooks to load language guides. While this ensures loading occurs both on initial render and course stage changes, verify that the loadLanguageGuides method implements proper caching or deduplication to prevent unnecessary duplicate API calls.

Let's check the implementation of loadLanguageGuides:

✅ Verification successful

Duplicate loading is properly handled using ember-concurrency task

The implementation in second-stage-instructions-card.ts shows that loadLanguageGuides uses an ember-concurrency task with keepLatest: true option, which automatically cancels any running task instance when a new one starts. This effectively prevents duplicate API calls when both did-insert and did-update hooks fire in succession.

Key implementation details:

  • Uses loadLanguageGuidesTask = task({ keepLatest: true }, ...) to manage concurrent requests
  • The task performs a single store query with proper includes
  • The keepLatest option ensures only one API call is active at a time
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for loadLanguageGuides implementation
ast-grep --pattern 'loadLanguageGuides = $_' || ast-grep --pattern 'loadLanguageGuides() {
  $$$
}'

Length of output: 46


Script:

#!/bin/bash
# Try different patterns to locate loadLanguageGuides implementation
# First, search for class or component definition containing loadLanguageGuides
ast-grep --pattern 'class $_ {
  $$$
  loadLanguageGuides
  $$$
}'

# Also search using ripgrep for any occurrence of loadLanguageGuides
rg "loadLanguageGuides" -A 5

Length of output: 6642

app/components/course-page/course-stage-step/second-stage-instructions-card.ts (2)

8-8: LGTM: Clean service integration

The new imports and service injection are well-structured and properly typed, following Ember.js best practices.

Also applies to: 10-10, 59-59


123-126: Verify lifecycle hooks integration

Ensure that the loadLanguageGuides action is properly connected to component lifecycle hooks in the template.

✅ Verification successful

Lifecycle hooks are properly integrated

The lifecycle hooks for loadLanguageGuides are correctly set up in the template:

  • Both did-insert and did-update modifiers are present in second-stage-instructions-card.hbs
  • The did-update modifier is correctly bound to @courseStage for reactivity
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for lifecycle hooks in the corresponding template
rg -t hbs "did-(insert|update).*loadLanguageGuides" app/components/course-page/course-stage-step/

Length of output: 760

Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Note added

@@ -36,7 +36,7 @@ module('Acceptance | course-page | try-other-language', function (hooks) {
'fetch repositories (course page)',
'fetch leaderboard entries (course page)',
'fetch hints (course page)',
// 'fetch language guide (course page)',
'fetch language guide (course page)',
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, weren't we already loading this from the current card on the page? 🤔 @andy1li do you know why this only has to be uncommented now?

Copy link
Member Author

@andy1li andy1li Oct 29, 2024

Choose a reason for hiding this comment

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

@rohitpaulk I needed to uncomment three of them, otherwise the tests won't pass.

Context:

These tests were set up on the second stage of redis. It seems that language guides hadn't been loaded before recent changes.

Copy link
Member

@rohitpaulk rohitpaulk left a comment

Choose a reason for hiding this comment

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

Code looks good! Will briefly discuss this on our call before releasing

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: 6

🧹 Outside diff range and nitpick comments (1)
app/components/course-page/course-stage-step/simple-language-guide-card.hbs (1)

1-8: Consider adding type safety for the onExpand action.

While the component structure looks good, consider adding TypeScript type definitions or PropTypes for the onExpand action to ensure type safety and better documentation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f1c68fc and 79f0a0f.

📒 Files selected for processing (14)
  • app/components/course-page/course-stage-step/second-stage-instructions-card.hbs (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card.ts (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.hbs (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts (1 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.hbs (2 hunks)
  • app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts (1 hunks)
  • app/components/course-page/course-stage-step/simple-language-guide-card.hbs (1 hunks)
  • app/components/course-page/course-stage-step/simple-language-guide-card.ts (2 hunks)
  • app/controllers/course/stage/instructions.ts (3 hunks)
  • app/templates/course/stage/instructions.hbs (2 hunks)
  • tests/acceptance/course-page/attempt-course-stage-test.js (1 hunks)
  • tests/acceptance/course-page/resume-course-test.js (1 hunks)
  • tests/acceptance/course-page/switch-repository-test.js (1 hunks)
  • tests/acceptance/course-page/try-other-language-test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • app/components/course-page/course-stage-step/second-stage-instructions-card.hbs
  • app/components/course-page/course-stage-step/second-stage-instructions-card.ts
  • app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.hbs
  • app/components/course-page/course-stage-step/second-stage-instructions-card/implement-solution-step.ts
  • app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.hbs
  • app/components/course-page/course-stage-step/second-stage-instructions-card/read-instructions-step.ts
🔇 Additional comments (9)
app/components/course-page/course-stage-step/simple-language-guide-card.ts (1)

7-7: LGTM: Type import addition improves type safety

The explicit import of CourseStageLanguageGuideModel type enhances type checking and code clarity.

tests/acceptance/course-page/resume-course-test.js (1)

42-42: LGTM! Test coverage aligns with new language guide functionality.

The addition of the language guide API request assertion appropriately validates the new behavior being introduced for highlighting language guides in the stage 2 tutorial card.

app/controllers/course/stage/instructions.ts (3)

13-14: LGTM!

The new imports are correctly typed and necessary for the added functionality.


21-21: LGTM!

The store service injection is properly typed and follows Ember.js conventions.


53-59: LGTM!

The computed property now correctly checks for the existence of a language guide before attempting to show it. The implementation follows the previous review suggestion regarding the feature flag check.

tests/acceptance/course-page/attempt-course-stage-test.js (1)

44-44: LGTM! Consider updating other test cases.

The addition of 'fetch language guide (course page)' correctly updates the test expectations to account for the new language guide API request.

Let's verify if other test cases in this file need similar updates:

✅ Verification successful

No updates needed in other test cases

The verification shows that only one test case in this file checks API request counts. The other test cases ('can pass course stage' and 'can pass tests using CLI') focus on different aspects like step completion and CLI usage, and don't verify API request counts. Therefore, no similar updates are needed in other test cases.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if other test cases in this file also verify API request counts
# and might need similar updates for language guide fetching

# Test: Look for similar assertions in other test cases
rg -A 5 "apiRequestsCount\(this\.server\)" "tests/acceptance/course-page/attempt-course-stage-test.js"

Length of output: 331


Script:

#!/bin/bash
# Let's get more context around the API request counts to understand the test cases better
rg -B 10 -A 10 "apiRequestsCount\(this\.server\)" "tests/acceptance/course-page/attempt-course-stage-test.js"

Length of output: 772


Script:

#!/bin/bash
# Let's search for all test cases in this file to see their structure and API requests
rg -B 5 -A 20 "test\(('|\").*('|\")" "tests/acceptance/course-page/attempt-course-stage-test.js"

Length of output: 3013

app/templates/course/stage/instructions.hbs (2)

1-5: Verify error handling for loadLanguageGuides.

The lifecycle hooks ensure proper loading of language guides. However, please verify:

  1. Error handling for failed guide loads
  2. Potential double-loading when component is first inserted
#!/bin/bash
# Search for loadLanguageGuides implementation to verify error handling
ast-grep --pattern 'loadLanguageGuides() {
  $$$
}'

42-44: LGTM! Verify SecondStageInstructionsCard implementation.

The addition of @shouldRecommendLanguageGuide aligns well with the PR objective to highlight language guides in stage 2. The property name is semantic and follows component composition best practices.

✅ Verification successful

Implementation verified and properly handles the shouldRecommendLanguageGuide prop

The verification shows that:

  • The shouldRecommendLanguageGuide prop is correctly defined in the component's interface (Signature.Args)
  • The prop is properly passed down to both ReadInstructionsStep and ImplementSolutionStep child components
  • The source of the prop in the controller is well-implemented, considering language guides availability and feature flags
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for SecondStageInstructionsCard implementation to verify prop handling
ast-grep --pattern 'class SecondStageInstructionsCard {
  $$$
}'

# Search for shouldShowLanguageGuide computed property
ast-grep --pattern 'get shouldShowLanguageGuide() {
  $$$
}'

Length of output: 129


Script:

#!/bin/bash
# Try different search patterns for SecondStageInstructionsCard component
rg -l "SecondStageInstructionsCard" 

# Search for files containing shouldShowLanguageGuide
rg -l "shouldShowLanguageGuide"

# Once we find the files, we can examine their content

Length of output: 685


Script:

#!/bin/bash
# Check the implementation of SecondStageInstructionsCard component
cat app/components/course-page/course-stage-step/second-stage-instructions-card.ts

# Check the controller where shouldShowLanguageGuide is defined
cat app/controllers/course/stage/instructions.ts

# Check the template of SecondStageInstructionsCard
cat app/components/course-page/course-stage-step/second-stage-instructions-card.hbs

Length of output: 10891

tests/acceptance/course-page/try-other-language-test.js (1)

39-39: LGTM: Test update correctly reflects new language guide loading behavior.

The addition of this expectation aligns with the recent changes to load language guides and matches the PR's objective of highlighting language guides in the tutorial card. The past review discussion confirms this was needed to reflect actual behavior.

Let's verify this is the only place needing this expectation:

✅ Verification successful

Test expectation is consistently implemented across related test files

The expectation for 'fetch language guide (course page)' is correctly added and appears consistently in all relevant course page test files, following the same pattern after 'fetch hints' and alongside 'fetch leaderboard entries'. This confirms the change is properly synchronized across the test suite.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar test expectations in other test files
rg -l "fetch language guide \(course page\)" tests/

Length of output: 218


Script:

#!/bin/bash
# Let's check the context of these expectations in other files
echo "=== try-other-language-test.js ==="
rg "fetch language guide \(course page\)" -B 2 -A 2 tests/acceptance/course-page/try-other-language-test.js

echo -e "\n=== resume-course-test.js ==="
rg "fetch language guide \(course page\)" -B 2 -A 2 tests/acceptance/course-page/resume-course-test.js

echo -e "\n=== attempt-course-stage-test.js ==="
rg "fetch language guide \(course page\)" -B 2 -A 2 tests/acceptance/course-page/attempt-course-stage-test.js

Length of output: 1026

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: 1

🧹 Outside diff range and nitpick comments (2)
app/components/course-page/course-stage-step/simple-language-guide-card.ts (1)

18-21: Consider adding tests for the expand functionality.

While the code changes look good, this component handles user interactions that should be tested. Consider adding tests to verify:

  1. The expand action correctly calls createView()
  2. The component properly renders with different language guide data

Would you like me to help generate test cases for this component?

app/templates/course/stage/instructions.hbs (1)

89-92: Consider simplifying the nested conditions.

While the TypeScript type narrowing is necessary, the nested conditions could be combined using the and helper for better readability.

Consider this alternative:

-    {{#if this.shouldShowLanguageGuide}}
-      {{! Extra if condition convinces typescript that languageGuide isn't null }}
-      {{#if this.languageGuide}}
-        <CoursePage::CourseStageStep::SimpleLanguageGuideCard @languageGuide={{this.languageGuide}} class="mt-6" />
-      {{/if}}
-    {{/if}}
+    {{#if (and this.shouldShowLanguageGuide this.languageGuide)}}
+      <CoursePage::CourseStageStep::SimpleLanguageGuideCard @languageGuide={{this.languageGuide}} class="mt-6" />
+    {{/if}}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 79f0a0f and eb8c049.

📒 Files selected for processing (4)
  • app/components/course-page/course-stage-step/simple-language-guide-card.hbs (1 hunks)
  • app/components/course-page/course-stage-step/simple-language-guide-card.ts (1 hunks)
  • app/controllers/course/stage/instructions.ts (4 hunks)
  • app/templates/course/stage/instructions.hbs (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/components/course-page/course-stage-step/simple-language-guide-card.hbs
🔇 Additional comments (9)
app/components/course-page/course-stage-step/simple-language-guide-card.ts (3)

5-5: LGTM! Clean import changes.

The simplified import structure better reflects the component's dependencies after the signature change.


11-11: LGTM! Improved component signature.

The direct languageGuide argument makes the component's requirements explicit and eliminates potential null/undefined issues from the previous implementation. This change successfully addresses the previous review feedback.


18-21: Verify createView() behavior.

The simplified implementation looks good, but let's verify the behavior of createView() across the codebase.

✅ Verification successful

Let me gather more information about the languageGuide type and its createView method.


Let me check the CourseStageLanguageGuideModel implementation since that seems to be the actual type being used.


Let me check the ViewableMixin since the model extends it and that's likely where createView is defined.


Let me check the viewable mixin implementation since it's been located.


createView() implementation is safe and consistent with its usage

The createView() method in the ViewableMixin is a standard analytics tracking implementation that:

  • Creates a view record with the resource's ID and type
  • Associates it with the current user
  • Saves it to the store
  • Supports optional metadata

The simplified implementation in the component is correct as it inherits this behavior through the CourseStageLanguageGuideModel which extends ViewableMixin.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check usage patterns of createView() method to ensure consistent behavior
# Expected: Find all implementations and calls to createView() to verify its behavior

# Search for createView method implementation
echo "Searching for createView implementation:"
ast-grep --pattern 'createView() {
  $$$
}'

# Search for createView method calls
echo -e "\nSearching for createView calls:"
rg 'createView\(\)' -A 2

Length of output: 771


Script:

#!/bin/bash
# Search for languageGuide type definition and createView method
echo "Searching for LanguageGuide class/interface definition:"
ast-grep --pattern 'class LanguageGuide {
  $$$
}'

ast-grep --pattern 'interface LanguageGuide {
  $$$
}'

# Search for imports of LanguageGuide
echo -e "\nSearching for LanguageGuide imports:"
rg "import.*LanguageGuide" -A 1

# Search for tests related to createView
echo -e "\nSearching for createView tests:"
rg "createView.*test" -A 2

Length of output: 973


Script:

#!/bin/bash
# Search for CourseStageLanguageGuideModel implementation
echo "Searching for CourseStageLanguageGuideModel definition:"
rg -A 10 "class CourseStageLanguageGuideModel" 

# Search for createView method in the model
echo -e "\nSearching for createView method in CourseStageLanguageGuideModel:"
ast-grep --pattern 'createView() {
  $$$
}'

# Check for any tracking or analytics related to createView
echo -e "\nSearching for tracking/analytics related to createView:"
rg "createView.*track" -A 2

Length of output: 1592


Script:

#!/bin/bash
# Search for ViewableMixin definition and its createView method
echo "Searching for ViewableMixin:"
rg -A 10 "ViewableMixin\s*=|class ViewableMixin"

# Search for any mixins related to view tracking
echo -e "\nSearching for view tracking mixins:"
fd -e ts -e js --exec grep -l "Viewable\|createView" {}

# Search for any view-related analytics
echo -e "\nSearching for view analytics:"
rg "track.*view" -A 2

Length of output: 4119


Script:

#!/bin/bash
# Check the implementation of viewable mixin
echo "Searching for viewable mixin implementation:"
cat app/mixins/viewable.js

# Search for any tests related to viewable mixin
echo -e "\nSearching for viewable mixin tests:"
fd -e ts -e js --exec grep -l "viewable.*test" {}

Length of output: 654

app/controllers/course/stage/instructions.ts (3)

13-14: LGTM: Required imports and service injection.

The new imports and store service injection are correctly implemented following Ember conventions.

Also applies to: 21-21


57-57: LGTM: Correct implementation of language guide visibility check.

The implementation correctly checks for first stage, guide existence, and feature flag.


120-130: Previous review comment is still applicable.

The implementation needs improvements in error handling, loading state tracking, and type safety as detailed in the previous review.

Let's verify the query parameters are used correctly:

#!/bin/bash
# Search for similar query patterns to ensure consistency
rg -A 2 "store.query\('course-stage-language-guide'" 
app/templates/course/stage/instructions.hbs (3)

42-44: LGTM! Clear and purposeful property addition.

The new property @shouldRecommendLanguageGuide is well-named and aligns with the PR objective of highlighting language guides in stage 2.


1-5: Verify loadLanguageGuides implementation for race conditions.

The dual lifecycle hooks ensure proper loading of language guides, but we should verify the implementation handles concurrent calls gracefully.

Let's check the implementation of loadLanguageGuides:

✅ Verification successful

Let me search for the implementation in JavaScript/TypeScript files since the previous search in Handlebars files didn't yield the method implementation.


Let me try a different search pattern to locate the implementation.


Race conditions are properly handled in loadLanguageGuides implementation

The implementation is safe from race conditions because:

  • It uses ember-concurrency's task decorator with keepLatest: true option, which cancels any running task before starting a new one
  • Both the controller and component implementations use this pattern, ensuring only one API request can be active at a time
  • The task performs a simple store query without any complex state mutations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for loadLanguageGuides implementation
ast-grep --pattern 'loadLanguageGuides() {
  $$$
}'

Length of output: 1462


Script:

#!/bin/bash
# Search for loadLanguageGuides in JS/TS files
rg -t js -t ts "loadLanguageGuides\s*=?\s*(?:async\s*)?function|loadLanguageGuides\s*=\s*(?:async\s*)?\(" -A 10

Length of output: 113


Script:

#!/bin/bash
# Search for loadLanguageGuides with a simpler pattern
rg "loadLanguageGuides" -t js -t ts -B 2 -A 10

Length of output: 4604


Line range hint 1-92: Verify stage-specific language guide behavior.

Let's ensure the language guide features are properly constrained to stage 2 and don't affect other stages unintentionally.

Run this check:

✅ Verification successful

Let me gather more information about the language guide integration to ensure it's properly constrained.


Let me check the component definition to understand how shouldShowLanguageGuide is controlled.


Let me try a different approach to find the property definition.


Let me try one final search with a broader pattern to find the component definition.


Based on the evidence gathered from multiple searches, I can now provide a final response:

Language guide integration appears properly constrained to stage 2

The code shows that language guide features are properly scoped:

  • Language guide is only rendered in stage 2 via @model.courseStage.isSecond condition
  • The SecondStageInstructionsCard component receives the language guide flag through @shouldRecommendLanguageGuide
  • The language guide card is rendered conditionally with proper null checks
  • Test files confirm the expected behavior of language guide components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for stage-specific conditions related to language guides
rg -A 3 'isSecond|stage.*2|second.*stage' --type hbs

Length of output: 1462


Script:

#!/bin/bash
# Search for language guide related conditions and components
rg -A 3 'languageGuide|shouldShowLanguageGuide' --type hbs --type js

Length of output: 6804


Script:

#!/bin/bash
# Search for the shouldShowLanguageGuide property definition
ast-grep --pattern 'shouldShowLanguageGuide = $_' 

Length of output: 51


Script:

#!/bin/bash
# Search for shouldShowLanguageGuide in JavaScript files
rg -A 5 'shouldShowLanguageGuide' --type js

Length of output: 43


Script:

#!/bin/bash
# Search for the component file and any language guide related computed properties
rg -A 10 'class CourseStageStep|get.*language|language.*guide' --type js app/components/

Length of output: 2210

app/controllers/course/stage/instructions.ts Show resolved Hide resolved
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