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: support V2 Backing Image in UI #831

Merged
merged 5 commits into from
Dec 20, 2024

Conversation

houhoucoop
Copy link
Contributor

@houhoucoop houhoucoop commented Dec 19, 2024

What this PR does / why we need it

  • Add Data Engine select in create backing image modal
  • Add new column Data Engine to backing image table
  • Disable Download options for v2 backing image
  • Disable bulk action Download if user select one of v2 backing image

Issue

[UI][FEATURE] Support V2 Backing Image in UI #9880

Test Result

User are able to select Data Engine when create a backing image
Screenshot 2024-12-19 at 5 25 08 PM (2)

Show Data Engine info on the table
Screenshot 2024-12-19 at 5 25 02 PM (2)

Disable Download options for v2 backing image
Screenshot 2024-12-19 at 5 46 00 PM (2)

Disable bulk action Download if user select one of v2 backing image
Screenshot 2024-12-19 at 5 47 07 PM (2)

Additional documentation or context

Test with LONGHORN_MANAGER_IP=http://159.89.205.43:30001/ npm run dev

Summary by CodeRabbit

  • New Features

    • Added a "Data Engine" column to the backing image list for improved visibility.
    • Introduced a new field for selecting data engine versions in the backing image creation modal, with validation logic.
  • Enhancements

    • Modified button disabling logic for download actions based on selected rows and data engine version.
    • Increased column widths in the backup backing image list for better content display.
  • Bug Fixes

    • Updated tooltip logic for backup actions to improve user guidance.

@houhoucoop houhoucoop self-assigned this Dec 19, 2024
Copy link

coderabbitai bot commented Dec 19, 2024

Walkthrough

The pull request introduces enhancements to the Backing Image management system, focusing on data engine version control and user interface improvements. Changes span multiple files in the src/routes/backingImage/ directory, adding a new dataEngine field, updating column configurations, and implementing version-specific validation and action restrictions. The modifications provide more granular control over backing image creation, listing, and actions while maintaining the existing component structures.

Changes

File Change Summary
BackingImageActions.js - Added condition to disable 'Download' action for 'v2' data engine
- Updated tooltip logic for backup action
BackingImageBulkActions.js - Enhanced 'Download' action disabling conditions
- Added check for 'v2' data engine in selected rows
BackingImageList.js - Added new "Data Engine" column to list view
BackupBackingImageList.js - Increased column widths for 'State', 'Backup Target', 'Size', and 'Created Time'
CreateBackingImage.js - Added dataEngine field with v1 and v2 options
- Implemented data engine version validation
- Updated genDataFromType to include dataEngine
index.js - Refactored settings handling
- Added explicit checks for data engine settings
- Updated prop passing for create modal

Sequence Diagram

sequenceDiagram
    participant User
    participant CreateBackingImage
    participant BackingImageActions
    
    User->>CreateBackingImage: Select Data Engine
    CreateBackingImage->>CreateBackingImage: Validate Data Engine
    CreateBackingImage-->>User: Enable/Disable Actions
    
    User->>BackingImageActions: Attempt Action
    BackingImageActions->>BackingImageActions: Check Data Engine
    BackingImageActions-->>User: Allow/Restrict Action
Loading

Poem

🐰 In the realm of backing images bright,
Data engines dance with newfound might
V1 and V2, versions so clear
Restrictions added with rabbit's cheer
A digital garden, precisely grown 🌱


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b9ffe97 and f357ca0.

📒 Files selected for processing (2)
  • src/routes/backingImage/BackingImageList.js (1 hunks)
  • src/routes/backingImage/index.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/routes/backingImage/index.js
  • src/routes/backingImage/BackingImageList.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 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.

@houhoucoop houhoucoop changed the title Issue 9880 feat: support V2 Backing Image in UI Dec 19, 2024
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: 3

🧹 Nitpick comments (3)
src/routes/backingImage/BackingImageBulkActions.js (1)

93-115: LGTM: Bulk actions configuration aligns with single action behavior

The implementation correctly:

  1. Maintains consistent v2 download restrictions across single and bulk actions
  2. Preserves existing validation logic
  3. Improves code readability through better structure

However, consider extracting the disabled state logic into shared utility functions to ensure future consistency.

+ // Add to src/utils/backingImage.js
+ export const isDownloadDisabled = (rows) => {
+   return rows.length === 0
+     || rows.every(row => !hasReadyBackingDisk(row))
+     || rows.some(row => row.dataEngine === 'v2')
+ }
+
+ export const isBackupDisabled = (rows, backupTargetAvailable) => {
+   return rows.length === 0
+     || backupTargetAvailable === false
+     || rows.every(row => !hasReadyBackingDisk(row))
+ }

  // In BackingImageBulkActions.js
  const allActions = [
    {
      key: 'download',
      name: 'Download',
-     disabled() {
-       return selectedRows.length === 0
-         || selectedRows.every(row => !hasReadyBackingDisk(row))
-         || selectedRows.some(row => row.dataEngine === 'v2')
-     }
+     disabled: () => isDownloadDisabled(selectedRows)
    },
    {
      key: 'backup',
      name: 'Back Up',
-     disabled() {
-       return selectedRows.length === 0
-         || backupTargetAvailable === false
-         || selectedRows.every(row => !hasReadyBackingDisk(row))
-     }
+     disabled: () => isBackupDisabled(selectedRows, backupTargetAvailable)
    },
  ]
