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

Fix/bob various #2573

Merged
merged 9 commits into from
Dec 20, 2024
Merged

Fix/bob various #2573

merged 9 commits into from
Dec 20, 2024

Conversation

bob0005
Copy link
Collaborator

@bob0005 bob0005 commented Dec 20, 2024

Closes #2493
Closes #2505
Closes #2519
Closes #2559

Summary by CodeRabbit

  • New Features

    • Enhanced order creation and confirmation logic in the Market Order Panel.
    • Improved resource selection process with structured resource hierarchy and filtering capabilities.
    • Added a success message display after resource transfer completion.
    • Introduced dynamic filtering in the ListSelect component based on user input.
    • Enhanced search functionality by normalizing diacritical marks in player names and addresses.
  • Bug Fixes

    • Adjusted conditions for confirming orders to allow processing when balance matches requirements.
  • Style

    • Improved button layout for better visual organization in the Transfer Between Entities component.

Copy link

vercel bot commented Dec 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
eternum ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 9:56am
eternum-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 9:56am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
eternum-landing ⬜️ Ignored (Inspect) Visit Preview Dec 20, 2024 9:56am

Copy link
Contributor

coderabbitai bot commented Dec 20, 2024

Walkthrough

The pull request introduces several modifications across multiple components in the client-side trading and UI utilities. The changes primarily focus on improving resource selection, transfer, and order creation processes. Key updates include adding a normalizeDiacriticalMarks utility function to handle diacritical marks in searches, refining the ListSelect component with filtering capabilities, and adjusting order confirmation logic for donkey-based transactions.

Changes

File Change Summary
client/src/ui/components/trading/MarketOrderPanel.tsx Updated order confirmation and creation logic to modify donkey balance checks for buy and sell orders.
client/src/ui/components/trading/SelectResources.tsx Imported RESOURCE_TIERS and modified resource selection using ordered resources.
client/src/ui/components/trading/TransferBetweenEntities.tsx Added diacritical mark normalization for entity filtering and adjusted button layout.
client/src/ui/components/worldmap/players/PlayersPanel.tsx Integrated diacritical mark normalization for player search functionality.
client/src/ui/elements/ListSelect.tsx Enhanced with search filtering and keyboard interaction capabilities.
client/src/ui/utils/utils.tsx Added normalizeDiacriticalMarks utility function.
client/src/ui/modules/navigation/LeftNavigationModule.tsx Removed commented-out condition for disabling button, simplifying logic.

Assessment against linked issues

