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
Migrate "Design > Image Settings" #35192
Migrate "Design > Image Settings" #35192
Conversation
d7a6576
to
abf5f6e
Compare
foreach ($configuredImageFormats as $imageFormat) { | ||
// For JPG images, we let Imagemanager decide what to do and choose between JPG/PNG. | ||
// For webp and avif extensions, we want it to follow our command and ignore the original format. | ||
$forceFormat = ($imageFormat !== 'jpg'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the current code, there have been some changes in #34172. :-)
// Else show the format selector... | ||
$parentImageFormat.show(); | ||
// and the formats by the type selected | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a @ts-ignore here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, is it because ot the formatId: any
maybe ti should be formatId: int
instead?
src/Core/Domain/ImageSettings/Command/BulkDeleteImageTypeCommand.php
Outdated
Show resolved
Hide resolved
src/Core/Domain/ImageSettings/Command/DeleteImageTypeCommand.php
Outdated
Show resolved
Hide resolved
src/Core/Domain/ImageSettings/Command/DeleteImagesFromTypeCommand.php
Outdated
Show resolved
Hide resolved
src/Core/Form/IdentifiableObject/DataHandler/ImageTypeFormDataHandler.php
Show resolved
Hide resolved
src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php
Outdated
Show resolved
Hide resolved
Adding tests could also be helpful. |
abf5f6e
to
5b33a0f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/Core/Grid/Definition/Factory/ImageTypeGridDefinitionFactory.php
Outdated
Show resolved
Hide resolved
cc20e1c
to
8beb2b1
Compare
0058742
to
924c38c
Compare
Tests before merging: https://github.com/boherm/ga.tests.ui.pr/actions/runs/7841551459 |
924c38c
to
683dfa2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, sorry for the late review
I have a few questions maybe not blocking but still worth thinking about if we want to maintain consistency. I still need to review the behat part, but the only thing really blocking for me though is the lack of AdminSecurity
on one of the controllers
...js/components/grid/extension/action/row/image_type/delete-image-type-row-action-extension.ts
Show resolved
Hide resolved
$parentImageFormat.hide(); | ||
|
||
// On image type change, show the image format by the type selected | ||
$selectImage.on('change', (event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like there is a remaining ESlint warning, even though it doesn't seem to be blocking the CI it'd be nice to fix or all the following PRs will have this warning
// Else show the format selector... | ||
$parentImageFormat.show(); | ||
// and the formats by the type selected | ||
// @ts-ignore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, is it because ot the formatId: any
maybe ti should be formatId: int
instead?
if (!file_exists($dir . $image) || !filesize($dir . $image)) { | ||
$errors[] = $this->translator->trans('Source file does not exist or is empty (%filepath%)', ['%filepath%' => $dir . $image], 'Admin.Design.Notification'); | ||
} else { | ||
if (!LegacyImageManager::resize( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One day it'd be nice to refactor this legacy tool with more modern code, but not the scope of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like I wrote in the description, PLEASE YES!
Btw, I will create a new issue about this right after merge this PR.
/** | ||
* @return Image[] | ||
*/ | ||
public function getAllImages(): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one has risks of returning a lot of data on shops with millions of images, but it was maybe already the case in legacy page and could be improved in another topic dedicated to performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the first reason to find a better way in the futur about this.
src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php
Show resolved
Hide resolved
src/PrestaShopBundle/Controller/Admin/Improve/Design/ImageSettingsController.php
Show resolved
Hide resolved
src/PrestaShopBundle/Form/Admin/Improve/Design/ImageSettings/DeleteImageTypeType.php
Show resolved
Hide resolved
src/PrestaShopBundle/Form/Admin/Improve/Design/ImageSettings/ImageSettingsFormDataProvider.php
Show resolved
Hide resolved
src/PrestaShopBundle/Resources/views/Admin/Common/Grid/Columns/Content/pixel_data.html.twig
Show resolved
Hide resolved
} | ||
|
||
// Delete all images linked to image type | ||
$this->deleteImagesFromType('small_default', _PS_IMG_DIR_ . '{c,m,su,p,st}/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to dynamize the hard-coded value here
* | ||
* @throws ImageTypeException | ||
*/ | ||
public function deleteImagesFromType($imageTypeName, $path): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in a dedicated service
683dfa2
to
6ad5b77
Compare
6ad5b77
to
869d3d9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @boherm
Almost all good, just a typo in the name of a handler to fix
The other suggestions in behat tests are optional so it's up to you
/** | ||
* Defines contract for BulkImageTypeHandler | ||
*/ | ||
interface BulkImageTypeHandlerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
interface BulkImageTypeHandlerInterface | |
interface BulkDeleteImageTypeHandlerInterface |
* Handles command that bulk delete image types | ||
*/ | ||
#[AsCommandHandler] | ||
class BulkImageTypeHandler extends AbstractBulkCommandHandler implements BulkImageTypeHandlerInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class BulkImageTypeHandler extends AbstractBulkCommandHandler implements BulkImageTypeHandlerInterface | |
class BulkDeleteImageTypeHandler extends AbstractBulkCommandHandler implements BulkImageTypeHandlerInterface |
tests/Integration/Behaviour/Features/Context/Domain/ImageSettings/ImageTypeContext.php
Show resolved
Hide resolved
$this->getSharedStorage()->exists($imageTypeName); | ||
$imageTypeId = $this->getSharedStorage()->get($imageTypeName); | ||
$command = new DeleteImageTypeCommand($imageTypeId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->getSharedStorage()->exists($imageTypeName); | |
$imageTypeId = $this->getSharedStorage()->get($imageTypeName); | |
$command = new DeleteImageTypeCommand($imageTypeId); | |
$command = new DeleteImageTypeCommand($this->getSharedStorage()->get($imageTypeName)); |
Just a suggestion, but since the get
method already checks if the key exist this code could be simplified (same suggestion for other similar use cases in this PR, but also optional) especially since exists
simply return a bool and does not trigger an exception so calling it like this doesn't bring anything
| generation-method | 1 | | ||
| picture-max-size | 5000 | | ||
| picture-max-width | 123 | | ||
| picture-max-height | 345 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional, but maybe you could add an EOL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @boherm
🎉 😄 |
This new page is hidden behind a feature flag.
2. Go to "Design > Image Settings" pages.
3. Use the pages as usual.
For now, I have created an adapter to regenerate images, but I think that we should find/create and use an optimized brand new way to do this task. Maybe, we can create an issue about this change!