CRUD icon indicating copy to clipboard operation
CRUD copied to clipboard

Uploaders - Refactor and fixes

Open pxpm opened this issue 11 months ago • 13 comments

This PR aims to fix and at the same time refactor uploaders and it's related validation classes.

Since launched some issues were identified for example the lack of validation support inside repeatables, or the tight coupling between an "ajax uploader" and a "dropzone uploader", that would prevent us from adding other types of ajax uploads like EasyMDE. Issues in dropzone validation .. etc.

There is a companion PR to this one in: https://github.com/Laravel-Backpack/PRO/pull/232

pxpm avatar Mar 21 '24 11:03 pxpm

Please please PLEASE start writing a title and description for every PR you create Pedro. It takes 2-3 minutes, man. And it helps YOU and the rest of the team understand what's happening there.

I swear I will start closing PRs that are not descriptive. You've been warned.

tabacitu avatar Mar 25 '24 02:03 tabacitu

Check https://github.com/Laravel-Backpack/CRUD/issues/5484 before merging this.

pxpm avatar Apr 04 '24 09:04 pxpm

Hey @pxpm

I tested fields of uploaders-test-branch. I'm facing many issues with it:

  • [x] 1) Base64 Image CRUD::field('image')->type('image'); results✔️(fixed in demo branch): image

  • [ ] 2) Dropezone not working without validation, results:❌

image

  • [ ] 3) EasyMDE Setting custom destination & path breaks it.❌
CRUD::field('easymde')->type('easymde')->withFiles([
  'disk' => 'public',
  'path' => 'destinations'
]);
  • [ ] 4) Upload Multiple IDK exactly when, but some combination empty the array and removes the past stored items of another Multiple Upload field.❌

I'm considering testing subfields after the Green Flag on the above direct-use fields.

karandatwani92 avatar Apr 05 '24 10:04 karandatwani92

I am sorry @karandatwani92

But I am not able to reproduce any of the issue you mentioned: image

I think I made the mistake of giving the test branch I used, I should have just let you guys create your own tests. It was intended to be used aa a guide, the branch it's not working AFAIK, it's missing routes for example.

I think in 1) it's clearly missing ->withFiles(). 🤷

I couldn't reproduce any of the other bugs you mentioned. The image of the easy mde in the screenshot is in:

CRUD::field('easymde')->type('easymde')->withFiles([
            'path' => 'test',
        ]);

image

Let me know if I can help you with something.

pxpm avatar Apr 05 '24 11:04 pxpm

Hey @pxpm, I'm facing the same issues even with a fresh installation. PLUS, I found one more bug:

  • [ ] Using an upload field with ['disk'=>'public', 'path'=>'destination'] attributes appends the path to the stored path(old file on different path), which breaks the URL. It is not supposed to append anything to the DB stored path/value. The deletion of the old file is working fine in this case.

karandatwani92 avatar Apr 07 '24 14:04 karandatwani92

@karandatwani92 test issues:

  • [x] Dropzone don't work without defining validation.

  • [x] EasyMDE appends an extra slash (/) when defining the upload with some custom path and that breaks file url.

  • [ ] Single file upload behaves different than multiple file. Single file upload builds the file using the disk and prefix, while multiple uploads use the file as is in the database. I am not sure this one is related with this PR specifically. As far as I can see, this PR does not touch Uploaders.php class, so it does not change the retrieve behavior, nor the changes done in upload.blade.php touch any of this bit. Looking at upload.blade.php history https://github.com/Laravel-Backpack/CRUD/blame/main/src/resources/views/crud/fields/upload.blade.php I don't see any changes that would have changed this behavior, so I can assume that's something @karandatwani92 found while testing this, but it's not specifically related to this changes, so I opened https://github.com/Laravel-Backpack/CRUD/issues/5491 for further discussion on the topic.

pxpm avatar Apr 10 '24 09:04 pxpm

Hey @pxpm

The above bugs are fixed✅. Now I started testing subfields under repeatable and there is an issue:

  • Suppose we created two rows and saved them. Go to Edit and Reorder - (It breaks saving: causes validation error)❌

karandatwani92 avatar Apr 13 '24 15:04 karandatwani92

Hey @pxpm

The above bugs are fixed✅. Now I started testing subfields under repeatable and there is an issue:

  • Suppose we created two rows and saved them. Go to Edit and Reorder - (It breaks saving: causes validation error)❌

Thanks @karandatwani92 haven't spotted that. 🙏 nice catch!

I've just pushed fixes both in this PR and in PRO PR to address that issue. Please note that I rebased both branches, so if you have any troubles with a git pull, please just delete the local branch and download a new copy.

Thanks again 🙏

pxpm avatar Apr 17 '24 15:04 pxpm

Hey @pxpm

New Issue: Create new, edit, and save without changes(validation error even when the file is already attached): Screenshot 2024-04-18 at 2 47 54 PM

karandatwani92 avatar Apr 18 '24 09:04 karandatwani92

New Bugs:

  1. Message for Default Validation Error is missing. (See the difference.) Screenshot 2024-05-24 at 9 09 27 PM
  2. If I switch the repeatable row position, the subfield upload value stays, but the file gets deleted. Screenshot 2024-05-24 at 9 19 08 PM

karandatwani92 avatar May 24 '24 15:05 karandatwani92

1 is not a bug, in the demo app mimetypes is not added to translations, it comes by default with Laravel since Laravel 9 if I am not mistaken, we never bothered adding it to the demo because we don't use it.

2 might be a bug, I am not sure if I have a test case covering that, if not I will add one and evaluate that scenario.

Thanks.

pxpm avatar May 24 '24 15:05 pxpm

@karandatwani92 I've identified the issue you reported in 2 and added a test alongside with the fix for it. 🙏

pxpm avatar May 26 '24 08:05 pxpm

Hey @pxpm

I tested it, and it is working completely fine. Please continue with the media uploader and we'll re-test again.

karandatwani92 avatar May 28 '24 10:05 karandatwani92