Objective Addressed Explanation
Remove need for perfect punctuation in transfers [#2493]
Add previous button for transfers [#2505]
Remove min donkey requirement for sell orders [#2519]

Possibly related PRs

  • Raschel/dev #1818: The changes in the main PR regarding order creation and confirmation logic may relate to the modifications in the useStructureEntityId hook, which also deals with state management and could impact how orders are processed based on entity states.
  • Refactor deposit resources and entity list components #2243: The refactor of the DepositResources and EntityList components may connect with the main PR's focus on resource management, particularly in how resources are handled during order processing.
  • various bridge updates #2328: The updates in the BridgeIn and BridgeOutStep1 components, which enhance user interface and experience related to resource transactions, could be relevant to the changes in order confirmation and resource availability in the main PR.

Suggested reviewers

  • ponderingdemocritus

Poem

🐰 Donkeys dance, resources flow free,
Diacritics bow to our coding spree!
Buttons align, filters shine bright,
Our UI leaps with algorithmic might!
Code rabbit hops, innovation takes flight! 🚀


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
Contributor

mentatbot bot commented Dec 20, 2024

You are out of MentatBot reviews. Your usage will refresh December 23 at 08:00 AM.

Copy link

Failed to generate code suggestions for PR

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

🧹 Nitpick comments (5)
client/src/ui/elements/ListSelect.tsx (3)

25-27: Search input and ref
Storing searchInput in state and using a ref for the input element is logical. Consider if you need further key-based interactions or side effects.


44-53: Keyboard handling
“StopPropagation” on all keys except “Enter” is sometimes beneficial, but consider arrow-key navigation or tabbing that might be suppressed. If your design requires blocking those events, this is fine. If not, you might remove the call for better accessibility.


93-103: Search filter UI
Displaying the TextInput only if “enableFilter” is true is a great approach. The conditional rendering is straightforward and ensures no confusion for consumers not using filtering.

client/src/ui/components/trading/SelectResources.tsx (1)

52-52: Layout note
Shifting to “p-3” for the container’s padding is purely stylistic but does appear consistent with spacing used elsewhere. Looks good.

client/src/ui/components/worldmap/players/PlayersPanel.tsx (1)

84-84: Address matching
No issues, but confirm that toHexString handles all valid addresses, including empties.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60fe5bd and 86a2227.

📒 Files selected for processing (6)
  • client/src/ui/components/trading/MarketOrderPanel.tsx (2 hunks)
  • client/src/ui/components/trading/SelectResources.tsx (5 hunks)
  • client/src/ui/components/trading/TransferBetweenEntities.tsx (3 hunks)
  • client/src/ui/components/worldmap/players/PlayersPanel.tsx (2 hunks)
  • client/src/ui/elements/ListSelect.tsx (3 hunks)
  • client/src/ui/utils/utils.tsx (1 hunks)
🔇 Additional comments (22)
client/src/ui/elements/ListSelect.tsx (5)

5-6: UseRef vs. forwardRef for TextInput usage
You introduce both TextInput (line 6) and a ref (line 26), but TextInput is not receiving a forwarded ref if it's a functional component. Double-check that TextInput properly consumes the ref or that you actually need it.


11-11: New optional property: searchText
The new field “searchText” is optional. Ensure that any usage of this field (for example, string transformations) gracefully handles the undefined case, as you do in line 39.


21-21: Conditional filter enabling
The new prop “enableFilter” is a neat feature. Confirm that default behavior remains intact for consumers who are not yet aware of this new prop.


35-42: Filtering logic
Your “filteredOptions” useMemo is clear and concise. However, watch out for a potential performance bottleneck if the options array grows large. Since you already useMemo with the same dependencies, you’re likely fine.


105-105: Use filteredOptions carefully
Confirm that “filteredOptions” is always non-empty before doing your .map calls in other usage contexts. The existing code is safe here, but just keep it in mind.

client/src/ui/components/trading/SelectResources.tsx (6)

8-8: Centralized resource reference
Importing RESOURCE_TIERS and ResourcesIds from “@bibliothecadao/eternum” is beneficial for maintaining a single source of truth. Good approach to ensure data consistency.


27-35: orderedResources creation
Mapping over RESOURCE_TIERS and skipping Lords is logical. However, confirm that no undefined or extraneous resource IDs slip in.


36-38: unselectedResources
You filter out selected resource IDs from orderedResources — clear approach. Ensure that any concurrency issues (like a user selecting multiple resources at the same time) are handled or that the UI prevents them.


55-56: Options array logic
Constructing the “options” array from both the found resource and unselectedResources is correct. Validate that “find” returns a valid object when the resource is already unselected.


79-82: Attach searchText for filter
Attaching “searchText” by looking up “resources.find((res) => res.id === option.id)?.trait” ensures you have the right textual label for filtering. Confirm that “resources” array has all needed traits.


94-94: enableFilter usage
Turning on filtering in this context is helpful for large resource lists. Good job integrating with the updated ListSelect.

client/src/ui/components/worldmap/players/PlayersPanel.tsx (4)

6-6: normalizeDiacriticalMarks import
Great move to unify string comparisons for diacritical marks. This approach reduces user confusion when searching for names with accents.


76-77: Normalized searchTerm
Applying “normalizeDiacriticalMarks” once at the beginning of your search is more efficient than repeating it for each comparison. Well done.


81-81: Player name comparison
Ensure that “player.name” is always a string. If it is occasionally null or undefined, consider adding a fallback within the normalization logic.


87-89: Structures array
You check each structure’s normalized name. This is consistent. Just watch for an empty structure name that could return a false positive or throw an error.

client/src/ui/components/trading/TransferBetweenEntities.tsx (4)

10-10: normalizeDiacriticalMarks import
Same usage pattern as in PlayersPanel. Good consistent approach to searching by normalized terms.


79-79: FilterEntities
You store the normalized search term in “normalizedSearchTerm” only once, which is best practice performance-wise.


83-85: Account name check
Your “entity.accountName” check is a subtle but important addition. This supports searching by account name as well. Good job.


324-334: Button layout changes
Switching to a 4-column grid with a single-col “Back” button and a 3-col “Confirm Transfer” aligns the UI better. This is more user-friendly.

client/src/ui/utils/utils.tsx (1)

534-536: LGTM! Clean implementation of diacritical mark normalization.

The function correctly uses Unicode normalization (NFD) and proper regex pattern to handle diacritical marks.

client/src/ui/components/trading/MarketOrderPanel.tsx (2)

454-454: Improved order confirmation logic.

The disabled condition now correctly handles buy orders by only checking donkey balance for sell orders. This fixes a potential UX issue where buy orders might have been incorrectly disabled due to donkey balance checks.


603-603: LGTM! Fixed edge case in donkey balance check.

The comparison now correctly allows orders when the donkey balance exactly matches the required amount.

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

🧹 Nitpick comments (2)
client/src/ui/modules/navigation/LeftNavigationModule.tsx (2)

Line range hint 259-259: Clean up commented code.

Consider removing the commented-out <EventStream /> component if it's no longer needed, or add a TODO comment explaining why it's temporarily disabled.


Line range hint 64-75: Document keyboard shortcuts.

Consider adding JSDoc comments or user documentation for the keyboard shortcuts. Currently, only the 'E' key for toggling entity view is implemented, but the event listener setup suggests more shortcuts might be added in the future.

Example documentation:

/**
 * Keyboard shortcuts:
 * - E: Toggle entity view
 */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 86a2227 and 5ee5701.

📒 Files selected for processing (1)
  • client/src/ui/modules/navigation/LeftNavigationModule.tsx (1 hunks)
🔇 Additional comments (1)
client/src/ui/modules/navigation/LeftNavigationModule.tsx (1)

129-129: LGTM! Verify construction menu accessibility.

The disabled condition !structureIsMine || !isRealm is logically correct, ensuring that the construction menu is only accessible for realms owned by the player.

Let's verify the construction menu accessibility conditions:

✅ Verification successful

Construction menu access control is consistently implemented

The verification confirms that the disabled condition !structureIsMine || !isRealm for the construction menu is correctly implemented and aligns with other access controls in the module:

  • The construction menu button is specifically restricted to owned realms
  • Other navigation buttons (military, trade, world structures) only check for structureIsMine
  • The realm check is consistently implemented across related components using structureCategory === "Realm"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the construction menu accessibility conditions
# Look for other instances where structureIsMine or isRealm are used to control access

# Search for structureIsMine usage in conditional statements
rg -A 3 "structureIsMine.*\?" 

# Search for isRealm usage in conditional statements
rg -A 3 "isRealm.*\?"

# Search for other construction-related access controls
ast-grep --pattern 'disabled={$_}'

Length of output: 92


Script:

#!/bin/bash
# Let's try a different approach to verify the construction menu accessibility

# Search for structureIsMine without the question mark
rg "structureIsMine" -A 3

# Search for disabled prop in the LeftNavigationModule
rg "disabled=" client/src/ui/modules/navigation/LeftNavigationModule.tsx -A 2

# Look for construction menu related components and their access controls
rg "ConstructionView" -A 3

# Search for realm-related conditions
rg "structureCategory.*Realm" -A 2

Length of output: 6284

@aymericdelab aymericdelab merged commit b4b9145 into next Dec 20, 2024
7 of 9 checks passed
@aymericdelab aymericdelab deleted the fix/bob-various branch December 20, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants