8000 ENG-1206 - fix weird level numbers for ozaria by adamkecskes · Pull Request #7731 · codecombat/codecombat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ENG-1206 - fix weird level numbers for ozaria #7731

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 3, 2024

Conversation

adamkecskes
Copy link
Collaborator
@adamkecskes adamkecskes commented Sep 26, 2024
Ozaria_Teacher_Dashboard_and_Ozaria_-_Computer_science_that_captivates

Summary by CodeRabbit

  • New Features

    • Enhanced level number management in the teacher dashboard, improving the accuracy of content display.
    • Updated curriculum guide structure for better clarity and indexing of levels.
  • Bug Fixes

    • Adjusted the logic for mapping values in the Module Content, ensuring correct behavior based on the CodeCombat context.

These changes enhance the accuracy of content display for users, particularly in different environments.

Copy link
Contributor
coderabbitai bot commented Sep 26, 2024

Walkthrough

The changes in this pull request involve multiple components and files, primarily focusing on the management and retrieval of level numbers within the application. Key modifications include the introduction of new methods and computed properties in ModuleContent.vue, the addition of a mutation and a getter in the Vuex store module gameContent.js, and updates to the generateLevelNumberMap function in curriculum-guide-helper.js. These alterations aim to enhance the clarity and efficiency of level number handling across the application.

Changes

File Change Summary
ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/components/ModuleContent.vue Introduced created lifecycle hook, modified getLevelNumber method, added generateLevelNumberMap, and updated props and computed properties.
app/core/store/modules/gameContent.js Added mutation setLevelNumberMap and getter levelNumberMap, modified generateLevelNumberMap action.
app/models/Campaign.js Updated regex in levelIsPractice method to broaden criteria for practice levels.
ozaria/site/components/play/PagePlayLevel/index.vue Updated fetchLevelNumber method to change the argument passed to getLevelNumber.
ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/curriculum-guide-helper.js Modified generateLevelNumberMap function to change how levels are indexed and accessed.

Assessment against linked issues

Objective Addressed Explanation
Weird level numbering (ENG-1206)

Possibly related PRs

Suggested reviewers

  • mrfinch
  • smallst

Poem

🐰 In the land of code where rabbits play,
A change was made to brighten the day.
With checks for combat, levels align,
Hopping through logic, all will be fine!
So let’s celebrate this code we adore,
For every tweak opens a new door! 🌟


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
@mrfinch mrfinch left a comment

Choose a reason for hiding this comment

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

I think we show the numbers in increment and don't reset the counter at a module to match with level number shown on level load and have a different number

@adamkecskes adamkecskes force-pushed the adamk/weird-level-numbering branch from 7416838 to dd3320d Compare October 3, 2024 08:59
@adamkecskes
Copy link
Collaborator Author

@mrfinch fix pushed: Ozaria_Teacher_Dashboard

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 (3)
app/models/Campaign.js (1)

Line range hint 1-7: Address technical debt: Review decaffeinate conversion

The file contains comments indicating it was created by bulk-decaffeinate and lists several suggestions for improvement. To enhance code quality and maintainability, consider addressing these items:

  1. Review and verify the decaffeinate conversion.
  2. Remove the TODO comment once the conversion has been checked.
  3. Address the decaffeinate suggestions, particularly:
    • DS101: Remove unnecessary use of Array.from
    • DS102: Remove unnecessary code created because of implicit returns
    • DS206: Consider reworking classes to avoid initClass
    • DS207: Consider shorter variations of null checks

These improvements will help modernize the codebase and potentially improve performance and readability.

ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/components/ModuleContent.vue (2)

18-18: Consistent use of trailing commas in component definitions

Adding a trailing comma after CodeDiff in the components object improves code consistency and aligns with best practices for object notation in JavaScript.


24-35: Maintain consistency with trailing commas in props

Including trailing commas in the props definitions (moduleNum, isCapstone, levelSessions) enhances readability and adheres to consistent coding style throughout the file.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7416838 and dd3320d.

📒 Files selected for processing (5)
  • app/core/store/modules/gameContent.js (8 hunks)
  • app/models/Campaign.js (1 hunks)
  • ozaria/site/components/play/PagePlayLevel/index.vue (1 hunks)
  • ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/components/ModuleContent.vue (6 hunks)
  • ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/curriculum-guide-helper.js (2 hunks)
🧰 Additional context used
🪛 Biome
app/core/store/modules/gameContent.js

[error] 113-113: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (20)
ozaria/site/components/play/PagePlayLevel/index.vue (1)

104-104: Approved: Change aligns with PR objectives

The modification from store.state.game.level.original to store.state.game.level._id appears to address the issue of "weird level numbers for ozaria" as mentioned in the PR objectives. This change likely fixes the inconsistent level numbering problem.

To ensure this change doesn't introduce any unintended side effects, please verify the following:

  1. Confirm that _id is always available and correct for all levels in the Ozaria platform.
  2. Check if this change is consistent with how level numbers are handled in other parts of the codebase.

You can use the following script to verify the usage of level IDs across the codebase:

