Hugo
Hugo
FFilament
Created by Grégoire on 8/12/2024 in #❓┊help
Looping through multiple Livewire components containing Filament Action crashes Firefox/Safari
@Grégoire I've found a solution that works even when leaving the InteractsWithActions. This is a temporary solution, allowing you to space out requests if they're too close to each other. Just add this JS script to your page:
@push('scripts')
<script>
const original = window.history.replaceState;
let timer = Date.now();

let timeout = null;
let lastArgs = null;

window.history.replaceState = function (...args) {
const time = Date.now();
if (time - timer < 300) {
lastArgs = args;

if (timeout) {
clearTimeout(timeout);
}

timeout = setTimeout(() => {
original.apply(this, lastArgs);

timeout = null;
lastArgs = null;
}, 100);

return;
}

timer = time;

original.apply(this, args);
};
</script>
@endpush
@push('scripts')
<script>
const original = window.history.replaceState;
let timer = Date.now();

let timeout = null;
let lastArgs = null;

window.history.replaceState = function (...args) {
const time = Date.now();
if (time - timer < 300) {
lastArgs = args;

if (timeout) {
clearTimeout(timeout);
}

timeout = setTimeout(() => {
original.apply(this, lastArgs);

timeout = null;
lastArgs = null;
}, 100);

return;
}

timer = time;

original.apply(this, args);
};
</script>
@endpush
11 replies
FFilament
Created by Grégoire on 8/12/2024 in #❓┊help
Looping through multiple Livewire components containing Filament Action crashes Firefox/Safari
Yes, I came across it while looking for a solution. I hope this problem will be solved
11 replies
FFilament
Created by Grégoire on 8/12/2024 in #❓┊help
Looping through multiple Livewire components containing Filament Action crashes Firefox/Safari
Have you been able to create an issue on filament or livewire ?
11 replies
FFilament
Created by Grégoire on 8/12/2024 in #❓┊help
Looping through multiple Livewire components containing Filament Action crashes Firefox/Safari
And indeed I confirm that by removing the InteractsWithActions I no longer have the problem, however this is really problematic for the logic of my application...
11 replies
FFilament
Created by Grégoire on 8/12/2024 in #❓┊help
Looping through multiple Livewire components containing Filament Action crashes Firefox/Safari
No description
11 replies
FFilament
Created by Hugo on 7/30/2024 in #❓┊help
Closure on column action doesn't work
Okay, that's how it worked, I hadn't thought of that. Thanks for your help !
7 replies
FFilament
Created by Hugo on 7/30/2024 in #❓┊help
Closure on column action doesn't work
Up
7 replies
FFilament
Created by atabegruslan on 7/24/2024 in #❓┊help
How loop a list in View item view (infolist)?
Yes exactly ! 👍
12 replies
FFilament
Created by atabegruslan on 7/24/2024 in #❓┊help
How loop a list in View item view (infolist)?
You can build a new section dynamically before the “return $infolist”, by doing your foreach on the variants of your product, store this section in a variable and display it in your schema. Something like that :
public static function infolist(Infolist $infolist): Infolist
{
$variantsSection = // build your variantSection with a foreach here

return $infolist
->schema([
Forms\Components\Section::make()
->schema([
TextEntry::make('name'),
TextEntry::make('category.name'),
ImageEntry::make('thumbnail'),
]),

$variantSection
]);
}
public static function infolist(Infolist $infolist): Infolist
{
$variantsSection = // build your variantSection with a foreach here

return $infolist
->schema([
Forms\Components\Section::make()
->schema([
TextEntry::make('name'),
TextEntry::make('category.name'),
ImageEntry::make('thumbnail'),
]),

$variantSection
]);
}
12 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
This pretty much works, not all of my fields are completely populated. I think it's a good lead in any case. I'll continue to dig in this direction. Thanks ! 😄
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
i call my Action like that :
PaginatedAction::make('paginated')
->form(ApplicationResource::getResourceForm())
->stickyModalHeader()
->stickyModalFooter()
->modalCancelAction(false)
->modalFooterActionsAlignment(Alignment::Center)
->modalWidth('full'),
PaginatedAction::make('paginated')
->form(ApplicationResource::getResourceForm())
->stickyModalHeader()
->stickyModalFooter()
->modalCancelAction(false)
->modalFooterActionsAlignment(Alignment::Center)
->modalWidth('full'),
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
Yes
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
I've also tried using ->fillForm(), but it doesn't work either
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
When you click on prev or next, the new record is applied to the action, but the fields in the form are not updated
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
The record doesn't change with the next or the prev... and I have no errors :
trait CanPaginateViewRecord
{
public function prepareModalAction(StaticAction $action): StaticAction
{
$action = match (true) {
$action instanceof PreviousAction => $this->configurePreviousAction($action),
$action instanceof NextAction => $this->configureNextAction($action),

default => null,
};

return parent::prepareModalAction($action);
}

protected function configurePreviousAction(Action $action): Action
{
if ($this->getPreviousRecord()) {
$action->action(function () {
$this->record($this->getPreviousRecord());
$this->model(Application::class);
});
} else {
$action
->disabled()
->color('gray');
}

return $action;
}

protected function configureNextAction(Action $action): Action
{
if ($this->getNextRecord()) {
$action->action(function () {
$this->record($this->getNextRecord());
$this->model(Application::class);
});
} else {
$action
->disabled()
->color('gray');
}

return $action;
}
...
trait CanPaginateViewRecord
{
public function prepareModalAction(StaticAction $action): StaticAction
{
$action = match (true) {
$action instanceof PreviousAction => $this->configurePreviousAction($action),
$action instanceof NextAction => $this->configureNextAction($action),

default => null,
};

return parent::prepareModalAction($action);
}

protected function configurePreviousAction(Action $action): Action
{
if ($this->getPreviousRecord()) {
$action->action(function () {
$this->record($this->getPreviousRecord());
$this->model(Application::class);
});
} else {
$action
->disabled()
->color('gray');
}

return $action;
}

protected function configureNextAction(Action $action): Action
{
if ($this->getNextRecord()) {
$action->action(function () {
$this->record($this->getNextRecord());
$this->model(Application::class);
});
} else {
$action
->disabled()
->color('gray');
}

return $action;
}
...
class PaginatedAction extends ViewAction
{
use CanPaginateViewRecord;

protected function setUp(): void
{
parent::setUp();

$this->extraModalFooterActions([
PreviousAction::make(),
NextAction::make(),
]);
}
}
class PaginatedAction extends ViewAction
{
use CanPaginateViewRecord;

protected function setUp(): void
{
parent::setUp();

$this->extraModalFooterActions([
PreviousAction::make(),
NextAction::make(),
]);
}
}
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
But as I don't use pages, but a modal, I have to change the record to next or previous, so how to do instead of $action->url(fn (): string => static::getResource()::getUrl(static::getResourcePageName(), ['record' => $this->getNextRecord() ])); in your trait ? 😕
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
Nice, I'd seen 😉
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
I see, I'll try to adapt it to my ViewAction, thanks !
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
No description
29 replies
FFilament
Created by Hugo on 4/18/2024 in #❓┊help
Navigate between records on ViewAction
Now the next button works, but the form loses the record and I don't know how to set the new record :
->action(function (array $data, array $arguments, Tables\Actions\ViewAction $action, Table $table, $record, Form $form): void {

if ($arguments['type'] == 'next') {

$records = $table->getRecords();
$index = array_search($record, $records->items());
$next = $records[$index + 1] ?? $records[0];

$action->record($next);
$action->model(Application::class);

$form->model(Application::class);
$form->operation('view');

$form->fill($next->attributesToArray());

$action->halt();

return;
}

}),
->action(function (array $data, array $arguments, Tables\Actions\ViewAction $action, Table $table, $record, Form $form): void {

if ($arguments['type'] == 'next') {

$records = $table->getRecords();
$index = array_search($record, $records->items());
$next = $records[$index + 1] ?? $records[0];

$action->record($next);
$action->model(Application::class);

$form->model(Application::class);
$form->operation('view');

$form->fill($next->attributesToArray());

$action->halt();

return;
}

}),
29 replies