Skip to content

Switching between Media Gallery bookmarks does not change the selected folder #29411

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8020a01
Merge branch '2.4-develop' of github.com:magento/magento2 into ASI-15…
Aug 5, 2020
8e1e390
magento/adobe-stock-integration#1523: Switching between Views does no…
Aug 5, 2020
ee2ab23
magento/adobe-stock-integration#1523: Switching between Views does no…
Aug 5, 2020
e94ffe6
Merge branch '2.4-develop' of github.com:magento/magento2 into ASI-15…
Aug 6, 2020
3396cfd
Merge branch '2.4-develop' of github.com:magento/magento2 into ASI-15…
Aug 6, 2020
20dc815
magento/adobe-stock-integration#1523: Switching between Views does no…
Aug 6, 2020
58efb76
magento/adobe-stock-integration#1523: Switching between Views does no…
Aug 7, 2020
60da76c
magento/magento2#29411: Directory Tree refactoring
sivaschenko Aug 13, 2020
a516ee5
magento/magento2#29411: Naming update
sivaschenko Aug 18, 2020
0d0aa22
Merge branch '2.4-develop' of github.com:magento/magento2 into ASI-15…
sivaschenko Aug 18, 2020
eb1f0bb
magento/magento2#29411: Updated requested directory selection behaviour
sivaschenko Aug 18, 2020
36074a9
magento/magento2#29411: Formatting fixes
sivaschenko Aug 18, 2020
9a69a6a
magento/magento2#29411: Fixed static tests
sivaschenko Aug 18, 2020
79c8386
magento/magento2#29411: Fixed MFTF test
sivaschenko Aug 24, 2020
4a354da
Merge branch '2.4-develop' into ASI-1523-switching-between-views-does…
sivaschenko Aug 24, 2020
ae61599
Fixed static tests
sivaschenko Aug 24, 2020
a68bbbd
Fixed static tests
sivaschenko Aug 25, 2020
e533396
Fixed static tests
sivaschenko Aug 25, 2020
218c017
Merge branch '2.4-develop' into ASI-1523-switching-between-views-does…
sivaschenko Aug 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function execute(array $paths): void
if (!empty($failedPaths)) {
throw new CouldNotSaveException(
__(
'Could not save directories: %paths',
'Could not create directories: %paths',
[
'paths' => implode(' ,', $failedPaths)
]
Expand Down
57 changes: 18 additions & 39 deletions app/code/Magento/MediaGalleryUi/Model/Directories/GetFolderTree.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

namespace Magento\MediaGalleryUi\Model\Directories;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Exception\ValidatorException;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\Read;
use Magento\MediaGalleryApi\Api\IsPathExcludedInterface;

/**
* Build folder tree structure by path
* Build media gallery folder tree structure by path
*/
class GetFolderTree
{
Expand All @@ -22,43 +23,45 @@ class GetFolderTree
*/
private $filesystem;

/**
* @var string
*/
private $path;

/**
* @var IsPathExcludedInterface
*/
private $isPathExcluded;

/**
* Constructor
*
* @param Filesystem $filesystem
* @param string $path
* @param IsPathExcludedInterface $isPathExcluded
*/
public function __construct(
Filesystem $filesystem,
string $path,
IsPathExcludedInterface $isPathExcluded
) {
$this->filesystem = $filesystem;
$this->path = $path;
$this->isPathExcluded = $isPathExcluded;
}

/**
* Return directory folder structure in array
*
* @param bool $skipRoot
* @return array
* @throws ValidatorException
*/
public function execute(bool $skipRoot = true): array
public function execute(): array
{
return $this->buildFolderTree($this->getDirectories(), $skipRoot);
$tree = [
'name' => 'root',
'path' => '/',
'children' => []
];
$directories = $this->getDirectories();
foreach ($directories as $idx => &$node) {
$node['children'] = [];
$result = $this->findParent($node, $tree);
$parent = &$result['treeNode'];

$parent['children'][] = &$directories[$idx];
}
return $tree['children'];
}

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

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

if (!$directory->isDirectory()) {
return $directories;
Expand All @@ -96,30 +99,6 @@ private function getDirectories(): array
return $directories;
}

/**
* Build folder tree structure by provided directories path
*
* @param array $directories
* @param bool $skipRoot
* @return array
*/
private function buildFolderTree(array $directories, bool $skipRoot): array
{
$tree = [
'name' => 'root',
'path' => '/',
'children' => []
];
foreach ($directories as $idx => &$node) {
$node['children'] = [];
$result = $this->findParent($node, $tree);
$parent = & $result['treeNode'];

$parent['children'][] =& $directories[$idx];
}
return $skipRoot ? $tree['children'] : $tree;
}

/**
* Find parent directory
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AssertFolderIsChangedActionGroup">
<annotations>
<description>Assert that folder is changed</description>
</annotations>
<arguments>
<argument name="newSelectedFolder" type="string"/>
<argument name="oldSelectedFolder" type="string" defaultValue="{{AdminMediaGalleryFolderData.name}}"/>
</arguments>

<assertNotEquals stepKey="assertNotEqual">
<actualResult type="string">{{newSelectedFolder}}</actualResult>
<expectedResult type="string">{{oldSelectedFolder}}</expectedResult>
</assertNotEquals>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminMediaGallerySwitchingBetweenViewsTest">
<annotations>
<features value="MediaGallery"/>
<useCaseId value="https://github.com/magento/adobe-stock-integration/issues/1523"/>
<title value="User switches between Views and checks if the folder is changed"/>
<stories value="User switches between Views and checks if the folder is changed"/>
<testCaseId value="https://studio.cucumber.io/projects/131313/test-plan/folders/1337102/scenarios/5060037"/>
<description value="User switches between Views and checks if the folder is changed"/>
<severity value="CRITICAL"/>
<group value="media_gallery_ui"/>
</annotations>
<before>
<createData entity="SimpleSubCategory" stepKey="category"/>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
<actionGroup ref="AdminEnhancedMediaGalleryDeleteGridViewActionGroup" stepKey="deleteView">
<argument name="viewToDelete" value="New View"/>
</actionGroup>
<actionGroup ref="AdminMediaGalleryFolderSelectActionGroup" stepKey="selectFolderForDelete"/>
<actionGroup ref="AdminMediaGalleryFolderDeleteActionGroup" stepKey="deleteFolder"/>
<actionGroup ref="AdminMediaGalleryAssertFolderDoesNotExistActionGroup" stepKey="assertFolderWasDeleted"/>
<deleteData createDataKey="category" stepKey="deleteCategory"/>
</after>
<actionGroup ref="AdminOpenCreateNewCMSPageActionGroup" stepKey="openNewPage"/>
<actionGroup ref="AdminOpenMediaGalleryFromPageNoEditorActionGroup" stepKey="openMediaGalleryForPage"/>
<actionGroup ref="ClearFiltersAdminDataGridActionGroup" stepKey="clearFilters"/>
<actionGroup ref="AdminMediaGalleryOpenNewFolderFormActionGroup" stepKey="openNewFolderForm"/>
<actionGroup ref="AdminMediaGalleryCreateNewFolderActionGroup" stepKey="createNewFolder"/>
<actionGroup ref="AdminMediaGalleryAssertFolderNameActionGroup" stepKey="assertNewFolderCreated"/>
<waitForLoadingMaskToDisappear stepKey="waitForFolderContents"/>
<actionGroup ref="AdminEnhancedMediaGallerySaveCustomViewActionGroup" stepKey="saveCustomView">
<argument name="viewName" value="New View"/>
</actionGroup>
<actionGroup ref="AdminOpenCategoryPageActionGroup" stepKey="openCategoryPage"/>
<actionGroup ref="AdminCategoriesOpenCategoryActionGroup" stepKey="openCategory">
<argument name="category" value="$$category$$"/>
</actionGroup>
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
<actionGroup ref="AdminEnhancedMediaGallerySelectCustomBookmarksViewActionGroup" stepKey="selectDefaultView">
<argument name="selectView" value="Default View"/>
</actionGroup>
<actionGroup ref="AssertFolderIsChangedActionGroup" stepKey="assertFolderIsChanged">
<argument name="newSelectedFolder" value="category" />
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGallerySelectCustomBookmarksViewActionGroup" stepKey="switchBackToNewView">
<argument name="selectView" value="New View"/>
</actionGroup>
<actionGroup ref="AdminEnhancedMediaGalleryAssertActiveFiltersActionGroup" stepKey="assertFilterApplied">
<argument name="resultValue" value="{{AdminMediaGalleryFolderData.name}}"/>
</actionGroup>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImage"/>
<actionGroup ref="AdminSaveCategoryFormActionGroup" stepKey="saveCategoryForm"/>
<actionGroup ref="AdminOpenMediaGalleryFromCategoryImageUploaderActionGroup" stepKey="openMediaGalleryFromImageUploader"/>
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="resetAdminDataGridToDefaultView"/>
<actionGroup ref="AdminMediaGalleryAssertImageInGridActionGroup" stepKey="assertImageInGrid">
<argument name="title" value="ProductImage.filename"/>
</actionGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Directories tree component
*/
class DirectoriesTree extends Container
class DirectoryTree extends Container
{
/**
* @var UrlInterface
Expand Down Expand Up @@ -50,9 +50,9 @@ public function prepare(): void
array_replace_recursive(
(array) $this->getData('config'),
[
'getDirectoryTreeUrl' => $this->url->getUrl("media_gallery/directories/gettree"),
'deleteDirectoryUrl' => $this->url->getUrl("media_gallery/directories/delete"),
'createDirectoryUrl' => $this->url->getUrl("media_gallery/directories/create")
'getDirectoryTreeUrl' => $this->url->getUrl('media_gallery/directories/gettree'),
'deleteDirectoryUrl' => $this->url->getUrl('media_gallery/directories/delete'),
'createDirectoryUrl' => $this->url->getUrl('media_gallery/directories/create')
]
)
);
Expand Down
5 changes: 0 additions & 5 deletions app/code/Magento/MediaGalleryUi/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
</argument>
</arguments>
</type>
<type name="Magento\MediaGalleryUi\Model\Directories\GetFolderTree">
<arguments>
<argument name="path" xsi:type="string">media</argument>
</arguments>
</type>
<type name="Magento\MediaGallerySynchronizationApi\Model\ImportFilesComposite">
<plugin name="createMediaGalleryThumbnails" type="Magento\MediaGalleryUi\Plugin\CreateThumbnails"/>
</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
</container>
</listingToolbar>
<container name="media_gallery_directories"
class="Magento\MediaGalleryUi\Ui\Component\DirectoriesTree"
class="Magento\MediaGalleryUi\Ui\Component\DirectoryTree"
template="Magento_MediaGalleryUi/grid/directories/directoryTree"
component="Magento_MediaGalleryUi/js/directory/directoryTree"/>
<columns name="media_gallery_columns" component="Magento_MediaGalleryUi/js/grid/masonry">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
</container>
</listingToolbar>
<container name="media_gallery_directories"
class="Magento\MediaGalleryUi\Ui\Component\DirectoriesTree"
class="Magento\MediaGalleryUi\Ui\Component\DirectoryTree"
template="Magento_MediaGalleryUi/grid/directories/directoryTree"
component="Magento_MediaGalleryUi/js/directory/directoryTree"/>
<columns name="media_gallery_columns" component="Magento_MediaGalleryUi/js/grid/masonry">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,24 @@ define([
* @param {String} deleteImageUrl
*/
deleteImageAction: function (recordsIds, imageDetailsUrl, deleteImageUrl) {
var confirmationContent = $t('%1 Are you sure you want to delete "%2" image(s)?')
var confirmationContent = $t('%1Are you sure you want to delete "%2" image(s)?')
.replace('%2', Object.keys(recordsIds).length),
deferred = $.Deferred();

getDetails(imageDetailsUrl, recordsIds)
.then(function (imageDetails) {
getDetails(imageDetailsUrl, recordsIds).then(function (images) {
confirmationContent = confirmationContent.replace(
'%1',
this.getRecordRelatedContentMessage(imageDetails)
this.getRecordRelatedContentMessage(images) + ' '
);
}.bind(this)).fail(function () {
confirmationContent = confirmationContent.replace('%1', '');
}).always(function () {
deleteImages(recordsIds, deleteImageUrl, confirmationContent).then(function (status) {
deferred.resolve(status);
}).fail(function (error) {
deferred.reject(error);
});
});
confirmationContent = confirmationContent.replace('%1', '');
}).always(function () {
deleteImages(recordsIds, deleteImageUrl, confirmationContent).then(function (status) {
deferred.resolve(status);
}).fail(function (error) {
deferred.reject(error);
});
});

return deferred.promise();
},
Expand Down
Loading