This commit is contained in:
Dan Harrin
2023-07-10 08:47:19 +01:00
parent b6b28b74b7
commit 8bc4f4457e
66 changed files with 239 additions and 186 deletions
+4
View File
@@ -69,6 +69,10 @@
}
},
"scripts": {
"cs": [
"pint",
"npm run prettier"
],
"pint": "pint",
"test:pest": "pest --parallel",
"test:phpstan": "phpstan analyse",
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace Livewire\Features\SupportUnitTesting\Tests {
namespace Livewire\Features\SupportTesting\Tests {
class Testable {
public function mountAction(string $name, array $arguments = []): static {}
@@ -6,7 +6,7 @@
<select
id="{{ $getId() }}"
wire:model.live="{{ $getName() }}"
{{ $attributes->class(['block h-9 text-sm w-full rounded-lg border-gray-300 py-1 text-gray-900 shadow-sm outline-none transition duration-75 invalid:text-gray-400 focus:border-primary-500 focus:ring-1 focus:ring-inset focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:focus:border-primary-500']) }}
{{ $attributes->class(['block h-9 w-full rounded-lg border-gray-300 py-1 text-sm text-gray-900 shadow-sm outline-none transition duration-75 invalid:text-gray-400 focus:border-primary-500 focus:ring-1 focus:ring-inset focus:ring-primary-500 dark:border-gray-600 dark:bg-gray-700 dark:text-gray-200 dark:focus:border-primary-500']) }}
>
@if (($placeholder = $getPlaceholder()) !== null)
<option value="">{{ $placeholder }}</option>
@@ -3,7 +3,7 @@
namespace Filament\Actions;
use Filament\Actions\Testing\TestsActions;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -6,7 +6,6 @@ use Closure;
use Filament\Actions\Action;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Support\Contracts\TranslatableContentDriver;
use Filament\Support\Exceptions\Cancel;
use Filament\Support\Exceptions\Halt;
use Illuminate\Database\Eloquent\Model;
@@ -3,7 +3,6 @@
namespace Filament\Actions\Contracts;
use Filament\Actions\Action;
use Filament\Forms\Contracts\HasForms;
use Filament\Support\Contracts\TranslatableContentDriver;
interface HasActions
+23
View File
@@ -6,7 +6,9 @@ use Closure;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Form;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
class CreateAction extends Action
{
@@ -14,6 +16,8 @@ class CreateAction extends Action
protected bool | Closure $canCreateAnother = true;
protected ?Closure $getRelationshipUsing = null;
public static function getDefaultName(): ?string
{
return 'create';
@@ -51,6 +55,13 @@ class CreateAction extends Action
$record->fill($data);
}
if ($relationship = $this->getRelationship()) {
/** @phpstan-ignore-next-line */
$relationship->save($record);
return $record;
}
$record->save();
return $record;
@@ -79,6 +90,13 @@ class CreateAction extends Action
});
}
public function relationship(?Closure $relationship): static
{
$this->getRelationshipUsing = $relationship;
return $this;
}
public function createAnother(bool | Closure $condition = true): static
{
$this->canCreateAnother = $condition;
@@ -105,4 +123,9 @@ class CreateAction extends Action
{
return true;
}
public function getRelationship(): Relation | Builder | null
{
return $this->evaluate($this->getRelationshipUsing);
}
}
-5
View File
@@ -2,11 +2,6 @@
namespace Filament\Actions;
use Closure;
use Filament\Support\Contracts\HasLabel as LabelInterface;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Collection;
class SelectAction extends Action
{
use Concerns\HasSelect;
@@ -11,7 +11,7 @@ use Filament\Actions\MountableAction;
use Filament\Actions\StaticAction;
use Illuminate\Support\Arr;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use function Livewire\store;
/**
+1 -1
View File
@@ -2,7 +2,7 @@
use Closure;
namespace Livewire\Features\SupportUnitTesting\Tests {
namespace Livewire\Features\SupportTesting\Tests {
class Testable {
public function fillForm(array $state = [], string $formName = 'form'): static {}
@@ -31,12 +31,15 @@ export default function colorPickerFormComponent({
if (isLiveOnPickerClose) {
new MutationObserver(() => {
if (this.$refs.panel.style.display !== 'none'){
if (this.$refs.panel.style.display !== 'none') {
return
}
this.$wire.call('$refresh')
}).observe(this.$refs.panel, { attributes: true, childList: true })
}).observe(this.$refs.panel, {
attributes: true,
childList: true,
})
}
},
@@ -175,9 +175,8 @@ export default function markdownEditorFormComponent({
)
if (isLiveOnBlur) {
this.editor.codemirror.on(
'blur',
() => this.$wire.call('$refresh'),
this.editor.codemirror.on('blur', () =>
this.$wire.call('$refresh'),
)
}
@@ -49,9 +49,7 @@ Trix.LineBreakInsertion.prototype.shouldInsertBlockBreak = function () {
}
}
export default function richEditorFormComponent({
state,
}) {
export default function richEditorFormComponent({ state }) {
return {
state,
@@ -42,7 +42,7 @@
@if (filled($statePath))
x-bind:class="{
'text-gray-400': ! (@js($statePath) in $wire.__instance.snapshot.memo.errors),
'text-danger-400': (@js($statePath) in $wire.__instance.snapshot.memo.errors),
'text-danger-400': @js($statePath) in $wire.__instance.snapshot.memo.errors,
}"
@endif
>
@@ -26,8 +26,10 @@
<input
x-data="{}"
x-bind:class="{
'border-gray-300 focus:border-primary-500 focus:ring-primary-500 dark:border-gray-600 dark:focus:border-primary-500': ! (@js($statePath) in $wire.__instance.snapshot.memo.errors),
'border-danger-600 ring-danger-600 dark:border-danger-400 dark:ring-danger-400': @js($statePath) in $wire.__instance.snapshot.memo.errors,
'border-gray-300 focus:border-primary-500 focus:ring-primary-500 dark:border-gray-600 dark:focus:border-primary-500':
! (@js($statePath) in $wire.__instance.snapshot.memo.errors),
'border-danger-600 ring-danger-600 dark:border-danger-400 dark:ring-danger-400':
@js($statePath) in $wire.__instance.snapshot.memo.errors,
}"
{{
$getExtraInputAttributeBag()
@@ -39,10 +39,7 @@
->class(['filament-forms-markdown-editor-component font-mono'])
}}
>
<textarea
x-ref="editor"
class="hidden"
></textarea>
<textarea x-ref="editor" class="hidden"></textarea>
</div>
@else
<div
@@ -10,7 +10,6 @@ use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Livewire\Livewire;
use function Livewire\store;
trait HasState
{
@@ -2,9 +2,7 @@
namespace Filament\Forms\Concerns;
use App\Models\Shop\Product;
use Filament\Forms\Components\Component;
use InvalidArgumentException;
trait HasStateBindingModifiers
{
@@ -160,6 +158,6 @@ trait HasStateBindingModifiers
return ((int) (string) str($debounce)->beforeLast('s')) * 1000;
}
return preg_replace("/[^0-9]/", '', $debounce) ?: 0;
return preg_replace('/[^0-9]/', '', $debounce) ?: 0;
}
}
+1 -1
View File
@@ -7,7 +7,7 @@ use Filament\Support\Assets\AlpineComponent;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Illuminate\Filesystem\Filesystem;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
+1 -1
View File
@@ -9,7 +9,7 @@ use Filament\Forms\Components\TextInput;
use Filament\Forms\Contracts\HasForms;
use Illuminate\Support\Arr;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
/**
* @method HasForms instance()
@@ -2,7 +2,6 @@
namespace Filament\Infolists\Contracts;
use Filament\Forms\Contracts\HasForms;
use Filament\Infolists\Infolist;
interface HasInfolists
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace Livewire\Features\SupportUnitTesting\Tests {
namespace Livewire\Features\SupportTesting\Tests {
use Filament\Notifications\Notification;
@@ -134,9 +134,13 @@ class Notification {
}
send() {
window.dispatchEvent(new CustomEvent('notificationSent', { detail: {
notification: this,
} }))
window.dispatchEvent(
new CustomEvent('notificationSent', {
detail: {
notification: this,
},
}),
)
return this
}
@@ -8,7 +8,7 @@ use Filament\Notifications\Testing\TestsNotifications;
use Filament\Support\Assets\Js;
use Filament\Support\Facades\FilamentAsset;
use Livewire\Component;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use Livewire\Livewire;
use function Livewire\on;
use function Livewire\store;
@@ -5,7 +5,7 @@ namespace Filament\Notifications\Testing;
use Closure;
use Filament\Notifications\Notification;
use Livewire\Component;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
/**
* @method Component instance()
@@ -39,7 +39,7 @@ return [
'buttons' => [
'back' => [
'label' => 'back'
'label' => 'back',
],
],
@@ -4,7 +4,9 @@
'subheading' => null,
])
<div class="filament-card-layout flex min-h-screen items-center justify-center py-14">
<div
class="filament-card-layout flex min-h-screen items-center justify-center py-14"
>
<div
@class([
'w-screen space-y-8 px-6 md:mt-0 md:px-2',
@@ -35,9 +37,7 @@
<div class="space-y-2">
@if (filled($heading ??= $this->getHeading()))
<h2
class="text-center text-2xl font-bold tracking-tight"
>
<h2 class="text-center text-2xl font-bold tracking-tight">
{{ $heading }}
</h2>
@endif
@@ -64,7 +64,8 @@
class="absolute end-0 top-0 flex w-full items-center justify-end p-2"
>
@if (filament()->hasDatabaseNotifications())
@livewire(Filament\Livewire\DatabaseNotifications::class, ['lazy' => true]))
@livewire(Filament\Livewire\DatabaseNotifications::class, ['lazy' => true])
)
@endif
<x-filament::user-menu />
@@ -4,6 +4,7 @@
$profileItem = $items['profile'] ?? $items['account'] ?? null;
$profileItemUrl = $profileItem?->getUrl();
$profilePage = filament()->getProfilePage();
$hasProfile = filament()->hasProfile() || filled($profileItemUrl);
$logoutItem = $items['logout'] ?? null;
@@ -33,7 +34,7 @@
:href="$profileItemUrl ?? filament()->getProfileUrl()"
tag="a"
>
{{ $profileItem?->getLabel() ?? filament()->getProfilePage()::getLabel() ?? filament()->getUserName($user) }}
{{ $profileItem?->getLabel() ?? ($profilePage ? $profilePage::getLabel() : null) ?? filament()->getUserName($user) }}
</x-filament::dropdown.list.item>
</x-filament::dropdown.list>
@else
@@ -13,7 +13,9 @@
@if ($this->hasInfolist())
{{ $this->infolist }}
@else
<div wire:key="{{ $this->getId() }}.forms.{{ $this->getFormStatePath() }}">
<div
wire:key="{{ $this->getId() }}.forms.{{ $this->getFormStatePath() }}"
>
{{ $this->form }}
</div>
@endif
@@ -2,7 +2,6 @@
namespace Filament\GlobalSearch\Actions;
use Filament\Actions\Concerns\CanDispatchEvent;
use Filament\Actions\StaticAction;
class Action extends StaticAction
+11 -3
View File
@@ -2,6 +2,7 @@
namespace Filament\Pages\Auth;
use Exception;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Facades\Filament;
@@ -14,7 +15,8 @@ use Filament\Pages\CardPage;
use Filament\Pages\Concerns;
use Filament\Panel;
use Filament\Support\Exceptions\Halt;
use Illuminate\Contracts\Auth\Authenticatable;use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Route;
@@ -68,9 +70,15 @@ class EditProfile extends CardPage
$this->fillForm();
}
public function getUser(): Authenticatable
public function getUser(): Authenticatable & Model
{
return Filament::auth()->getUser();
$user = Filament::auth()->user();
if (! $user instanceof Model) {
throw new Exception('The authenticated user object must be an Eloquent model to allow the profile page to update it.');
}
return $user;
}
protected function fillForm(): void
@@ -7,7 +7,6 @@ use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Filament\Actions\Action;
use Filament\Facades\Filament;
use Filament\Forms\Components\Component;
use Filament\Forms\Components\Field;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Http\Responses\Auth\Contracts\RegistrationResponse;
@@ -4,10 +4,10 @@ namespace Filament\Pages\Tenancy;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use function Filament\authorize;
use Filament\Facades\Filament;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Pages\CardPage;
use Filament\Pages\Concerns;
use Filament\Pages\Page;
use Filament\Panel;
@@ -17,7 +17,6 @@ use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Route;
use Livewire\Attributes\Locked;
use function Filament\authorize;
/**
* @property Form $form
@@ -37,6 +36,9 @@ abstract class EditTenantProfile extends Page
*/
public ?array $data = [];
/**
* @var ?Model
*/
#[Locked]
public $tenant = null;
@@ -2,7 +2,6 @@
namespace Filament\Resources\Pages;
use Exception;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Facades\Filament;
@@ -102,7 +101,7 @@ class CreateRecord extends Page
/**
* @internal Never override or call this method. If you completely override `create()`, copy the contents of this method into your override.
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data
*/
protected function createRecordAndCallHooks(array $data): void
{
@@ -174,7 +173,7 @@ class CreateRecord extends Page
$record = new ($this->getModel())($data);
if ($tenant = Filament::getTenant()) {
$this->associateRecordWithTenant($record, $tenant);
return $this->associateRecordWithTenant($record, $tenant);
}
$record->save();
@@ -182,18 +181,9 @@ class CreateRecord extends Page
return $record;
}
protected function associateRecordWithTenant(Model $record, Model $tenant): void
protected function associateRecordWithTenant(Model $record, Model $tenant): Model
{
$relationshipName = Filament::getTenantOwnershipRelationshipName();
if (! $record->isRelation($relationshipName)) {
$pageClass = static::class;
$recordClass = $record::class;
throw new Exception("The model [{$recordClass}] does not have a relationship named [{$relationshipName}]. This relationship is required to associate the record with the tenant. You can change the relationship being used by passing it to the [ownershipRelationship] argument of the [tenant()] method in configuration. Alternatively, you can override the [associateRecordWithTenant()] method on the [{$pageClass}] class to associate the record with the tenant in a different way.");
}
$record->{$relationshipName}()->associate($tenant);
return static::getResource()::getTenantRelationship($tenant)->save($record);
}
/**
@@ -84,7 +84,7 @@ class EditRecord extends Page
/**
* @internal Never override or call this method. If you completely override `fillForm()`, copy the contents of this method into your override.
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data
*/
protected function fillFormWithDataAndCallHooks(array $data): void
{
@@ -4,6 +4,7 @@ namespace Filament\Resources\Pages;
use Filament\Actions\Action;
use Filament\Actions\CreateAction;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists\Infolist;
@@ -14,6 +15,7 @@ use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;
class ListRecords extends Page implements Forms\Contracts\HasForms, Tables\Contracts\HasTable
@@ -97,7 +99,8 @@ class ListRecords extends Page implements Forms\Contracts\HasForms, Tables\Contr
->authorize($resource::canCreate())
->model($this->getModel())
->modelLabel($this->getModelLabel())
->form(fn (Form $form): Form => $this->form($form->columns(2)));
->form(fn (Form $form): Form => $this->form($form->columns(2)))
->relationship(($tenant = Filament::getTenant()) ? fn (): Relation => static::getResource()::getTenantRelationship($tenant) : null);
if ($resource::hasPage('create')) {
$action->url(fn (): string => $resource::getUrl('create'));
@@ -221,6 +224,7 @@ class ListRecords extends Page implements Forms\Contracts\HasForms, Tables\Contr
{
return $this->makeBaseTable()
->query(fn (): Builder => $this->getTableQuery())
->relationship(($tenant = Filament::getTenant()) ? fn (): Relation => static::getResource()::getTenantRelationship($tenant) : null)
->modelLabel($this->getModelLabel() ?? static::getResource()::getModelLabel())
->pluralModelLabel($this->getPluralModelLabel() ?? static::getResource()::getPluralModelLabel())
->recordAction(function (Model $record, Table $table): ?string {
@@ -87,7 +87,7 @@ class ViewRecord extends Page implements HasInfolists
/**
* @internal Never override or call this method. If you completely override `fillForm()`, copy the contents of this method into your override.
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data
*/
protected function fillFormWithDataAndCallHooks(array $data): void
{
@@ -16,8 +16,8 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Str;
use Livewire\Component;
use Livewire\Attributes\Locked;
use Livewire\Component;
class RelationManager extends Component implements Forms\Contracts\HasForms, Tables\Contracts\HasTable
{
+64 -2
View File
@@ -2,6 +2,7 @@
namespace Filament\Resources;
use Exception;
use function Filament\authorize;
use Filament\Facades\Filament;
use Filament\Forms\Form;
@@ -21,6 +22,8 @@ use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Connection;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route;
@@ -74,6 +77,10 @@ abstract class Resource
protected static ?string $slug = null;
protected static ?string $tenantOwnershipRelationshipName = null;
protected static ?string $tenantRelationshipName = null;
/**
* @var string | array<string>
*/
@@ -299,9 +306,23 @@ abstract class Resource
return $query;
}
public static function scopeEloquentQueryToTenant(Builder $query, Model $tenant): Builder
public static function scopeEloquentQueryToTenant(Builder $query, ?Model $tenant): Builder
{
return $query->whereBelongsTo($tenant);
$tenant ??= Filament::getTenant();
$tenantOwnershipRelationship = static::getTenantOwnershipRelationship($query->getModel());
$tenantOwnershipRelationshipName = static::getTenantOwnershipRelationshipName();
return match (true) {
$tenantOwnershipRelationship instanceof BelongsTo => $query->whereBelongsTo(
$tenant,
$tenantOwnershipRelationshipName,
),
default => $query->whereHas(
$tenantOwnershipRelationshipName,
fn (Builder $query) => $query->whereKey($tenant->getKey()),
),
};
}
/**
@@ -708,4 +729,45 @@ abstract class Resource
{
return static::$isDiscovered;
}
public static function getTenantOwnershipRelationshipName(): string
{
return static::$tenantOwnershipRelationshipName ?? Filament::getTenantOwnershipRelationshipName();
}
public static function getTenantOwnershipRelationship(Model $record): Relation
{
$relationshipName = static::getTenantOwnershipRelationshipName();
if (! $record->isRelation($relationshipName)) {
$resourceClass = static::class;
$recordClass = $record::class;
throw new Exception("The model [{$recordClass}] does not have a relationship named [{$relationshipName}]. You can change the relationship being used by passing it to the [ownershipRelationship] argument of the [tenant()] method in configuration. You can change the relationship being used per-resource by setting it as the [\$tenantOwnershipRelationshipName] static property on the [{$resourceClass}] resource class.");
}
return $record->{$relationshipName}();
}
public static function getTenantRelationshipName(): string
{
return static::$tenantRelationshipName ?? (string) str(static::getModel())
->classBasename()
->pluralStudly()
->camel();
}
public static function getTenantRelationship(Model $tenant): Relation
{
$relationshipName = static::getTenantRelationshipName();
if (! $tenant->isRelation($relationshipName)) {
$resourceClass = static::class;
$tenantClass = $tenant::class;
throw new Exception("The model [{$tenantClass}] does not have a relationship named [{$relationshipName}]. You can change the relationship being used by setting it as the [\$tenantRelationshipName] static property on the [{$resourceClass}] resource class.");
}
return $tenant->{$relationshipName}();
}
}
@@ -7,9 +7,7 @@ use Filament\Tables\Contracts\HasTable;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Livewire\Attributes\Reactive;
use function Livewire\store;
use function Livewire\trigger;
trait InteractsWithPageTable
@@ -2,8 +2,6 @@
namespace Filament\Actions;
use Filament\SpatieLaravelTranslatablePlugin;
class LocaleSwitcher extends SelectAction
{
use Concerns\HasTranslatableLocaleOptions;
@@ -2,8 +2,6 @@
namespace Filament\Resources\Pages\Concerns;
use Illuminate\Database\Eloquent\Model;
trait HasTranslatableFormWithExistingRecordData
{
protected function fillForm(): void
@@ -3,7 +3,6 @@
namespace Filament\Resources\Pages\CreateRecord\Concerns;
use Filament\Resources\Concerns\HasActiveLocaleSwitcher;
use Filament\Resources\Pages\Concerns\HasTranslatableRecordTitle;
use Filament\Support\Exceptions\Halt;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
@@ -5,7 +5,6 @@ namespace Filament\Resources\Pages\EditRecord\Concerns;
use Filament\Resources\Concerns\HasActiveLocaleSwitcher;
use Filament\Resources\Pages\Concerns\HasTranslatableFormWithExistingRecordData;
use Filament\Resources\Pages\Concerns\HasTranslatableRecord;
use Filament\Resources\Pages\Concerns\HasTranslatableRecordTitle;
use Filament\Support\Exceptions\Halt;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
@@ -77,6 +76,7 @@ trait Translatable
$this->form->validate();
} catch (ValidationException $exception) {
$this->activeLocale = $this->oldActiveLocale;
throw $exception;
}
@@ -3,11 +3,6 @@
namespace Filament\Resources\Pages\ListRecords\Concerns;
use Filament\Resources\Concerns\HasActiveLocaleSwitcher;
use Filament\SpatieLaravelTranslatableContentDriver;
use Filament\Support\Contracts\TranslatableContentDriver;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
trait Translatable
{
@@ -2,13 +2,7 @@
namespace Filament\Resources\Pages\ManageRecords\Concerns;
use Filament\Resources\Concerns\HasActiveLocaleSwitcher;
use Filament\Resources\Pages\ListRecords\Concerns\Translatable as ListRecordsTranslatable;
use Filament\SpatieLaravelTranslatableContentDriver;
use Filament\Support\Contracts\TranslatableContentDriver;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
trait Translatable
{
@@ -5,9 +5,6 @@ namespace Filament\Resources\Pages\ViewRecord\Concerns;
use Filament\Resources\Concerns\HasActiveLocaleSwitcher;
use Filament\Resources\Pages\Concerns\HasTranslatableFormWithExistingRecordData;
use Filament\Resources\Pages\Concerns\HasTranslatableRecord;
use Filament\Resources\Pages\Concerns\HasTranslatableRecordTitle;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\ValidationException;
trait Translatable
{
@@ -3,11 +3,6 @@
namespace Filament\Resources\RelationManagers\Concerns;
use Filament\Resources\Concerns\HasActiveLocaleSwitcher;
use Filament\SpatieLaravelTranslatableContentDriver;
use Filament\Support\Contracts\TranslatableContentDriver;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
trait Translatable
{
@@ -3,8 +3,6 @@
namespace Filament\Tables\Actions;
use Filament\Actions\Concerns\HasTranslatableLocaleOptions;
use Filament\Tables\Actions\SelectAction;
use Filament\SpatieLaravelTranslatablePlugin;
class LocaleSwitcher extends SelectAction
{
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace Livewire\Features\SupportUnitTesting\Tests {
namespace Livewire\Features\SupportTesting\Tests {
use Illuminate\Support\Collection;
@@ -9,28 +9,25 @@
isLoading: false,
}"
x-init="
Livewire.hook(
'commit',
({ component, commit, succeed, fail, respond }) => {
succeed(({ snapshot, effect }) => {
if (component.id !== @js($this->getId())) {
return
}
Livewire.hook('commit', ({ component, commit, succeed, fail, respond }) => {
succeed(({ snapshot, effect }) => {
if (component.id !== @js($this->getId())) {
return
}
if (! $refs.newState) {
return
}
if (! $refs.newState) {
return
}
let newState = $refs.newState.value === '1' ? true : false
let newState = $refs.newState.value === '1' ? true : false
if (state === newState) {
return
}
if (state === newState) {
return
}
state = newState
})
},
)
state = newState
})
})
"
{{
$attributes
@@ -10,28 +10,25 @@
isLoading: false,
}"
x-init="
Livewire.hook(
'commit',
({ component, commit, succeed, fail, respond }) => {
succeed(({ snapshot, effect }) => {
if (component.id !== @js($this->getId())) {
return
}
Livewire.hook('commit', ({ component, commit, succeed, fail, respond }) => {
succeed(({ snapshot, effect }) => {
if (component.id !== @js($this->getId())) {
return
}
if (! $refs.newState) {
return
}
if (! $refs.newState) {
return
}
let newState = $refs.newState.value
let newState = $refs.newState.value
if (state === newState) {
return
}
if (state === newState) {
return
}
state = newState
})
},
)
state = newState
})
})
"
{{
$attributes
@@ -11,32 +11,29 @@
isEditing: false,
}"
x-init="
Livewire.hook(
'commit',
({ component, commit, succeed, fail, respond }) => {
succeed(({ snapshot, effect }) => {
if (component.id !== @js($this->getId())) {
return
}
Livewire.hook('commit', ({ component, commit, succeed, fail, respond }) => {
succeed(({ snapshot, effect }) => {
if (component.id !== @js($this->getId())) {
return
}
if (isEditing) {
return
}
if (isEditing) {
return
}
if (! $refs.newState) {
return
}
if (! $refs.newState) {
return
}
let newState = $refs.newState.value
let newState = $refs.newState.value
if (state === newState) {
return
}
if (state === newState) {
return
}
state = newState
})
},
)
state = newState
})
})
"
{{
$attributes
@@ -119,7 +119,9 @@
shouldCheckUniqueSelection: true,
init: function () {
$el.addEventListener('deselectAllTableRecords', () => this.deselectAllRecords())
$el.addEventListener('deselectAllTableRecords', () =>
this.deselectAllRecords(),
)
$watch('selectedRecords', () => {
if (! this.shouldCheckUniqueSelection) {
@@ -2,7 +2,6 @@
namespace Filament\Tables\Actions\Contracts;
use Filament\Support\Contracts\TranslatableContentDriver;
use Filament\Tables\Table;
interface HasTable
@@ -2,12 +2,7 @@
namespace Filament\Tables\Actions;
use Closure;
use Filament\Tables\Actions\Action;
use Filament\Actions\Concerns;
use Filament\Support\Contracts\HasLabel as LabelInterface;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Support\Collection;
class SelectAction extends Action
{
@@ -4,14 +4,12 @@ namespace Filament\Tables\Concerns;
use Closure;
use Filament\Forms;
use Filament\Support\Contracts\TranslatableContentDriver;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\BulkAction;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\Relation;
use Livewire\Features\SupportPagination\HandlesPagination;
use Livewire\WithPagination;
trait InteractsWithTable
@@ -2,7 +2,6 @@
namespace Filament\Tables\Contracts;
use Filament\Forms\Contracts\HasForms;
use Filament\Forms\Form;
use Filament\Support\Contracts\TranslatableContentDriver;
use Filament\Tables\Actions\Action;
@@ -11,7 +11,7 @@ use Filament\Tables\Testing\TestsFilters;
use Filament\Tables\Testing\TestsRecords;
use Filament\Tables\Testing\TestsSummaries;
use Illuminate\Filesystem\Filesystem;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
+1 -1
View File
@@ -9,7 +9,7 @@ use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use function Livewire\store;
/**
@@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
use function Livewire\store;
/**
+1 -1
View File
@@ -7,7 +7,7 @@ use Filament\Tables\Columns\Column;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
/**
* @method HasTable instance()
+1 -1
View File
@@ -10,7 +10,7 @@ use Filament\Tables\Filters\TernaryFilter;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
/**
* @method HasTable instance()
+1 -1
View File
@@ -7,7 +7,7 @@ use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
/**
* @method HasTable instance()
@@ -6,7 +6,7 @@ use Closure;
use Filament\Tables\Columns\Summarizers\Summarizer;
use Filament\Tables\Contracts\HasTable;
use Illuminate\Testing\Assert;
use Livewire\Features\SupportUnitTesting\Testable;
use Livewire\Features\SupportTesting\Testable;
/**
* @method HasTable instance()
@@ -23,7 +23,9 @@ it('can request password reset', function () {
$userToResetPassword = User::factory()->create();
livewire(RequestPasswordReset::class)
->set('email', $userToResetPassword->email)
->fillForm([
'email' => $userToResetPassword->email,
])
->call('request')
->assertNotified();
@@ -39,7 +41,9 @@ it('can throttle requests', function () {
$userToResetPassword = User::factory()->create();
livewire(RequestPasswordReset::class)
->set('email', $userToResetPassword->email)
->fillForm([
'email' => $userToResetPassword->email,
])
->call('request')
->assertNotified();
@@ -49,7 +53,9 @@ it('can throttle requests', function () {
$userToResetPassword = User::factory()->create();
livewire(RequestPasswordReset::class)
->set('email', $userToResetPassword->email)
->fillForm([
'email' => $userToResetPassword->email,
])
->call('request')
->assertNotified();
@@ -58,14 +64,18 @@ it('can throttle requests', function () {
it('can validate `email` is required', function () {
livewire(RequestPasswordReset::class)
->set('email', '')
->fillForm([
'email' => '',
])
->call('request')
->assertHasErrors(['email' => ['required']]);
->assertHasFormErrors(['email' => ['required']]);
});
it('can validate `email` is valid email', function () {
livewire(RequestPasswordReset::class)
->set('email', 'invalid-email')
->fillForm([
'email' => 'invalid-email',
])
->call('request')
->assertHasErrors(['email' => ['email']]);
->assertHasFormErrors(['email' => ['email']]);
});