Skip to content

Commit

Permalink
Merge branch '4.x' into optimize-table-blade-components
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Oct 9, 2024
2 parents ce2d7c7 + 661e080 commit 6364fe3
Show file tree
Hide file tree
Showing 25 changed files with 199 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github: [danharrin, zepfietje]
github: [danharrin]
polar: filamentphp
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion packages/actions/docs/06-prebuilt-actions/09-export.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public static function getCsvDelimiter(): string

You can only specify a single character, otherwise an exception will be thrown.

## Styling XLSX cells
## Customizing XLSX files

If you want to style the cells of the XLSX file, you may override the `getXlsxCellStyle()` method on the exporter class, returning an [OpenSpout `Style` object](https://github.com/openspout/openspout/blob/4.x/docs/documentation.md#styling):

Expand Down Expand Up @@ -588,6 +588,21 @@ public function getXlsxHeaderCellStyle(): ?Style
}
```

Alternatively, if you want to pass "options" to the [OpenSpout XLSX `Writer`](https://github.com/openspout/openspout/blob/4.x/docs/documentation.md#column-widths), you can return an `OpenSpout\Writer\XLSX\Options` instance from the `getXlsxWriterOptions()` method of the exporter class:

```php
use OpenSpout\Writer\XLSX\Options;

public function getXlsxWriterOptions(): ?Options
{
$options = new Options();
$options->setColumnWidth(10, 1);
$options->setColumnWidthForRange(12, 2, 3);

return $options;
}
```

## Customizing the export job

The default job for processing exports is `Filament\Actions\Exports\Jobs\PrepareCsvExport`. If you want to extend this class and override any of its methods, you may replace the original class in the `register()` method of a service provider:
Expand Down
1 change: 1 addition & 0 deletions packages/actions/src/Concerns/CanExportRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ protected function setUp(): void
);

$export->file_disk = $action->getFileDisk() ?? $exporter->getFileDisk();
// Temporary save to obtain the sequence number of the export file.
$export->save();

$export->file_name = $action->getFileName($export) ?? $exporter->getFileName($export);
Expand Down
6 changes: 6 additions & 0 deletions packages/actions/src/Exports/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Queue\Middleware\WithoutOverlapping;
use OpenSpout\Common\Entity\Style\Style;
use OpenSpout\Writer\XLSX\Options;

abstract class Exporter
{
Expand Down Expand Up @@ -194,6 +195,11 @@ public function getXlsxHeaderCellStyle(): ?Style
return null;
}

public function getXlsxWriterOptions(): ?Options
{
return null;
}

public static function modifyQuery(Builder $query): Builder
{
return $query;
Expand Down
2 changes: 1 addition & 1 deletion packages/actions/src/Exports/Jobs/CreateXlsxFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function handle(): void
{
$disk = $this->export->getFileDisk();

$writer = app(Writer::class);
$writer = app(Writer::class, ['options' => $this->exporter->getXlsxWriterOptions()]);
$writer->openToFile($temporaryFile = tempnam(sys_get_temp_dir(), $this->export->file_name));

$csvDelimiter = $this->exporter::getCsvDelimiter();
Expand Down
11 changes: 11 additions & 0 deletions packages/actions/src/Exports/Jobs/PrepareCsvExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,22 @@ public function handle(): void
->reject(fn (array $order): bool => in_array($order['column'] ?? null, [$keyName, $qualifiedKeyName]))
->unique('column');

/** @var array<string, mixed> $originalBindings */
$originalBindings = $query->getRawBindings();

$query->reorder($qualifiedKeyName);

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

$newBindings = $query->getRawBindings();

foreach ($originalBindings as $key => $value) {
if ($binding = array_diff($value, $newBindings[$key])) {
$query->addBinding($binding, $key);
}
}
}

$exportCsvJob = $this->getExportCsvJob();
Expand Down
4 changes: 4 additions & 0 deletions packages/actions/src/Testing/TestsActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ public function callAction(): Closure
return $this;
}

if (store($this->instance())->has('redirect')) {
return $this;
}

/** @phpstan-ignore-next-line */
$this->setActionData($data);

Expand Down
11 changes: 11 additions & 0 deletions packages/forms/docs/02-fields/10-rich-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,14 @@ RichEditor::make('content')
->fileAttachmentsDirectory('attachments')
->fileAttachmentsVisibility('private')
```

