From c01be7fcca5df5b383590da8d0914332067b5e32 Mon Sep 17 00:00:00 2001
From: tiny-craft <137850705+tiny-craft@users.noreply.github.com>
Date: Mon, 28 Aug 2023 15:21:08 +0800
Subject: [PATCH] feat: add clean command history
---
backend/services/connection_service.go | 8 ++++++
.../src/components/content/ContentLogPane.vue | 20 ++++++++++++++-
frontend/src/langs/en.json | 2 ++
frontend/src/langs/zh-cn.json | 2 ++
frontend/src/stores/connections.js | 14 +++++++++++
frontend/src/utils/discrete.js | 25 +++++++++++--------
6 files changed, 60 insertions(+), 11 deletions(-)
diff --git a/backend/services/connection_service.go b/backend/services/connection_service.go
index b27fe53..0737bbe 100644
--- a/backend/services/connection_service.go
+++ b/backend/services/connection_service.go
@@ -1040,6 +1040,7 @@ func (c *connectionService) RenameKey(connName string, db int, key, newKey strin
return
}
+// GetCmdHistory get redis command history
func (c *connectionService) GetCmdHistory(pageNo, pageSize int) (resp types.JSResp) {
resp.Success = true
if pageSize <= 0 || pageNo <= 0 {
@@ -1062,6 +1063,13 @@ func (c *connectionService) GetCmdHistory(pageNo, pageSize int) (resp types.JSRe
return
}
+// CleanCmdHistory clean redis command history
+func (c *connectionService) CleanCmdHistory() (resp types.JSResp) {
+ c.cmdHistory = []cmdHistoryItem{}
+ resp.Success = true
+ return
+}
+
// update or insert key info to database
//func (c *connectionService) updateDBKey(connName string, db int, keys []string, separator string) {
// dbStruct := map[string]any{}
diff --git a/frontend/src/components/content/ContentLogPane.vue b/frontend/src/components/content/ContentLogPane.vue
index 3701949..a1e4f90 100644
--- a/frontend/src/components/content/ContentLogPane.vue
+++ b/frontend/src/components/content/ContentLogPane.vue
@@ -5,6 +5,7 @@ import Refresh from '@/components/icons/Refresh.vue'
import useConnectionStore from 'stores/connections.js'
import { map, uniqBy } from 'lodash'
import { useI18n } from 'vue-i18n'
+import Delete from '@/components/icons/Delete.vue'
import dayjs from 'dayjs'
const connectionStore = useConnectionStore()
@@ -43,6 +44,20 @@ const loadHistory = () => {
})
}
+const cleanHistory = async () => {
+ $dialog.warning(i18n.t('confirm_clean_log'), () => {
+ data.loading = true
+ connectionStore.cleanCmdHistory().then((success) => {
+ if (success) {
+ data.history = []
+ data.loading = false
+ tableRef.value?.scrollTo({ top: 0 })
+ $message.success(i18n.t('success'))
+ }
+ })
+ })
+}
+
defineExpose({
refresh: () => nextTick().then(loadHistory),
})
@@ -67,6 +82,9 @@ defineExpose({