Skip to content

Commit

Permalink
54. Improves user table filters
Browse files Browse the repository at this point in the history
Enhances the user table filters by grouping date pickers within fieldsets for better organization and improved user experience.  Adds a new filter for user registration date.
  • Loading branch information
dmitrakovich committed Dec 4, 2024
1 parent bc5234f commit 679f431
Showing 1 changed file with 50 additions and 21 deletions.
71 changes: 50 additions & 21 deletions src/app/Filament/Resources/User/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ public static function table(Table $table): Table
->boolean()
->sortable(),
Tables\Columns\TextColumn::make('email')
->label('E-mail'),
->label('E-mail')
->toggleable()
->toggledHiddenByDefault(),
Tables\Columns\TextColumn::make('phone')
->label('Телефон'),
Tables\Columns\TextColumn::make('orders')
Expand Down Expand Up @@ -206,17 +208,19 @@ public static function table(Table $table): Table
->falseLabel('Только оффлайн заказы'),
Tables\Filters\Filter::make('order_date')
->form([
DatePicker::make('ordered_from')
->label('Совершали покупки с:')
->native(false)
->closeOnDateSelection(),
DatePicker::make('ordered_until')
->label('Совершали покупки по:')
->native(false)
->closeOnDateSelection(),
Fieldset::make()
->label('Совершали покупки')
->schema([
DatePicker::make('ordered_from')
->label('с:')
->native(false)
->closeOnDateSelection(),
DatePicker::make('ordered_until')
->label('по:')
->native(false)
->closeOnDateSelection(),
])
])
->columns()
->columnSpan(2)
->query(function (Builder $query, array $data) {
if (!$data['ordered_from'] && !$data['ordered_until']) {
return;
Expand All @@ -232,17 +236,19 @@ public static function table(Table $table): Table
}),
Tables\Filters\Filter::make('birth_date')
->form([
DatePicker::make('birth_date_from')
->label('День рождения с:')
->native(false)
->closeOnDateSelection(),
DatePicker::make('birth_date_until')
->label('День рождения по:')
->native(false)
->closeOnDateSelection(),
Fieldset::make()
->label('День рождения')
->schema([
DatePicker::make('birth_date_from')
->label('с:')
->native(false)
->closeOnDateSelection(),
DatePicker::make('birth_date_until')
->label('по:')
->native(false)
->closeOnDateSelection(),
])
])
->columns()
->columnSpan(2)
->query(function (Builder $query, array $data) {
if ($data['birth_date_from']) {
$from = Carbon::parse($data['birth_date_from']);
Expand All @@ -267,6 +273,29 @@ public static function table(Table $table): Table
});
}
}),
Tables\Filters\Filter::make('register_date')
->form([
Fieldset::make()
->label('Дата регистрации')
->schema([
DatePicker::make('registered_from')
->label('с:')
->native(false)
->closeOnDateSelection(),
DatePicker::make('registered_until')
->label('по:')
->native(false)
->closeOnDateSelection(),
])
])
->query(function (Builder $query, array $data) {
if ($data['registered_from']) {
$query->where('created_at', '>=', $data['registered_from']);
}
if ($data['registered_until']) {
$query->where('created_at', '<=', $data['registered_until']);
}
}),
QueryBuilder::make()
->constraints([
TextConstraint::make('first_name')->label('Имя'),
Expand Down

0 comments on commit 679f431

Please sign in to comment.