Skip to content

feat: fill in the secret and secret namespace when restoring the BackupBackingImage #822

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

Merged
merged 4 commits into from
Dec 10, 2024

Conversation

houhoucoop
Copy link
Contributor

@houhoucoop houhoucoop commented Dec 6, 2024

What this PR does / why we need it

  • Display icon only for encrypted BackupBackingImages
  • Auto-fill secret and namespace when restoring an encrypted BackupBackingImage

Issue

[UI FEATURE] Fill in the secret and secret namespace when restoring the BackupBackingImage

Test Result

Display icon only for encrypted BackupBackingImages
Screenshot 2024-12-06 at 10 14 38 AM (2)

Auto-fill secret and namespace when restoring an encrypted BackupBackingImage
Screenshot 2024-12-06 at 10 14 43 AM (2)

Additional documentation or context

  • Test with LONGHORN_MANAGER_IP=http://139.59.122.79:30001/ npm run dev

Summary by CodeRabbit

  • New Features

    • Enhanced table layout with updated column widths for improved readability.
    • New icons and tooltips added to indicate encrypted records in the backup list.
    • Default value for the item prop in the restore modal ensures consistent behavior.
  • Bug Fixes

    • Improved handling of the item prop to enhance user experience by disabling inputs when appropriate.
  • Style

    • Introduced new CSS classes for better styling of encrypted items in both lists.

Copy link

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces several modifications across multiple components related to backing images. Key changes include adjustments to column widths and rendering logic in the BackingImageList.js and BackupBackingImageList.js files, with new CSS classes added for styling. The RestoreBackupBackingImageModal.js component has been updated to handle the item prop more robustly, including default values and conditional disabling of input fields. Overall, these changes focus on improving the layout, styling, and user experience without altering the core functionality.

Changes

File Path Change Summary
src/routes/backingImage/BackingImageList.js Adjusted column widths, updated 'Name' column rendering with new CSS class, imported styles module.
src/routes/backingImage/BackingImageList.less Added .encryptedBackingImage class for styling.
src/routes/backingImage/BackupBackingImageList.js Increased 'Name' column width, added conditional rendering for encrypted records with icons.
src/routes/backingImage/BackupBackingImageList.less Added .encryptedBackup class for styling.
src/routes/backingImage/RestoreBackupBackingImageModal.js Set default value for item prop, updated input fields to disable based on item properties.

Possibly related PRs

Suggested reviewers

  • ChanYiLin
  • a110605

Poem

In the land of backups, where images reside,
Columns now wider, with style as our guide.
Encrypted names sparkle, like stars in the night,
With tooltips and icons, everything feels right.
A modal that’s smarter, inputs now gleam,
Hopping through changes, we’re living the dream! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3294266 and b64af6c.

📒 Files selected for processing (1)
  • src/routes/backingImage/RestoreBackupBackingImageModal.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/routes/backingImage/RestoreBackupBackingImageModal.js

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. (Experiment)
  • @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 (1)
src/routes/backingImage/BackupBackingImageList.js (1)

31-42: LGTM: Well-implemented encryption indicator with room for minor optimization

The implementation effectively shows encryption status through a lock icon with helpful tooltip. Consider a minor optimization to simplify the boolean expression.

-        const isEncrypted = Boolean(record.secret || record.secretNamespace)
+        const isEncrypted = !!(record.secret || record.secretNamespace)

The !! operator is more commonly used in JavaScript for boolean coercion and is slightly more performant than the Boolean constructor.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d19e284 and 8334140.