## Disabling Grammarly checks

If the user has Grammarly installed and you would like to prevent it from analyzing the contents of the editor, you can use the `disableGrammarly()` method:

```php
use Filament\Forms\Components\RichEditor;

RichEditor::make('content')
->disableGrammarly()
```
15 changes: 15 additions & 0 deletions packages/forms/docs/02-fields/12-repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ Repeater::make('members')
->addActionLabel('Add member')
```

### Aligning the add action button

By default, the add action is aligned in the center. You may adjust this using the `addActionAlignment()` method, passing an `Alignment` option of `Alignment::Start` or `Alignment::End`:

```php
use Filament\Forms\Components\Repeater;
use Filament\Support\Enums\Alignment;

Repeater::make('members')
->schema([
// ...
])
->addActionAlignment(Alignment::Start)
```

### Preventing the user from adding items

You may prevent the user from adding items to the repeater using the `addable(false)` method:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@php
use Filament\Actions\Action;
use Filament\Support\Enums\Alignment;
$containers = $getChildComponentContainers();
Expand Down Expand Up @@ -238,7 +239,17 @@ class="absolute -top-3 left-3 px-1 text-sm font-medium"
@endif

@if ($isAddable && $addAction->isVisible())
<div class="flex justify-center">
<div
@class([
'flex',
match ($getAddActionAlignment()) {
Alignment::Start, Alignment::Left => 'justify-start',
Alignment::Center, null => 'justify-center',
Alignment::End, Alignment::Right => 'justify-end',
default => $alignment,
},
])
>
{{ $addAction }}
</div>
@endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ class="trix-button trix-button--dialog"
@endif
x-ref="trix"
wire:ignore
@if ($isGrammarlyDisabled())
data-gramm="false"
data-gramm_editor="false"
data-enable-grammarly="false"
@endif
{{
$getExtraInputAttributeBag()->class([
'prose min-h-[theme(spacing.48)] max-w-none !border-none px-3 py-1.5 text-base text-gray-950 dark:prose-invert focus-visible:outline-none dark:text-white sm:text-sm sm:leading-6',
Expand Down
22 changes: 22 additions & 0 deletions packages/forms/src/Components/Concerns/CanDisableGrammarly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Filament\Forms\Components\Concerns;

use Closure;

trait CanDisableGrammarly
{
protected bool | Closure $isGrammarlyDisabled = false;

public function disableGrammarly(bool | Closure $condition = true): static
{
$this->isGrammarlyDisabled = $condition;

return $this;
}

public function isGrammarlyDisabled(): bool
{
return (bool) $this->evaluate($this->isGrammarlyDisabled);
}
}
1 change: 1 addition & 0 deletions packages/forms/src/Components/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Field extends Component implements Contracts\HasValidationRules
use Concerns\CanBeAutofocused;
use Concerns\CanBeMarkedAsRequired;
use Concerns\CanBeValidated;
use Concerns\CanDisableGrammarly;
use Concerns\HasEnum;
use Concerns\HasExtraFieldWrapperAttributes;
use Concerns\HasHelperText;
Expand Down
25 changes: 24 additions & 1 deletion packages/forms/src/Components/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Filament\Schema\Schema;
use Filament\Support\Concerns\HasReorderAnimationDuration;
use Filament\Support\Enums\ActionSize;
use Filament\Support\Enums\Alignment;
use Filament\Support\Facades\FilamentIcon;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Collection;
Expand Down Expand Up @@ -58,6 +59,8 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction

protected Field | Closure | null $simpleField = null;

protected Alignment | string | Closure | null $addActionAlignment = null;

protected ?Closure $modifyRelationshipQueryUsing = null;

protected ?Closure $modifyAddActionUsing = null;
Expand Down Expand Up @@ -201,6 +204,24 @@ public function getAddAction(): Action
return $action;
}

public function addActionAlignment(Alignment | string | Closure | null $addActionAlignment): static
{
$this->addActionAlignment = $addActionAlignment;

return $this;
}

public function getAddActionAlignment(): Alignment | string | null
{
$alignment = $this->evaluate($this->addActionAlignment);

if (is_string($alignment)) {
$alignment = Alignment::tryFrom($alignment) ?? $alignment;
}

return $alignment;
}

public function addAction(?Closure $callback): static
{
$this->modifyAddActionUsing = $callback;
Expand Down Expand Up @@ -919,7 +940,9 @@ public function relationship(string | Closure | null $name = null, ?Closure $mod
->get()
->each(static fn (Model $record) => $record->delete());

$childComponentContainers = $component->getChildComponentContainers();
$childComponentContainers = $component->getChildComponentContainers(
withHidden: $component->shouldSaveRelationshipsWhenHidden(),
);

$itemOrder = 1;
$orderColumn = $component->getOrderColumn();
Expand Down
7 changes: 2 additions & 5 deletions packages/notifications/docs/02-database-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,16 @@ DatabaseNotifications::pollingInterval(null);

Alternatively, the package has a native integration with [Laravel Echo](https://laravel.com/docs/broadcasting#client-side-installation). Make sure Echo is installed, as well as a [server-side websockets integration](https://laravel.com/docs/broadcasting#server-side-installation) like Pusher.

Once websockets are set up, after sending a database notification you may dispatch a `DatabaseNotificationsSent` event, which will immediately fetch new notifications for that user:
Once websockets are set up, you can automatically dispatch a `DatabaseNotificationsSent` event by setting the `isEventDispatched` parameter to `true` when sending the notification. This will trigger the immediate fetching of new notifications for the user:

```php
use Filament\Notifications\Events\DatabaseNotificationsSent;
use Filament\Notifications\Notification;

