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

Uploaders - Refactor and fixes #5478

Merged
merged 93 commits into from
Nov 7, 2024
Merged

Uploaders - Refactor and fixes #5478

merged 93 commits into from
Nov 7, 2024

Conversation

pxpm
Copy link
Contributor

@pxpm pxpm commented Mar 21, 2024

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

@tabacitu
Copy link
Member

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.

@pxpm pxpm changed the title WIP Uploaders - Refactor and fixes Apr 3, 2024
@pxpm
Copy link
Contributor Author

pxpm commented Apr 4, 2024

Check #5484 before merging this.

@karandatwani92
Copy link
Contributor

karandatwani92 commented Apr 5, 2024

Hey @pxpm

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

  • 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.

@pxpm
Copy link
Contributor Author

pxpm commented Apr 5, 2024

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.

@karandatwani92
Copy link
Contributor

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.

@pxpm
Copy link
Contributor Author

pxpm commented Apr 10, 2024

@karandatwani92 test issues:

  • Dropzone don't work without defining validation.

  • 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 [WIP] upload vs upload_multiple file display inconsistent behavior.  #5491 for further discussion on the topic.

@karandatwani92
Copy link
Contributor

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)❌

@pxpm
Copy link
Contributor Author

pxpm commented Apr 17, 2024

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 🙏

@karandatwani92
Copy link
Contributor

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
Copy link
Contributor

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

@pxpm
Copy link
Contributor Author

pxpm commented May 24, 2024

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
Copy link
Contributor Author

pxpm commented May 26, 2024

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

@karandatwani92
Copy link
Contributor

Hey @pxpm

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

@pxpm pxpm changed the base branch from main to v7 October 9, 2024 13:39
@tabacitu tabacitu assigned tabacitu and unassigned pxpm and jcastroa87 Nov 7, 2024
@tabacitu tabacitu merged commit 7bf60ea into next Nov 7, 2024
8 checks passed
@tabacitu tabacitu deleted the fix-uploaders branch November 7, 2024 13:42
@tabacitu tabacitu mentioned this pull request Nov 7, 2024
2 tasks
pxpm added a commit that referenced this pull request Nov 21, 2024
* add method to get ajax uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* use an abstract class

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* refactor uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* refactor rules

* Apply fixes from StyleCI

[ci skip] [skip ci]

* move ajax to PRO, cleanup

* Apply fixes from StyleCI

[ci skip] [skip ci]

* make attributes available for all subfields

* fix tests

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* upload multiple and upload properly working 🙏

* fixes

* Apply fixes from StyleCI

[ci skip] [skip ci]

* allow the configuration of valueWithoutPath call.

* fix valid upload inside repeatables

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix condition

* cleanup

* fix

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix use case for enabling validation after entry is created

* Apply fixes from StyleCI

[ci skip] [skip ci]

* dont save array keys

* fix ajax validation

* fix validation messages

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fixes ValidUpload

* Apply fixes from StyleCI

[ci skip] [skip ci]

* dont json encode if casted in the model

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix previous file identification in repeatable

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix getting values

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add fake fields support

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip add uploaders tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add pro columns

* fix test suite

* fix tests

* ffix tests

* remove unused test views

* add uploaders to test coverage

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add coverage folder to gitignore

* make tests run faster by not reloading db when not necessary

* add coverage to validation tests

* add fake tests to uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add more tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add more upload assets

* fixes

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix single file

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add image column

* fix tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* remove hardcoded macro names

* Apply fixes from StyleCI

[ci skip] [skip ci]

* remove double loop, fix single file uploader

* Apply fixes from StyleCI

[ci skip] [skip ci]

* use a big increments and unsigned for primary key

* handle pivot file deletion

* Apply fixes from StyleCI

[ci skip] [skip ci]

* register events for relation models

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix typo

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix relationship uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* update temporary time key

* save objects in the macro

---------

