Skip to content

Commit

Permalink
feat(Notify): allow exponential notation for timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Dec 18, 2023
1 parent 2723585 commit a59eb69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions ui/src/plugins/Notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const notificationsList = {}
const positionClass = {}
const emptyRE = /^\s*$/
const notifRefs = []
const invalidTimeoutValues = [ void 0, null, true, false, '' ]

const positionList = [
'top-left', 'top-right',
Expand Down Expand Up @@ -112,15 +113,15 @@ function addNotification (config, $q, originalApi) {
notif.position = 'bottom'
}

if (notif.timeout === void 0) {
if (invalidTimeoutValues.includes(notif.timeout) === true) {
notif.timeout = 5000
}
else {
const t = parseInt(notif.timeout, 10)
const t = Number(notif.timeout) // we catch exponential notation too with Number() casting
if (isNaN(t) || t < 0) {
return logError('wrong timeout', config)
}
notif.timeout = t
notif.timeout = Number.isFinite(t) ? t : 0
}

if (notif.timeout === 0) {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/plugins/Notify.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

"timeout": {
"type": "Number",
"desc": "Amount of time to display (in milliseconds)",
"desc": "Amount of time to display (in milliseconds). Set to 0 to never dismiss automatically.",
"default": 5000
},

Expand Down Expand Up @@ -392,7 +392,7 @@

"timeout": {
"type": "Number",
"desc": "Amount of time to display (in milliseconds)",
"desc": "Amount of time to display (in milliseconds). Set to 0 to never dismiss automatically.",
"default": 5000,
"examples": [ 2500 ]
},
Expand Down

0 comments on commit a59eb69

Please sign in to comment.