Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated: Repeater's grid() method can except closure as parameter #14630

Open
wants to merge 17 commits into
base: 4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/actions/resources/lang/pt_PT/import.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
'file' => [
'label' => 'Ficheiro',
'placeholder' => 'Carregar um ficheiro CSV',
'rules' => [
'duplicate_columns' => '{0} O ficheiro não pode conter, em falta, mais de um cabeçalho.|{1,*} O ficheiro não pode conter cabeçalhos em duplicado: :columns.',
],
],

'columns' => [
'label' => 'Colunas',
'placeholder' => 'Seleccione uma coluna',
'rules' => [
'duplicate_columns' => '{0} O ficheiro não pode conter, em falta, mais de um cabeçalho.|{1,*} O ficheiro não pode conter cabeçalhos em duplicado: :columns.',
],
],

],
Expand Down Expand Up @@ -75,6 +75,7 @@
'file_name' => 'import-:import_id-:csv_name-failed-rows',
'error_header' => 'erro',
'system_error' => 'Erro de sistema, por favor, contacte o suporte técnico.',
'column_mapping_required_for_new_record' => 'A coluna :attribute não foi mapeada a uma coluna no ficheiro, no entanto é necessária para a criação de novos registos.',
],

];
4 changes: 4 additions & 0 deletions packages/actions/src/Exports/Jobs/PrepareCsvExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public function handle(): void
$query->reorder($qualifiedKeyName);

foreach ($originalOrders as $order) {
if (blank($order['column'] ?? null) || blank($order['direction'] ?? null)) {
continue;
}

$query->orderBy($order['column'], $order['direction']);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public function __invoke(Import $import): StreamedResponse
$csv = Writer::createFromFileObject(new SplTempFileObject);
$csv->setOutputBOM(ByteSequence::BOM_UTF8);

$columnHeaders = array_keys($import->failedRows()->first()->data);
$firstFailedRow = $import->failedRows()->first();

$columnHeaders = $firstFailedRow ? array_keys($firstFailedRow->data) : [];
$columnHeaders[] = __('filament-actions::import.failure_csv.error_header');

$csv->insertOne($columnHeaders);
Expand Down
2 changes: 1 addition & 1 deletion packages/forms/docs/03-fields/12-repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ Repeater::make('qualifications')

<AutoScreenshot name="forms/fields/repeater/grid" alt="Repeater with a 2 column grid of items" version="3.x" />

This method accepts the same options as the `columns()` method of the [grid](../layout/grid). This allows you to responsively customize the number of grid columns at various breakpoints.
This method accepts the same options as the `columns()` method of the [grid](../layout/grid). This allows you to responsively customize the number of grid columns at various breakpoints. You can also pass a closure to dynamically calculate the grid size, enabling custom logic based on the repeater's state or other conditions.

## Adding a label to repeater items based on their content

Expand Down
33 changes: 29 additions & 4 deletions packages/forms/src/Components/Concerns/HasContainerGridLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@

namespace Filament\Forms\Components\Concerns;

use Closure;

trait HasContainerGridLayout
{
/**
* @var array<string, int | string | null> | null
* @var array<string, int | string | null> | int | string | null
*/
protected ?array $gridColumns = null;
protected array | int | string | null $gridColumns = null;

protected ?Closure $gridClosure = null;

/**
* @param array<string, int | string | null> | int | string | null $columns
* @param array<string, int | string | null> | int | string | Closure | null $columns
*/
public function grid(array | int | string | null $columns = 2): static
public function grid(array | int | string | Closure | null $columns = 2): static
{
if ($columns instanceof Closure) {
$this->gridClosure = $columns;

return $this;
}

if (! is_array($columns)) {
$columns = [
'lg' => $columns,
Expand Down Expand Up @@ -42,6 +52,21 @@ public function getGridColumns(?string $breakpoint = null): array | int | string
'2xl' => null,
];

if (isset($this->gridClosure)) {
$result = $this->evaluate($this->gridClosure) ?? [];

if (! is_array($result)) {
$result = [
'lg' => $result,
];
}

$columns = [
...$columns,
...$result,
];
}

if ($breakpoint !== null) {
return $columns[$breakpoint] ?? null;
}
Expand Down
7 changes: 7 additions & 0 deletions packages/panels/src/FilamentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ public function packageBooted(): void
$file->getRealPath() => base_path("stubs/filament/{$file->getFilename()}"),
], 'filament-stubs');
}

if (method_exists($this, 'optimizes')) {
$this->optimizes(
optimize: 'filament:optimize', /** @phpstan-ignore-line */
clear: 'filament:optimize-clear', /** @phpstan-ignore-line */
);
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions packages/tables/resources/lang/pt_PT/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

'columns' => [

'actions' => [
'label' => 'Acção|Acções',
],

'text' => [

'actions' => [
Expand Down
Loading