Skip to content

Commit

Permalink
Merge pull request #26 from Log1x/enhance/add-item-count-to-table
Browse files Browse the repository at this point in the history
💄 Add item counts to menu table
  • Loading branch information
datlechin authored Aug 20, 2024
2 parents 7a8d4d4 + 01c755b commit a76aeb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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
13 changes: 12 additions & 1 deletion src/Resources/MenuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,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')
->default($default = __('filament-menu-builder::menu-builder.resource.locations.empty'))
->label(__('filament-menu-builder::menu-builder.resource.locations.label'))
->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 a76aeb2

Please sign in to comment.