This script will help identify if there are any inconsistencies in how level IDs are accessed throughout the codebase.

✅ Verification successful

Verified: Change does not introduce issues

The update from store.state.game.level.original to store.state.game.level._id in ozaria/site/components/play/PagePlayLevel/index.vue has been successfully verified. The change is localized to the intended method and aligns with the PR objective of addressing inconsistent level numbering. No unintended side effects were detected based on the shell script results.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent usage of level IDs

# Search for uses of 'level._id' and 'level.original'
echo "Searching for 'level._id' usage:"
rg --type vue --type js 'level\._id'

echo "\nSearching for 'level.original' usage:"
rg --type vue --type js 'level\.original'

# Check for any remaining uses of 'getLevelNumber' with 'original'
echo "\nChecking for any remaining uses of 'getLevelNumber' with 'original':"
rg --type vue --type js 'getLevelNumber.*original'

Length of output: 558


Script:

#!/bin/bash
# Description: Check for consistent usage of level IDs

# Search for uses of 'level._id' and 'level.original'
echo "Searching for 'level._id' usage:"
rg --glob '*.vue' --glob '*.js' 'level\._id'

echo "\nSearching for 'level.original' usage:"
rg --glob '*.vue' --glob '*.js' 'level\.original'

# Check for any remaining uses of 'getLevelNumber' with 'original'
echo "\nChecking for any remaining uses of 'getLevelNumber' with 'original':"
rg --glob '*.vue' --glob '*.js' 'getLevelNumber.*original'

Length of output: 16108

app/models/Campaign.js (1)

122-122: Approved: Broadened criteria for practice levels

The change from / [ABCD]$/ to / [A-Z]$/ expands the range of level names that can be considered as practice levels, which aligns with the PR objective of fixing "weird level numbers for ozaria".

Consider the following suggestions to improve code clarity and maintainability:

  1. Add a comment explaining the rationale behind this change, e.g.:

    // Expanded regex to include all uppercase letters, addressing inconsistent level numbering in Ozaria
  2. Review other parts of the codebase that might be affected by this change, such as level generation or display logic.

  3. Update or add unit tests to cover this new behavior, ensuring that levels with various ending letters are correctly classified as practice or non-practice.

To help identify potentially affected areas, you can run the following script:

ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/components/ModuleContent.vue (10)

8-8: Import mapActions to use Vuex actions

You've added mapActions to the import statement, which is necessary for mapping Vuex actions in your component. This aligns with the usage of generateLevelNumberMap later in the code.


80-80: Pass codeLanguage to getCurriculumGuideContentList

By passing codeLanguage: this.getSelectedLanguage, you ensure that the content list is generated based on the currently selected programming language. This enhances the component's responsiveness to user preferences.


94-95: Update solution and sample code when language changes

By watching the getSelectedLanguage property and updating solutionCodeByLevel and sampleCodeByLevel, you're ensuring that the code displayed matches the user's language selection. This provides a better user experience.


97-101: Initialize level number mapping on component creation

Adding the async created() hook to call generateLevelNumberMap ensures that the level numbers are properly mapped when the component is initialized. This is crucial for displaying correct level numbers in the curriculum guide.


105-107: Map Vuex action generateLevelNumberMap

Mapping the generateLevelNumberMap action using mapActions allows the component to dispatch this action seamlessly. This facilitates the asynchronous generation of the level number map during component creation.


172-173: Ensure proper closure of methods object

The added closing braces at lines 172-173 properly close the methods object. This is essential for the component to function correctly without syntax errors.


200-200: Ensure isOzariaNoCodeLevel method is utilized if necessary

If the isOzariaNoCodeLevel method is intended to control the display of code-related elements, ensure that it is properly called in the template or logic. Otherwise, consider removing it as it might be redundant.

Check for references to isOzariaNoCodeLevel in the component:

#!/bin/bash
# Description: Verify usage of 'isOzariaNoCodeLevel' method.

# Test: Search for 'isOzariaNoCodeLevel' method calls. Expect: Method is called somewhere in the code.

rg "isOzariaNoCodeLevel\(" --type vue .

200-200: Update level number assignment in template

The modification of the :set directive to levelNumber = getLevelNumber(_id) ensures that the correct level number is assigned based on the level's _id. This change reflects the updated method signature of getLevelNumber.

Please verify that the _id being passed to getLevelNumber corresponds to the expected parameter in the Vuex getter.

You can run the following script to check for all usages of getLevelNumber and ensure consistency:

#!/bin/bash
# Description: Verify that 'getLevelNumber' is called with the correct parameters throughout the codebase.

# Test: Search for calls to 'getLevelNumber' in the code. Expect: Consistent use with a single parameter.

rg --type vue "getLevelNumber\(\s*[^)]+\s*\)" .

172-173: 🛠️ Refactor suggestion

Remove unused method isOzariaNoCodeLevel

The method isOzariaNoCodeLevel is defined but not used anywhere in the component. Consider removing it to keep the codebase clean and maintainable.

Apply this diff to remove the unused method:

