F
Filament8mo ago
nowak

Why is this bad? Sending export completion notification to the UI as well as to the database.

I played around with the built in filament/packages/actions/src/Exports/Jobs/ExportCompletion.php handle() Notification, where adding ->send() to this shows the notification directly in the UI instead of only being hidden in the notifications tray:
public function handle(): void
{
$this->export->touch('completed_at');

if (! $this->export->user instanceof Authenticatable) {
return;
}

$failedRowsCount = $this->export->getFailedRowsCount();

Notification::make()
->title(__('filament-actions::export.notifications.completed.title'))
->body($this->exporter::getCompletedNotificationBody($this->export))
->when(
! $failedRowsCount,
fn (Notification $notification) => $notification->success(),
)
->when(
$failedRowsCount && ($failedRowsCount < $this->export->total_rows),
fn (Notification $notification) => $notification->warning(),
)
->when(
$failedRowsCount === $this->export->total_rows,
fn (Notification $notification) => $notification->danger(),
)
->when(
$failedRowsCount < $this->export->total_rows,
fn (Notification $notification) => $notification->actions(array_map(
fn (ExportFormat $format): NotificationAction => $format->getDownloadNotificationAction($this->export),
$this->formats,
)),
)
+ ->send()
->sendToDatabase($this->export->user);
}
public function handle(): void
{
$this->export->touch('completed_at');

if (! $this->export->user instanceof Authenticatable) {
return;
}

$failedRowsCount = $this->export->getFailedRowsCount();

Notification::make()
->title(__('filament-actions::export.notifications.completed.title'))
->body($this->exporter::getCompletedNotificationBody($this->export))
->when(
! $failedRowsCount,
fn (Notification $notification) => $notification->success(),
)
->when(
$failedRowsCount && ($failedRowsCount < $this->export->total_rows),
fn (Notification $notification) => $notification->warning(),
)
->when(
$failedRowsCount === $this->export->total_rows,
fn (Notification $notification) => $notification->danger(),
)
->when(
$failedRowsCount < $this->export->total_rows,
fn (Notification $notification) => $notification->actions(array_map(
fn (ExportFormat $format): NotificationAction => $format->getDownloadNotificationAction($this->export),
$this->formats,
)),
)
+ ->send()
->sendToDatabase($this->export->user);
}
I feel like this would make the user experience more intuitive, and reduces the amount of clicks needed by the user to download a file, and I am wondering why it wasn't implemented like this originally?
3 Replies
lukevi
lukevi8mo ago
thanks for sharing this - I don't yet have db-notifications working, so this is the only way I can see the completed exports. have you managed to implement this with an override outside of the vendors dir?
nowak
nowakOP8mo ago
What is the issue with getting database notifications working? No I have not yet managed to implement this, as I don't know if an override is safe and/or possible in this case. I created another help topic here, which also didn't provide a helpful answer: https://discord.com/channels/883083792112300104/1225793971666681866
lukevi
lukevi8mo ago
Thanks for asking – they actually started working after I closed my browser and came back. Multiple hard refreshes had not worked.
Want results from more Discord servers?
Add your server