Skip to content

Commit

Permalink
💄 Add item counts to menu table
Browse files Browse the repository at this point in the history
🌐 Translate the `Locations` table column
  • Loading branch information
Log1x committed Aug 20, 2024
1 parent 396d054 commit ca5cb0f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions resources/lang/en/menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
'label' => 'Name',
],
'locations' => [
'label' => 'Locations',
'empty' => 'Unassigned',
],
'items' => [
'label' => 'Items',
],
'is_visible' => [
'label' => 'Visibility',
'visible' => 'Visible',
Expand Down
4 changes: 4 additions & 0 deletions resources/lang/vi/menu-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
'label' => 'Tên',
],
'locations' => [
'label' => 'Vị trí',
'empty' => 'Chưa gán',
],
'items' => [
'label' => 'Mục',
],
'is_visible' => [
'label' => 'Hiển thị',
'visible' => 'Hiển thị',
Expand Down
11 changes: 11 additions & 0 deletions src/Resources/MenuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,29 @@ public static function table(Table $table): Table
$locations = FilamentMenuBuilderPlugin::get()->getLocations();

return $table
->modifyQueryUsing(fn ($query) => $query->withCount('menuItems'))
->columns([
Tables\Columns\TextColumn::make('name')
->searchable()
->sortable()
->label(__('filament-menu-builder::menu-builder.resource.name.label')),
Tables\Columns\TextColumn::make('locations.location')
->label(__('filament-menu-builder::menu-builder.resource.locations.label'))
->default($default = __('filament-menu-builder::menu-builder.resource.locations.empty'))
->color(fn (string $state) => array_key_exists($state, $locations) ? 'primary' : 'gray')
->formatStateUsing(fn (string $state) => $locations[$state] ?? $state)
->limitList(2)
->sortable()
->badge(),
Tables\Columns\TextColumn::make('menu_items_count')
->label(__('filament-menu-builder::menu-builder.resource.items.label'))
->icon('heroicon-o-link')
->numeric()
->default(0)
->sortable(),
Tables\Columns\IconColumn::make('is_visible')
->label(__('filament-menu-builder::menu-builder.resource.is_visible.label'))
->sortable()
->boolean(),
])
->actions([
Expand Down

0 comments on commit ca5cb0f

Please sign in to comment.