diff --git a/docs/05-panel-configuration.md b/docs/05-panel-configuration.md index 1841d8b7a83..c606128e5a4 100644 --- a/docs/05-panel-configuration.md +++ b/docs/05-panel-configuration.md @@ -489,6 +489,26 @@ public function panel(Panel $panel): Panel } ``` +You may also choose to hide a notification for a specific HTTP status code, such as `403`, by passing that status code to the `hideErrorNotification` method. A hidden status code will still be caught by filament, but no notification will be shown. + +Alternatively, you can use the `disableErrorNotification` method to fall back to Livewire's built-in error handling for that status code. This is useful if you want to hook into the Livewire error handling system to customize the error handling behavior for a specific status code but maintain Filament's error notification system for everything else. + +```php +use Filament\Panel; + +public function panel(Panel $panel): Panel +{ + return $panel + // ... + ->registerErrorNotification( + title: 'An error occurred', + body: 'Please try again later.', + ) + ->hideErrorNotification(403) + ->disableErrorNotification(503); +} +``` + You can also enable or disable error notifications for specific pages in a panel by setting the `$hasErrorNotifications` property on the page class: ```php @@ -565,3 +585,28 @@ class Dashboard extends BaseDashboard // ... } ``` + +You may also choose to hide a notification for a specific HTTP status code, such as `403`, by passing that status code to the `hideErrorNotification` method. A hidden status code will still be caught by filament, but no notification will be shown. + +Alternatively, you can use the `disableErrorNotification` method to fall back to Livewire's built-in error handling for that status code. This is useful if you want to hook into the Livewire error handling system to customize the error handling behavior for a specific status code but maintain Filament's error notification system for everything else. + +```php +use Filament\Pages\Dashboard as BaseDashboard; + +class Dashboard extends BaseDashboard +{ + protected function setUpErrorNotifications(): void + { + $this->registerErrorNotification( + title: 'An error occurred', + body: 'Please try again later.', + ); + + $this->disableErrorNotification(403); + + $this->disableErrorNotification(503); + } + + // ... +} +``` diff --git a/packages/panels/dist/index.js b/packages/panels/dist/index.js index 53548916e9a..ca6674e78af 100644 --- a/packages/panels/dist/index.js +++ b/packages/panels/dist/index.js @@ -1 +1 @@ -(()=>{var re=Object.create,N=Object.defineProperty,ne=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty,oe=Object.getOwnPropertyNames,ae=Object.getOwnPropertyDescriptor,se=t=>N(t,"__esModule",{value:!0}),le=(t,n)=>()=>(n||(n={exports:{}},t(n.exports,n)),n.exports),fe=(t,n,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of oe(n))!ie.call(t,a)&&a!=="default"&&N(t,a,{get:()=>n[a],enumerable:!(i=ae(n,a))||i.enumerable});return t},ue=t=>fe(se(N(t!=null?re(ne(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),pe=le((t,n)=>{(function(i,a,w){if(!i)return;for(var u={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},v={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},y={"~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},U={option:"alt",command:"meta",return:"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},A,m=1;m<20;++m)u[111+m]="f"+m;for(m=0;m<=9;++m)u[m+96]=m.toString();function C(e,r,s){if(e.addEventListener){e.addEventListener(r,s,!1);return}e.attachEvent("on"+r,s)}function G(e){if(e.type=="keypress"){var r=String.fromCharCode(e.which);return e.shiftKey||(r=r.toLowerCase()),r}return u[e.which]?u[e.which]:v[e.which]?v[e.which]:String.fromCharCode(e.which).toLowerCase()}function V(e,r){return e.sort().join(",")===r.sort().join(",")}function F(e){var r=[];return e.shiftKey&&r.push("shift"),e.altKey&&r.push("alt"),e.ctrlKey&&r.push("ctrl"),e.metaKey&&r.push("meta"),r}function H(e){if(e.preventDefault){e.preventDefault();return}e.returnValue=!1}function B(e){if(e.stopPropagation){e.stopPropagation();return}e.cancelBubble=!0}function P(e){return e=="shift"||e=="ctrl"||e=="alt"||e=="meta"}function X(){if(!A){A={};for(var e in u)e>95&&e<112||u.hasOwnProperty(e)&&(A[u[e]]=e)}return A}function Y(e,r,s){return s||(s=X()[e]?"keydown":"keypress"),s=="keypress"&&r.length&&(s="keydown"),s}function Q(e){return e==="+"?["+"]:(e=e.replace(/\+{2}/g,"+plus"),e.split("+"))}function T(e,r){var s,h,k,S=[];for(s=Q(e),k=0;k1){$(o,b,f,c);return}p=T(o,c),r._callbacks[p.key]=r._callbacks[p.key]||[],I(p.key,p.modifiers,{type:p.action},l,o,d),r._callbacks[p.key][l?"unshift":"push"]({callback:f,modifiers:p.modifiers,action:p.action,seq:l,level:d,combo:o})}r._bindMultiple=function(o,f,c){for(var l=0;l-1||R(r,s.target))return!1;if("composedPath"in e&&typeof e.composedPath=="function"){var h=e.composedPath()[0];h!==e.target&&(r=h)}return r.tagName=="INPUT"||r.tagName=="SELECT"||r.tagName=="TEXTAREA"||r.isContentEditable},_.prototype.handleKey=function(){var e=this;return e._handleKey.apply(e,arguments)},_.addKeycodes=function(e){for(var r in e)e.hasOwnProperty(r)&&(u[r]=e[r]);A=null},_.init=function(){var e=_(a);for(var r in e)r.charAt(0)!=="_"&&(_[r]=(function(s){return function(){return e[s].apply(e,arguments)}})(r))},_.init(),i.Mousetrap=_,typeof n<"u"&&n.exports&&(n.exports=_),typeof define=="function"&&define.amd&&define(function(){return _})})(typeof window<"u"?window:null,typeof window<"u"?document:null)}),q=ue(pe());(function(t){if(t){var n={},i=t.prototype.stopCallback;t.prototype.stopCallback=function(a,w,u,v){var y=this;return y.paused?!0:n[u]||n[v]?!1:i.call(y,a,w,u)},t.prototype.bindGlobal=function(a,w,u){var v=this;if(v.bind(a,w,u),a instanceof Array){for(var y=0;yArray.from(document.querySelectorAll('[aria-modal="true"]')).find(t=>window.getComputedStyle(t).display!=="none"),ce=t=>{t.directive("mousetrap",(n,{modifiers:i,expression:a},{evaluate:w})=>{let u=()=>a?w(a):n.click();i=i.map(v=>v.replace(/--/g," ").replace(/-/g,"+").replace(/\bslash\b/g,"/")),i.includes("global")&&(i=i.filter(v=>v!=="global"),q.default.bindGlobal(i,v=>{let y=J();y&&!y.contains(n)||(v.preventDefault(),u())})),q.default.bind(i,v=>{let y=J();y&&!y.contains(n)||(v.preventDefault(),u())}),document.addEventListener("livewire:navigating",()=>{q.default.unbind(i)},{once:!0})})},W=ce;var j=()=>({isOpen:window.Alpine.$persist(!0).as("isOpen"),isOpenDesktop:window.Alpine.$persist(!0).as("isOpenDesktop"),collapsedGroups:window.Alpine.$persist(null).as("collapsedGroups"),init(){this.resizeObserver=null,this.setUpResizeObserver(),document.addEventListener("livewire:navigated",()=>{this.setUpResizeObserver()})},setUpResizeObserver(){this.resizeObserver&&this.resizeObserver.disconnect();let t=window.innerWidth;this.resizeObserver=new ResizeObserver(()=>{let n=window.innerWidth,i=t>=1024,a=n<1024,w=n>=1024;i&&a?(this.isOpenDesktop=this.isOpen,this.isOpen&&this.close()):!i&&w&&(this.isOpen=this.isOpenDesktop),t=n}),this.resizeObserver.observe(document.body),window.innerWidth<1024?this.isOpen&&(this.isOpenDesktop=!0,this.close()):this.isOpen=this.isOpenDesktop},groupIsCollapsed(t){return this.collapsedGroups.includes(t)},collapseGroup(t){this.collapsedGroups.includes(t)||(this.collapsedGroups=this.collapsedGroups.concat(t))},toggleCollapsedGroup(t){this.collapsedGroups=this.collapsedGroups.includes(t)?this.collapsedGroups.filter(n=>n!==t):this.collapsedGroups.concat(t)},close(){this.isOpen=!1,window.innerWidth>=1024&&(this.isOpenDesktop=!1)},open(){this.isOpen=!0,window.innerWidth>=1024&&(this.isOpenDesktop=!0)}});document.addEventListener("alpine:init",()=>{let t=localStorage.getItem("theme")??getComputedStyle(document.documentElement).getPropertyValue("--default-theme-mode");window.Alpine.store("theme",t==="dark"||t==="system"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),window.addEventListener("theme-changed",n=>{let i=n.detail;localStorage.setItem("theme",i),i==="system"&&(i=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),window.Alpine.store("theme",i)}),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",n=>{localStorage.getItem("theme")==="system"&&window.Alpine.store("theme",n.matches?"dark":"light")}),window.Alpine.effect(()=>{window.Alpine.store("theme")==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")})});document.addEventListener("livewire:init",()=>{Livewire.hook("request",({payload:t,fail:n})=>{n(({status:i,preventDefault:a})=>{let w=window.filamentErrorNotifications;if(!w)return;if(JSON.parse(t).components.length===1){for(let v of JSON.parse(t).components)if(JSON.parse(v.snapshot).data.isFilamentNotificationsComponent)return}a();let u=w[i]??w[""];new FilamentNotification().title(u.title).body(u.body).danger().send()})})});var x=window.history.replaceState,de=window.history.pushState;window.history.replaceState=function(t,n,i){t?.url instanceof URL&&(t.url=t.url.toString());let a=i||t?.url||window.location.href,w=window.location.href;if(a!==w){x.call(window.history,t,n,i);return}try{let u=window.history.state;JSON.stringify(t)!==JSON.stringify(u)&&x.call(window.history,t,n,i)}catch{x.call(window.history,t,n,i)}};window.history.pushState=function(t,n,i){t?.url instanceof URL&&(t.url=t.url.toString()),de.call(window.history,t,n,i)};document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{let t=document.querySelector(".fi-main-sidebar .fi-sidebar-item.fi-active");if((!t||t.offsetParent===null)&&(t=document.querySelector(".fi-main-sidebar .fi-sidebar-group.fi-active")),!t||t.offsetParent===null)return;let n=document.querySelector(".fi-main-sidebar .fi-sidebar-nav");n&&n.scrollTo(0,t.offsetTop-window.innerHeight/2)},10)});window.setUpUnsavedDataChangesAlert=({body:t,livewireComponent:n,$wire:i})=>{window.addEventListener("beforeunload",a=>{window.jsMd5(JSON.stringify(i.data).replace(/\\/g,""))===i.savedDataHash||i?.__instance?.effects?.redirect||(a.preventDefault(),a.returnValue=!0)})};window.setUpSpaModeUnsavedDataChangesAlert=({body:t,resolveLivewireComponentUsing:n,$wire:i})=>{let a=()=>i?.__instance?.effects?.redirect?!1:window.jsMd5(JSON.stringify(i.data).replace(/\\/g,""))!==i.savedDataHash,w=()=>confirm(t);document.addEventListener("livewire:navigate",u=>{if(typeof n()<"u"){if(!a()||w())return;u.preventDefault()}}),window.addEventListener("beforeunload",u=>{a()&&(u.preventDefault(),u.returnValue=!0)})};window.setUpUnsavedActionChangesAlert=({resolveLivewireComponentUsing:t,$wire:n})=>{window.addEventListener("beforeunload",i=>{if(!(typeof t()>"u")&&(n.mountedActions?.length??0)&&!n?.__instance?.effects?.redirect){i.preventDefault(),i.returnValue=!0;return}})};document.addEventListener("alpine:init",()=>{window.Alpine.plugin(W),window.Alpine.store("sidebar",j())});})(); +(()=>{var re=Object.create,N=Object.defineProperty,ne=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty,oe=Object.getOwnPropertyNames,ae=Object.getOwnPropertyDescriptor,se=t=>N(t,"__esModule",{value:!0}),fe=(t,n)=>()=>(n||(n={exports:{}},t(n.exports,n)),n.exports),le=(t,n,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let a of oe(n))!ie.call(t,a)&&a!=="default"&&N(t,a,{get:()=>n[a],enumerable:!(i=ae(n,a))||i.enumerable});return t},ue=t=>le(se(N(t!=null?re(ne(t)):{},"default",t&&t.__esModule&&"default"in t?{get:()=>t.default,enumerable:!0}:{value:t,enumerable:!0})),t),pe=fe((t,n)=>{(function(i,a,w){if(!i)return;for(var u={8:"backspace",9:"tab",13:"enter",16:"shift",17:"ctrl",18:"alt",20:"capslock",27:"esc",32:"space",33:"pageup",34:"pagedown",35:"end",36:"home",37:"left",38:"up",39:"right",40:"down",45:"ins",46:"del",91:"meta",93:"meta",224:"meta"},v={106:"*",107:"+",109:"-",110:".",111:"/",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},y={"~":"`","!":"1","@":"2","#":"3",$:"4","%":"5","^":"6","&":"7","*":"8","(":"9",")":"0",_:"-","+":"=",":":";",'"':"'","<":",",">":".","?":"/","|":"\\"},U={option:"alt",command:"meta",return:"enter",escape:"esc",plus:"+",mod:/Mac|iPod|iPhone|iPad/.test(navigator.platform)?"meta":"ctrl"},A,m=1;m<20;++m)u[111+m]="f"+m;for(m=0;m<=9;++m)u[m+96]=m.toString();function C(e,r,s){if(e.addEventListener){e.addEventListener(r,s,!1);return}e.attachEvent("on"+r,s)}function G(e){if(e.type=="keypress"){var r=String.fromCharCode(e.which);return e.shiftKey||(r=r.toLowerCase()),r}return u[e.which]?u[e.which]:v[e.which]?v[e.which]:String.fromCharCode(e.which).toLowerCase()}function V(e,r){return e.sort().join(",")===r.sort().join(",")}function F(e){var r=[];return e.shiftKey&&r.push("shift"),e.altKey&&r.push("alt"),e.ctrlKey&&r.push("ctrl"),e.metaKey&&r.push("meta"),r}function H(e){if(e.preventDefault){e.preventDefault();return}e.returnValue=!1}function B(e){if(e.stopPropagation){e.stopPropagation();return}e.cancelBubble=!0}function P(e){return e=="shift"||e=="ctrl"||e=="alt"||e=="meta"}function X(){if(!A){A={};for(var e in u)e>95&&e<112||u.hasOwnProperty(e)&&(A[u[e]]=e)}return A}function Y(e,r,s){return s||(s=X()[e]?"keydown":"keypress"),s=="keypress"&&r.length&&(s="keydown"),s}function Q(e){return e==="+"?["+"]:(e=e.replace(/\+{2}/g,"+plus"),e.split("+"))}function T(e,r){var s,h,k,S=[];for(s=Q(e),k=0;k1){$(o,b,l,c);return}p=T(o,c),r._callbacks[p.key]=r._callbacks[p.key]||[],I(p.key,p.modifiers,{type:p.action},f,o,d),r._callbacks[p.key][f?"unshift":"push"]({callback:l,modifiers:p.modifiers,action:p.action,seq:f,level:d,combo:o})}r._bindMultiple=function(o,l,c){for(var f=0;f-1||R(r,s.target))return!1;if("composedPath"in e&&typeof e.composedPath=="function"){var h=e.composedPath()[0];h!==e.target&&(r=h)}return r.tagName=="INPUT"||r.tagName=="SELECT"||r.tagName=="TEXTAREA"||r.isContentEditable},_.prototype.handleKey=function(){var e=this;return e._handleKey.apply(e,arguments)},_.addKeycodes=function(e){for(var r in e)e.hasOwnProperty(r)&&(u[r]=e[r]);A=null},_.init=function(){var e=_(a);for(var r in e)r.charAt(0)!=="_"&&(_[r]=(function(s){return function(){return e[s].apply(e,arguments)}})(r))},_.init(),i.Mousetrap=_,typeof n<"u"&&n.exports&&(n.exports=_),typeof define=="function"&&define.amd&&define(function(){return _})})(typeof window<"u"?window:null,typeof window<"u"?document:null)}),q=ue(pe());(function(t){if(t){var n={},i=t.prototype.stopCallback;t.prototype.stopCallback=function(a,w,u,v){var y=this;return y.paused?!0:n[u]||n[v]?!1:i.call(y,a,w,u)},t.prototype.bindGlobal=function(a,w,u){var v=this;if(v.bind(a,w,u),a instanceof Array){for(var y=0;yArray.from(document.querySelectorAll('[aria-modal="true"]')).find(t=>window.getComputedStyle(t).display!=="none"),ce=t=>{t.directive("mousetrap",(n,{modifiers:i,expression:a},{evaluate:w})=>{let u=()=>a?w(a):n.click();i=i.map(v=>v.replace(/--/g," ").replace(/-/g,"+").replace(/\bslash\b/g,"/")),i.includes("global")&&(i=i.filter(v=>v!=="global"),q.default.bindGlobal(i,v=>{let y=J();y&&!y.contains(n)||(v.preventDefault(),u())})),q.default.bind(i,v=>{let y=J();y&&!y.contains(n)||(v.preventDefault(),u())}),document.addEventListener("livewire:navigating",()=>{q.default.unbind(i)},{once:!0})})},W=ce;var j=()=>({isOpen:window.Alpine.$persist(!0).as("isOpen"),isOpenDesktop:window.Alpine.$persist(!0).as("isOpenDesktop"),collapsedGroups:window.Alpine.$persist(null).as("collapsedGroups"),init(){this.resizeObserver=null,this.setUpResizeObserver(),document.addEventListener("livewire:navigated",()=>{this.setUpResizeObserver()})},setUpResizeObserver(){this.resizeObserver&&this.resizeObserver.disconnect();let t=window.innerWidth;this.resizeObserver=new ResizeObserver(()=>{let n=window.innerWidth,i=t>=1024,a=n<1024,w=n>=1024;i&&a?(this.isOpenDesktop=this.isOpen,this.isOpen&&this.close()):!i&&w&&(this.isOpen=this.isOpenDesktop),t=n}),this.resizeObserver.observe(document.body),window.innerWidth<1024?this.isOpen&&(this.isOpenDesktop=!0,this.close()):this.isOpen=this.isOpenDesktop},groupIsCollapsed(t){return this.collapsedGroups.includes(t)},collapseGroup(t){this.collapsedGroups.includes(t)||(this.collapsedGroups=this.collapsedGroups.concat(t))},toggleCollapsedGroup(t){this.collapsedGroups=this.collapsedGroups.includes(t)?this.collapsedGroups.filter(n=>n!==t):this.collapsedGroups.concat(t)},close(){this.isOpen=!1,window.innerWidth>=1024&&(this.isOpenDesktop=!1)},open(){this.isOpen=!0,window.innerWidth>=1024&&(this.isOpenDesktop=!0)}});document.addEventListener("alpine:init",()=>{let t=localStorage.getItem("theme")??getComputedStyle(document.documentElement).getPropertyValue("--default-theme-mode");window.Alpine.store("theme",t==="dark"||t==="system"&&window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),window.addEventListener("theme-changed",n=>{let i=n.detail;localStorage.setItem("theme",i),i==="system"&&(i=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"),window.Alpine.store("theme",i)}),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",n=>{localStorage.getItem("theme")==="system"&&window.Alpine.store("theme",n.matches?"dark":"light")}),window.Alpine.effect(()=>{window.Alpine.store("theme")==="dark"?document.documentElement.classList.add("dark"):document.documentElement.classList.remove("dark")})});document.addEventListener("livewire:init",()=>{Livewire.hook("request",({payload:t,fail:n})=>{n(({status:i,preventDefault:a})=>{let w=window.filamentErrorNotifications;if(!w)return;if(JSON.parse(t).components.length===1){for(let v of JSON.parse(t).components)if(JSON.parse(v.snapshot).data.isFilamentNotificationsComponent)return}let u=w[i]??w[""];u.isHidden!==!0&&(a(),new FilamentNotification().title(u.title).body(u.body).danger().send())})})});var x=window.history.replaceState,de=window.history.pushState;window.history.replaceState=function(t,n,i){t?.url instanceof URL&&(t.url=t.url.toString());let a=i||t?.url||window.location.href,w=window.location.href;if(a!==w){x.call(window.history,t,n,i);return}try{let u=window.history.state;JSON.stringify(t)!==JSON.stringify(u)&&x.call(window.history,t,n,i)}catch{x.call(window.history,t,n,i)}};window.history.pushState=function(t,n,i){t?.url instanceof URL&&(t.url=t.url.toString()),de.call(window.history,t,n,i)};document.addEventListener("DOMContentLoaded",()=>{setTimeout(()=>{let t=document.querySelector(".fi-main-sidebar .fi-sidebar-item.fi-active");if((!t||t.offsetParent===null)&&(t=document.querySelector(".fi-main-sidebar .fi-sidebar-group.fi-active")),!t||t.offsetParent===null)return;let n=document.querySelector(".fi-main-sidebar .fi-sidebar-nav");n&&n.scrollTo(0,t.offsetTop-window.innerHeight/2)},10)});window.setUpUnsavedDataChangesAlert=({body:t,livewireComponent:n,$wire:i})=>{window.addEventListener("beforeunload",a=>{window.jsMd5(JSON.stringify(i.data).replace(/\\/g,""))===i.savedDataHash||i?.__instance?.effects?.redirect||(a.preventDefault(),a.returnValue=!0)})};window.setUpSpaModeUnsavedDataChangesAlert=({body:t,resolveLivewireComponentUsing:n,$wire:i})=>{let a=()=>i?.__instance?.effects?.redirect?!1:window.jsMd5(JSON.stringify(i.data).replace(/\\/g,""))!==i.savedDataHash,w=()=>confirm(t);document.addEventListener("livewire:navigate",u=>{if(typeof n()<"u"){if(!a()||w())return;u.preventDefault()}}),window.addEventListener("beforeunload",u=>{a()&&(u.preventDefault(),u.returnValue=!0)})};window.setUpUnsavedActionChangesAlert=({resolveLivewireComponentUsing:t,$wire:n})=>{window.addEventListener("beforeunload",i=>{if(!(typeof t()>"u")&&(n.mountedActions?.length??0)&&!n?.__instance?.effects?.redirect){i.preventDefault(),i.returnValue=!0;return}})};document.addEventListener("alpine:init",()=>{window.Alpine.plugin(W),window.Alpine.store("sidebar",j())});})(); diff --git a/packages/panels/resources/js/error-notifications.js b/packages/panels/resources/js/error-notifications.js index e9a947293fe..869638128f3 100644 --- a/packages/panels/resources/js/error-notifications.js +++ b/packages/panels/resources/js/error-notifications.js @@ -18,11 +18,19 @@ document.addEventListener('livewire:init', () => { } } - preventDefault() - const errorNotification = errorNotifications[status] ?? errorNotifications[''] + if (errorNotification.isDisabled === true) { + return + } + + preventDefault() + + if (errorNotification.isHidden === true) { + return + } + new FilamentNotification() .title(errorNotification.title) .body(errorNotification.body) diff --git a/packages/panels/src/Pages/Concerns/HasErrorNotifications.php b/packages/panels/src/Pages/Concerns/HasErrorNotifications.php index 4c9e4f85738..14b94e8c927 100644 --- a/packages/panels/src/Pages/Concerns/HasErrorNotifications.php +++ b/packages/panels/src/Pages/Concerns/HasErrorNotifications.php @@ -2,6 +2,7 @@ namespace Filament\Pages\Concerns; +use Closure; use Filament\Facades\Filament; trait HasErrorNotifications @@ -20,6 +21,32 @@ public function registerErrorNotification(string $title, ?string $body = null, ? $this->errorNotifications[$statusCode] = [ 'title' => $title, 'body' => $body, + 'isHidden' => false, + 'isDisabled' => false, + ]; + + return $this; + } + + public function hideErrorNotification(int $statusCode): static + { + $this->errorNotifications[$statusCode] = [ + 'title' => null, + 'body' => null, + 'isHidden' => true, + 'isDisabled' => false, + ]; + + return $this; + } + + public function disableErrorNotification(int $statusCode): static + { + $this->errorNotifications[$statusCode] = [ + 'title' => null, + 'body' => null, + 'isHidden' => false, + 'isDisabled' => true, ]; return $this; diff --git a/packages/panels/src/Panel/Concerns/HasErrorNotifications.php b/packages/panels/src/Panel/Concerns/HasErrorNotifications.php index d9e90bdd45c..caf647987dd 100644 --- a/packages/panels/src/Panel/Concerns/HasErrorNotifications.php +++ b/packages/panels/src/Panel/Concerns/HasErrorNotifications.php @@ -30,6 +30,32 @@ public function registerErrorNotification(string | Closure $title, string | Clos $this->errorNotifications[$statusCode] = [ 'title' => $title, 'body' => $body, + 'isHidden' => false, + 'isDisabled' => false, + ]; + + return $this; + } + + public function hideErrorNotification(int $statusCode): static + { + $this->errorNotifications[$statusCode] = [ + 'title' => null, + 'body' => null, + 'isHidden' => true, + 'isDisabled' => false, + ]; + + return $this; + } + + public function disableErrorNotification(int $statusCode): static + { + $this->errorNotifications[$statusCode] = [ + 'title' => null, + 'body' => null, + 'isHidden' => false, + 'isDisabled' => true, ]; return $this;