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

modify lock button to change colour based on status #685

Conversation

drizzentic
Copy link
Collaborator

@drizzentic drizzentic commented Sep 23, 2024

Summary by CodeRabbit

  • New Features
    • Enhanced visual feedback for transaction statuses with dynamic colors for the status button.
    • Improved hover state that reflects the current status of transactions.

@rcrichton
Copy link
Member

Copy link

coderabbitai bot commented Sep 23, 2024

Walkthrough

The changes involve a modification to the TransactionLogTable component, specifically the rendering of an IconButton that indicates the status of transactions. The button's appearance now dynamically reflects the transaction's status, with different colors for background and icons based on states such as 'Processing', 'Pending Async', 'Successful', 'Completed', and 'Completed with error(s)'. The hover state has also been updated to match the button's current status.

Changes

Files Change Summary
packages/transaction-log/src/components/common/... Updated IconButton rendering to use dynamic colors based on transaction.status for various transaction states.

Poem

In the log, where transactions play,
Colors dance in a vibrant display.
From processing to success, they gleam,
A button's glow, like a rabbit's dream.
With each status, a tale to tell,
In the world of logs, all is well! 🐇✨


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.

@drizzentic
Copy link
Collaborator Author

@coderabbitai review

Copy link

coderabbitai bot commented Sep 23, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Outside diff range and nitpick comments (2)
packages/transaction-log/src/components/common/transactionlog.datatable.component.tsx (2)

143-192: Ensure consistent hover behavior

The current hover styling applies the same background color as the default state. If a different hover effect is intended, you might want to adjust the hover background color to provide visual feedback upon interaction.

Consider slightly altering the opacity or color on hover to enhance user experience:

'&:hover': {
  backgroundColor:
-   statusStyles[transaction.status]?.backgroundColor || statusStyles['default'].backgroundColor,
+   statusStyles[transaction.status]
+     ? lighten(statusStyles[transaction.status].backgroundColor, 0.1)
+     : lighten(statusStyles['default'].backgroundColor, 0.1),
},

Note: You'll need to import the lighten utility from @mui/material/styles:

import { lighten } from '@mui/material/styles'

143-192: Consider extracting the lock button into a separate component

To promote reusability and cleaner code, consider creating a separate component for the lock button that accepts transaction.status as a prop.

Here's how you might implement it:

Create a new component StatusLockButton.tsx:

import React from 'react'
import { IconButton } from '@mui/material'
import LockIcon from '@mui/icons-material/Lock'

const statusStyles = {
  // ...define statusStyles as before
}

const StatusLockButton: React.FC<{ status: string }> = ({ status }) => (
  <IconButton
    sx={{
      height: '32px',
      width: '32px',
      backgroundColor: statusStyles[status]?.backgroundColor || statusStyles['default'].backgroundColor,
      borderRadius: 0,
      '&:hover': {
        backgroundColor: statusStyles[status]?.backgroundColor || statusStyles['default'].backgroundColor,
      },
    }}
  >
    <LockIcon
      sx={{
        color: statusStyles[status]?.color || statusStyles['default'].color,
      }}
    />
  </IconButton>
)

export default StatusLockButton

Then, in your main component:

<TableCell>
- <IconButton
-   sx={{ /* existing styles */ }}
- >
-   <LockIcon sx={{ /* existing styles */ }} />
- </IconButton>
+ <StatusLockButton status={transaction.status} />
</TableCell>
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f9879fa and 4f444ee.

Files selected for processing (1)
  • packages/transaction-log/src/components/common/transactionlog.datatable.component.tsx (1 hunks)
Additional comments not posted (2)
packages/transaction-log/src/components/common/transactionlog.datatable.component.tsx (2)

143-192: Check for theme consistency

Ensure that the colors used align with the application's overall theme, especially if theming support (like dark mode) is intended.

Confirm that the colors adapt correctly in different theme modes. If not, consider using theme variables.


177-190: Verify the correctness of the status values

Ensure that all possible transaction.status values are accounted for in the statusStyles mapping to prevent any undefined styling.

Run the following script to list all unique transaction.status values used in the codebase:

This will help confirm that all statuses are handled appropriately.

Comment on lines +143 to +192
<IconButton
sx={{
height: '32px',
width: '32px',
backgroundColor:
transaction.status === 'Processing'
? 'rgba(33, 150, 243, 0.2)' // info.light with 20% opacity
: transaction.status === 'Pending Async'
? 'rgba(33, 150, 243, 0.2)' // info.light with 20% opacity
: transaction.status === 'Successful'
? 'rgba(76, 175, 80, 0.2)' // success.light with 20% opacity
: transaction.status === 'Completed'
? 'rgba(255, 193, 7, 0.2)' // warning.light with 20% opacity
: transaction.status === 'Completed with error(s)'
? 'rgba(255, 193, 7, 0.2)' // warning.light with 20% opacity
: 'rgba(244, 67, 54, 0.2)', // error.light with 20% opacity
borderRadius: 0,
'&:hover': {
backgroundColor:
transaction.status === 'Processing'
? 'rgba(33, 150, 243, 0.2)' // info.light with 20% opacity
: transaction.status === 'Pending Async'
? 'rgba(33, 150, 243, 0.2)' // info.light with 20% opacity
: transaction.status === 'Successful'
? 'rgba(76, 175, 80, 0.2)' // success.light with 20% opacity
: transaction.status === 'Completed'
? 'rgba(255, 193, 7, 0.2)' // warning.light with 20% opacity
: transaction.status === 'Completed with error(s)'
? 'rgba(255, 193, 7, 0.2)' // warning.light with 20% opacity
: 'rgba(244, 67, 54, 0.2)', // error.light with 20% opacity
},
}}
>
<LockIcon
sx={{
color:
transaction.status === 'Processing'
? 'info.main'
: transaction.status === 'Pending Async'
? 'info.main'
: transaction.status === 'Successful'
? 'success.main'
: transaction.status === 'Completed'
? 'warning.main'
: transaction.status === 'Completed with error(s)'
? 'warning.main'
: 'error.main',
}}
/>
</IconButton>
Copy link