$recipient = auth()->user();

Notification::make()
->title('Saved successfully')
->sendToDatabase($recipient);

event(new DatabaseNotificationsSent($recipient));
->sendToDatabase($recipient, isEventDispatched: true);
```

## Marking database notifications as read
Expand Down
10 changes: 10 additions & 0 deletions packages/panels/resources/css/base.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@layer base {
:root.dark {
color-scheme: dark;
}

/* When scrolling to validation error, do not hide element behind the top bar */
[data-field-wrapper] {
scroll-margin-top: 8rem;
}
}
19 changes: 5 additions & 14 deletions packages/panels/resources/css/index.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind variants;
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
@import 'tailwindcss/variants';

@layer base {
:root.dark {
color-scheme: dark;
}

/* When scrolling to validation error, do not hide element behind the top bar */
[data-field-wrapper] {
scroll-margin-top: 8rem;
}
}
@import 'base.css';
2 changes: 1 addition & 1 deletion packages/schema/docs/02-layout/08-custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ You may create your own custom component classes and views, which you can reuse

> If you're just creating a simple custom component to use once, you could instead use a [view component](#view-components) to render any custom Blade file.
To create a custom column class and view, you may use the following command:
To create a custom component class and view, you may use the following command:

```bash
php artisan make:filament-schema-layout Wizard
Expand Down
8 changes: 4 additions & 4 deletions packages/schema/src/Components/Concerns/HasState.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ public function dehydrateState(array &$state, bool $isDehydrated = true): void
}
}

foreach ($this->getChildComponentContainers() as $container) {
if ($container->isHidden()) {
continue;
}
if ($this->isHiddenAndNotDehydrated()) {
return;
}

foreach ($this->getChildComponentContainers(withHidden: true) as $container) {
$container->dehydrateState($state, $isDehydrated);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"illuminate/contracts": "^10.45|^11.0",
"illuminate/support": "^10.45|^11.0",
"illuminate/view": "^10.45|^11.0",
"kirschbaum-development/eloquent-power-joins": "^3.0",
"kirschbaum-development/eloquent-power-joins": "^3.0|^4.0",
"livewire/livewire": "^3.4.10 <= 3.5.6",
"ryangjchandler/blade-capture-directive": "^0.2|^0.3|^1.0",
"spatie/color": "^1.5",
Expand Down
Loading

0 comments on commit 6364fe3

Please sign in to comment.