Skip to content

Commit 0d75669

Browse files
ENGCOM-8008: 1523: Switching between Views does not change the selected folder. [Media Gallery] #29411
- Merge Pull Request #29411 from joweecaquicla/magento2:ASI-1523-switching-between-views-does-not-change-the-selected-folder - Merged commits: 1. 8020a01 2. 8e1e390 3. ee2ab23 4. e94ffe6 5. 3396cfd 6. 20dc815 7. 58efb76 8. 60da76c 9. a516ee5 10. 0d0aa22 11. eb1f0bb 12. 36074a9 13. 9a69a6a 14. 79c8386 15. 4a354da 16. ae61599 17. a68bbbd 18. e533396 19. 218c017
2 parents 1ce8bcb + 218c017 commit 0d75669

File tree

12 files changed

+247
-171
lines changed

12 files changed

+247
-171
lines changed

app/code/Magento/MediaGallery/Model/Directory/Command/CreateByPaths.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function execute(array $paths): void
7878
if (!empty($failedPaths)) {
7979
throw new CouldNotSaveException(
8080
__(
81-
'Could not save directories: %paths',
81+
'Could not create directories: %paths',
8282
[
8383
'paths' => implode(' ,', $failedPaths)
8484
]

app/code/Magento/MediaGalleryUi/Model/Directories/GetFolderTree.php

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
namespace Magento\MediaGalleryUi\Model\Directories;
99

10+
use Magento\Framework\App\Filesystem\DirectoryList;
1011
use Magento\Framework\Exception\ValidatorException;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Filesystem\Directory\Read;
1314
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;
1415

1516
/**
16-
* Build folder tree structure by path
17+
* Build media gallery folder tree structure by path
1718
*/
1819
class GetFolderTree
1920
{
@@ -22,43 +23,45 @@ class GetFolderTree
2223
*/
2324
private $filesystem;
2425

25-
/**
26-
* @var string
27-
*/
28-
private $path;
29-
3026
/**
3127
* @var IsPathExcludedInterface
3228
*/
3329
private $isPathExcluded;
3430

3531
/**
36-
* Constructor
37-
*
3832
* @param Filesystem $filesystem
39-
* @param string $path
4033
* @param IsPathExcludedInterface $isPathExcluded
4134
*/
4235
public function __construct(
4336
Filesystem $filesystem,
44-
string $path,
4537
IsPathExcludedInterface $isPathExcluded
4638
) {
4739
$this->filesystem = $filesystem;
48-
$this->path = $path;
4940
$this->isPathExcluded = $isPathExcluded;
5041
}
5142

5243
/**
5344
* Return directory folder structure in array
5445
*
55-
* @param bool $skipRoot
5646
* @return array
5747
* @throws ValidatorException
5848
*/
59-
public function execute(bool $skipRoot = true): array
49+
public function execute(): array
6050
{
61-
return $this->buildFolderTree($this->getDirectories(), $skipRoot);
51+
$tree = [
52+
'name' => 'root',
53+
'path' => '/',
54+
'children' => []
55+
];
56+
$directories = $this->getDirectories();
57+
foreach ($directories as $idx => &$node) {
58+
$node['children'] = [];
59+
$result = $this->findParent($node, $tree);
60+
$parent = &$result['treeNode'];
61+
62+
$parent['children'][] = &$directories[$idx];
63+
}
64+
return $tree['children'];
6265
}
6366

6467
/**
@@ -72,7 +75,7 @@ private function getDirectories(): array
7275
$directories = [];
7376

7477
/** @var Read $directory */
75-
$directory = $this->filesystem->getDirectoryRead($this->path);
78+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
7679

7780
if (!$directory->isDirectory()) {
7881
return $directories;
@@ -96,30 +99,6 @@ private function getDirectories(): array
9699
return $directories;
97100
}
98101

99-
/**
100-
* Build folder tree structure by provided directories path
101-
*
102-
* @param array $directories
103-
* @param bool $skipRoot
104-
* @return array
105-
*/
106-
private function buildFolderTree(array $directories, bool $skipRoot): array
107-
{
108-
$tree = [
109-
'name' => 'root',
110-
'path' => '/',
111-
'children' => []
112-
];
113-
foreach ($directories as $idx => &$node) {
114-
$node['children'] = [];
115-
$result = $this->findParent($node, $tree);
116-
$parent = & $result['treeNode'];
117-
118-
$parent['children'][] =& $directories[$idx];
119-
}
120-
return $skipRoot ? $tree['children'] : $tree;
121-
}
122-
123102
/**
124103
* Find parent directory
125104
*
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AssertFolderIsChangedActionGroup">
12+
<annotations>
13+
<description>Assert that folder is changed</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="newSelectedFolder" type="string"/>
17+
<argument name="oldSelectedFolder" type="string" defaultValue="{{AdminMediaGalleryFolderData.name}}"/>
18+
</arguments>
19+
20+
<assertNotEquals stepKey="assertNotEqual">
21+
<actualResult type="string">{{newSelectedFolder}}</actualResult>
22+
<expectedResult type="string">{{oldSelectedFolder}}</expectedResult>
23+
</assertNotEquals>
24+
</actionGroup>
25+
</actionGroups>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminMediaGallerySwitchingBetweenViewsTest">
11+
<annotations>
12+
<features value="MediaGallery"/>
13+
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1523"/>
14+
<title value="User switches between Views and checks if the folder is changed"/>
15+
<stories value="User switches between Views and checks if the folder is changed"/>
16+
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1337102/scenarios/5060037"/>
17+
<description value="User switches between Views and checks if the folder is changed"/>
18+
<severity value="CRITICAL"/>
19+
<group value="media_gallery_ui"/>
20+
</annotations>
21+
<before>
22+
<createData entity="SimpleSubCategory" stepKey="category"/>
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
</before>
25+
<after>
26+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
27+
<actionGroup ref="AdminEnhancedMediaGalleryDeleteGridViewActionGroup" stepKey="deleteView">
28+
<argument name="viewToDelete" value="New View"/>
29+
</actionGroup>
30+
<actionGroup ref="AdminMediaGalleryFolderSelectActionGroup" stepKey="selectFolderForDelete"/>
31+
<actionGroup ref="AdminMediaGalleryFolderDeleteActionGroup" stepKey="deleteFolder"/>
32+
<actionGroup ref="AdminMediaGalleryAssertFolderDoesNotExistActionGroup" stepKey="assertFolderWasDeleted"/>
33+
<deleteData createDataKey="category" stepKey="deleteCategory"/>
34+
</after>
35+
<actionGroup ref="AdminOpenCreateNewCMSPageActionGroup" stepKey="openNewPage"/>
36+
<actionGroup ref="AdminOpenMediaGalleryFromPageNoEditorActionGroup" stepKey="openMediaGalleryForPage"/>
37+
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilters"/>
38+
<actionGroup ref="AdminMediaGalleryOpenNewFolderFormActionGroup" stepKey="openNewFolderForm"/>
39+
<actionGroup ref="AdminMediaGalleryCreateNewFolderActionGroup" stepKey="createNewFolder"/>
40+
<actionGroup ref="AdminMediaGalleryAssertFolderNameActionGroup" stepKey="assertNewFolderCreated"/>
41+
<waitForLoadingMaskToDisappear stepKey="waitForFolderContents"/>
42+
<actionGroup ref="AdminEnhancedMediaGallerySaveCustomViewActionGroup" stepKey="saveCustomView">
43+
<argument name="viewName" value="New View"/>
44+
</actionGroup>
45+
<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openCategoryPage"/>
46+
<actionGroup ref="AdminCategoriesOpenCategoryActionGroup" stepKey="openCategory">
47+
<argument name="category" value="$$category$$"/>
48+
</actionGroup>
49+
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
50+
<actionGroup ref="AdminEnhancedMediaGallerySelectCustomBookmarksViewActionGroup" stepKey="selectDefaultView">
51+
<argument name="selectView" value="Default View"/>
52+
</actionGroup>
53+
<actionGroup ref="AssertFolderIsChangedActionGroup" stepKey="assertFolderIsChanged">
54+
<argument name="newSelectedFolder" value="category" />
55+
</actionGroup>
56+
<actionGroup ref="AdminEnhancedMediaGallerySelectCustomBookmarksViewActionGroup" stepKey="switchBackToNewView">
57+
<argument name="selectView" value="New View"/>
58+
</actionGroup>
59+
<actionGroup ref="AdminEnhancedMediaGalleryAssertActiveFiltersActionGroup" stepKey="assertFilterApplied">
60+
<argument name="resultValue" value="{{AdminMediaGalleryFolderData.name}}"/>
61+
</actionGroup>
62+
</test>
63+
</tests>

app/code/Magento/MediaGalleryUi/Test/Mftf/Test/AdminMediaGalleryUploadCategoryImageTest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImage"/>
3737
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
3838
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
39+
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
3940
<actionGroup ref="AdminMediaGalleryAssertImageInGridActionGroup" stepKey="assertImageInGrid">
4041
<argument name="title" value="ProductImage.filename"/>
4142
</actionGroup>

app/code/Magento/MediaGalleryUi/Ui/Component/DirectoriesTree.php renamed to app/code/Magento/MediaGalleryUi/Ui/Component/DirectoryTree.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Directories tree component
1616
*/
17-
class DirectoriesTree extends Container
17+
class DirectoryTree extends Container
1818
{
1919
/**
2020
* @var UrlInterface
@@ -50,9 +50,9 @@ public function prepare(): void
5050
array_replace_recursive(
5151
(array) $this->getData('config'),
5252
[
53-
'getDirectoryTreeUrl' => $this->url->getUrl("media_gallery/directories/gettree"),
54-
'deleteDirectoryUrl' => $this->url->getUrl("media_gallery/directories/delete"),
55-
'createDirectoryUrl' => $this->url->getUrl("media_gallery/directories/create")
53+
'getDirectoryTreeUrl' => $this->url->getUrl('media_gallery/directories/gettree'),
54+
'deleteDirectoryUrl' => $this->url->getUrl('media_gallery/directories/delete'),
55+
'createDirectoryUrl' => $this->url->getUrl('media_gallery/directories/create')
5656
]
5757
)
5858
);

app/code/Magento/MediaGalleryUi/etc/di.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
</argument>
2929
</arguments>
3030
</type>
31-
<type name="Magento\MediaGalleryUi\Model\Directories\GetFolderTree">
32-
<arguments>
33-
<argument name="path" xsi:type="string">media</argument>
34-
</arguments>
35-
</type>
3631
<type name="Magento\MediaGallerySynchronizationApi\Model\ImportFilesComposite">
3732
<plugin name="createMediaGalleryThumbnails" type="Magento\MediaGalleryUi\Plugin\CreateThumbnails"/>
3833
</type>

app/code/Magento/MediaGalleryUi/view/adminhtml/ui_component/media_gallery_listing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
</container>
220220
</listingToolbar>
221221
<container name="media_gallery_directories"
222-
class="Magento\MediaGalleryUi\Ui\Component\DirectoriesTree"
222+
class="Magento\MediaGalleryUi\Ui\Component\DirectoryTree"
223223
template="Magento_MediaGalleryUi/grid/directories/directoryTree"
224224
component="Magento_MediaGalleryUi/js/directory/directoryTree"/>
225225
<columns name="media_gallery_columns" component="Magento_MediaGalleryUi/js/grid/masonry">

app/code/Magento/MediaGalleryUi/view/adminhtml/ui_component/standalone_media_gallery_listing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
</container>
207207
</listingToolbar>
208208
<container name="media_gallery_directories"
209-
class="Magento\MediaGalleryUi\Ui\Component\DirectoriesTree"
209+
class="Magento\MediaGalleryUi\Ui\Component\DirectoryTree"
210210
template="Magento_MediaGalleryUi/grid/directories/directoryTree"
211211
component="Magento_MediaGalleryUi/js/directory/directoryTree"/>
212212
<columns name="media_gallery_columns" component="Magento_MediaGalleryUi/js/grid/masonry">

app/code/Magento/MediaGalleryUi/view/adminhtml/web/js/action/deleteImageWithDetailConfirmation.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,24 @@ define([
2121
* @param {String} deleteImageUrl
2222
*/
2323
deleteImageAction: function (recordsIds, imageDetailsUrl, deleteImageUrl) {
24-
var confirmationContent = $t('%1 Are you sure you want to delete "%2" image(s)?')
24+
var confirmationContent = $t('%1Are you sure you want to delete "%2" image(s)?')
2525
.replace('%2', Object.keys(recordsIds).length),
2626
deferred = $.Deferred();
2727

28-
getDetails(imageDetailsUrl, recordsIds)
29-
.then(function (imageDetails) {
28+
getDetails(imageDetailsUrl, recordsIds).then(function (images) {
3029
confirmationContent = confirmationContent.replace(
3130
'%1',
32-
this.getRecordRelatedContentMessage(imageDetails)
31+
this.getRecordRelatedContentMessage(images) + ' '
3332
);
3433
}.bind(this)).fail(function () {
35-
confirmationContent = confirmationContent.replace('%1', '');
36-
}).always(function () {
37-
deleteImages(recordsIds, deleteImageUrl, confirmationContent).then(function (status) {
38-
deferred.resolve(status);
39-
}).fail(function (error) {
40-
deferred.reject(error);
41-
});
42-
});
34+
confirmationContent = confirmationContent.replace('%1', '');
35+
}).always(function () {
36+
deleteImages(recordsIds, deleteImageUrl, confirmationContent).then(function (status) {
37+
deferred.resolve(status);
38+
}).fail(function (error) {
39+
deferred.reject(error);
40+
});
41+
});
4342

4443
return deferred.promise();
4544
},

0 commit comments

Comments
 (0)