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

feat: add profile tab tooltip in FS #1567

Merged
merged 2 commits into from
Oct 1, 2024
Merged

feat: add profile tab tooltip in FS #1567

merged 2 commits into from
Oct 1, 2024

Conversation

Nick-1979
Copy link
Member

@Nick-1979 Nick-1979 commented Sep 30, 2024

  • removing alerts after shown from context

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced alert management with the introduction of a removeAlert method for better control over alert visibility.
    • New localization string added to improve user interaction: "Click to hide all the profile accounts from websites!"
  • Bug Fixes

    • Adjusted the ProfileTabFullScreen component to improve the display of contextual tooltips.
  • Style

    • Minor styling adjustments made to the ProfileTabsFullScreen component for improved visual spacing.
  • Refactor

    • Updated the useAlerts hook to provide additional functionality for managing alerts and streamline alert handling in the AlertBox component.

+ removing alerts after shown from context
Copy link
Contributor

coderabbitai bot commented Sep 30, 2024

Walkthrough

The pull request introduces several modifications across multiple components in the codebase. Key changes include updates to the Infotip2 component for improved styling, adjustments in the ProfileTabFullScreen to integrate Infotip2, enhancements to the useAlerts hook for better alert management, and updates to the localization file to improve user interaction. The overall structure and logic of the components remain largely intact, focusing on minor enhancements and functionality improvements.

Changes

File Change Summary
packages/extension-polkagate/src/components/Infotip2.tsx Adjusted function signature and reordered style prop in FontAwesomeIcon. Conditional rendering logic remains unchanged.
packages/extension-polkagate/src/components/contexts.tsx Updated import of noop function from a local utility to @polkadot/util. No changes to context declarations.
packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/ProfileTabFullScreen.tsx Integrated Infotip2 into the component, added state management for account visibility, and adjusted rendering logic while preserving existing functionalities.
packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/ProfileTabsFullScreen.tsx Minor styling adjustments to the scrollable container's padding without altering visibility logic or existing functionalities.
packages/extension-polkagate/src/hooks/useAlerts.ts Enhanced useAlerts hook to include alerts state and a new removeAlert method for better alert management.
packages/extension/polkagate/src/partials/Alert.tsx Removed local state and timeout for alert visibility, now using removeAlert from useAlerts for closure.
packages/extension/polkagate/src/partials/AlertBox.tsx Removed useContext, added useEffect for alert removal, and integrated useAlerts for managing alerts. Introduced a constant for alert duration.
packages/extension/public/locales/en/translation.json Added new localization strings and made minor formatting adjustments.
packages/extension/polkagate/src/util/types.ts Added id property to AlertType interface for unique alert identification.

Possibly related PRs

Suggested labels

new feature

Suggested reviewers

  • AMIRKHANEF

Poem

🐰 In the garden where changes bloom,
The Infotip2 brings light to the room.
Alerts now dance, then fade away,
With each new string, we brighten the day!
Hops of joy in every line,
Code and carrots, all align! 🌼


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

🧹 Outside diff range and nitpick comments (2)
packages/extension-polkagate/src/hooks/useAlerts.ts (1)

17-19: Approve with suggestion: Add error handling to removeAlert

The removeAlert function is well-implemented using useCallback for memoization and follows React's immutable state update pattern. However, consider adding a check for invalid indices to prevent unexpected behavior.

Consider adding an index check:

 const removeAlert = useCallback((index: number) => {
+  if (index < 0 || index >= alerts.length) {
+    console.warn(`Attempted to remove alert at invalid index: ${index}`);
+    return;
+  }
   setAlerts((prev) => prev.filter((_, i) => i !== index));
 }, [setAlerts]);
packages/extension-polkagate/src/components/Infotip2.tsx (1)

91-91: LGTM: Style prop reordering.

The reordering of style properties doesn't affect functionality. However, for better consistency and maintainability, consider adopting a standard order for style properties across the project.

You might want to consider using a consistent order for style properties throughout the project. For example, you could order them alphabetically or group them by type (layout, spacing, typography, etc.). This can make it easier to scan and maintain styles across the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6c3fbcd and 5fafee2.