📒 Files selected for processing (5)
  • src/routes/backingImage/BackingImageList.js (5 hunks)
  • src/routes/backingImage/BackingImageList.less (1 hunks)
  • src/routes/backingImage/BackupBackingImageList.js (3 hunks)
  • src/routes/backingImage/BackupBackingImageList.less (1 hunks)
  • src/routes/backingImage/RestoreBackupBackingImageModal.js (2 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/routes/backingImage/BackupBackingImageList.less
  • src/routes/backingImage/BackingImageList.less
🔇 Additional comments (11)
src/routes/backingImage/RestoreBackupBackingImageModal.js (3)

18-18: LGTM: Good defensive programming practice

Adding a default empty object for the item prop prevents potential null pointer issues.


52-52: LGTM: Appropriate field constraint

Correctly disables the backup name field when restoring an existing backup.


55-58: LGTM: Secure implementation of secret field handling

The implementation correctly:

  1. Auto-fills secret and secretNamespace from the backup
  2. Disables modification of existing secret information
  3. Maintains security by preventing tampering with encrypted backup credentials

This aligns perfectly with the PR objective of streamlining the restoration process for encrypted backups.

src/routes/backingImage/BackupBackingImageList.js (2)

3-3: LGTM: Appropriate UI component imports

Added necessary antd components and styles for implementing the encrypted backup UI enhancements.

Also applies to: 9-9


29-29: Verify column width adjustments

The increased column widths should accommodate the new lock icon without causing layout issues.

Also applies to: 88-88

✅ Verification successful

Column width adjustments are consistent with related components

The width changes in BackupBackingImageList.js are consistent with the existing table layouts in the codebase:

  • The Name column width of 180px matches exactly with the BackingImageList.js component
  • Other column widths in both components maintain similar proportions (80-120px range)
  • The increased widths provide adequate space for the UI elements while maintaining layout consistency
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any other files with similar table layouts that might need width adjustments
rg -l "Table.*columns.*width" --type js

Length of output: 41


Script:

#!/bin/bash
# Let's try a broader search for table-related width configurations
rg "width.*\d+" --type js src/routes/backingImage/

Length of output: 1334


Script:

#!/bin/bash
# Search for Table components with column definitions
rg "columns.*=.*\[" --type js -A 5 src/routes/backingImage/

Length of output: 1240


Script:

#!/bin/bash
# Look for similar BackupBackingImage related components
fd "BackupBackingImage.*\.js$" src/

Length of output: 255

src/routes/backingImage/BackingImageList.js (6)

Line range hint 10-17: LGTM! Props are well-defined and properly documented.

The explicit listing of props in the function signature improves code readability and matches the PropTypes declaration.


Line range hint 19-45: LGTM! Icon rendering logic is clear and follows best practices.

The implementation:

  • Uses semantic color classes for different states
  • Provides clear tooltip messages
  • Correctly handles both encrypted and deletion states

Line range hint 169-182: LGTM! Table implementation follows best practices.

The table component:

  • Uses proper pagination
  • Handles dynamic height based on content
  • Implements responsive scrolling

Line range hint 184-194: LGTM! PropTypes are well-defined.

The PropTypes declaration properly validates all component props with appropriate types.


8-8: Verify the existence of the BackingImageList.less file.

The code imports styles from BackingImageList.less, which should contain the new .encryptedBackingImage class.

✅ Verification successful

The BackingImageList.less file exists with the required styles

The file exists at the expected location and contains the necessary .encryptedBackingImage and .encryptedBackup classes that are used for styling encrypted backing images.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence of BackingImageList.less and its content
fd -t f "BackingImageList.less" src/routes/backingImage/ -x cat {}

Length of output: 193


54-54: Verify table layout with adjusted column widths.

The column width adjustments look reasonable, but we should verify that:

  1. The total width (970px) in the table's scroll prop matches the sum of column widths
  2. The content fits well within the adjusted widths without truncation

Also applies to: 60-60, 80-80, 94-94, 107-107

✅ Verification successful

The previous search might have been too specific. Let's broaden it to understand the table implementations better and their scroll configurations.


I'm looking for the complete column definitions and any global table styles that might affect scrolling behavior.


I need to see the complete file content to analyze the column definitions and table configuration. The previous searches might have failed due to different formatting or multiline declarations.


Column widths are correctly configured with appropriate scroll settings

The table implementation shows that:

  1. The total width of all columns (910px) plus default padding matches the scroll prop's x value (970px)
  2. Column widths are appropriately sized for their content:
    • Name: 180px (for longer names + icons)
    • UUID: 120px
    • Size: 100px (for formatted Mib values)
    • Created From: 120px
    • Minimum Copies: 130px
    • Node Tags: 120px
    • Disk Tags: 120px
    • Operation: 120px

The table uses the antd Table component with proper horizontal scrolling configuration and responsive height based on content.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for other table implementations to compare column widths
rg -U "Table.*scroll.*x:.*" src/

Length of output: 34


Script:

#!/bin/bash
# Let's try a different approach to find table implementations and their scroll configurations
rg -U "Table.*scroll" src/

# Also search for specific table components that might contain scroll configurations
rg -U "<Table.*" -A 5 src/

Length of output: 9918


Script:

#!/bin/bash
# Let's examine the specific table implementation in BackingImageList.js to verify column definitions
rg -U "columns.*=.*\[.*\]" src/routes/backingImage/BackingImageList.js -A 100

# Also check for any scroll configuration in the component
rg -U "className=\"common-table-class\"" src/components/ -A 5

Length of output: 141


Script:

#!/bin/bash
# Let's try a different approach to find the column definitions
cat src/routes/backingImage/BackingImageList.js

Length of output: 5582

@houhoucoop houhoucoop self-assigned this Dec 6, 2024
@a110605
Copy link
Contributor

a110605 commented Dec 9, 2024

To restore non-encrypted backing image backup, does modal need to show secret / secret namespace to user ?

I think they're not required fields and can be hidden ? @ChanYiLin

Screenshot 2024-12-09 at 11 14 04 AM

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 (1)
src/routes/backingImage/BackupBackingImageList.js (1)

31-42: Consider extracting encryption check to a utility function

The encryption status check logic is correct but could be more reusable. Consider extracting it to a utility function:

+ // In src/utils/backup.js
+ export const isBackupEncrypted = (record) => Boolean(record.secret || record.secretNamespace)

  // In this file
  render: (text, record) => {
-   const isEncrypted = Boolean(record.secret || record.secretNamespace)
+   const isEncrypted = isBackupEncrypted(record)
    return (
      <>
        {isEncrypted && (
          <Tooltip title="Encrypted Backing Image Backup">
            <Icon className="color-warning" type="lock" />
          </Tooltip>
        )}
        <span className={styles.encryptedBackup}>{text}</span>
      </>
    )
  },

Also, consider making the tooltip more descriptive by including information about the secret and namespace being used.

- <Tooltip title="Encrypted Backing Image Backup">
+ <Tooltip title={`Encrypted Backing Image Backup (Secret: ${record.secret} in ${record.secretNamespace})`}>

The core implementation looks good and aligns with the PR objectives.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8334140 and 2fcb5e9.

📒 Files selected for processing (5)
  • src/routes/backingImage/BackingImageList.js (5 hunks)
  • src/routes/backingImage/BackingImageList.less (1 hunks)
  • src/routes/backingImage/BackupBackingImageList.js (3 hunks)
  • src/routes/backingImage/BackupBackingImageList.less (1 hunks)
  • src/routes/backingImage/RestoreBackupBackingImageModal.js (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/routes/backingImage/BackupBackingImageList.less
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/routes/backingImage/BackingImageList.less
  • src/routes/backingImage/RestoreBackupBackingImageModal.js
  • src/routes/backingImage/BackingImageList.js
🔇 Additional comments (3)
src/routes/backingImage/BackupBackingImageList.js (3)

3-3: LGTM: Import statements are properly organized

The new imports for Icon, Tooltip, and styles are well-organized and align with the PR's objective of adding encryption indicators.

Also applies to: 9-9


37-37: Verify styling dependencies

Please ensure:

  1. The color-warning class is available in your antd theme
  2. The styles.encryptedBackup class is properly defined in BackupBackingImageList.less

Also applies to: 40-40

✅ Verification successful

Both styling classes are properly defined and used across the codebase

The verification shows that:

  • The color-warning class is defined in src/assets/styles/classes.less and uses the @color-warning variable from vars.less
  • The class is consistently used across multiple components for warning icons
  • The encryptedBackup class exists in BackupBackingImageList.less and is properly imported and used in the component
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for required style definitions

# Check if the less file exists and contains the required class
echo "Checking for encryptedBackup class definition..."
rg -l "\.encryptedBackup\s*{" "src/routes/backingImage/BackupBackingImageList.less"

# Check for color-warning class in antd theme or custom styles
echo "Checking for color-warning class usage..."
rg -l "\.color-warning\s*{" "src/**/*.less"

Length of output: 537


Script:

#!/bin/bash
# Description: Check for required style definitions with corrected regex

# Check if the less file exists and contains the required class
echo "Checking for encryptedBackup class definition..."
rg "\.encryptedBackup" "src/routes/backingImage/"

# Check for color-warning class in antd theme or custom styles
echo "Checking for color-warning class usage..."
rg "color-warning" "src/"

# Check if the less file exists
echo "Checking if the less file exists..."
fd "BackupBackingImageList.less" "src/"

Length of output: 3150


29-29: Verify table layout with new column widths

The increased column widths (Name: 180px, Created Time: 100px) should be verified to ensure:

  1. The lock icon fits without text wrapping
  2. The table's horizontal scroll behavior works correctly (table has scroll.x: 970)

Let's check if the total column width matches the scroll width:

Also applies to: 88-88

✅ Verification successful

Let me verify if there are any other table components in the codebase with similar structure to ensure consistency.


Let me try a different search pattern to find table configurations.


Let me check the specific file to verify the scroll configuration.


Column width adjustments are appropriate and consistent

The increased column widths are well-balanced with the table's scroll configuration:

  • Total column width (800px) = Name(180) + State(80) + Size(80) + URL(240) + Created Time(100) + Operation(120)
  • Table scroll.x is set to 970px, providing adequate space for borders, padding, and scroll bar
  • The Name column width (180px) accommodates the new lock icon and text without causing layout issues
  • The width adjustments align with other tables in the codebase that use similar column widths for similar content types
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Calculate total column width and compare with scroll.x value
echo "Column widths:"
echo "Name: 180"
echo "State: 80"
echo "Size: 80"
echo "URL: 240"
echo "Created Time: 100"
echo "Operation: 120"
echo "Total: 800px (excluding padding/borders)"
echo "Scroll.x: 970px"
echo "Difference: 170px (seems reasonable for padding/borders)"

Length of output: 489


Script:

#!/bin/bash
# Search for other table components with column definitions
rg -A 5 "scroll:\s*{\s*x:" --type js

# Look for other width definitions in table columns
ast-grep --pattern 'width: $_'

Length of output: 181


Script:

#!/bin/bash
# Search for scroll configurations in tables
rg "scroll: {" --type js -A 5

# Search for table column definitions
rg "columns = \[" --type js -A 10

Length of output: 15460


Script:

#!/bin/bash
# Get the full content of BackupBackingImageList.js to verify scroll configuration
cat src/routes/backingImage/BackupBackingImageList.js

Length of output: 3560

@ChanYiLin
Copy link

To restore non-encrypted backing image backup, does modal need to show secret / secret namespace to user ?

I think they're not required fields and can be hidden ? @ChanYiLin

Screenshot 2024-12-09 at 11 14 04 AM

Yes, you are right
we shouldn't allow user to fill in these fields when restoring non-encrypted BackupBackingImage
Thanks

@houhoucoop
Copy link
Contributor Author

To restore non-encrypted backing image backup, does modal need to show secret / secret namespace to user ?

I think they're not required fields and can be hidden ? @ChanYiLin

Screenshot 2024-12-09 at 11 14 04 AM

updated in commit b64af6c.
Screenshot 2024-12-10 at 10 47 31 AM (2)

Copy link

@ChanYiLin ChanYiLin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@derekbit derekbit left a comment

Choose a reason for hiding this comment

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

LGTM

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.

4 participants