Skip to content

Commit cda7efe

Browse files
committed
Add Filament resource navigation badges
1 parent 60622b0 commit cda7efe

File tree

5 files changed

+56
-0
lines changed

5 files changed

+56
-0
lines changed

src/Enums/ComponentStatusEnum.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ enum ComponentStatusEnum: int implements HasColor, HasIcon, HasLabel
1414
case major_outage = 4;
1515
case unknown = 5;
1616

17+
public static function outage(): array
18+
{
19+
return [
20+
self::performance_issues,
21+
self::partial_outage,
22+
self::major_outage,
23+
];
24+
}
25+
1726
public function getLabel(): string
1827
{
1928
return match ($this) {

src/Filament/Resources/ComponentResource.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,18 @@ public static function getLabel(): ?string
117117
{
118118
return __('Component');
119119
}
120+
121+
public static function getNavigationBadge(): ?string
122+
{
123+
return static::getModel()::outage()->count();
124+
}
125+
126+
public static function getNavigationBadgeColor(): string
127+
{
128+
if ((int) static::getNavigationBadge() > 0) {
129+
return 'danger';
130+
}
131+
132+
return 'success';
133+
}
120134
}

src/Filament/Resources/IncidentResource.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,18 @@ public static function getLabel(): ?string
176176
{
177177
return __('Incident');
178178
}
179+
180+
public static function getNavigationBadge(): ?string
181+
{
182+
return static::getModel()::unresolved()->count();
183+
}
184+
185+
public static function getNavigationBadgeColor(): string
186+
{
187+
if ((int) static::getNavigationBadge() > 0) {
188+
return 'danger';
189+
}
190+
191+
return 'success';
192+
}
179193
}

src/Filament/Resources/ScheduleResource.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,18 @@ public static function getLabel(): ?string
110110
{
111111
return __('Schedule');
112112
}
113+
114+
public static function getNavigationBadge(): ?string
115+
{
116+
return static::getModel()::incomplete()->count();
117+
}
118+
119+
public static function getNavigationBadgeColor(): string
120+
{
121+
if ((int) static::getNavigationBadge() > 0) {
122+
return 'warning';
123+
}
124+
125+
return 'success';
126+
}
113127
}

src/Models/Component.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,9 @@ public function scopeStatus(Builder $query, ComponentStatusEnum $status): Builde
8888
{
8989
return $query->where('status', $status);
9090
}
91+
92+
public function scopeOutage(Builder $query): Builder
93+
{
94+
return $query->whereIn('status', ComponentStatusEnum::outage());
95+
}
9196
}

0 commit comments

Comments
 (0)