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

Preserve Locked State for Artifacts #2575

Merged

Conversation

AiZm8
Copy link
Contributor

@AiZm8 AiZm8 commented Dec 13, 2024

Describe your changes

When existing locked artifacts get updated by one that is unlocked, the locked state is preserved

Issue or discord link

Testing/validation

I tested it by uploading a database with unlocked artifacts, manually locked them in the site, and then re-uploaded the same JSON batch to see if the artifacts I locked became unlocked or not
Additionally tested for if the lock property is missing from the new JSON upload ("lock": false/true) by removing it, and the artifact remains in its former state (locked/unlocked)

Checklist before requesting a review (leave this PR as draft if any part of this list is not done.)

  • I have commented my code in hard-to understand areas.
  • I have made corresponding changes to README or wiki.
  • For front-end changes, I have updated the corresponding English translations.
  • I have run yarn run mini-ci locally to validate format and lint.
  • If I have added a new library or app, I have updated the deployment scripts to ignore changes as needed

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced artifact import functionality to preserve the lock state during operations.
  • Bug Fixes

    • Improved handling of artifact lock states to ensure accuracy during imports.

Copy link

coderabbitai bot commented Dec 13, 2024

Walkthrough

The changes in this pull request focus on the ArtifactDataManager class within ArtifactDataManager.ts. The primary modification is to the importGOOD method, which now includes logic to maintain the lock state of artifacts during the import process. A new conditional statement checks the artifact's lock status, ensuring that if an artifact is unlocked or if no locks are detected, its existing lock state is preserved. The structure of the method is adjusted to incorporate this logic without altering its fundamental functionality.

Changes

File Path Change Summary
libs/gi/db/src/Database/DataManagers/ArtifactDataManager.ts Modified importGOOD method to include logic for preserving artifact lock state during imports.

Possibly related PRs

Suggested reviewers

  • frzyc

Poem

In the burrow deep, where artifacts lay,
A lock state preserved, come what may.
With each import, the treasures stay bright,
Hopping through code, oh what a delight! 🐇✨
So let’s cheer for the changes, both clever and spry,
For the lock on our artifacts will never say goodbye!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between affab81 and 450ccda.

📒 Files selected for processing (1)
  • libs/gi/db/src/Database/DataManagers/ArtifactDataManager.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/gi/db/src/Database/DataManagers/ArtifactDataManager.ts

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
libs/gi/db/src/Database/DataManagers/ArtifactDataManager.ts (2)

218-219: LGTM! Consider adding a clarifying comment

The logic correctly preserves the lock state of existing artifacts when updating them with unlocked artifacts. This implementation aligns well with the PR objective.

Consider expanding the comment to be more explicit about the behavior:

-    // Preserve existing lock state for artifacts reported as unlocked or when the scanner doesn't detect locks ("lock": false JSON)
+    // Preserve existing lock state in two cases:
+    // 1. When the imported artifact is explicitly unlocked (lock: false)
+    // 2. When the scanner doesn't detect locks (missing "lock" property in JSON)

218-219: Well-designed data preservation approach

The implementation follows good architectural principles by:

  1. Preserving user preferences during data updates
  2. Maintaining backward compatibility with existing import formats
  3. Gracefully handling edge cases with scanners that don't detect locks

This approach could serve as a pattern for preserving other user-set states during future import operations.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 85c8277 and affab81.

📒 Files selected for processing (1)
  • libs/gi/db/src/Database/DataManagers/ArtifactDataManager.ts (1 hunks)
🔇 Additional comments (1)
libs/gi/db/src/Database/DataManagers/ArtifactDataManager.ts (1)

218-219: Verify lock state handling consistency

While the implementation looks correct, let's verify that lock state handling is consistent across the codebase.

✅ Verification successful

Let me try a different approach to verify the lock state handling.


Let me try one more search to specifically focus on the artifact lock handling in the codebase.


Based on the search results, I can see that the lock state handling is consistently implemented across the codebase. The key findings show:

  1. The lock state is properly preserved in ArtifactDataManager.ts when importing artifacts
  2. Lock state is consistently used in UI components for toggling and displaying lock status
  3. Lock state is properly handled in artifact filtering and deletion operations
  4. Lock state is included in artifact interfaces and types

Let me generate the final response:

Lock state handling is correctly implemented

