-
Notifications
You must be signed in to change notification settings - Fork 33
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
refactor: restructure alert system for default integration and Livewire compatibility #78
base: master
Are you sure you want to change the base?
refactor: restructure alert system for default integration and Livewire compatibility #78
Conversation
…re compatibility - Added dynamic alert container for handling Livewire events - Updated configuration for customizable alert positions, duration, and dismissibility - Improved JavaScript listener for seamless Livewire integration - Ensured backward compatibility with session-based static alerts - Removed deprecated `alert.blade.php` view in favor of `alerts-container.blade.php` This refactor enhances the flexibility and usability of the Tablar alert system while maintaining compatibility with existing functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know your update, and I will do further examination. It would be super helpful if you could write some tests for it.
@@ -10,6 +10,9 @@ | |||
@section('classes_body', $layoutHelper->makeBodyClasses()) | |||
|
|||
@section('layout') | |||
@if(config('tablar','display_alert')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should have resolved 2 conditions.
- when display_alert = true
- when livewire = true
It's all about livewire, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @takielias,
Thanks for your feedback! The changes I made are not just about Livewire. I’ve also modified the normal (non-Livewire) usage of alerts to ensure they are always included as an overlay, making them more dynamic and consistent across all use cases.
This means:
When display_alert = true, the alert container will always be rendered, regardless of whether Livewire is being used or not.
For normal (non-Livewire) alerts, they now behave dynamically with improved configuration options (e.g., duration, dismissibility).
For Livewire, the alerts integrate seamlessly using JavaScript events.
If you'd prefer, I can create a separate, more focused PR that resolves the Livewire compatibility issue without modifying the normal alert behavior.
Let me know if this approach works better for you, and I’ll be happy to make the adjustments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ser-tec Thanks for the detailed explanation! For better maintainability and extensibility, would it make sense to keep the concerns separated? I think having a dedicated PR for the Livewire integration would help keep the codebase cleaner. Let me know what you think.
@@ -10,6 +10,9 @@ | |||
@section('classes_body', $layoutHelper->makeBodyClasses()) | |||
|
|||
@section('layout') | |||
@if(config('tablar','display_alert')) | |||
@include('tablar::partials.common.alerts-container') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be great if you make it common.livewire-alert
Problem
This PR addresses Issue #77, which describes a compatibility problem between the Tablar alert system and Livewire. The session-based flash messages were not displayed during Livewire's render cycle, causing alerts to fail.
Solution
alerts-container.blade.php
for rendering alerts dynamically.alert
events and manage alert display.tablar.php
configuration for additional options like positions, duration, and dismissibility.Related Issue
Resolves #77
How to Use the Updated Alert System
This update introduces a more flexible alert system compatible with Livewire, while maintaining full backward compatibility. Here’s how it works:
1. Enable Alerts in Configuration
In your
config/tablar.php
file, ensure that alerts are enabled:'display_alert' => true,
You can also customize the default alert behavior:
2. Alert Container
The alert container is already included in
page.blade.php
:If your project uses a custom layout and does not rely on
page.blade.php
, you must include the container manually in your layout file:3. Backward Compatibility with Static Alerts
This system is fully backward compatible with static session-based alerts. You can use them as before:
Static alerts will inherit the default configuration values (e.g., dismissibility and duration). If you want to customize these values, you can pass an array instead of a string:
4. Using Alerts with Livewire
To trigger alerts dynamically from Livewire, dispatch a browser event:
5. Error Handling
If there are validation errors, they will automatically be displayed as alerts. Ensure you handle validation errors properly in your controller:
Notes on CSS and JavaScript Placement
Currently, the CSS and JavaScript code for the alert system are included directly in resources/views/partials/common/alerts-container.blade.php.
This was done because I don’t know where the maintainers prefer to place these assets. If you can provide specific guidance on where to move the CSS and JavaScript, I will be happy to update the implementation accordingly.
Please let me know where you’d like these assets to be placed, and I’ll make the necessary changes.