8000 show mto locked message by mrfinch · Pull Request #7785 · codecombat/codecombat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

show mto locked message #7785

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

Merged
merged 1 commit into from
Oct 23, 2024
Merged

show mto locked message #7785

merged 1 commit into from
Oct 23, 2024

Conversation

mrfinch
Copy link
Contributor
@mrfinch mrfinch commented Oct 22, 2024

fixes ENG-1311

Summary by CodeRabbit

  • New Features

    • Introduced a game development alert for teachers with a link to request licenses.
    • Enhanced display of campaign elements based on user context and campaign properties.
    • Added conditional rendering for logos and updated level display logic.
    • Implemented tracking for user interactions with the campaign view.
  • Bug Fixes

    • Improved resource management to prevent memory leaks.
  • Refactor

    • Streamlined logic for displaying buttons based on level completion and user enrollment status.

Copy link
Contributor
coderabbitai bot commented Oct 22, 2024

Walkthrough

The pull request introduces modifications to the Pug template and JavaScript class for the campaign view. Key changes include the addition of a conditional block for displaying game development alerts, streamlined logo rendering, and enhanced level display logic based on user context. The JavaScript class CampaignView has been updated to include a new property for MTO users, improved event tracking, and refined resource management to prevent memory leaks. Overall, the changes aim to improve user experience and accurately reflect campaign states.

Changes

File Change Summary
app/templates/play/campaign-view.pug Added conditional block for game development alert; streamlined logo rendering; enhanced level display logic with additional checks for level statuses and buttons.
app/views/play/CampaignView.js Introduced this.isMto property; updated constructor and onLoaded method for event tracking; modified destroy method for resource cleanup; refined updateVolume method.

Assessment against linked issues

Objective Addressed Explanation
Change locked by to Locked for GF Trainings (ENG-1311)

Possibly related PRs

  • ENG-1139 - Fix map if first levels are skipped #7695: This PR modifies the rendering logic in app/templates/play/campaign-view.pug to ensure that only levels that are not locked are displayed, which relates to the changes made in the main PR regarding the handling of level statuses and visibility based on user context.
  • ENG-1150 - i18n for Show a message on locked AI HS project #7705: Although this PR focuses on internationalization and user messaging for locked projects, it is indirectly related to the main PR's enhancements in displaying campaign-related elements and user interactions, particularly regarding locked content.

🐇 In fields of code where bunnies play,
New alerts and logos brighten the day.
With MTO checks and levels refined,
A smoother path for all we find.
Hops of joy in every line,
Campaigns flourish, all will shine! 🌟


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.

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 (4)
app/views/play/CampaignView.js (4)

Line range hint 1012-1012: Consider making the volume scaling configurable.

The volume is hardcoded to scale down to 0.6 when set to 1. This scaling should ideally be configurable or documented with a comment explaining why it's needed.

-    createjs.Sound.volume = volume === 1 ? 0.6 : volume // Quieter for now until individual sound FX controls work again.
+    const VOLUME_SCALE = 0.6 // Scale down max volume until individual sound FX controls are implemented
+    createjs.Sound.volume = volume === 1 ? VOLUME_SCALE : volume

Line range hint 359-371: Consider enhancing cleanup in destroy method.

The destroy method could be improved to:

  1. Remove all event listeners explicitly
  2. Clear any remaining timeouts/intervals
  3. Stop and cleanup sound/music players properly
 destroy () {
   this.setupManager?.destroy()
   this.$el.find('.ui-draggable').off().draggable('destroy')
   window.removeEventListener('resize', this.onWindowResize)
+  // Clear all intervals
+  clearInterval(this.portalScrollInterval)
+  clearTimeout(this.playMusicTimeout)
+
+  // Cleanup sound players
   const ambientSound = this.ambientSound
   if (ambientSound) {
-    // Doesn't seem to work; stops immediately.
-    createjs.Tween.get(ambientSound).to({ volume: 0.0 }, 1500).call(() => ambientSound.stop())
+    createjs.Tween.get(ambientSound)
+      .to({ volume: 0.0 }, 1500)
+      .call(() => {
+        ambientSound.stop()
+        ambientSound.destroy()
+      })
   }
   this.musicPlayer?.destroy()
-  clearTimeout(this.playMusicTimeout)
-  clearInterval(this.portalScrollInterval)
+
+  // Remove all Backbone event listeners
   Backbone.Mediator.unsubscribe('audio-player:loaded', this.playAmbientSound, this)
+  this.stopListening()
+
   super.destroy()
 }

Line range hint 1040-1048: Validate poll URL to prevent potential security issues.< 8000 /strong>

The loadPoll method accepts a URL parameter that is used directly in the request. This could potentially lead to security issues if the URL is not properly validated.

