Skip to content

Commit

Permalink
Merge pull request #844 from open-sausages/pulls/1.2/sort-it-out
Browse files Browse the repository at this point in the history
BUG Folder sort incorrect
  • Loading branch information
robbieaverill authored Oct 3, 2018
2 parents 5133295 + 5422e28 commit 32e0346
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 49 deletions.
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

0 comments on commit 32e0346

Please sign in to comment.