Skip to content

Commit bdba579

Browse files
committed
Handle list default sort
1 parent 8c10504 commit bdba579

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/Console/ConfigureCmsCommand.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public function handle(Client $ozuClient): int
4848
'isReorderable' => $list->isReorderable(),
4949
'isSearchable' => $list->isSearchable(),
5050
'isPaginated' => $list->isPaginated(),
51+
'defaultSort' => $list->defaultSort(),
5152
'columns' => $list
5253
->columns()
5354
->map(fn (OzuColumn $column) => [

src/OzuCms/OzuCollectionListConfig.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,15 @@ public function columns(): Collection
5959
{
6060
return collect($this->columns);
6161
}
62+
63+
public function defaultSort(): ?array
64+
{
65+
$column = collect($this->columns)
66+
->filter(fn (OzuColumn $column) => $column->isDefaultSort())
67+
->last();
68+
69+
return $column
70+
? ['column' => $column->key(), 'direction' => $column->getDefaultSortDirection()]
71+
: null;
72+
}
6273
}

tests/Console/ConfigureCmsCommandTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public static function configureOzuCollectionList(OzuCollectionListConfig $confi
116116
->addColumn(OzuColumn::makeText('dummy-text', 1)->setLabel('Dummy text'))
117117
->addColumn(OzuColumn::makeCheck('dummy-check', 2)->setLabel('Dummy check'))
118118
->addColumn(OzuColumn::makeImage('dummy-image', 3)->setLabel('Dummy image'))
119-
->addColumn(OzuColumn::makeDate('dummy-date', 3)->setLabel('Dummy date'));
119+
->addColumn(OzuColumn::makeDate('dummy-date', 3)->setLabel('Dummy date')->setDefaultSort());
120120
}
121121
}
122122
]]);
@@ -129,6 +129,7 @@ public static function configureOzuCollectionList(OzuCollectionListConfig $confi
129129
return $request['list']['isReorderable'] == true
130130
&& $request['list']['isSearchable'] == true
131131
&& $request['list']['isPaginated'] == true
132+
&& $request['list']['defaultSort'] == ['dummy-date', 'asc']
132133
&& $request['list']['columns'] == collect([
133134
[
134135
'type' => 'text',

0 commit comments

Comments
 (0)