-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add crash notifications #4409
Merged
Merged
Add crash notifications #4409
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9d0b8c5
In cases where there is more than one entry, get the latest
Steve-Mcl c4ccfca
Add getTeamMembers(filter) to TeamMembers - required for sending no…
Steve-Mcl 5335bb7
Support updating or superseding notifications
Steve-Mcl 5811852
Add notification.send(...) for instance and device crashed
Steve-Mcl 6abf4ee
Add support for notification count, hiding read notifications and gen…
Steve-Mcl a502d80
default to well formatted timestamp in base notification
Steve-Mcl 0d9f9ac
include grouped notifications in the total count
Steve-Mcl a032435
add unit tests for notification options `upsert` and `supersede`
Steve-Mcl d8c452c
rename file so that tests are actually ran
Steve-Mcl ad334ac
Add unit tests for instance and device crash/safe mode notifications
Steve-Mcl 4ecfb0b
delete unused users from test
Steve-Mcl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<template> | ||
<NotificationMessage | ||
:notification="notification" | ||
:selections="selections" | ||
data-el="generic-notification" :to="to" | ||
> | ||
<template #icon> | ||
<component :is="notificationData.iconComponent" /> | ||
</template> | ||
<template #title> | ||
{{ notificationData.title }} | ||
</template> | ||
<template #message> | ||
<!-- eslint-disable-next-line vue/no-v-html --> | ||
<span v-html="notificationData.message" /> | ||
</template> | ||
</NotificationMessage> | ||
</template> | ||
|
||
<script> | ||
import { defineAsyncComponent } from 'vue' | ||
|
||
import IconDeviceSolid from '../../components/icons/DeviceSolid.js' | ||
import IconNodeRedSolid from '../../components/icons/NodeRedSolid.js' | ||
import NotificationMessageMixin from '../../mixins/NotificationMessage.js' | ||
|
||
import NotificationMessage from './Notification.vue' | ||
|
||
export default { | ||
name: 'GenericNotification', | ||
components: { NotificationMessage, IconNodeRedSolid }, | ||
mixins: [NotificationMessageMixin], | ||
data () { | ||
return { | ||
knownEvents: { | ||
'instance-crashed': { | ||
icon: 'instance', | ||
title: 'Node-RED Instance Crashed', | ||
message: '"<i>{{instance.name}}</i>" has crashed' | ||
}, | ||
'instance-safe-mode': { | ||
icon: 'instance', | ||
title: 'Node-RED Instance Safe Mode', | ||
message: '"<i>{{instance.name}}</i>" is running in safe mode' | ||
}, | ||
'device-crashed': { | ||
icon: 'device', | ||
title: 'Node-RED Device Crashed', | ||
message: '"<i>{{device.name}}</i>" has crashed' | ||
}, | ||
'device-safe-mode': { | ||
icon: 'device', | ||
title: 'Node-RED Device Safe Mode', | ||
message: '"<i>{{device.name}}</i>" is running in safe mode' | ||
} | ||
} | ||
} | ||
}, | ||
computed: { | ||
to () { | ||
if (typeof this.notification.data?.to === 'object') { return this.notification.data.to } | ||
if (typeof this.notification.data?.to === 'string') { return { path: this.notification.data.to } } | ||
if (typeof this.notification.data?.url === 'string') { return { url: this.notification.data.url } } | ||
if (this.notification.data?.instance?.id) { | ||
return { | ||
name: 'instance-overview', | ||
params: { id: this.notification.data.instance.id } | ||
} | ||
} | ||
return null // no link | ||
}, | ||
notificationData () { | ||
const event = this.knownEvents[this.notification.type] || {} | ||
event.createdAt = new Date(this.notification.createdAt).toLocaleString() | ||
// get title and message | ||
if (!event.title) { | ||
event.title = this.notification.data?.title || this.notification.type.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase()) | ||
} | ||
if (!event.message) { | ||
event.message = this.notification.data?.message || `Event occurred at ${event.createdAt}` | ||
} | ||
|
||
// icon handling | ||
event.icon = event.icon || this.notification.data?.icon | ||
if (event.icon === 'instance' || event.icon === 'project') { | ||
event.iconComponent = IconNodeRedSolid | ||
} else if (event.icon === 'device') { | ||
event.iconComponent = IconDeviceSolid | ||
} else { | ||
event.iconComponent = defineAsyncComponent(() => import('@heroicons/vue/solid').then(x => x[event.icon] || x.BellIcon)) | ||
} | ||
|
||
// Perform known substitutions | ||
event.title = this.substitutions(event.title) | ||
event.message = this.substitutions(event.message) | ||
return event | ||
} | ||
}, | ||
methods: { | ||
substitutions (str) { | ||
let result = str | ||
const regex = /{{([^}]+)}}/g // find all {{key}} occurrences | ||
let match = regex.exec(result) | ||
while (match) { | ||
const key = match[1] | ||
const value = this.getObjectProperty(this.notification.data || {}, key) || key.split('.')[0].replace(/\b\w/g, l => l.toUpperCase()) | ||
result = result.replace(match[0], value) | ||
match = regex.exec(result) | ||
} | ||
return result | ||
}, | ||
getObjectProperty (obj, path) { | ||
return (path || '').trim().split('.').reduce((acc, part) => acc && acc[part], obj) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
|
||
</style> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ewww... but okay