src/routes/backingImage/BackingImageList.js (1)

129-141: Add visual indication for v2 backing images

Since v2 backing images have download restrictions, consider adding visual indication to help users quickly identify them.

      render: (text) => {
        return (
          <div>
-            {text}
+            {text === 'v2' ? (
+              <Tooltip title="Download not available for v2 backing images">
+                <Tag color="blue">{text}</Tag>
+              </Tooltip>
+            ) : (
+              <span>{text}</span>
+            )}
          </div>
        )
      },
src/routes/backingImage/CreateBackingImage.js (1)

89-90: Consider reversing the default values

The default values suggest v1 is enabled and v2 is disabled, but the initialization logic in the form (line 317) prefers v2 when enabled. This could be confusing.

Consider this more consistent approach:

-  v1DataEngineEnabled = true,
-  v2DataEngineEnabled = false
+  v2DataEngineEnabled = true,
+  v1DataEngineEnabled = false
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cf5fcff and b9ffe97.

📒 Files selected for processing (6)
  • src/routes/backingImage/BackingImageActions.js (1 hunks)
  • src/routes/backingImage/BackingImageBulkActions.js (1 hunks)
  • src/routes/backingImage/BackingImageList.js (1 hunks)
  • src/routes/backingImage/BackupBackingImageList.js (4 hunks)
  • src/routes/backingImage/CreateBackingImage.js (4 hunks)
  • src/routes/backingImage/index.js (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/routes/backingImage/index.js

[error] 120-120: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

🔇 Additional comments (7)
src/routes/backingImage/BackingImageActions.js (1)

55-76: LGTM: Actions configuration is well-structured and implements v2 restrictions correctly

The restructured actions array improves readability and correctly implements the download restriction for v2 backing images as per requirements.

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

50-50: Verify column width adjustments across different screen sizes

The column width increases look reasonable but should be tested across different screen sizes to ensure:

  1. No horizontal scrolling issues on smaller screens
  2. Proper content accommodation without truncation
  3. Balanced column distribution

Also applies to: 61-61, 74-74, 103-103

✅ Verification successful

Let me gather more information about the table structure and responsive behavior.


Column widths are properly configured with horizontal scrolling support

The implementation is correctly handling wide tables:

  • Total column width (1601px) is managed with horizontal scrolling (scroll={{ x: 970 }})
  • Table uses Ant Design's built-in responsive features
  • Horizontal scroll threshold is set to 970px, ensuring smaller screens can navigate the content
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the total width of columns exceeds typical screen sizes
# Description: Calculate total width of all columns

# Get all width values from the columns array
rg -n 'width:.*\d+' src/routes/backingImage/BackupBackingImageList.js | \
  grep -o '[0-9]\+' | \
  awk '{ sum += $1 } END { print "Total width: " sum "px" }'

Length of output: 172


Script:

#!/bin/bash
# Check for responsive table implementation and container width constraints
rg -A 5 -B 5 "Table|table" src/routes/backingImage/BackupBackingImageList.js

# Check for scroll related properties
rg "scroll|overflow" src/routes/backingImage/BackupBackingImageList.js

# Look for any parent container width definitions
rg "width:|maxWidth:|minWidth:" src/routes/backingImage/BackupBackingImageList.js

Length of output: 1559

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

Line range hint 3-9: Verify download restriction implementation

The PR objectives mention disabling downloads for v2 backing images. Let's verify the integration between BackingImageList and BackingImageActions.

✅ Verification successful

Download restriction for v2 backing images properly implemented

The verification confirms that the download functionality is properly restricted for v2 backing images in BackingImageActions.js. The implementation includes:

  • Download action is disabled when selected.dataEngine === 'v2'
  • The condition is correctly placed in the action configuration
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if BackingImageActions properly implements the download restriction
ast-grep --pattern 'const availableActions = $$$disabled$$$dataEngine === "v2"$$$'

# Check if the bulk actions component also implements this restriction
ast-grep --pattern 'const bulkActions = $$$disabled$$$dataEngine === "v2"$$$'

Length of output: 164


Script:

#!/bin/bash
# Let's check BackingImageActions.js for download-related code and v2 engine checks
rg -A 5 "download" src/routes/backingImage/BackingImageActions.js

# Also check for any v2 engine related conditions
rg -A 5 "dataEngine.*v2|v2.*dataEngine" src/routes/backingImage/BackingImageActions.js

# Look for the actual implementation of availableActions
ast-grep --pattern 'const availableActions = {
  $$$
}'