The implementation preserves existing lock states appropriately when importing artifacts, and the lock state is consistently handled across artifact operations in the codebase:

  • Lock state preservation during import considers both explicit unlocks and scanner limitations
  • Lock state is properly enforced in deletion operations
  • Lock state is consistently toggled and displayed in UI components
  • Lock state is properly typed in interfaces and database operations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify lock state handling across the codebase

# Check for all lock state manipulations
echo "Checking lock state handling patterns:"
rg -A 2 -B 2 'lock[^a-zA-Z]' --type typescript

# Check for potential lock state serialization/deserialization
echo -e "\nChecking lock state serialization patterns:"
rg -A 2 -B 2 '(JSON\.|parse|stringify).*lock' --type typescript

# Look for any GOOD-related type definitions that might affect lock state
echo -e "\nChecking GOOD-related type definitions:"
ast-grep --pattern 'interface $name {
  $$$
  lock$_
  $$$
}'

Length of output: 533


Script:

#!/bin/bash
# Search for lock-related patterns without specifying file type
echo "Checking lock state handling patterns:"
rg -A 2 -B 2 'lock[^a-zA-Z]'

# Check for GOOD-related interfaces and types
echo -e "\nChecking GOOD-related definitions:"
rg -A 5 -B 1 'interface.*GOOD|type.*GOOD'

# Check for artifact-related lock handling
echo -e "\nChecking artifact lock handling:"
rg -A 2 -B 2 'art(ifact)?\.lock'

Length of output: 93440


Script:

#!/bin/bash
# Search for artifact lock handling in the database layer
echo "Checking artifact lock handling in database:"
rg -A 3 -B 3 'lock.*art|art.*lock' --type ts

# Search for artifact-related interfaces and types
echo -e "\nChecking artifact interfaces and types:"
rg -A 3 -B 1 'interface.*Artifact|type.*Artifact' --type ts

# Search for GOOD-related imports and exports
echo -e "\nChecking GOOD-related imports/exports:"
rg -A 2 -B 2 'import.*GOOD|export.*GOOD' --type ts

Length of output: 67592

Copy link
Contributor

github-actions bot commented Dec 13, 2024

[frontend] [Fri Dec 13 09:35:45 UTC 2024] - Deployed f84442b to https://genshin-optimizer-prs.github.io/pr/2575/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Tue Dec 17 06:22:00 UTC 2024] - Deployed c57295e to https://genshin-optimizer-prs.github.io/pr/2575/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Wed Dec 18 05:01:23 UTC 2024] - Deployed f0d5a53 to https://genshin-optimizer-prs.github.io/pr/2575/frontend (Takes 3-5 minutes after this completes to be available)

[frontend] [Wed Dec 18 05:19:36 UTC 2024] - Deployed 6911762 to https://genshin-optimizer-prs.github.io/pr/2575/frontend (Takes 3-5 minutes after this completes to be available)

[Wed Dec 18 19:49:10 UTC 2024] - Deleted deployment

@@ -215,6 +215,8 @@ export class ArtifactDataManager extends DataManager<
importArt = {
...art,
location: hasEquipment ? art.location : match.location,
// Preserve existing lock state for artifacts reported as unlocked or when the scanner doesn't detect locks ("lock": false JSON)
lock: art.lock === false ? match.lock : art.lock,
Copy link
Owner

@frzyc frzyc Dec 16, 2024

Choose a reason for hiding this comment

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

I would preferred if we do

const hasLock = artifacts.some((a)=>a.lock)
...
lock: hasLock? art.lock : match.lock

similiar to hasEquipment

since the current PR logic would not allow unlocking of artifacts from the scanned data (if user unlocked in game, and scanner scanned it, but it's locked in GO)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made the requested change and confirmed with testing where having all the lock properties as false keeps the original lock statuses (locked/unlocked), and if there are locks present, artifacts can become be locked or unlocked

Previously thought to not overwrite locks, but now it can if locks are present. If no locks are present then assume no lock detection and do not modify the existing lock statuses
@frzyc frzyc merged commit 805d84d into frzyc:master Dec 18, 2024
9 checks passed
@AiZm8 AiZm8 deleted the AiZm8/go/bugfix/T-2549-Locked-State-Detection-Fix branch December 19, 2024 01:45
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