Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Header Action Not Displaying in MyManageOrder in LunarPHP #2043

Open
artur33s opened this issue Dec 24, 2024 · 4 comments
Open

Custom Header Action Not Displaying in MyManageOrder in LunarPHP #2043

artur33s opened this issue Dec 24, 2024 · 4 comments
Labels
bug Something isn't working unconfirmed

Comments

@artur33s
Copy link

  • Lunar version: 1.0.0-beta6
  • Laravel Version: 11.33.2
  • PHP Version: 8.3.15
  • Database Driver & Version:

Hello, I am facing an issue with adding a custom header action to the MyManageOrder page in LunarPHP. I have extended the ManageOrder class and overridden the getDefaultHeaderActions() method to include a new action using Filament's Action::make.
The custom action appears to be correctly added to the $actions array, and I confirmed that the MyManageOrder class is loaded by testing it with dd(). However, the action does not render on the page. I have already tried the following:

When I directly edit the vendor-provided ManageOrder class (within the LunarPHP vendor folder) and add the same Action::make, the button is rendered and works as expected. This makes me think that I may be missing a configuration or process when extending the ManageOrder class with my own.
Could you provide guidance on what might be causing the custom action to not render in my extended class? My task is simply to add a button to the header that performs a specific action. Any advice or suggestions would be greatly appreciated. Thank you!

class MyManageOrder extends ManageOrder
{
    protected function getDefaultHeaderActions(): array
    {
        return [
            $this->getCaptureAction(),
            $this->getRefundAction(),
            UpdateStatusAction::make('update_status')
                ->after(
                    function () {
                        $this->dispatchActivityUpdated();
                    }
                ),
            PdfDownload::make('download_pdf')
                ->pdfView('lunarpanel::pdf.order')
                ->label(__('lunarpanel::order.action.download_order_pdf.label'))
                ->filename(function ($record) {
                    return "Order-{$record->reference}.pdf";
                }),
            Action::make('shipment_label') // New Button
            ->label(__('Shipment Create'))
                ->action(function () {
                    // Shipment Label
                }),
        ];
    }
}
@artur33s artur33s added bug Something isn't working unconfirmed labels Dec 24, 2024
@glennjacobs
Copy link
Contributor

glennjacobs commented Dec 24, 2024

It looks like you are trying to extend the main class. This isn't the correct approach.

ManagerOrder is a page, so you need to use its page extension.

It's the same concept as this

https://docs.lunarphp.io/admin/extending/pages.html

@artur33s
Copy link
Author

Thanks you

It looks like you are trying to extend the main class. This isn't the correct approach.

ManagerOrder is a page, so you need to use its page extension.

It's the same concept as this

https://docs.lunarphp.io/admin/extending/pages.html

Thanks you, My update code:

ManageOrderExtension

class ManageOrderExtension extends ViewPageExtension
{
    public function headerActions(array $actions): array
    {
        return [
            ...$actions,
            Actions\Action::make('shipmentDownloadLabel')
            ->label('Download Label')
            ->color('primary')
            ->action(function ($record) {
                dd($record);
            }),
        ];
    }
}

AppServiceProvider

 public function boot(): void
    {
        LunarPanel::extensions([
            \Lunar\Admin\Filament\Resources\OrderResource\Pages\ManageOrder::class => ManageOrderExtension::class,
        ]);
    }

Right now is working! Thank you for helping me!

@glennjacobs
Copy link
Contributor

That's great news.

I'm going to leave this open, as I expected us to have the page extension in the codebase and it wasn't.

We should really have something like Lunar\Admin\Support\Extending\ManageOrderPageExtension

@alecritson
Copy link
Collaborator

@glennjacobs I'm not sure why we need a ManageOrderPageExtension class as it won't provide anything that extending the ViewPageExtension won't provide? ManageOrder is just an extension of BaseViewRecord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed
Projects
None yet
Development

No branches or pull requests

3 participants