-    isOzariaNoCodeLevel (icon) {
-      return ['cutscene', 'cinematic', 'interactive'].includes(icon)
-    },

Likely invalid or redundant comment.


56-58: Verify the existence of new Vuex getters

The computed properties getLevelNumber and levelNumberMap have been added using mapGetters. Ensure that these getters are correctly defined in the gameContent module of your Vuex store.

You can run the following script to confirm that these getters are defined:

ozaria/site/components/teacher-dashboard/BaseCurriculumGuide/curriculum-guide-helper.js (3)

86-86: Ensure consistency in level mapping with updated keys

The map function now assigns the key as _id:

.map(({ original, assessment, icon, _id, practice }) => ({ _id, original, key: _id, assessment, practice: practice || (icon === 'practicelvl') }))

Confirm that using _id as the key aligns with the expectations of utils.createLevelNumberMap and that it maintains consistent level numbering throughout the application.

Consider checking how key is utilized within utils.createLevelNumberMap to ensure compatibility.


97-97: Verify the impact of returning levelNumberMap

The function now explicitly returns levelNumberMap:

return levelNumberMap

Please ensure that all consumers of generateLevelNumberMap expect this return value and that the structure of levelNumberMap meets their requirements.

Would you like assistance in identifying all usages of generateLevelNumberMap to confirm compatibility?


35-35: Confirm the necessity of _id in intro heading rows

The addition of _id: content._id to the introHeadingRow entries ensures each intro heading has a unique identifier. Please verify that this property is utilized appropriately in downstream components and that it doesn't conflict with existing logic.

You can verify the usage of _id in intro heading rows by searching the codebase:

app/core/store/modules/gameContent.js (5)

15-15: Field selection in 'levels' projection is comprehensive

The added fields in the levels projection cover all necessary properties for level data, ensuring that the fetched level information is complete and useful for the application.


51-51: Initialization of 'levelNumberMap' state

Initializing levelNumberMap as an empty object sets up the store for mapping level IDs to level numbers, which is essential for resolving the weird level numbering issue mentioned in the PR objectives.


82-84: Addition of 'setLevelNumberMap' mutation is correct

The new mutation setLevelNumberMap properly updates the levelNumberMap in the state, allowing batch updates to the level number mapping efficiently.


97-99: New getter 'levelNumberMap' enhances state accessibility

Introducing the levelNumberMap getter provides easy access to the level number mapping from components, improving the modularity and reusability of the code.


199-200: Efficient generation and committing of 'levelNumberMap'

The creation of levelNumberMap using generateLevelNumberMap(allLevels) and committing it via setLevelNumberMap mutation effectively updates the state with the new level numbers.

@@ -205,7 +197,7 @@ export default {
<template v-else>
<module-row
v-if="!isJunior || icon !== 'practicelvl' || showCodeLevelSlugs.includes(slug)"
:set="levelNumber = getLevelNumber(original, key + 1)"
:set="levelNumber = getLevelNumber(_id)"
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

Handle potential issues with the :set directive

The use of the :set directive is not a standard Vue.js feature. If you're aiming to assign levelNumber within the template, consider calculating levelNumber within a computed property or method instead. This will adhere to Vue.js best practices and avoid potential reactivity issues.

You might refactor this line as follows:

<module-row
  :icon-type="icon"
  :name-type="assessment ? null : icon"
  :level-number="getLevelNumber(_id)"
  :display-name="name"
  :description="calculateLevelDescription(description, slug, getLevelNumber(_id))"
  ...
/>

And update your methods or computed properties accordingly.

Comment on lines +92 to +94
if (!levelNumberMap[original]) {
levelNumberMap[original] = levelNumberMap[level._id]
}
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

Handle potential undefined mappings in levelNumberMap

The newly added condition addresses missing mappings:

if (!levelNumberMap[original]) {
  levelNumberMap[original] = levelNumberMap[level._id]
}

Ensure that levelNumberMap[level._id] is always defined before assignment to avoid possible undefined values. Adding a check or fallback could prevent runtime errors.

Consider updating the code to include a safety check:

if (!levelNumberMap[original] && levelNumberMap[level._id]) {
  levelNumberMap[original] = levelNumberMap[level._id]
}

@@ -104,7 +110,7 @@ export default {
cinematics: (options.project || {}).cinematics || defaultProjections.cinematics,
interactives: (options.project || {}).interactives || defaultProjections.interactives,
cutscenes: (options.project || {}).cutscenes || defaultProjections.cutscenes,
levels: (options.project || {}).levels || defaultProjections.levels
levels: (options.project || {}).levels || defaultProjections.levels,
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

Simplify code using optional chaining

You can refactor the code to use optional chaining for better readability and to handle undefined values more gracefully.

Apply this change:

-            levels: (options.project || {}).levels || defaultProjections.levels,
+            levels: options.project?.levels || defaultProjections.levels,
📝 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
levels: (options.project || {}).levels || defaultProjections.levels,
levels: options.project?.levels || defaultProjections.levels,
🧰 Tools
🪛 Biome

[error] 113-113: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

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