@@ -13,22 +13,42 @@ final class Peoplelog extends Component
1313{
1414 use WithPagination;
1515
16- public $ perPage = 50 ;
16+ public $ perPage = 25 ;
17+
18+ public $ subjectTypeFilter = 'all ' ;
1719
1820 // -----------------------------------------------------------------------
1921 public function render (): View
2022 {
2123 $ timezone = session ('timezone ' , 'UTC ' );
2224
23- $ activities = Activity::with ('causer ' )
25+ $ query = Activity::with ('causer ' )
2426 ->where ('log_name ' , 'person_couple ' )
2527 ->where ('team_id ' , auth ()->user ()->currentTeam ->id )
26- ->where ('updated_at ' , '>= ' , today ()->startOfMonth ()->subMonths (1 ))
28+ ->where ('updated_at ' , '>= ' , today ()->startOfMonth ()->subMonths (1 ));
29+
30+ // Apply subject_type filter if not 'all'
31+ if ($ this ->subjectTypeFilter !== 'all ' ) {
32+ $ query ->where ('subject_type ' , $ this ->subjectTypeFilter );
33+ }
34+
35+ $ activities = $ query
2736 ->orderBy ('updated_at ' , 'desc ' )
2837 ->paginate ($ this ->perPage );
2938
39+ // Get distinct subject types for the filter dropdown
40+ $ subjectTypes = Activity::where ('log_name ' , 'person_couple ' )
41+ ->where ('team_id ' , auth ()->user ()->currentTeam ->id )
42+ ->where ('updated_at ' , '>= ' , today ()->startOfMonth ()->subMonths (1 ))
43+ ->distinct ()
44+ ->pluck ('subject_type ' )
45+ ->map (fn ($ type ) => class_basename ($ type ))
46+ ->sort ()
47+ ->values ()
48+ ->toArray ();
49+
3050 // Transform only the current page data
31- $ logs = $ activities ->getCollection ()->map (function ($ record ) use ($ timezone ) {
51+ $ logs = $ activities ->getCollection ()->map (function ($ record ) use ($ timezone ): array {
3252 $ event = $ record ->event ;
3353
3454 return [
@@ -46,11 +66,17 @@ public function render(): View
4666 // Replace the collection with transformed data
4767 $ activities ->setCollection ($ logs );
4868
49- return view ('livewire.peoplelog ' , compact ('activities ' ));
69+ return view ('livewire.peoplelog ' , compact ('activities ' , 'subjectTypes ' ));
70+ }
71+
72+ // Reset pagination when filter changes
73+ public function updatedSubjectTypeFilter (): void
74+ {
75+ $ this ->resetPage ();
5076 }
5177
52- // Optional: Method to change per page
53- public function updatedPerPage ()
78+ // Reset pagination when per page changes
79+ public function updatedPerPage (): void
5480 {
5581 $ this ->resetPage ();
5682 }
0 commit comments