📒 Files selected for processing (7)
  • packages/extension-polkagate/src/components/Infotip2.tsx (2 hunks)
  • packages/extension-polkagate/src/components/contexts.tsx (1 hunks)
  • packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/ProfileTabFullScreen.tsx (3 hunks)
  • packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/ProfileTabsFullScreen.tsx (1 hunks)
  • packages/extension-polkagate/src/hooks/useAlerts.ts (1 hunks)
  • packages/extension-polkagate/src/partials/AlertBox.tsx (1 hunks)
  • packages/extension/public/locales/en/translation.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/ProfileTabsFullScreen.tsx
  • packages/extension/public/locales/en/translation.json
🔇 Additional comments (16)
packages/extension-polkagate/src/hooks/useAlerts.ts (1)

11-11: LGTM: Accessing alerts from context

The modification to destructure alerts along with setAlerts from the context is a good change. It allows the hook to access the current list of alerts, which is necessary for the new functionality and for exposing the alerts in the return value.

packages/extension-polkagate/src/components/contexts.tsx (2)

Line range hint 1-54: Summary: Minor import change with no functional impact.

The only change in this file is the import of the noop function from @polkadot/util instead of a local utility file. This change does not affect the functionality of the contexts defined in this file. The overall structure and purpose of the file remain intact.


11-11: Approved: Good practice to use standard library function.

The change from a local noop implementation to the one provided by @polkadot/util is a good practice. It promotes consistency and leverages a well-maintained library.

To ensure consistency across the project, let's verify if there are any remaining usages of the local noop function:

If this script returns any results, consider updating those instances to use the @polkadot/util import as well.

packages/extension-polkagate/src/components/Infotip2.tsx (2)

22-22: LGTM: Improved function signature formatting.

The addition of a space after the function name in the signature improves readability and aligns with common coding conventions.


Line range hint 1-138: Summary: Minor stylistic improvements with no functional changes.

The changes in this file are purely stylistic and don't affect the component's functionality. The Infotip2 component's logic, structure, and behavior remain unchanged. These improvements enhance code readability without introducing any risks or requiring additional testing.

packages/extension-polkagate/src/fullscreen/homeFullScreen/partials/ProfileTabFullScreen.tsx (7)

13-13: LGTM: Import statement updated correctly.

The import statement has been appropriately updated to include Infotip2, which is used later in the component.


31-31: LGTM: Expanded useAlerts hook usage.

The useAlerts hook now correctly includes alerts, which is used later in the component for conditional rendering. This change aligns with the PR objectives regarding alert handling improvements.


87-93: LGTM: Infotip2 wrapper implemented correctly.

The Infotip2 component has been appropriately added to wrap the existing Grid component, implementing the profile tab tooltip feature as per the PR objectives. The conditional logic for the tooltip text is well-structured, ensuring it's displayed only under specific conditions (no alerts, selected tab, and not all accounts hidden).


94-119: LGTM: Grid component props enhanced for better layout and styling.

The Grid component's props have been updated to improve layout, alignment, and styling. The additions of alignItems, columnGap, and justifyContent props, along with the expanded sx object, contribute to a more polished and responsive UI. These changes enhance the overall user experience without introducing any apparent issues.


120-120: LGTM: Checkmark icon implemented correctly.

The VaadinIcon component is appropriately used to display a checkmark, with its visibility conditionally set based on the isSelected prop. This implementation provides clear visual feedback for the selected profile tab, enhancing the user experience.


121-133: LGTM: Typography component styling enhanced.

The Typography component has been updated with improved styling, including better handling of text overflow and smooth visibility transitions. These changes enhance the display of profile names, especially for longer text, and improve the overall responsiveness of the UI. The implementation aligns well with best practices for text display in limited space.


134-142: LGTM: Eye-slash icon implemented correctly.

The new VaadinIcon component for the eye-slash icon is well-implemented. Its visibility and appearance are appropriately conditioned on the areAllHidden and visibleContent states, providing clear visual feedback about the hidden state of profile accounts. This addition enhances the user interface and aligns with the PR objectives regarding profile account visibility management.

packages/extension-polkagate/src/partials/AlertBox.tsx (4)

9-9: Importing useEffect from React is appropriate

The addition of useEffect is necessary for managing side effects related to alerts.


11-11: Verify the necessity of useTransactionState

While useAlerts is used, please confirm whether useTransactionState is required in this component, as it doesn't appear in the provided code.


14-15: Good practice: Define a constant for alert removal time

Defining TIME_TO_REMOVE_ALERT as a constant enhances readability and maintainability.


17-17: Destructuring alerts and removeAlert

Using object destructuring for alerts and removeAlert from useAlerts hook is concise and clear.

