Skip to content
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 11 commits into from
Aug 28, 2024
Merged

Add crash notifications #4409

merged 11 commits into from
Aug 28, 2024

Conversation

Steve-Mcl
Copy link
Contributor

@Steve-Mcl Steve-Mcl commented Aug 27, 2024

closes #4408

Description

Firstly, my apologies for what looks and smells like feature creep. That was not the intention. Initial implementation was done and as was soon discovered, the crash notifications were very quickly filling the notification area. This was discussed in slack and suggestions for change were made. Rather than throwing away good (and relevant) dev work, I kept it in.

  • Adds the calls to notification.send for instances devices and devices
  • Updates the notification.send API to support upserting and superseding
    • options.supersede was added first as discussed in slack. Essentially, this permits a repeated notification to to be auto-marked as read and its new (superseding) notification to be added
    • After some more show and tell & discussion in Slack, it was suggested a counter would be better. options.upsert was implemented to "update" an existing notification (or add is not existing) while adding a counter to the data. This permits multiple successive notifications to be shown as one item (with a pill/badge) and not fill up the notification panel with read notifications
  • Adds supports hiding read notifications
    • This was added AFTER implementing options.supersede and discussed in slack as a viable option.
    • However, while useful (and therefore left in this PR) we switched track to using options.upsert. It is left is as useful development and worthy of keeping as more notifications from other instances and occurrences could easily fill (and push unread items) down the list.
  • Adds a Generic notification that simplifies and reduces boilerplate
  • Updates the base Notification for common things like timestamp and styling (to reduce repeated coding in dedicated components)

MVP parts of this.

Ideally, the notification API and DB tables would natively support severity and counter but as MVP, I added them into the data object of the notification under a meta object. This may end up being a retro thing but until we have more notifications to add it is not fully clear - something to be aware of.

Demo

Default view - [x] Hide Read

image

View with [ ] Hide Read unchecked

image

Tests

test/unit/forge/routes/logging/index_spec.js

  Logging API
    adds notification
      ✔ for every member and owner when instance crashed (41ms)
      ✔ for every member and owner when device crashed
      ✔ for every member and owner when instance safe-mode
      ✔ for every member and owner when device safe-mode

test/unit/forge/routes/api/userNotifications_spec.js (was previously named userNotifications.js and thus NEVER ran!

  User Notifications API
    User notifications
      ✔ Updates notification when options.upsert is set
      ✔ Updates notification when options.supersede is set

Related Issue(s)

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production

Labels

  • Includes a DB migration? -> add the area:migration label

@joepavitt
Copy link
Contributor

Screenshot 2024-08-27 at 13 07 36

This is 7 notifications, but the total in the top if 5 because the "2" on thr right include read messages, but reads like it doesn't...

@joepavitt
Copy link
Contributor

I wouldn't be showing the number on the right at all - if they view "read" messages, they can see them all, we're notifying them correctly, think it's fine

@Steve-Mcl
Copy link
Contributor Author

Partly due to MVP aspect, I did not add a counter field to the DB meaning i would need to iterate all rows data objects and manipulate the count and either alter the API response or massage the value clientside.

Is doable and will do that if insisted, however, I left like this for your eyes to see whether you think this is something to worry about now or later?

PS: The way I chose to read this is:
image

@joepavitt
Copy link
Contributor

I know, but you're filtering on "unread only", but showing the count to include "read" messages, I think just remove the counters on the right for now please

@Steve-Mcl
Copy link
Contributor Author

I wouldn't be showing the number on the right at all - if they view "read" messages, they can see them all, we're notifying them correctly, think it's fine

That was not the approach Joe. It is a possible approach, but not the chosen approach.

This is a single updated notification using the upsert option

  • After some more show and tell & discussion in Slack, it was suggested a counter would be better. options.upsert was implemented to "update" an existing notification (or add is not existing) while adding a counter to the data. This permits multiple successive notifications to be shown as one item (with a pill/badge) and not fill up the notification panel with read notifications

In other words, there is only ONE notification with a counter value (clicking "show read" will not reveal the others)

Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 97.56098% with 1 line in your changes missing coverage. Please review.

Project coverage is 78.43%. Comparing base (495a7a6) to head (4ecfb0b).
Report is 61 commits behind head on main.

Files Patch % Lines
forge/notifications/index.js 94.44% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4409      +/-   ##
==========================================
+ Coverage   78.34%   78.43%   +0.09%     
==========================================
  Files         294      294              
  Lines       13588    13673      +85     
  Branches     3056     3078      +22     
==========================================
+ Hits        10646    10725      +79     
- Misses       2942     2948       +6     
Flag Coverage Δ
backend 78.43% <97.56%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Steve-Mcl
Copy link
Contributor Author

Discussed notification count conundrum with @joepavitt

Decision was made to incorporate any "grouped" notifications into the overall counter pill.
This is implemented client side to keep things MVP.

Implemented in include grouped notifications in the total count

Demo:
chrome_1IhMqpBzae

@Steve-Mcl
Copy link
Contributor Author

@joepavitt grouped notification count included in header pill & and tests added - ready for review.

Comment on lines +100 to +111
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
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ewww... but okay

@joepavitt joepavitt merged commit 8c97fec into main Aug 28, 2024
14 checks passed
@joepavitt joepavitt deleted the 4295-crash-notifications branch August 28, 2024 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add notifications for instance/device crashed
2 participants