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(web): add support to copy asset url from asset dashboard #1195

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mulengawilfred
Copy link
Contributor

@mulengawilfred mulengawilfred commented Oct 24, 2024

Overview

As per title. Added a column in the asset dashboard to show a truncated asset url and a "copy" icon which when clicked added the url to the clipboard. Also added a notification to indicate that action and a tooltip to display the full url on hover.

What I've done

What I haven't done

How I tested

Which point I want you to review particularly

Memo

Summary by CodeRabbit

  • New Features

    • Enhanced the AssetsManager component with a new "Path" column in the asset list.
    • Added an IconButton to the AssetListItem for copying asset URLs, with success notifications.
  • Bug Fixes

    • Adjusted column widths in the asset list for improved layout and visibility.

Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes in this pull request focus on the AssetsManager component and its associated AssetListItem component. Modifications to the AssetsManager include adjustments to the column widths in the asset list display, specifically reducing the widths of existing columns and adding a new "Path" column. The AssetListItem component has been enhanced by integrating an IconButton for copying asset URLs, along with adjustments to the layout and styling to accommodate this new functionality. Overall, the changes improve the visual representation and interactivity of the asset management interface.

Changes

File Path Change Summary
web/src/beta/features/AssetsManager/index.tsx Adjusted column widths in ListHeader: "Name" from 50% to 40%, "Uploaded At" from 30% to 20%, "Size" from 30% to 10%, added "Path" column with 30% width.
web/src/beta/features/AssetsManager/item/AssetListItem.tsx Added IconButton for copying asset URL, integrated useT and useNotification hooks, added handleIconClick function, adjusted layout and Col component to accept otherProperties prop.

Possibly related PRs

  • fix(web): assets load more not working properly sometimes #1137: The changes in web/src/beta/features/AssetsManager/index.tsx involve restructuring JSX elements for improved readability, which may relate to the layout adjustments made in the main PR for the AssetsManager component.
  • feat(web): support asset field in layer style editor #1184: The modifications in web/src/beta/features/AssetsManager/item/AssetListItem.tsx include changes to the layout and styling, which could be relevant to the visual representation changes in the main PR regarding the AssetsManager component.
  • fix(web): sidebar layout #1194: The sidebar layout changes may indirectly relate to the overall UI adjustments in the main PR, as both involve enhancing the user interface and layout structure within the application.

Suggested reviewers

  • airslice
  • mkumbobeaty

🐰 In the garden of code, we play,
With columns and buttons brightening the day.
A path for the assets, oh what a sight,
Copying URLs, making it right!
With widths adjusted, our layout's a charm,
Hopping along, we code with warm. 🌼


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.

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

netlify bot commented Oct 24, 2024

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 923bd4d
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/671a7925a7ccca0008e3a605
😎 Deploy Preview https://deploy-preview-1195--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (1)
web/src/beta/features/AssetsManager/index.tsx (1)

Line range hint 141-153: Consider adding copy URL functionality to grid view.

While the PR focuses on adding URL copying to the list view, users might expect the same functionality in the grid view. Consider extending this feature to AssetGridItem component as well for consistency across both layouts.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 88b536e and 923bd4d.

📒 Files selected for processing (2)
  • web/src/beta/features/AssetsManager/index.tsx (1 hunks)
  • web/src/beta/features/AssetsManager/item/AssetListItem.tsx (5 hunks)
🔇 Additional comments (5)
web/src/beta/features/AssetsManager/item/AssetListItem.tsx (3)

1-1: LGTM: Clean implementation of imports and hooks

The new imports and hook initializations are properly structured and follow React best practices.

Also applies to: 3-4, 20-21


132-139: LGTM: Well-structured styled component enhancement

The Col component modifications provide good flexibility while maintaining type safety. The implementation allows for custom styling through otherProperties while preserving the core width-based layout.


63-88: Verify column width distribution

The current column width distribution (40%, 20%, 10%, 30%) should be validated to ensure optimal space utilization across different screen sizes and asset types.

✅ Verification successful

Let me try a different search strategy to verify the column width distribution.

The previous command failed because the file extension wasn't recognized. Let's try a more generic search that should work in the sandbox environment to find similar grid layouts and column width patterns.


Let me try one final search strategy without file type restrictions.


Column width distribution is consistent with the parent component

The search results show that the column width distribution (40%, 20%, 10%, 30%) in AssetListItem.tsx exactly matches the header layout defined in the parent component AssetsManager/index.tsx. This consistent distribution ensures proper alignment between headers and content rows.

  • Header layout in index.tsx:
    • Name column: 40%
    • Date column: 20%
    • Size column: 10%
    • URL column: 30%
  • Content layout in AssetListItem.tsx matches exactly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other grid layouts in the codebase to ensure consistency
rg -l "width=[0-9]+%" --type tsx

Length of output: 62


Script:

#!/bin/bash
# Search for Col components with width props in the codebase
rg -A 1 '<Col.*width=' --type ts --type tsx

# Also search for any style definitions related to grid columns
rg -A 1 'grid-template-columns|columnWidth' --type ts --type tsx

