Skip to content

Commit 0c9932e

Browse files
committed
navigation badges for static data
1 parent 2443a8c commit 0c9932e

File tree

8 files changed

+117
-86
lines changed

8 files changed

+117
-86
lines changed

packages/data/src/Filament/Resources/StaticCountriesStaticCurrenciesResource.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ public static function table(Table $table): Table
121121
->query(function (Builder $query, array $data): Builder {
122122
return $query->when(
123123
$data['id'],
124-
fn (Builder $query, $value): Builder => $query->where('id', 'like', "%{$value}%"),
124+
fn(Builder $query, $value): Builder => $query->where('id', 'like', "%{$value}%"),
125125
);
126126
})
127127
->indicateUsing(function (array $data): ?string {
128-
if (! $data['id']) {
128+
if (!$data['id']) {
129129
return null;
130130
}
131131

132-
return 'ID: '.$data['id'];
132+
return 'ID: ' . $data['id'];
133133
}),
134134
Filter::make('country_id')
135135
->schema([
@@ -140,15 +140,15 @@ public static function table(Table $table): Table
140140
->query(function (Builder $query, array $data): Builder {
141141
return $query->when(
142142
$data['country_id'],
143-
fn (Builder $query, $value): Builder => $query->where('country_id', 'like', "%{$value}%"),
143+
fn(Builder $query, $value): Builder => $query->where('country_id', 'like', "%{$value}%"),
144144
);
145145
})
146146
->indicateUsing(function (array $data): ?string {
147-
if (! $data['country_id']) {
147+
if (!$data['country_id']) {
148148
return null;
149149
}
150150

151-
return 'Country ID: '.$data['country_id'];
151+
return 'Country ID: ' . $data['country_id'];
152152
}),
153153
Filter::make('currency_id')
154154
->schema([
@@ -159,15 +159,15 @@ public static function table(Table $table): Table
159159
->query(function (Builder $query, array $data): Builder {
160160
return $query->when(
161161
$data['currency_id'],
162-
fn (Builder $query, $value): Builder => $query->where('currency_id', 'like', "%{$value}%"),
162+
fn(Builder $query, $value): Builder => $query->where('currency_id', 'like', "%{$value}%"),
163163
);
164164
})
165165
->indicateUsing(function (array $data): ?string {
166-
if (! $data['currency_id']) {
166+
if (!$data['currency_id']) {
167167
return null;
168168
}
169169

170-
return 'Currency ID: '.$data['currency_id'];
170+
return 'Currency ID: ' . $data['currency_id'];
171171
}),
172172
SelectFilter::make('currency')
173173
->label(__('data::fields.currency_name'))
@@ -187,4 +187,9 @@ public static function getPages(): array
187187
'view' => ViewStaticCountriesStaticCurrencies::route('/{record}'),
188188
];
189189
}
190+
191+
public static function getNavigationBadge(): ?string
192+
{
193+
return (string) static::getModel()::count();
194+
}
190195
}

packages/data/src/Filament/Resources/StaticCountriesStaticTimezonesResource.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,9 @@ public static function getPages(): array
117117
'view' => ViewStaticCountriesStaticTimezones::route('/{record}'),
118118
];
119119
}
120+
121+
public static function getNavigationBadge(): ?string
122+
{
123+
return (string) static::getModel()::count();
124+
}
120125
}

packages/data/src/Filament/Resources/StaticCountryResource.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public static function table(Table $table): Table
173173
->columns([
174174
IconColumn::make('flag_icon')
175175
->label('')
176-
->icon(fn (string $state): string => $state),
176+
->icon(fn(string $state): string => $state),
177177
TextColumn::make('alpha2')
178178
->label('Alpha-2')
179179
->searchable()
@@ -192,12 +192,12 @@ public static function table(Table $table): Table
192192
->formatStateUsing(function ($state) {
193193
if (is_array($state)) {
194194
$values = array_filter($state, function ($value) {
195-
return is_string($value) && ! empty($value);
195+
return is_string($value) && !empty($value);
196196
});
197197

198-
return ! empty($values) ? implode(', ', $values) : '-';
198+
return !empty($values) ? implode(', ', $values) : '-';
199199
}
200-
if (is_string($state) && ! empty($state)) {
200+
if (is_string($state) && !empty($state)) {
201201
return $state;
202202
}
203203

@@ -222,12 +222,12 @@ public static function table(Table $table): Table
222222
->formatStateUsing(function ($state) {
223223
if (is_array($state)) {
224224
$values = array_filter($state, function ($value) {
225-
return is_string($value) && ! empty($value);
225+
return is_string($value) && !empty($value);
226226
});
227227

228-
return ! empty($values) ? implode(', ', $values) : '-';
228+
return !empty($values) ? implode(', ', $values) : '-';
229229
}
230-
if (is_string($state) && ! empty($state)) {
230+
if (is_string($state) && !empty($state)) {
231231
return $state;
232232
}
233233

@@ -240,19 +240,19 @@ public static function table(Table $table): Table
240240
->sortable()
241241
->toggleable()
242242
->numeric()
243-
->formatStateUsing(fn ($state) => number_format($state, 0, ',', '.').' '.__('data::fields.people')),
243+
->formatStateUsing(fn($state) => number_format($state, 0, ',', '.') . ' ' . __('data::fields.people')),
244244
TextColumn::make('area')
245245
->label(__('data::fields.area'))
246246
->sortable()
247247
->numeric()
248-
->formatStateUsing(fn ($state) => $state ? number_format((float) $state, 2, ',', '.').' km²' : '-'),
248+
->formatStateUsing(fn($state) => $state ? number_format((float) $state, 2, ',', '.') . ' km²' : '-'),
249249
TextColumn::make('embargo')
250250
->label(__('data::fields.embargo'))
251251
->sortable()
252252
->searchable()
253253
->toggleable()
254254
->badge()
255-
->color(fn ($state) => match ($state) {
255+
->color(fn($state) => match ($state) {
256256
'none' => 'info',
257257
'partial' => 'warning',
258258
'full' => 'danger',
@@ -261,7 +261,7 @@ public static function table(Table $table): Table
261261
->label(__('data::fields.calling_code'))
262262
->badge()
263263
->color('info')
264-
->formatStateUsing(fn ($state) => $state ? '+'.$state : '-')
264+
->formatStateUsing(fn($state) => $state ? '+' . $state : '-')
265265
->toggleable(),
266266
])
267267
->defaultSort('id', 'desc')
@@ -288,8 +288,8 @@ public static function table(Table $table): Table
288288
->trueLabel('Mit Einwohnerzahl')
289289
->falseLabel('Ohne Einwohnerzahl')
290290
->queries(
291-
true: fn ($query) => $query->whereNotNull('population')->where('population', '>', 0),
292-
false: fn ($query) => $query->where(function ($q) {
291+
true: fn($query) => $query->whereNotNull('population')->where('population', '>', 0),
292+
false: fn($query) => $query->where(function ($q) {
293293
$q->whereNull('population')->orWhere('population', 0);
294294
}),
295295
),
@@ -299,8 +299,8 @@ public static function table(Table $table): Table
299299
->trueLabel('Mit Vorwahl')
300300
->falseLabel('Ohne Vorwahl')
301301
->queries(
302-
true: fn ($query) => $query->whereNotNull('calling_code'),
303-
false: fn ($query) => $query->whereNull('calling_code'),
302+
true: fn($query) => $query->whereNotNull('calling_code'),
303+
false: fn($query) => $query->whereNull('calling_code'),
304304
),
305305
SelectFilter::make('population_size')
306306
->label('Bevölkerungsgröße')
@@ -340,4 +340,9 @@ public static function getPages(): array
340340
'view' => ViewStaticCountry::route('/{record}'),
341341
];
342342
}
343+
344+
public static function getNavigationBadge(): ?string
345+
{
346+
return (string) static::getModel()::count();
347+
}
343348
}

packages/data/src/Filament/Resources/StaticCurrencyResource.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ public static function table(Table $table): Table
113113
->query(function (Builder $query, array $data): Builder {
114114
return $query->when(
115115
$data['id'],
116-
fn (Builder $query, $value): Builder => $query->where('id', 'like', "%{$value}%"),
116+
fn(Builder $query, $value): Builder => $query->where('id', 'like', "%{$value}%"),
117117
);
118118
})
119119
->indicateUsing(function (array $data): ?string {
120-
if (! $data['id']) {
120+
if (!$data['id']) {
121121
return null;
122122
}
123123

124-
return 'ID: '.$data['id'];
124+
return 'ID: ' . $data['id'];
125125
}),
126126
Filter::make('code')
127127
->schema([
@@ -132,15 +132,15 @@ public static function table(Table $table): Table
132132
->query(function (Builder $query, array $data): Builder {
133133
return $query->when(
134134
$data['code'],
135-
fn (Builder $query, $value): Builder => $query->where('code', 'like', "%{$value}%"),
135+
fn(Builder $query, $value): Builder => $query->where('code', 'like', "%{$value}%"),
136136
);
137137
})
138138
->indicateUsing(function (array $data): ?string {
139-
if (! $data['code']) {
139+
if (!$data['code']) {
140140
return null;
141141
}
142142

143-
return 'Code: '.$data['code'];
143+
return 'Code: ' . $data['code'];
144144
}),
145145
Filter::make('common_name')
146146
->schema([
@@ -151,15 +151,15 @@ public static function table(Table $table): Table
151151
->query(function (Builder $query, array $data): Builder {
152152
return $query->when(
153153
$data['common_name'],
154-
fn (Builder $query, $value): Builder => $query->where('common_name', 'like', "%{$value}%"),
154+
fn(Builder $query, $value): Builder => $query->where('common_name', 'like', "%{$value}%"),
155155
);
156156
})
157157
->indicateUsing(function (array $data): ?string {
158-
if (! $data['common_name']) {
158+
if (!$data['common_name']) {
159159
return null;
160160
}
161161

162-
return 'Common Name: '.$data['common_name'];
162+
return 'Common Name: ' . $data['common_name'];
163163
}),
164164
Filter::make('symbol')
165165
->schema([
@@ -170,15 +170,15 @@ public static function table(Table $table): Table
170170
->query(function (Builder $query, array $data): Builder {
171171
return $query->when(
172172
$data['symbol'],
173-
fn (Builder $query, $value): Builder => $query->where('symbol', 'like', "%{$value}%"),
173+
fn(Builder $query, $value): Builder => $query->where('symbol', 'like', "%{$value}%"),
174174
);
175175
})
176176
->indicateUsing(function (array $data): ?string {
177-
if (! $data['symbol']) {
177+
if (!$data['symbol']) {
178178
return null;
179179
}
180180

181-
return 'Symbol: '.$data['symbol'];
181+
return 'Symbol: ' . $data['symbol'];
182182
}),
183183
Filter::make('exonyms')
184184
->schema([
@@ -189,15 +189,15 @@ public static function table(Table $table): Table
189189
->query(function (Builder $query, array $data): Builder {
190190
return $query->when(
191191
$data['exonyms'],
192-
fn (Builder $query, $value): Builder => $query->where('exonyms', 'like', "%{$value}%"),
192+
fn(Builder $query, $value): Builder => $query->where('exonyms', 'like', "%{$value}%"),
193193
);
194194
})
195195
->indicateUsing(function (array $data): ?string {
196-
if (! $data['exonyms']) {
196+
if (!$data['exonyms']) {
197197
return null;
198198
}
199199

200-
return 'Exonyms: '.$data['exonyms'];
200+
return 'Exonyms: ' . $data['exonyms'];
201201
}),
202202
]);
203203
}
@@ -216,4 +216,9 @@ public static function getPages(): array
216216
'view' => ViewStaticCurrency::route('/{record}'),
217217
];
218218
}
219+
220+
public static function getNavigationBadge(): ?string
221+
{
222+
return (string) static::getModel()::count();
223+
}
219224
}

0 commit comments

Comments
 (0)