From 01e0dafaa803a1a9281e04e9f862f21dfbf5cd77 Mon Sep 17 00:00:00 2001 From: Hamza Bham <92208535+MHamzaBham@users.noreply.github.com> Date: Tue, 22 Oct 2024 15:28:11 +0500 Subject: [PATCH] XW-89: Transaction filter keeps expanded on selection (#107) * XW-89: Transaction filter keeps expanded on selection * XW-89: Transaction filter keeps expanded on selection --- app/Models/Category.php | 15 +++++++ .../categories/subCategoryCheckbox.blade.php | 12 +++-- resources/views/transactions/index.blade.php | 44 ++++++++++++------- 3 files changed, 50 insertions(+), 21 deletions(-) diff --git a/app/Models/Category.php b/app/Models/Category.php index bde699d..015b5be 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -63,4 +63,19 @@ public static function bulkCreateForUser(int $userId, array $subCategories = nul } } } + + public function hasSelectedDescendant(array $selectedCategories): bool + { + if (in_array($this->id, $selectedCategories)) { + return true; + } + + foreach ($this->subcategories as $subcategory) { + if ($subcategory->hasSelectedDescendant($selectedCategories)) { + return true; + } + } + + return false; + } } diff --git a/resources/views/categories/subCategoryCheckbox.blade.php b/resources/views/categories/subCategoryCheckbox.blade.php index e9bcd04..33aaa91 100644 --- a/resources/views/categories/subCategoryCheckbox.blade.php +++ b/resources/views/categories/subCategoryCheckbox.blade.php @@ -1,18 +1,22 @@ {{-- subCategoryList.blade.php --}} @foreach($subcategories as $subcategory) + @php + $isExpanded = isset($filters['categories']) && + $subcategory->hasSelectedDescendant($filters['categories']); + @endphp
  • id, $filters['categories']) ? 'checked' : '' }}>
    -