-
Notifications
You must be signed in to change notification settings - Fork 29
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
modify lock button to change colour based on status #685
Conversation
WalkthroughThe changes involve a modification to the Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@coderabbitai review |
Actions performedReview triggered.
|
There was a problem hiding this 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 behaviorThe 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 componentTo 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 StatusLockButtonThen, 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
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 consistencyEnsure 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 valuesEnsure that all possible
transaction.status
values are accounted for in thestatusStyles
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.
<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> |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Summary by CodeRabbit