Skip to content

Commit c01be7f

Browse files
committed
feat: add clean command history
1 parent df63381 commit c01be7f

File tree

6 files changed

+60
-11
lines changed

6 files changed

+60
-11
lines changed

backend/services/connection_service.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ func (c *connectionService) RenameKey(connName string, db int, key, newKey strin
10401040
return
10411041
}
10421042

1043+
// GetCmdHistory get redis command history
10431044
func (c *connectionService) GetCmdHistory(pageNo, pageSize int) (resp types.JSResp) {
10441045
resp.Success = true
10451046
if pageSize <= 0 || pageNo <= 0 {
@@ -1062,6 +1063,13 @@ func (c *connectionService) GetCmdHistory(pageNo, pageSize int) (resp types.JSRe
10621063
return
10631064
}
10641065

1066+
// CleanCmdHistory clean redis command history
1067+
func (c *connectionService) CleanCmdHistory() (resp types.JSResp) {
1068+
c.cmdHistory = []cmdHistoryItem{}
1069+
resp.Success = true
1070+
return
1071+
}
1072+
10651073
// update or insert key info to database
10661074
//func (c *connectionService) updateDBKey(connName string, db int, keys []string, separator string) {
10671075
// dbStruct := map[string]any{}

frontend/src/components/content/ContentLogPane.vue

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Refresh from '@/components/icons/Refresh.vue'
55
import useConnectionStore from 'stores/connections.js'
66
import { map, uniqBy } from 'lodash'
77
import { useI18n } from 'vue-i18n'
8+
import Delete from '@/components/icons/Delete.vue'
89
import dayjs from 'dayjs'
910
1011
const connectionStore = useConnectionStore()
@@ -43,6 +44,20 @@ const loadHistory = () => {
4344
})
4445
}
4546
47+
const cleanHistory = async () => {
48+
$dialog.warning(i18n.t('confirm_clean_log'), () => {
49+
data.loading = true
50+
connectionStore.cleanCmdHistory().then((success) => {
51+
if (success) {
52+
data.history = []
53+
data.loading = false
54+
tableRef.value?.scrollTo({ top: 0 })
55+
$message.success(i18n.t('success'))
56+
}
57+
})
58+
})
59+
}
60+
4661
defineExpose({
4762
refresh: () => nextTick().then(loadHistory),
4863
})
@@ -67,6 +82,9 @@ defineExpose({
6782
<n-form-item label="&nbsp;">
6883
<icon-button :icon="Refresh" border t-tooltip="refresh" @click="loadHistory" />
6984
</n-form-item>
85+
<n-form-item label="&nbsp;">
86+
<icon-button :icon="Delete" border t-tooltip="clean_log" @click="cleanHistory" />
87+
</n-form-item>
7088
</n-form>
7189
<div class="fill-height flex-box-h" style="user-select: text">
7290
<n-data-table
@@ -81,7 +99,7 @@ defineExpose({
8199
align: 'center',
82100
titleAlign: 'center',
83101
render({ timestamp }, index) {
84-
return dayjs(timestamp).locale('zh-cn').format('YYYY-MM-DD hh:mm:ss')
102+
return dayjs(timestamp).format('YYYY-MM-DD HH:mm:ss')
85103
},
86104
},
87105
{

frontend/src/langs/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@
159159
"launch_log": "Launch Log",
160160
"filter_server": "Filter Server",
161161
"filter_keyword": "Filter Keyword",
162+
"clean_log": "Clean Launch Log",
163+
"confirm_clean_log": "Confirm clean launch log",
162164
"exec_time": "Exec Time",
163165
"cmd": "Command",
164166
"cost_time": "Cost"

frontend/src/langs/zh-cn.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@
159159
"launch_log": "运行日志",
160160
"filter_server": "筛选服务器",
161161
"filter_keyword": "筛选关键字",
162+
"clean_log": "清空运行日志",
163+
"confirm_clean_log": "确定清空运行日志",
162164
"exec_time": "执行时间",
163165
"cmd": "命令",
164166
"cost_time": "耗时"

frontend/src/stores/connections.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
AddListItem,
66
AddStreamValue,
77
AddZSetValue,
8+
CleanCmdHistory,
89
CloseConnection,
910
CreateGroup,
1011
DeleteConnection,
@@ -1423,6 +1424,19 @@ const useConnectionStore = defineStore('connections', {
14231424
}
14241425
},
14251426

1427+
/**
1428+
* clean cmd history
1429+
* @return {Promise<boolean>}
1430+
*/
1431+
async cleanCmdHistory() {
1432+
try {
1433+
const { success } = await CleanCmdHistory()
1434+
return success === true
1435+
} catch {
1436+
return false
1437+
}
1438+
},
1439+
14261440
/**
14271441
* get key filter pattern and filter type
14281442
* @param {string} server

frontend/src/utils/discrete.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function setupMessage(message) {
1212
info: (content, option = null) => {
1313
return message.info(content, option)
1414
},
15-
loading: (content, option = null) => {
16-
option.duration = option.duration || 30000
15+
loading: (content, option = {}) => {
16+
option.duration = option.duration != null ? option.duration : 30000
1717
option.keepAliveOnHover = option.keepAliveOnHover !== undefined ? option.keepAliveOnHover : true
1818
return message.loading(content, option)
1919
},
@@ -28,20 +28,24 @@ function setupMessage(message) {
2828

2929
function setupNotification(notification) {
3030
return {
31-
error: (content, option = null) => {
31+
error: (content, option = {}) => {
32+
option.content = content
3233
option.title = option.title || i18nGlobal.t('error')
33-
return notification.error(content, option)
34+
return notification.error(option)
3435
},
35-
info: (content, option = null) => {
36-
return notification.info(content, option)
36+
info: (content, option = {}) => {
37+
option.content = content
38+
return notification.info(option)
3739
},
38-
success: (content, option = null) => {
40+
success: (content, option = {}) => {
41+
option.content = content
3942
option.title = option.title || i18nGlobal.t('success')
40-
return notification.success(content, option)
43+
return notification.success(option)
4144
},
42-
warning: (content, option = null) => {
45+
warning: (content, option = {}) => {
46+
option.content = content
4347
option.title = option.title || i18nGlobal.t('warning')
44-
return notification.warning(content, option)
48+
return notification.warning(option)
4549
},
4650
}
4751
}
@@ -81,6 +85,7 @@ export async function setupDiscreteApi() {
8185
placement: 'bottom-right',
8286
},
8387
notificationProviderProps: {
88+
max: 5,
8489
placement: 'top-right',
8590
keepAliveOnHover: true,
8691
},

0 commit comments

Comments
 (0)