Skip to content

Commit

Permalink
[Bug] Fix sorting by fileSize. (#717)
Browse files Browse the repository at this point in the history
* Add mapping from size to filesize.

* Fix typo.

* Fix Test.

* Fix Test.
  • Loading branch information
martineiber authored Jan 22, 2025
1 parent b986081 commit b980272
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Grid/Mapper/ColumnMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'filename' => 'string',
'creationDate' => 'datetime',
'modificationDate' => 'datetime',
'size' => 'fileSize',
'fileSize' => 'fileSize',
'key' => 'string',
'published' => 'boolean',
'classname' => 'string',
Expand Down
11 changes: 11 additions & 0 deletions src/Grid/Service/SystemColumnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function getSystemColumnsForAssets(): array
$systemColumns = Service::GRID_SYSTEM_COLUMNS;
$columns = [];
foreach ($systemColumns as $column) {
$column = $this->mapCustomColumnKeys($column);

$columns[$column] = $this->columnMapper->getType($column);
}

Expand All @@ -51,4 +53,13 @@ public function getSystemColumnsForDataObjects(): array

return $columns;
}

private function mapCustomColumnKeys(string $key): string
{
$keyMapping = [
'size' => 'fileSize',
];

return $keyMapping[$key] ?? $key;
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Grid/Mapper/ColumnMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function testMapperForModificationDate(): void
public function testMapperForSize(): void
{
$mapper = new ColumnMapper();
$this->assertSame('fileSize', $mapper->getType('size'));
$this->assertSame('fileSize', $mapper->getType('fileSize'));
}

public function testMapperForKey(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Grid/Service/SystemColumnServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testGetSystemColumnsForAssets(): void
'filename' => 'string',
'creationDate' => 'datetime',
'modificationDate' => 'datetime',
'size' => 'fileSize',
'fileSize' => 'fileSize',
'mimetype' => 'string',
], $systemColumnService->getSystemColumnsForAssets());
}
Expand Down

0 comments on commit b980272

Please sign in to comment.