-  loadPoll (url, forceShowPoll) {
-    if (url == null) { url = `/db/poll/${this.userPollsRecord.id}/next` }
-    let tempLoadingPoll = new Poll().setURL(url)
+  loadPoll (pollUrl, forceShowPoll) {
+    let url
+    if (!pollUrl) {
+      url = `/db/poll/${this.userPollsRecord.id}/next`
+    } else if (typeof pollUrl === 'string' && /^\/db\/poll\/[a-f0-9]+(?:\/next)?$/.test(pollUrl)) {
+      url = pollUrl
+    } else {
+      console.error('Invalid poll URL')
+      return
+    }
+    let tempLoadingPoll = new Poll().setURL(url)

Line range hint 1000-1010: Consider debouncing the window resize handler.

The onWindowResize handler performs expensive calculations and DOM updates on every resize event. Consider debouncing this handler to improve performance during window resizing.

 constructor (options, terrain) {
   super(options)
   this.
-  this.>
+  this. 100)
   // ... rest of the constructor
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 26aa679 and 3eeca65.

📒 Files selected for processing (2)
  • app/templates/play/campaign-view.pug (1 hunks)
  • app/views/play/CampaignView.js (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
app/views/play/CampaignView.js (1)

352-352: Verify MTO property usage.

The this.isMto property is initialized correctly using me.isMto(), but I don't see where this property is being used to change the locking message from "locked by" to "Locked" as mentioned in the PR objectives.

Let's verify if the locking message change is implemented in the template:

✅ Verification successful

Let me try a different approach to find the template and locking message references.

The first command will help us locate the template file as the path might be different, and the second command will search for locking messages in the view directory where the changes are being made.


Let me check the template file and the view code to see how the isMto property is being used.

This will help us understand how the locking message is implemented in the template and how the isMto property is being used in the view code.


Based on the template code and view code analysis, I can now provide a final response:

The MTO property is correctly implemented and used

The isMto property is properly initialized and used in the template to show a different locking message for MTO students. In the template, there's a conditional check:

(level.lockedByTeacher ? (view.isMto ? 'Locked for GF trainings' : translate('play.locked_by_teacher')) : translate('play.locked'))

This shows:

  • "Locked for GF trainings" for MTO students
  • "Locked by Teacher" for non-MTO students
  • "Locked" for other cases
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for locking message in the template
rg -A 5 "locked.*by|Locked" templates/play/campaign-view

Length of output: 127


Script:

#!/bin/bash
# First, let's find the template file
fd "campaign.*view" --type f

# Then search for locking related strings in the codebase
rg -A 5 "locked.*by|Locked" app/views/play/

Length of output: 5722


Script:

#!/bin/bash
# Check the campaign view template
cat app/templates/play/campaign-view.pug

# Check for usage of isMto in the view
rg -A 5 "isMto" app/views/play/CampaignView.js

Length of output: 28636

@@ -200,7 +200,7 @@ if showGameDevAlert

div(class="level-info rtl-allowed " + levelStatus + (level.requiresSubscription ? " premium" : "") + (showsLeaderboard ? " shows-leaderboard" : ""))
.level-status.rtl-allowed(dir="auto")
- var levelName = levelNumber + i18n(level, 'name') + (level.disabled ? " (" + translate('common.coming_soon') + ")" : (level.locked ? " (" + (level.lockedByTeacher ? translate('play.locked_by_teacher') : translate('play.locked')) + ")" : (level.practice ? " (" + translate('courses.practice') + ")" : "")));
- var levelName = levelNumber + i18n(level, 'name') + (level.disabled ? " (" + translate('common.coming_soon') + ")" : (level.locked ? " (" + (level.lockedByTeacher ? (view.isMto ? 'Locked for GF trainings' : translate('play.locked_by_teacher')) : translate('play.locked')) + ")" : (level.practice ? " (" + translate('courses.practice') + ")" : "")));
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

Align the locked message with the PR objectives

The message 'Locked for GF trainings' does not match the PR objective of changing "locked by" to simply "Locked" for MTO students. To ensure consistency and clarity, consider updating the message to display "Locked" when view.isMto is true.

Apply this diff to update the message:

- var levelName = levelNumber + i18n(level, 'name') + (level.disabled ? " (" + translate('common.coming_soon') + ")" : (level.locked ? " (" + (level.lockedByTeacher ? (view.isMto ? 'Locked for GF trainings' : translate('play.locked_by_teacher')) : translate('play.locked')) + ")" : (level.practice ? " (" + translate('courses.practice') + ")" : "")));
+ var levelName = levelNumber + i18n(level, 'name') + (level.disabled ? " (" + translate('common.coming_soon') + ")" : (level.locked ? " (" + (level.lockedByTeacher ? (view.isMto ? translate('play.locked') : translate('play.locked_by_teacher')) : translate('play.locked')) + ")" : (level.practice ? " (" + translate('courses.practice') + ")" : "")));
📝 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
- var levelName = levelNumber + i18n(level, 'name') + (level.disabled ? " (" + translate('common.coming_soon') + ")" : (level.locked ? " (" + (level.lockedByTeacher ? (view.isMto ? 'Locked for GF trainings' : translate('play.locked_by_teacher')) : translate('play.locked')) + ")" : (level.practice ? " (" + translate('courses.practice') + ")" : "")));
var levelName = levelNumber + i18n(level, 'name') + (level.disabled ? " (" + translate('common.coming_soon') + ")" : (level.locked ? " (" + (level.lockedByTeacher ? (view.isMto ? translate('play.locked') : translate('play.locked_by_teacher')) : translate('play.locked')) + ")" : (level.practice ? " (" + translate('courses.practice') + ")" : "")));

@mrfinch mrfinch merged commit 317d9fa into master Oct 23, 2024
2 checks passed
@mrfinch mrfinch deleted the saurabh/locked-by branch October 23, 2024 15:20
This was referenced Oct 31, 2024
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
0