packages/extension-polkagate/src/partials/AlertBox.tsx Outdated Show resolved Hide resolved
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)
packages/extension-polkagate/src/partials/Alert.tsx (1)

23-25: LGTM: Alert closure logic updated and optimized.

The closeAlert function has been optimized using useCallback and now directly removes the alert using the removeAlert function from the useAlerts hook. This change aligns with the new alert management approach described in the AI summary.

Consider moving the useCallback dependency array to a new line for better readability:

  const closeAlert = useCallback(() => {
    removeAlert(alert.id);
-  }, [alert.id, removeAlert]);
+  }, [
+    alert.id,
+    removeAlert
+  ]);
packages/extension-polkagate/src/hooks/useAlerts.ts (2)

11-11: LGTM: Alert removal time constant added

The addition of TIME_TO_REMOVE_ALERT constant is good for maintaining consistency in alert removal timing. The 5-second duration seems reasonable for most alerts.

Consider making this value configurable, either through a prop or a configuration object, to allow for flexibility in different use cases.


Line range hint 1-32: Overall: Excellent enhancements to alert management

The changes to useAlerts.ts significantly improve the alert management system:

  1. Unique IDs for alerts using the Chance library ensure proper tracking and removal of alerts.
  2. Automatic alert removal after a set time improves user experience.
  3. The expanded interface (alerts, notify, removeAlert) provides more control to consumers of the hook.
  4. Proper use of React hooks optimizes performance.

These enhancements result in a more robust, efficient, and user-friendly alert system. Great job on the improvements!

Consider the following for future iterations:

  1. Make the TIME_TO_REMOVE_ALERT configurable for different use cases.
  2. Implement a mechanism to pause the auto-removal timer when the user interacts with an alert, if applicable to your use case.
packages/extension-polkagate/src/hooks/useAssetsBalances.ts (1)

140-141: LGTM: Chance instance created and addAlert function implemented.

The Chance instance is correctly memoized, and the addAlert function is well-implemented. It generates unique IDs for alerts, sets them with a success message, and removes them after a specified duration.

Consider extracting the alert message to a constant or configuration file for easier maintenance and potential internationalization:

+const ACCOUNTS_BALANCE_UPDATED_MESSAGE = 'Accounts\' balances updated!';

 const addAlert = useCallback(() => {
   const id = random.string({ length: 10 });

-  setAlerts((perv) => [...perv, { id, severity: 'success', text: t('Accounts\' balances updated!') }]);
+  setAlerts((perv) => [...perv, { id, severity: 'success', text: t(ACCOUNTS_BALANCE_UPDATED_MESSAGE) }]);
   const timeout = setTimeout(() => setAlerts((prev) => prev.filter(({ id: alertId }) => alertId !== id)), TIME_TO_REMOVE_ALERT);

   return () => clearTimeout(timeout);
 }, [random, setAlerts, t]);

Also applies to: 154-161

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5fafee2 and 94be77b.

📒 Files selected for processing (5)
  • packages/extension-polkagate/src/hooks/useAlerts.ts (1 hunks)
  • packages/extension-polkagate/src/hooks/useAssetsBalances.ts (5 hunks)
  • packages/extension-polkagate/src/partials/Alert.tsx (1 hunks)
  • packages/extension-polkagate/src/partials/AlertBox.tsx (1 hunks)
  • packages/extension-polkagate/src/util/types.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/extension-polkagate/src/partials/AlertBox.tsx
🔇 Additional comments (11)
packages/extension-polkagate/src/partials/Alert.tsx (4)

11-11: LGTM: Import changes align with new functionality.

The addition of useCallback and useAlerts imports are consistent with the changes in alert handling logic described in the AI summary. These imports support the new implementation for managing alerts.

Also applies to: 13-13


28-28: LGTM: Slide transition always active.

The in prop of the Slide component is now always set to true, which aligns with the removal of the visibility state management mentioned in the AI summary. This ensures that the alert is always rendered with the slide transition.

To ensure this change doesn't affect the alert's disappearance animation, please verify the following:

  1. Check if the Slide component handles unmounting correctly when the alert is removed.
  2. Confirm that the unmountOnExit prop ensures proper cleanup after the exit animation.

You may want to test this behavior in the UI to ensure smooth transitions for both appearance and disappearance of alerts.


21-21: LGTM: Alert removal now managed through useAlerts hook.

