From 5c551a9f0a1e2fa6b612841d755b63ab55df4b68 Mon Sep 17 00:00:00 2001 From: wdog Date: Wed, 3 Apr 2024 17:18:24 +0200 Subject: [PATCH 1/3] ResultStatus HasColor --- app/Enums/ResultStatus.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Enums/ResultStatus.php b/app/Enums/ResultStatus.php index 448dd7237..cfe9d6e39 100644 --- a/app/Enums/ResultStatus.php +++ b/app/Enums/ResultStatus.php @@ -2,9 +2,10 @@ namespace App\Enums; +use Filament\Support\Contracts\HasColor; use Filament\Support\Contracts\HasLabel; -enum ResultStatus: string implements HasLabel +enum ResultStatus: string implements HasLabel, HasColor { case Completed = 'completed'; // a speedtest that ran successfully. case Failed = 'failed'; // a speedtest that failed to run successfully. @@ -14,4 +15,13 @@ public function getLabel(): ?string { return $this->name; } + + public function getColor(): ?string + { + return match ($this) { + ResultStatus::Completed => 'success', + ResultStatus::Failed => 'danger', + ResultStatus::Started => 'warning', + }; + } } From ad016b6fb53c140d89a22a630e27b545e8c8e502 Mon Sep 17 00:00:00 2001 From: wdog Date: Wed, 3 Apr 2024 17:36:11 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Better=20fix=20to=20=E2=80=9CDivision=20by?= =?UTF-8?q?=20zero=E2=80=9D=20Error=20#1326?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/helpers.php b/app/helpers.php index b70141cb9..ad3c350a6 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -27,7 +27,9 @@ function toBits(float $size, int $precision = 4): float if (! function_exists('percentChange')) { function percentChange(float $dividend, float $divisor, int $precision = 0): string { - if ($dividend === 0 || $divisor === 0) { + try { + $quotient = $dividend / $divisor; + } catch (DivisionByZeroError $e) { return 0; } @@ -73,7 +75,7 @@ function json_validate($data) { if (! empty($data)) { return is_string($data) && - is_array(json_decode($data, true)) ? true : false; + is_array(json_decode($data, true)) ? true : false; } return false; From a651bcb419a27fd520933f16b4da2a3404170363 Mon Sep 17 00:00:00 2001 From: wdog Date: Wed, 3 Apr 2024 17:43:13 +0200 Subject: [PATCH 3/3] ResultStatus HasColor --- app/Enums/ResultStatus.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Enums/ResultStatus.php b/app/Enums/ResultStatus.php index cfe9d6e39..dc0ea7b0c 100644 --- a/app/Enums/ResultStatus.php +++ b/app/Enums/ResultStatus.php @@ -5,7 +5,7 @@ use Filament\Support\Contracts\HasColor; use Filament\Support\Contracts\HasLabel; -enum ResultStatus: string implements HasLabel, HasColor +enum ResultStatus: string implements HasColor, HasLabel { case Completed = 'completed'; // a speedtest that ran successfully. case Failed = 'failed'; // a speedtest that failed to run successfully.