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

BUG Folder sort incorrect #844

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions client/src/containers/AssetAdmin/AssetAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,19 @@ class AssetAdmin extends Component {
queuedFiles,
} = this.props;

return [
const combinedFilesList = [
// Exclude uploaded files that have been reloaded via graphql
...queuedFiles
.items
.filter(item => !item.id || !files.find(file => file.id === item.id)),
...files,
].sort((left, right) => {
if (left.type !== right.type) {
if (left.type === 'folder') {
return -1;
}
if (right.type === 'folder') {
return 1;
}
}
return right.queuedId - left.queuedId;
});
];

// Seperate folder and files then return an array with folders at the top (for table view)
const foldersList = combinedFilesList.filter((file) => file.type === 'folder');
const filesList = combinedFilesList.filter((file) => file.type !== 'folder');

return foldersList.concat(filesList);
}

/**
Expand Down
13 changes: 0 additions & 13 deletions code/GraphQL/FolderTypeCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,6 @@ public function resolveChildrenConnection(
$filter['parentId'] = $object->ID;
$list = $filterInputType->filterList($list, $filter);

// Sort folders first
$list = $list->alterDataQuery(function (DataQuery $query, DataList $list) {
$existingOrderBys = $query->query()->getOrderBy();
$query->sort(
'(CASE WHEN "ClassName"=\'SilverStripe\\\\Assets\\\\Folder\' THEN 1 ELSE 0 END)',
'DESC',
true
);
foreach ($existingOrderBys as $field => $dir) {
$query->sort($field, $dir, false);
}
});

// Filter by permission
$ids = $list->column('ID');
$permissionChecker = File::singleton()->getPermissionChecker();
Expand Down
23 changes: 0 additions & 23 deletions tests/php/GraphQL/FolderTypeCreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,6 @@ class FolderTypeCreatorTest extends SapphireTest

protected $usesDatabase = true;

public function testItSortsChildrenOnTypeByDefault()
{
$rootFolder = Folder::singleton();

$file = File::create(['Name' => 'aaa file']);
$file->write();

$folder = Folder::create(['Name' => 'bbb folder']);
$folder->write();

$list = $this->resolveChildrenConnection(
$rootFolder,
[]
);
$this->assertEquals(
[
$folder->Name,
$file->Name,
],
$list['edges']->column('Name')
);
}

public function testItDoesNotFilterByParentIdWithRecursiveFlag()
{
$rootFolder = Folder::singleton();
Expand Down