The removeAlert function from the useAlerts hook is now used for alert management, which aligns with the changes described in the AI summary. This approach centralizes alert handling logic.

Let's verify the implementation of the useAlerts hook:


Line range hint 1-41: Overall: Good improvements to alert handling and component optimization.

The changes in this file align well with the PR objectives and the AI summary. The alert handling has been centralized using the useAlerts hook, and the component has been optimized with useCallback. These modifications improve code organization while maintaining existing functionality.

To ensure full compatibility with the rest of the application, please verify:

  1. The useAlerts hook implementation and its usage across the application.
  2. The behavior of alerts in different scenarios (e.g., multiple alerts, rapid alert creation/removal).

Run the following script to check for other uses of alert-related functions:

This will help ensure that the changes are consistent throughout the application.

✅ Verification successful

Alert Functions Usage Verified

The useAlerts, removeAlert, and addAlert functions are utilized across multiple files, including AlertBox.tsx, OptionalCopyPopup.tsx, and others. The changes in Alert.tsx effectively centralize alert handling and optimize the component without introducing issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other uses of alert-related functions

# Test: Search for uses of removeAlert and other alert-related functions
rg --type typescript -A 5 'removeAlert|addAlert|useAlerts'

Length of output: 95


Script:

#!/bin/bash
# Description: Check for other uses of alert-related functions with correct TypeScript file types

# Test: Search for uses of removeAlert and other alert-related functions in .ts and .tsx files
rg --type ts -A 5 'removeAlert|addAlert|useAlerts'
rg --type tsx -A 5 'removeAlert|addAlert|useAlerts'

Length of output: 14516


Script:

#!/bin/bash
# Description: Check for other uses of alert-related functions in .ts and .tsx files using glob patterns

# Test: Search for uses of removeAlert, addAlert, and useAlerts in .ts and .tsx files
rg 'removeAlert|addAlert|useAlerts' --glob '*.ts' --glob '*.tsx' -A 5

Length of output: 14453

packages/extension-polkagate/src/hooks/useAlerts.ts (2)

6-6: LGTM: Chance library import added

The addition of the Chance library import is appropriate for generating unique IDs for alerts. This change supports the new functionality in the hook.


16-29: LGTM: Improved alert management in useAlerts hook

The changes to the useAlerts hook implementation are well-structured and improve alert management:

  1. The use of useMemo for the Chance instance optimizes performance.
  2. The removeAlert function is correctly implemented with useCallback.
  3. The notify function now generates unique IDs and schedules alert removal, enhancing alert management.
  4. The use of setTimeout for alert removal with a proper cleanup function is correct.

These changes provide a more robust and efficient alert system.

packages/extension-polkagate/src/util/types.ts (1)

785-785: Approved: Addition of id property enhances alert management

The addition of the id: string; property to the AlertType interface is a positive change. This unique identifier will facilitate better management and tracking of individual alerts, aligning with the PR objective of removing alerts after they've been displayed. It's a non-breaking change that enhances the interface's functionality without disrupting existing code.

packages/extension-polkagate/src/hooks/useAssetsBalances.ts (4)

12-12: LGTM: Chance library import added.

The Chance library is appropriately imported for generating random strings, which will be used for creating unique alert IDs.


23-23: LGTM: TIME_TO_REMOVE_ALERT constant imported.

Importing the TIME_TO_REMOVE_ALERT constant from the useAlerts hook ensures consistency in alert duration across the application.


222-225: LGTM: Alert added after account saving.

The addAlert function is correctly called after handleAccountsSaving, ensuring that users are notified when account balances are successfully updated.


Line range hint 1-577: Overall assessment: Changes improve user feedback and code quality.

The modifications to this file enhance the user experience by providing notifications when account balances are updated. The implementation is solid, with good use of React hooks and proper management of side effects. The suggestion to extract the alert message to a constant is a minor improvement that could be considered for better maintainability.

@Nick-1979 Nick-1979 merged commit 929b519 into main Oct 1, 2024
8 checks passed
@Nick-1979 Nick-1979 deleted the addProfileTabTooltip branch October 1, 2024 12:58
github-actions bot pushed a commit that referenced this pull request Oct 1, 2024
# [0.15.0](v0.14.1...v0.15.0) (2024-10-01)

### Bug Fixes

* user added chains price id ([#1571](#1571)) ([0db1976](0db1976))

### Features

* add profile tab tooltip in FS ([#1567](#1567)) ([929b519](929b519)), closes [#1572](#1572)
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