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

Migrate "Design > Image Settings" #35192

Conversation

boherm
Copy link
Member

@boherm boherm commented Jan 27, 2024

Questions Answers
Branch? develop
Description? Migration of "Design > Image Settings" pages in backoffice.
This new page is hidden behind a feature flag.
Type? improvement
Category? BO
BC breaks? no
Deprecations? no
How to test? 1. Enable "Image settings" feature flag.
2. Go to "Design > Image Settings" pages.
3. Use the pages as usual.
UI Tests https://github.com/boherm/ga.tests.ui.pr/actions/runs/7678776674
Fixed issue or discussion? #10563
Related PRs
Sponsor company PrestaShop SA

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!

@boherm boherm requested a review from a team as a code owner January 27, 2024 12:55
@prestonBot prestonBot added develop Branch Improvement Type: Improvement labels Jan 27, 2024
@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch from d7a6576 to abf5f6e Compare January 27, 2024 13:02
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');
Copy link
Contributor

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

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?

Copy link
Contributor

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/ValueObject/ImageTypeId.php Outdated Show resolved Hide resolved
src/Core/Grid/Query/ImageTypeQueryBuilder.php Outdated Show resolved Hide resolved
src/Core/Search/Filters/ImageTypeFilters.php Show resolved Hide resolved
@M0rgan01
Copy link
Contributor

Adding tests could also be helpful.

@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch from abf5f6e to 5b33a0f Compare January 30, 2024 08:28
matks
matks previously approved these changes Jan 30, 2024
Copy link
Contributor

@matks matks left a comment

Choose a reason for hiding this comment

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

Good for me, nothing important to add to @Hlavtox and @M0rgan01 reviews

I added 1 typo suggestion and I have 1 question.

src/Adapter/ImageThumbnailsRegenerator.php Outdated Show resolved Hide resolved
@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch 2 times, most recently from cc20e1c to 8beb2b1 Compare January 31, 2024 17:22
@M0rgan01 M0rgan01 added this to the 9.0.0 milestone Feb 1, 2024
@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch from 0058742 to 924c38c Compare February 6, 2024 18:05
matks
matks previously approved these changes Feb 8, 2024
@M0rgan01 M0rgan01 added the migration symfony migration project label Feb 8, 2024
M0rgan01
M0rgan01 previously approved these changes Feb 8, 2024
@boherm
Copy link
Member Author

boherm commented Feb 9, 2024

@boherm boherm added the Waiting for author Status: action required, waiting for author feedback label Feb 9, 2024
@WahbiPS WahbiPS removed the Waiting for author Status: action required, waiting for author feedback label Feb 12, 2024
@boherm boherm dismissed stale reviews from M0rgan01 and matks via 683dfa2 February 12, 2024 08:44
@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch from 924c38c to 683dfa2 Compare February 12, 2024 08:44
matks
matks previously approved these changes Feb 12, 2024
Copy link
Contributor

@jolelievre jolelievre left a 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

$parentImageFormat.hide();

// On image type change, show the image format by the type selected
$selectImage.on('change', (event) => {
Copy link
Contributor

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

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

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

Copy link
Member Author

@boherm boherm Feb 12, 2024

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

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?

Copy link
Member Author

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.

@ps-jarvis ps-jarvis added the Waiting for author Status: action required, waiting for author feedback label Feb 12, 2024
}

// Delete all images linked to image type
$this->deleteImagesFromType('small_default', _PS_IMG_DIR_ . '{c,m,su,p,st}/');
Copy link
Contributor

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

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

@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch from 683dfa2 to 6ad5b77 Compare February 13, 2024 15:42
@boherm boherm force-pushed the #10563-migrate-bo-design-image-settings-page branch from 6ad5b77 to 869d3d9 Compare February 13, 2024 15:43
@boherm boherm removed the Waiting for author Status: action required, waiting for author feedback label Feb 14, 2024
matks
matks previously approved these changes Feb 14, 2024
Copy link
Contributor

@jolelievre jolelievre left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
interface BulkImageTypeHandlerInterface
interface BulkDeleteImageTypeHandlerInterface

* Handles command that bulk delete image types
*/
#[AsCommandHandler]
class BulkImageTypeHandler extends AbstractBulkCommandHandler implements BulkImageTypeHandlerInterface
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class BulkImageTypeHandler extends AbstractBulkCommandHandler implements BulkImageTypeHandlerInterface
class BulkDeleteImageTypeHandler extends AbstractBulkCommandHandler implements BulkImageTypeHandlerInterface

Comment on lines 93 to 95
$this->getSharedStorage()->exists($imageTypeName);
$imageTypeId = $this->getSharedStorage()->get($imageTypeName);
$command = new DeleteImageTypeCommand($imageTypeId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$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 |
Copy link
Contributor

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

@ps-jarvis ps-jarvis added the Waiting for author Status: action required, waiting for author feedback label Feb 14, 2024
@WahbiPS WahbiPS removed the Waiting for author Status: action required, waiting for author feedback label Feb 15, 2024
Copy link
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

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

Thanks @boherm

@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Feb 15, 2024
@jolelievre jolelievre removed the Waiting for QA Status: action required, waiting for test feedback label Feb 15, 2024
@jolelievre jolelievre merged commit f88272a into PrestaShop:develop Feb 15, 2024
23 checks passed
@matks
Copy link
Contributor

matks commented Feb 15, 2024

🎉 😄

@boherm boherm deleted the #10563-migrate-bo-design-image-settings-page branch February 15, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
develop Branch Improvement Type: Improvement migration symfony migration project
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

9 participants