Length of output: 1105

src/routes/backingImage/CreateBackingImage.js (3)

27-27: LGTM: Data engine field added to payload

The dataEngine field is correctly added to the payload object in genDataFromType.


371-372: LGTM: PropTypes correctly defined

The new props are properly typed as boolean values.


315-335: Verify data engine validation logic

The validation logic correctly prevents selection of disabled engines. However, there are a few considerations:

  1. The initial value logic prefers v2 when enabled, which might not align with the default prop values
  2. The validation message could be more descriptive

Consider these improvements:

   initialValue: v2DataEngineEnabled ? 'v2' : 'v1',
   rules: [
     {
       validator: (_rule, value, callback) => {
         if ((value === 'v1' && !v1DataEngineEnabled) || (value === 'v2' && !v2DataEngineEnabled)) {
-          callback(`${value} data engine is not enabled`)
+          callback(`Data engine ${value} is not enabled in the system settings`)
         } else {
           callback()
         }
       },
     },
   ],
✅ Verification successful

Based on the codebase analysis, I can now provide the final response:

Data engine validation logic is appropriate but needs default value alignment

The validation logic is correctly implemented for preventing selection of disabled engines. The codebase shows that:

  1. The v2 data engine has special handling (disabled for download actions)
  2. The default preference for v2 when enabled is consistent with the application's behavior across volume and backing image components
  3. The validation message improvement suggestion remains valid for better user experience
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are any direct usages of data engine values
rg -l "dataEngine.*[\"']v[12][\"']" 

Length of output: 397


Script:

#!/bin/bash
# Let's check the usage context of dataEngine in these files to understand the validation patterns
rg -A 5 -B 5 "dataEngine.*[\"']v[12][\"']" src/routes/volume/CreateVolume.js src/routes/backingImage/BackingImageBulkActions.js src/routes/backingImage/BackingImageActions.js

Length of output: 2657


Script:

#!/bin/bash
# Let's check the props and default values in the component
ast-grep --pattern 'const CreateBackingImage = ({ $$$, v1DataEngineEnabled, v2DataEngineEnabled, $$$}) => {
  $$$
}'  src/routes/backingImage/CreateBackingImage.js

Length of output: 164


Script:

#!/bin/bash
# Let's check the component definition and props differently
rg -A 5 "CreateBackingImage = \(" src/routes/backingImage/CreateBackingImage.js

# Also check where this component is used to understand default prop values
rg -l "<CreateBackingImage"

Length of output: 144


Script:

#!/bin/bash
# Let's check how CreateBackingImage is used in the parent component
rg -B 5 -A 10 "<CreateBackingImage" src/routes/backingImage/index.js

# Also check the file content to understand the component definition
cat src/routes/backingImage/CreateBackingImage.js | head -n 20

Length of output: 1360

src/routes/backingImage/index.js (1)

215-216: LGTM: Data engine props correctly passed

The data engine enablement flags are properly passed to the create modal component.

src/routes/backingImage/BackingImageList.js Outdated Show resolved Hide resolved
Comment on lines 129 to 141
}, {
title: 'Data Engine',
dataIndex: 'dataEngine',
key: 'dataEngine',
width: 130,
sorter: (a, b) => a.dataEngine.toString().localeCompare(b.dataEngine.toString()),
render: (text) => {
return (
<div>
{text}
</div>
)
},
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add PropTypes validation for dataEngine field

The new dataEngine field should be included in the component's PropTypes validation.

Add the following to the PropTypes definition at the bottom of the file:

list.propTypes = {
  loading: PropTypes.bool,
  dataSource: PropTypes.arrayOf(PropTypes.shape({
+   dataEngine: PropTypes.string.isRequired,
    id: PropTypes.string.isRequired,
    // ... other existing prop validations
  })),
  // ... rest of the propTypes
}

Committable suggestion skipped: line range outside the PR's diff.

src/routes/backingImage/index.js Outdated Show resolved Hide resolved
Signed-off-by: Yi-Ya Chen <[email protected]>
Copy link
Contributor

@a110605 a110605 left a comment

Choose a reason for hiding this comment

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

LGTM

@houhoucoop houhoucoop merged commit 30274e8 into longhorn:master Dec 20, 2024
7 checks passed
@a110605
Copy link
Contributor

a110605 commented Dec 20, 2024

@houhoucoop , please backport this PR to v1.8.x branch

@houhoucoop
Copy link
Contributor Author

@mergify backport v1.8.x

Copy link

mergify bot commented Dec 20, 2024

⚠️ The sha of the head commit of this PR conflicts with #832. Mergify cannot evaluate rules on this PR. ⚠️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants