Skip to content

Commit

Permalink
Merge pull request #2222 from rappasoft/development
Browse files Browse the repository at this point in the history
v3.7.1
  • Loading branch information
lrljoe authored Feb 28, 2025
2 parents 0036a9a + aa98a14 commit 0c8bbef
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Traits/Filters/HandlesPillsData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function getPillDataForFilter(): array
$filters = [];

foreach ($this->getAppliedFiltersWithValuesForPills() as $filterKey => $value) {
if (! is_null($filter = $this->getFilterByKey($filterKey))) {
if (! is_null($filter = $this->getFilterByKey($filterKey)) && ! $filter->isEmpty($filter->validate($value))) {
$filters[$filter->getKey()] = FilterPillData::make(
filterKey: $filter->getKey(),
customPillBlade: $filter->getCustomPillBlade() ?? null,
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/Filters/Helpers/FilterPillsHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ public function getAppliedFiltersWithValuesForPills(): array
}

$validatedValue = $filter->validate($item);

if ($filter instanceof BooleanFilter) {
return ! ($filter->isEmpty($validatedValue));
} elseif ($validatedValue === null || $validatedValue === 'null') {
} elseif ($validatedValue === null || $validatedValue === 'null' || $filter->isEmpty($validatedValue)) {
return false;
} elseif (is_array($validatedValue)) {
$filter->isEmpty($validatedValue);
if (array_key_exists(0, $validatedValue) && (is_null($validatedValue[0]) || $validatedValue[0] == 'null')) {
return false;
}
Expand Down
9 changes: 5 additions & 4 deletions src/Views/Filters/DateRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ public function validate(array|string|null $values): array|bool
return false;
}

$startDate = $this->createCarbonDate($returnedValues['minDate']);
$endDate = $this->createCarbonDate($returnedValues['maxDate']);

if (! ($startDate instanceof Carbon) || ! ($endDate instanceof Carbon)) {
if (! (($startDate = $this->createCarbonDate($returnedValues['minDate'])) instanceof Carbon) || ! (($endDate = $this->createCarbonDate($returnedValues['maxDate'])) instanceof Carbon)) {
return false;
}

if ($startDate->gt($endDate)) {
return false;
}
Expand Down Expand Up @@ -198,6 +196,9 @@ public function getFilterPillValue($value): array|string|bool|null

public function isEmpty(array|string|null $value): bool
{
if (is_null($value) || empty($value)) {
return true;
}
$values = [];
if (is_array($value)) {
if (! isset($value['minDate']) || ! isset($value['maxDate'])) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Unit/Views/Filters/DateRangeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,27 @@ public function test_check_if_can_get_locale(): void
$this->assertSame('de', self::$filterInstance->getPillsLocale());
$this->assertTrue(self::$filterInstance->hasPillsLocale());
}

public function test_can_check_validation_rejects_invalid_values_array(): void
{
$missingStartDate = self::$filterInstance->validate([null, '2020-01-01']);
$missingEndDate = self::$filterInstance->validate(['2020-01-01', null]);
$missingBoth = self::$filterInstance->validate([null, null]);

$this->assertFalse($missingStartDate);
$this->assertFalse($missingEndDate);
$this->assertFalse($missingBoth);
$this->assertTrue(self::$filterInstance->isEmpty($missingStartDate));
$this->assertTrue(self::$filterInstance->isEmpty($missingEndDate));
$this->assertTrue(self::$filterInstance->isEmpty($missingBoth));
}

public function test_can_check_validation_rejects_broken_values_array(): void
{
$this->assertFalse(self::$filterInstance->validate(['minDate' => 'asdf', 'maxDate' => '2020-02-02']));
$this->assertFalse(self::$filterInstance->validate(['minDate' => '4121-31-31', 'maxDate' => '2020-02-02']));
$this->assertFalse(self::$filterInstance->validate(['minDate' => '2020-02-02', 'maxDate' => 'asdf']));
$this->assertFalse(self::$filterInstance->validate(['minDate' => '2020-02-02', 'maxDate' => '4121-31-31']));

}
}

0 comments on commit 0c8bbef

Please sign in to comment.