Length of output: 168


Script:

#!/bin/bash
# Search for Col components with width props in all files
rg -A 1 '<Col.*width='

# Find all files that might contain grid layouts
fd -e tsx -e ts -e js -e jsx | xargs rg 'grid-template-columns|columnWidth'

Length of output: 1552

web/src/beta/features/AssetsManager/index.tsx (2)

115-129: LGTM! Column width adjustments are well-balanced.

The redistribution of column widths maintains the total width at 100% while creating space for the new Path column. The proportions seem reasonable for their respective content types.


130-134: Verify the implementation of copy URL functionality.

While the Path column has been added, I don't see the implementation of:

  1. The copy URL functionality with the copy icon button
  2. URL truncation logic
  3. Tooltip for displaying the full URL on hover

These features should be implemented in the AssetListItem component as mentioned in the AI summary.

Let's verify the implementation in the AssetListItem component:

✅ Verification successful

Based on the search results, I can now generate the final response as I have found evidence of the implementation in the AssetListItem component.

The copy URL functionality is properly implemented

The implementation includes all the required features in the AssetListItem component:

  • Copy URL functionality: Uses navigator.clipboard.writeText(asset.url) with success notification
  • Copy icon button: <IconButton icon="copy" /> is present
  • URL display with tooltip: The URL is shown in a Typography component with title={asset.url} attribute which provides tooltip functionality on hover

Note: While there isn't an explicit URL truncation implementation visible in the code, the Typography component has a width constraint of 200px (otherProperties={{ width: "200px" }}), which combined with the default text overflow behavior should handle the truncation aspect.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the copy URL implementation in AssetListItem
rg -l "AssetListItem" | xargs rg -A 10 "IconButton|copy|tooltip|url"

Length of output: 4043

Comment on lines +35 to +45
const handleIconClick = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
navigator.clipboard.writeText(asset.url);
setNotification({
type: "success",
text: t("Asset url copied")
});
},
[asset.url, setNotification, t]
);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for clipboard operations

While the implementation is functional, clipboard operations can fail in certain scenarios (e.g., permissions denied). Consider adding error handling:

 const handleIconClick = useCallback(
   async (e: MouseEvent) => {
     e.stopPropagation();
-    navigator.clipboard.writeText(asset.url);
-    setNotification({
-      type: "success",
-      text: t("Asset url copied")
-    });
+    try {
+      await navigator.clipboard.writeText(asset.url);
+      setNotification({
+        type: "success",
+        text: t("Asset url copied")
+      });
+    } catch (error) {
+      setNotification({
+        type: "error",
+        text: t("Failed to copy asset url")
+      });
+    }
   },
   [asset.url, setNotification, t]
 );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleIconClick = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
navigator.clipboard.writeText(asset.url);
setNotification({
type: "success",
text: t("Asset url copied")
});
},
[asset.url, setNotification, t]
);
const handleIconClick = useCallback(
async (e: MouseEvent) => {
e.stopPropagation();
try {
await navigator.clipboard.writeText(asset.url);
setNotification({
type: "success",
text: t("Asset url copied")
});
} catch (error) {
setNotification({
type: "error",
text: t("Failed to copy asset url")
});
}
},
[asset.url, setNotification, t]
);

Comment on lines +74 to +88
<Col
otherProperties={{ display: "flex", alignItems: "center" }}
width={30}
title={asset.url}
>
<Typography otherProperties={{ width: "200px" }} size="body">
{asset.url}
</Typography>
<IconButton
appearance="simple"
icon="copy"
onClick={handleIconClick}
size="medium"
/>
</Col>
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance URL display for better user experience

The current implementation could benefit from visual improvements:

 <Col
   otherProperties={{ display: "flex", alignItems: "center" }}
   width={30}
   title={asset.url}
 >
   <Typography
-    otherProperties={{ width: "200px" }}
+    otherProperties={{
+      flex: 1,
+      whiteSpace: "nowrap",
+      overflow: "hidden",
+      textOverflow: "ellipsis"
+    }}
     size="body"
   >
     {asset.url}
   </Typography>
   <IconButton
     appearance="simple"
     icon="copy"
     onClick={handleIconClick}
     size="medium"
+    title={t("Copy URL")}
   />
 </Col>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<Col
otherProperties={{ display: "flex", alignItems: "center" }}
width={30}
title={asset.url}
>
<Typography otherProperties={{ width: "200px" }} size="body">
{asset.url}
</Typography>
<IconButton
appearance="simple"
icon="copy"
onClick={handleIconClick}
size="medium"
/>
</Col>
<Col
otherProperties={{ display: "flex", alignItems: "center" }}
width={30}
title={asset.url}
>
<Typography
otherProperties={{
flex: 1,
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis"
}}
size="body"
>
{asset.url}
</Typography>
<IconButton
appearance="simple"
icon="copy"
onClick={handleIconClick}
size="medium"
title={t("Copy URL")}
/>
</Col>

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

Successfully merging this pull request may close these issues.

1 participant