utils.showNotification needs improvement

Continuing the discussion from Notification timing:

Building my own notification widget out of modals because the built-in one is too primitive is not a great "solution". Very small changes to utils.showNotification would make it much better:

  1. Have it return a value which can be used to take it down before the timer expiration:
    let n = utils.showNotification({title: "Hey!",
      description: "This will take an unpredictable amount of time",
       notificationType: "info", duration: 999999 });

    await unpredictable.trigger();

    utils.hideNotification(n);
  1. Have an option for infinite duration in which case the upper-right-corner close โฎพ should appear without the user having to hover. This would tell the user "I am going to stay here until you click that โฎพ".
1 Like

Hey @Roland_Alden ,

Thanks for the insight โ€” totally agree that building modal-based notifications is overkill for something that should be simple. Fortunately, utils.showNotification already returns a handle that can be used with utils.hideNotification() to manually dismiss the message. Also, setting duration: 0 gives you an effectively "infinite" notification that stays visible with the โฎพ close icon always shown (no hover needed).

Hereโ€™s the cleanest way to do it:

const n = utils.showNotification({
  title: "Hey!",
  description: "This will take an unpredictable amount of time",
  notificationType: "info",
  duration: 0 // stays until manually dismissed
});

await unpredictable.trigger();

utils.hideNotification(n);

Small tweak, big improvement โ€” no need to reinvent the wheel!

Also, in case others land here from this Retool question: there's a built-in and supported way to handle this โ€” no need for a custom modal. Just use duration: 0 and you're all set.

Hope this helps!

Oh wow! How did I miss that?

I mean it's right there in the documentation:

Right next to showNotification.

:clown_face:
just kidding

And it seems to not be documented for good reason. From console.log:

utils.showNotification returns: undefined

Error:utils.hideNotification is not a function

Thank-you @WidleStudioLLP for your upvote. :cowboy_hat_face:

Hi folks!

Apologies for the lack of documentation @Roland_Alden, I can submit a request to our docs teams to improve the docs for showNotifcation to explain the function better. It seems that duration: 0 is fairly unintuitive and is more of a quirky work around as opposed to an intended option and that is why it isn't in the docs.

Also I was hoping to get some added context on the unpredictable function that you are calling in await unpredictable.trigger(); also curious as to what you would want utils.showNotification to return from a console.log() instead of undefined :sweat_smile:

I can confirm that utils.hideNotification is not a function, but I can make a feature request for that to be added with a feature request.

My "unpredictable.trigger()" function is meant to be an illustration of any function that takes a random amount of time and thus makes setting a constant value in duration problematic.

What utils.showNotification() should return is a 'uuid' that can be passed around and used later in a utils.hideNotification(n) call to take down the notification.

There is no point in updating the documentation until the whole thing has been enhanced. Given the existing (limited) functionality the documentation is fine as is.

1 Like

Thank you for the added details, I will convey this to the team :+1: