Skip to content

Commit

Permalink
refactor: notification module
Browse files Browse the repository at this point in the history
  • Loading branch information
0xJacky committed Feb 25, 2025
1 parent 34fa4eb commit ab46d1d
Show file tree
Hide file tree
Showing 41 changed files with 3,980 additions and 2,402 deletions.
4 changes: 2 additions & 2 deletions api/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func AddCert(c *gin.Context) {

err = cert.SyncToRemoteServer(certModel)
if err != nil {
notification.Error("Sync Certificate Error", err.Error())
notification.Error("Sync Certificate Error", err.Error(), nil)
return
}

Expand Down Expand Up @@ -188,7 +188,7 @@ func ModifyCert(c *gin.Context) {

err = cert.SyncToRemoteServer(certModel)
if err != nil {
notification.Error("Sync Certificate Error", err.Error())
notification.Error("Sync Certificate Error", err.Error(), nil)
return
}

Expand Down
8 changes: 8 additions & 0 deletions api/certificate/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Auto-generated notification messages
// Do not edit manually

const notifications: Record<string, string> = {
"Sync_Certificate_Error_Error": "err.Error()",
};

export default notifications;
3 changes: 2 additions & 1 deletion app/src/components/Notification/Notification.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { message, notification } from 'ant-design-vue'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { SSE } from 'sse.js'
import notifications from './notifications'
defineProps<{
headerRef: HTMLElement
Expand Down Expand Up @@ -181,7 +182,7 @@ function viewAll() {
<template #description>
<div class="flex justify-between items-center">
<div>
{{ detailRender({ text: item.details, record: item } as CustomRender) }}
{{ notifications[item.title].content(item.details) }}
</div>
<span
key="list-loadmore-remove"
Expand Down
15 changes: 0 additions & 15 deletions app/src/components/Notification/cert.ts

This file was deleted.

96 changes: 0 additions & 96 deletions app/src/components/Notification/config.ts

This file was deleted.

65 changes: 0 additions & 65 deletions app/src/components/Notification/detailRender.ts

This file was deleted.

26 changes: 26 additions & 0 deletions app/src/components/Notification/detailRender.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { CustomRender } from '@/components/StdDesign/StdDataDisplay/StdTableTransformer'
import { NotificationTypeT } from '@/constants'
import notifications from './notifications'

export function detailRender(args: CustomRender) {
try {
return (
<div>
<div class="mb-2">
{
notifications[args.record.title].content(args.record.details)
}
</div>
{args.record.type !== NotificationTypeT.Success && (
<div>
{ JSON.stringify(args.record.details.response) }
</div>
)}
</div>
)
}
// eslint-disable-next-line sonarjs/no-ignored-exceptions,unused-imports/no-unused-vars
catch (e) {
return args.text
}
}
126 changes: 126 additions & 0 deletions app/src/components/Notification/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// Auto-generated notification texts
// Extracted from Go source code notification function calls
/* eslint-disable ts/no-explicit-any */

const notifications: Record<string, { title: () => string, content: (args: any) => string }> = {

// cert module notifications
'Sync Certificate Error': {
title: () => $gettext('Sync Certificate Error'),
content: (args: any) => $gettext('Sync Certificate %{cert_name} to %{env_name} failed', args),
},
'Sync Certificate Success': {
title: () => $gettext('Sync Certificate Success'),
content: (args: any) => $gettext('Sync Certificate %{cert_name} to %{env_name} successfully', args),
},

// config module notifications
'Sync Config Error': {
title: () => $gettext('Sync Config Error'),
content: (args: any) => $gettext('Sync config %{config_name} to %{env_name} failed', args),
},
'Sync Config Success': {
title: () => $gettext('Sync Config Success'),
content: (args: any) => $gettext('Sync config %{config_name} to %{env_name} successfully', args),
},
'Rename Remote Config Error': {
title: () => $gettext('Rename Remote Config Error'),
content: (args: any) => $gettext('Rename %{orig_path} to %{new_path} on %{env_name} failed', args),
},
'Rename Remote Config Success': {
title: () => $gettext('Rename Remote Config Success'),
content: (args: any) => $gettext('Rename %{orig_path} to %{new_path} on %{env_name} successfully', args),
},

// site module notifications
'Delete Remote Site Error': {
title: () => $gettext('Delete Remote Site Error'),
content: (args: any) => $gettext('Delete site %{name} from %{node} failed', args),
},
'Delete Remote Site Success': {
title: () => $gettext('Delete Remote Site Success'),
content: (args: any) => $gettext('Delete site %{name} from %{node} successfully', args),
},
'Disable Remote Site Error': {
title: () => $gettext('Disable Remote Site Error'),
content: (args: any) => $gettext('Disable site %{name} from %{node} failed', args),
},
'Disable Remote Site Success': {
title: () => $gettext('Disable Remote Site Success'),
content: (args: any) => $gettext('Disable site %{name} from %{node} successfully', args),
},
'Enable Remote Site Error': {
title: () => $gettext('Enable Remote Site Error'),
content: (args: any) => $gettext('Enable site %{name} on %{node} failed', args),
},
'Enable Remote Site Success': {
title: () => $gettext('Enable Remote Site Success'),
content: (args: any) => $gettext('Enable site %{name} on %{node} successfully', args),
},
'Rename Remote Site Error': {
title: () => $gettext('Rename Remote Site Error'),
content: (args: any) => $gettext('Rename site %{name} to %{new_name} on %{node} failed', args),
},
'Rename Remote Site Success': {
title: () => $gettext('Rename Remote Site Success'),
content: (args: any) => $gettext('Rename site %{name} to %{new_name} on %{node} successfully', args),
},
'Save Remote Site Error': {
title: () => $gettext('Save Remote Site Error'),
content: (args: any) => $gettext('Save site %{name} to %{node} failed', args),
},
'Save Remote Site Success': {
title: () => $gettext('Save Remote Site Success'),
content: (args: any) => $gettext('Save site %{name} to %{node} successfully', args),
},

// stream module notifications
'Delete Remote Stream Error': {
title: () => $gettext('Delete Remote Stream Error'),
content: (args: any) => $gettext('Delete stream %{name} from %{node} failed', args),
},
'Delete Remote Stream Success': {
title: () => $gettext('Delete Remote Stream Success'),
content: (args: any) => $gettext('Delete stream %{name} from %{node} successfully', args),
},
'Disable Remote Stream Error': {
title: () => $gettext('Disable Remote Stream Error'),
content: (args: any) => $gettext('Disable stream %{name} from %{node} failed', args),
},
'Disable Remote Stream Success': {
title: () => $gettext('Disable Remote Stream Success'),
content: (args: any) => $gettext('Disable stream %{name} from %{node} successfully', args),
},
'Enable Remote Stream Error': {
title: () => $gettext('Enable Remote Stream Error'),
content: (args: any) => $gettext('Enable stream %{name} on %{node} failed', args),
},
'Enable Remote Stream Success': {
title: () => $gettext('Enable Remote Stream Success'),
content: (args: any) => $gettext('Enable stream %{name} on %{node} successfully', args),
},
'Rename Remote Stream Error': {
title: () => $gettext('Rename Remote Stream Error'),
content: (args: any) => $gettext('Rename stream %{name} to %{new_name} on %{node} failed', args),
},
'Rename Remote Stream Success': {
title: () => $gettext('Rename Remote Stream Success'),
content: (args: any) => $gettext('Rename stream %{name} to %{new_name} on %{node} successfully', args),
},
'Save Remote Stream Error': {
title: () => $gettext('Save Remote Stream Error'),
content: (args: any) => $gettext('Save stream %{name} to %{node} failed', args),
},
'Save Remote Stream Success': {
title: () => $gettext('Save Remote Stream Success'),
content: (args: any) => $gettext('Save stream %{name} to %{node} successfully', args),
},

// user module notifications
'All Recovery Codes Have Been Used': {
title: () => $gettext('All Recovery Codes Have Been Used'),
content: (args: any) => $gettext('Please generate new recovery codes in the preferences immediately to prevent lockout.', args),
},
}

export default notifications
Loading

0 comments on commit ab46d1d

Please sign in to comment.