Choose a reason for hiding this comment

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

Refactor conditional styling for better readability and maintainability

The current implementation uses long chains of nested ternary operators to determine the styling based on transaction.status. This can be hard to read and maintain, especially as the number of status values grows.

Consider using a mapping object to define styles for each status, which will make the code cleaner and easier to extend. Here's how you can refactor the code:

Define the style mappings outside the component:

const statusStyles = {
  'Processing': {
    backgroundColor: 'rgba(33, 150, 243, 0.2)', // info.light with 20% opacity
    color: 'info.main',
  },
  'Pending Async': {
    backgroundColor: 'rgba(33, 150, 243, 0.2)', // info.light with 20% opacity
    color: 'info.main',
  },
  'Successful': {
    backgroundColor: 'rgba(76, 175, 80, 0.2)', // success.light with 20% opacity
    color: 'success.main',
  },
  'Completed': {
    backgroundColor: 'rgba(255, 193, 7, 0.2)', // warning.light with 20% opacity
    color: 'warning.main',
  },
  'Completed with error(s)': {
    backgroundColor: 'rgba(255, 193, 7, 0.2)', // warning.light with 20% opacity
    color: 'warning.main',
  },
  'default': {
    backgroundColor: 'rgba(244, 67, 54, 0.2)', // error.light with 20% opacity
    color: 'error.main',
  },
}

Then, update your component to use these styles:

<IconButton
  sx={{
    height: '32px',
    width: '32px',
    backgroundColor:
-     transaction.status === 'Processing'
-       ? 'rgba(33, 150, 243, 0.2)'
-       : transaction.status === 'Pending Async'
-       ? 'rgba(33, 150, 243, 0.2)'
-       : transaction.status === 'Successful'
-       ? 'rgba(76, 175, 80, 0.2)'
-       : transaction.status === 'Completed'
-       ? 'rgba(255, 193, 7, 0.2)'
-       : transaction.status === 'Completed with error(s)'
-       ? 'rgba(255, 193, 7, 0.2)'
-       : 'rgba(244, 67, 54, 0.2)',
+     statusStyles[transaction.status]?.backgroundColor || statusStyles['default'].backgroundColor,
    borderRadius: 0,
    '&:hover': {
      backgroundColor:
-       transaction.status === 'Processing'
-         ? 'rgba(33, 150, 243, 0.2)'
-         : transaction.status === 'Pending Async'
-         ? 'rgba(33, 150, 243, 0.2)'
-         : transaction.status === 'Successful'
-         ? 'rgba(76, 175, 80, 0.2)'
-         : transaction.status === 'Completed'
-         ? 'rgba(255, 193, 7, 0.2)'
-         : transaction.status === 'Completed with error(s)'
-         ? 'rgba(255, 193, 7, 0.2)'
-         : 'rgba(244, 67, 54, 0.2)',
+       statusStyles[transaction.status]?.backgroundColor || statusStyles['default'].backgroundColor,
    },
  }}
>
  <LockIcon
    sx={{
      color:
-       transaction.status === 'Processing'
-         ? 'info.main'
-         : transaction.status === 'Pending Async'
-         ? 'info.main'
-         : transaction.status === 'Successful'
-         ? 'success.main'
-         : transaction.status === 'Completed'
-         ? 'warning.main'
-         : transaction.status === 'Completed with error(s)'
-         ? 'warning.main'
-         : 'error.main',
+       statusStyles[transaction.status]?.color || statusStyles['default'].color,
    }}
  />
</IconButton>

Avoid hardcoding color values

Hardcoding color values can make future theme adjustments more difficult. It's better to use theme palette references where possible.

Update the statusStyles to use theme palette references:

const statusStyles = {
  'Processing': {
    backgroundColor: theme => theme.palette.info.light, // Assuming light variant with default opacity
    color: theme => theme.palette.info.main,
  },
  // Repeat for other statuses...
}

And adjust the component accordingly:

<IconButton
  sx={{
    // ...
    backgroundColor: statusStyles[transaction.status]?.backgroundColor,
    // ...
    '&:hover': {
      backgroundColor: statusStyles[transaction.status]?.backgroundColor,
    },
  }}
>
  <LockIcon
    sx={{
      color: statusStyles[transaction.status]?.color,
    }}
  />
</IconButton>

Copy link
Collaborator

@marvinIsSacul marvinIsSacul left a comment

Choose a reason for hiding this comment

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

lgtm

@drizzentic drizzentic merged commit afe380e into poc-microfrontends Sep 23, 2024
3 checks passed
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.

3 participants