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

Database Notifications - Customizable "Mark All as Read" Action #14157

Open
wants to merge 8 commits into
base: 4.x
Choose a base branch
from

Conversation

leandrocfe
Copy link
Contributor

Description

This feature introduces the databaseNotificationsMarkAllAsReadAction() method, which allows passing a closure that returns a custom action. It enables full customization of the Mark All as Read button using the same methods available for customizing trigger buttons.

public function panel(Panel $panel): Panel
{
    return $panel
        ...
        ->databaseNotifications()
        ->databaseNotificationsMarkAllAsReadAction(fn (Action $action) => $action
            ->button()
            ->outlined()
            ->size('sm')
            ->color('success')
        )
...

Visual changes

image

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

@leandrocfe leandrocfe requested a review from danharrin September 5, 2024 15:18
@leandrocfe
Copy link
Contributor Author

If this is approved, I can also submit the Clear Notifications actions.

@danharrin danharrin added the enhancement New feature or request label Sep 8, 2024
@danharrin danharrin added this to the v4 milestone Sep 8, 2024
@@ -28,6 +29,8 @@ class DatabaseNotifications extends Component

public static ?string $authGuard = null;

public static ?Action $markAllNotificationsAsReadAction = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of storing the action, please add HasActions and InteractsWithActions to this component, and then rename getMarkAllNotificationsAsReadAction to markAllNotificationsAsReadAction. Then you can use $this->markAllNotificationsAsReadAction to render

Copy link
Member

@danharrin danharrin Dec 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You won't need this line anymore

Comment on lines +124 to +127
if ($action = static::$markAllNotificationsAsReadAction) {
return $action;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this

@leandrocfe leandrocfe requested a review from danharrin December 9, 2024 12:43
@danharrin
Copy link
Member

@leandrocfe please check my remaining comments

@danharrin danharrin removed their request for review December 9, 2024 14:30
@leandrocfe
Copy link
Contributor Author

@leandrocfe please check my remaining comments

@danharrin did you see my answers?

@danharrin
Copy link
Member

I don't see any responses, sorry

@leandrocfe
Copy link
Contributor Author

I don't see any responses, sorry

Hey @danharrin,

I fixed it implementing HasActions and HasForms as you told me:
d71eb2d

But I think we need this

if ($action = static::$markAllNotificationsAsReadAction) {
    return $action;
}

Because when we are using Notifications in standalone mode, we can do this in the provider:

public function boot(): void
{
    DatabaseNotifications::trigger('notifications-trigger');
    DatabaseNotifications::$markAllNotificationsAsReadAction = Action::make('markAllNotificationsAsRead')
        ->label('Mark all as read')
        ->button()
        ->action('markAllNotificationsAsRead');
}

Does it make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants