Skip to content

Commit

Permalink
Fix: Allow to override ExportFormat with custom enum instance
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiealvin committed Jan 25, 2025
1 parent ae86b8c commit 0c0339c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 14 additions & 0 deletions packages/actions/src/Exports/Contracts/ExportEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Filament\Actions\Exports\Contracts;

use Filament\Actions\Exports\Downloaders\Contracts\Downloader;
use Filament\Actions\Exports\Models\Export;
use Filament\Notifications\Actions\Action as NotificationAction;

interface ExportEnum
{
public function getDownloader(): Downloader;

public function getDownloadNotificationAction(Export $export): NotificationAction;
}
3 changes: 2 additions & 1 deletion packages/actions/src/Exports/Enums/ExportFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Filament\Actions\Exports\Enums;

use Filament\Actions\Exports\Contracts\ExportEnum;
use Filament\Actions\Exports\Downloaders\Contracts\Downloader;
use Filament\Actions\Exports\Downloaders\CsvDownloader;
use Filament\Actions\Exports\Downloaders\XlsxDownloader;
use Filament\Actions\Exports\Models\Export;
use Filament\Notifications\Actions\Action as NotificationAction;

enum ExportFormat: string
enum ExportFormat: string implements ExportEnum
{
case Csv = 'csv';

Expand Down
6 changes: 3 additions & 3 deletions packages/actions/src/Exports/Jobs/ExportCompletion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Filament\Actions\Exports\Jobs;

use Filament\Actions\Exports\Enums\ExportFormat;
use Filament\Actions\Exports\Contracts\ExportEnum;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use Filament\Notifications\Actions\Action as NotificationAction;
Expand All @@ -27,7 +27,7 @@ class ExportCompletion implements ShouldQueue

/**
* @param array<string, string> $columnMap
* @param array<ExportFormat> $formats
* @param array<ExportEnum> $formats
* @param array<string, mixed> $options
*/
public function __construct(
Expand Down Expand Up @@ -70,7 +70,7 @@ public function handle(): void
->when(
$failedRowsCount < $this->export->total_rows,
fn (Notification $notification) => $notification->actions(array_map(
fn (ExportFormat $format): NotificationAction => $format->getDownloadNotificationAction($this->export),
fn (ExportEnum $format): NotificationAction => $format->getDownloadNotificationAction($this->export),
$this->formats,
)),
)
Expand Down

0 comments on commit 0c0339c

Please sign in to comment.