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

Fix: Copy Path does not reflect the real path of the object in the media folder #5571

Closed
wants to merge 6 commits into from

Conversation

DenysLins
Copy link

fixes #5569

Summary

In the media assets screen, there is a useful Copy Path button. When the user clicks on the button, the path copied does not reflect the path that is specified in the backend. For example, it starts with uploads when it should start with /uploads.

Test plan

  1. Go to 'Media'
  2. Select any image or file
  3. Click on Copy Path
  4. Use this path in a link
  5. The path reflects the path that is specified in the backend

screenshot

A picture of a cute animal (not mandatory but encouraged)

see the issue for details

fixes issue decaporg#5569
@DenysLins DenysLins requested a review from a team July 1, 2021 20:39
@erezrokah erezrokah added the type: bug code to address defects in shipped code label Jul 5, 2021
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Hi @DenysLins! Thanks for opening the PR.

Some comments:

  1. Should we only prepend the / if the config media_folder has a forward /? With this PR / is always added.
  2. path can be an absolute URL (not very documented, but possible with the asset store integration). Should we only prepend if the path is not an absolute URL?

add a condition to verify if the path already starts with /, so we must not add another one

fixes issue decaporg#5569
add a condition to only add a / is the path is not absolute

fixes issue decaporg#5569
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks for the quick follow up @DenysLins.

See my additional comment

const { draft, name } = this.props;
let path = this.props.path;
if (isAbsolutePath(path)) {
copyToClipboard(path);
Copy link
Contributor

Choose a reason for hiding this comment

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

🚀

if (isAbsolutePath(path)) {
copyToClipboard(path);
} else {
path = path.charAt(0) !== '/' ? `/${path}` : path;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @DenysLins, I think I wasn't clear with my last comment.

  1. If media_folder: static/upload -> The copied path should not start with a /
  2. If media_folder: /static/upload -> The copied path should start with a /

It seems to me that this code prepends a / if it doesn't already exist. Please correct me if I missed anything.

Copy link
Author

Choose a reason for hiding this comment

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

I got it. I will work in this issue...

pass the media_folder parameter and use it before setting the path

fixes issue decaporg#5569
Now media_folder must starts with / and path must not starts to be updated

fixes issue decaporg#5569
Copy link
Contributor

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

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

Thanks @DenysLins, I added another comment as I believe we're missing some use cases.

/>
);
}
}

function mapStateToProps(state) {
const { mediaLibrary } = state;
const mediaFolder = state.config.media_folder;
Copy link
Contributor

@erezrokah erezrokah Jul 14, 2021

Choose a reason for hiding this comment

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

Thanks @DenysLins, this might not be accurate as media folders can be configured per collection and per field.

We might need to pass the untrimmed value from this function https://github.com/netlify/netlify-cms/blob/b94d5f6e7fe07a2816098b377b30a4ddd39c9520/packages/netlify-cms-core/src/reducers/entries.ts#L754

Copy link
Author

Choose a reason for hiding this comment

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

OK @erezrokah ... I will apply your suggestions...

@erezrokah
Copy link
Contributor

Closing this as stale. Please comment if you'd like to pick this up

@erezrokah erezrokah closed this Sep 10, 2021
@asset-web
Copy link

From an end user's perspective if the "public_folder" vs the "media_folder" suffix was used in the "Copy path" function this would match usage for wanting to link to a PDF or non image media item using the "link" button from the markdown editor.

@pierreleripoll
Copy link

It's been a long time but problem is still there, could we do something for it ?

@martinjagodic
Copy link
Member

@pierreleripoll I can reopen this PR if you want to work on it, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Copy Path does not reflect the real path of the object in the media folder
5 participants