Co-authored-by: StyleCI Bot <[email protected]>
pxpm added a commit that referenced this pull request Nov 28, 2024
* add method to get ajax uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* use an abstract class

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* refactor uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* refactor rules

* Apply fixes from StyleCI

[ci skip] [skip ci]

* move ajax to PRO, cleanup

* Apply fixes from StyleCI

[ci skip] [skip ci]

* make attributes available for all subfields

* fix tests

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* upload multiple and upload properly working 🙏

* fixes

* Apply fixes from StyleCI

[ci skip] [skip ci]

* allow the configuration of valueWithoutPath call.

* fix valid upload inside repeatables

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix condition

* cleanup

* fix

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix use case for enabling validation after entry is created

* Apply fixes from StyleCI

[ci skip] [skip ci]

* dont save array keys

* fix ajax validation

* fix validation messages

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fixes ValidUpload

* Apply fixes from StyleCI

[ci skip] [skip ci]

* dont json encode if casted in the model

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix previous file identification in repeatable

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix getting values

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add fake fields support

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip add uploaders tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add pro columns

* fix test suite

* fix tests

* ffix tests

* remove unused test views

* add uploaders to test coverage

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add coverage folder to gitignore

* make tests run faster by not reloading db when not necessary

* add coverage to validation tests

* add fake tests to uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add more tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add more upload assets

* fixes

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix single file

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add image column

* fix tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* remove hardcoded macro names

* Apply fixes from StyleCI

[ci skip] [skip ci]

* remove double loop, fix single file uploader

* Apply fixes from StyleCI

[ci skip] [skip ci]

* use a big increments and unsigned for primary key

* handle pivot file deletion

* Apply fixes from StyleCI

[ci skip] [skip ci]

* register events for relation models

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix typo

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix relationship uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* update temporary time key

* save objects in the macro

---------

Co-authored-by: StyleCI Bot <[email protected]>
pxpm added a commit that referenced this pull request Dec 3, 2024
* add method to get ajax uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* use an abstract class

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* refactor uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* refactor rules

* Apply fixes from StyleCI

[ci skip] [skip ci]

* move ajax to PRO, cleanup

* Apply fixes from StyleCI

[ci skip] [skip ci]

* make attributes available for all subfields

* fix tests

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* upload multiple and upload properly working 🙏

* fixes

* Apply fixes from StyleCI

[ci skip] [skip ci]

* allow the configuration of valueWithoutPath call.

* fix valid upload inside repeatables

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix condition

* cleanup

* fix

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix use case for enabling validation after entry is created

* Apply fixes from StyleCI

[ci skip] [skip ci]

* dont save array keys

* fix ajax validation

* fix validation messages

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fixes ValidUpload

* Apply fixes from StyleCI

[ci skip] [skip ci]

* dont json encode if casted in the model

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix previous file identification in repeatable

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix getting values

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add fake fields support

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip add uploaders tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add pro columns

* fix test suite

* fix tests

* ffix tests

* remove unused test views

* add uploaders to test coverage

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add coverage folder to gitignore

* make tests run faster by not reloading db when not necessary

* add coverage to validation tests

* add fake tests to uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add more tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add more upload assets

* fixes

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix single file

* Apply fixes from StyleCI

[ci skip] [skip ci]

* add image column

* fix tests

* Apply fixes from StyleCI

[ci skip] [skip ci]

* remove hardcoded macro names

* Apply fixes from StyleCI

[ci skip] [skip ci]

* remove double loop, fix single file uploader

* Apply fixes from StyleCI

[ci skip] [skip ci]

* use a big increments and unsigned for primary key

* handle pivot file deletion

* Apply fixes from StyleCI

[ci skip] [skip ci]

* register events for relation models

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix typo

* Apply fixes from StyleCI

[ci skip] [skip ci]

* fix relationship uploaders

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* wip

* Apply fixes from StyleCI

[ci skip] [skip ci]

* update temporary time key

* save objects in the macro

---------

Co-authored-by: StyleCI Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants