diff --git a/backend/graphql/notification_event/src/types/notification_event.rs b/backend/graphql/notification_event/src/types/notification_event.rs index 02ec8c56..99a89050 100644 --- a/backend/graphql/notification_event/src/types/notification_event.rs +++ b/backend/graphql/notification_event/src/types/notification_event.rs @@ -74,6 +74,10 @@ impl NotificationEventNode { self.row().send_attempts } + pub async fn context(&self) -> Option { + self.row().context.to_owned() + } + pub async fn notification_config( &self, ctx: &Context<'_>, diff --git a/backend/repository/migrations/2023-11-20-200847_add_notification_event_context/down.sql b/backend/repository/migrations/2023-11-20-200847_add_notification_event_context/down.sql new file mode 100644 index 00000000..291a97c5 --- /dev/null +++ b/backend/repository/migrations/2023-11-20-200847_add_notification_event_context/down.sql @@ -0,0 +1 @@ +-- This file should undo anything in `up.sql` \ No newline at end of file diff --git a/backend/repository/migrations/2023-11-20-200847_add_notification_event_context/up.sql b/backend/repository/migrations/2023-11-20-200847_add_notification_event_context/up.sql new file mode 100644 index 00000000..1f96ab3a --- /dev/null +++ b/backend/repository/migrations/2023-11-20-200847_add_notification_event_context/up.sql @@ -0,0 +1 @@ +ALTER TABLE notification_event ADD COLUMN context TEXT; \ No newline at end of file diff --git a/backend/repository/src/db_diesel/notification_event_row.rs b/backend/repository/src/db_diesel/notification_event_row.rs index 36a39ce2..2ea2091e 100644 --- a/backend/repository/src/db_diesel/notification_event_row.rs +++ b/backend/repository/src/db_diesel/notification_event_row.rs @@ -38,6 +38,7 @@ table! { retry_at -> Nullable, send_attempts -> Integer, error_message -> Nullable, + context -> Nullable, } } @@ -69,6 +70,7 @@ pub struct NotificationEventRow { pub retry_at: Option, pub send_attempts: i32, pub error_message: Option, + pub context: Option, // JSON object, the tera context for the event } pub struct NotificationEventRowRepository<'a> { diff --git a/backend/service/src/notification/enqueue.rs b/backend/service/src/notification/enqueue.rs index 7c41167b..5777b7a7 100644 --- a/backend/service/src/notification/enqueue.rs +++ b/backend/service/src/notification/enqueue.rs @@ -118,6 +118,13 @@ pub fn create_notification_events( notification_config_id: config_id.clone(), notification_type, retry_at: None, + context: match serde_json::to_string(&tera_context.clone().into_json()) { + Ok(context) => Some(context), + Err(e) => { + log::error!("Failed to stringify tera context: {:?}", e); + None + } + }, ..Default::default() }; diff --git a/frontend/packages/common/src/intl/locales/en/common.json b/frontend/packages/common/src/intl/locales/en/common.json index a66d815e..8495082a 100644 --- a/frontend/packages/common/src/intl/locales/en/common.json +++ b/frontend/packages/common/src/intl/locales/en/common.json @@ -71,6 +71,7 @@ "label.comment": "Comment", "label.contact-name": "Contact Name", "label.country": "Country", + "label.created": "Created", "label.date": "Date", "label.date-created": "Date Created", "label.description": "Description", @@ -141,6 +142,7 @@ "label.total-value": "Total Value", "label.type": "Type", "label.unit": "Unit", + "label.updated": "Updated", "label.upload": "Upload", "label.username": "Username", "label.website": "Website", @@ -169,6 +171,7 @@ "messages.import-error": "Errors were encountered during processing, please fix and re-upload", "messages.import-invalid-file": "An invalid file was supplied. Make sure you have the right file format and try again", "messages.loading": "Loading", + "messages.no-error": "No Error", "messages.no-errors": "No errors found", "messages.no-log-entries": "No log entries available", "messages.nothing-selected": "Nothing selected", diff --git a/frontend/packages/common/src/intl/locales/en/system.json b/frontend/packages/common/src/intl/locales/en/system.json index 82081d47..48d89a0a 100644 --- a/frontend/packages/common/src/intl/locales/en/system.json +++ b/frontend/packages/common/src/intl/locales/en/system.json @@ -40,6 +40,7 @@ "label.parameters-as-json": "JSON Parameters", "label.error": "Error", "label.filter-by-notification-config": "Filter by Notification Config", + "label.generated-notification": "Generated Notification", "label.invite-user": "Invite User", "label.new-recipient": "New Recipient", "label.new-recipient-list": "New Recipient List", @@ -51,6 +52,7 @@ "label.notification-type-EMAIL": "Email", "label.notification-type-TELEGRAM": "Telegram", "label.notification-type-UNKNOWN": "ERROR-UNSUPPORTED-NOTIFICATION-TYPE", + "label.parameters-query-results": "Parameters and Query Results", "label.password-strength": "Password Strength", "label.password-warning": "Warning", "label.phone-number": "Phone Number", @@ -62,6 +64,7 @@ "label.send-password-reset": "Send Password Reset", "label.setup-notification": "Setup {{type}} Notification", "label.telegram": "Telegram", + "label.to": "To", "label.update-contact": "Update Contact", "label.update-details": "Update Details", "label.update-profile": "Update Profile", diff --git a/frontend/packages/common/src/types/schema.ts b/frontend/packages/common/src/types/schema.ts index c7c12edb..cdd39f7a 100644 --- a/frontend/packages/common/src/types/schema.ts +++ b/frontend/packages/common/src/types/schema.ts @@ -675,6 +675,7 @@ export type NotificationEventFilterInput = { export type NotificationEventNode = { __typename: 'NotificationEventNode'; + context?: Maybe; createdAt: Scalars['DateTime']['output']; errorMessage?: Maybe; id: Scalars['String']['output']; diff --git a/frontend/packages/system/src/NotificationEvents/DetailView/DetailView.tsx b/frontend/packages/system/src/NotificationEvents/DetailView/DetailView.tsx index 4ee860ef..4bf70f5f 100644 --- a/frontend/packages/system/src/NotificationEvents/DetailView/DetailView.tsx +++ b/frontend/packages/system/src/NotificationEvents/DetailView/DetailView.tsx @@ -23,6 +23,7 @@ import { } from 'packages/common/src'; import { configRoute } from '../../Notifications/navigate'; import { NotificationStatusChip } from '../components/NotificationStatusChip'; +import { useParsedEventContext } from './eventContext'; export const DetailView = () => { const t = useTranslation('system'); @@ -37,6 +38,8 @@ export const DetailView = () => { const { data, isLoading } = useNotificationEvents(queryParams); const entity = data?.nodes[0]; + const eventContext = useParsedEventContext(entity?.context); + useEffect(() => { const listName = entity?.title; if (!suffix && listName) { @@ -81,18 +84,16 @@ export const DetailView = () => { {entity?.errorMessage ? (