diff --git a/frontend/src/components/dialogs/ConnectionDialog.vue b/frontend/src/components/dialogs/ConnectionDialog.vue index 9be5fa5..cb8fb81 100644 --- a/frontend/src/components/dialogs/ConnectionDialog.vue +++ b/frontend/src/components/dialogs/ConnectionDialog.vue @@ -3,7 +3,7 @@ import { every, get, includes, isEmpty, map } from 'lodash' import { computed, nextTick, ref, watch } from 'vue' import { useI18n } from 'vue-i18n' import { TestConnection } from 'wailsjs/go/services/connectionService.js' -import useDialog from 'stores/dialog' +import useDialog, { ConnDialogType } from 'stores/dialog' import Close from '@/components/icons/Close.vue' import useConnectionStore from 'stores/connections.js' @@ -36,7 +36,7 @@ const generalFormRules = () => { keySeparator: { required: true, message: requiredMsg, trigger: 'input' }, } } -const isEditMode = computed(() => !isEmpty(editName.value)) +const isEditMode = computed(() => dialogStore.connType === ConnDialogType.EDIT) const closingConnection = computed(() => { if (isEmpty(editName.value)) { return false @@ -133,11 +133,7 @@ const onTestConnection = async () => { } const onClose = () => { - if (isEditMode.value) { - dialogStore.closeEditDialog() - } else { - dialogStore.closeNewDialog() - } + dialogStore.closeConnDialog() } diff --git a/frontend/src/components/sidebar/ConnectionTree.vue b/frontend/src/components/sidebar/ConnectionTree.vue index 40503b7..ffd60a0 100644 --- a/frontend/src/components/sidebar/ConnectionTree.vue +++ b/frontend/src/components/sidebar/ConnectionTree.vue @@ -73,16 +73,16 @@ const menuOptions = { label: i18n.t('interface.disconnect'), icon: renderIcon(Unlink), }, - { - key: 'server_dup', - label: i18n.t('interface.dup_conn'), - icon: renderIcon(CopyLink), - }, { key: 'server_edit', label: i18n.t('interface.edit_conn'), icon: renderIcon(Config), }, + { + key: 'server_dup', + label: i18n.t('interface.dup_conn'), + icon: renderIcon(CopyLink), + }, { type: 'divider', key: 'd1', @@ -105,6 +105,11 @@ const menuOptions = { label: i18n.t('interface.edit_conn'), icon: renderIcon(Config), }, + { + key: 'server_dup', + label: i18n.t('interface.dup_conn'), + icon: renderIcon(CopyLink), + }, { type: 'divider', key: 'd1', @@ -387,6 +392,9 @@ const handleSelectContextMenu = (key) => { dialogStore.openEditDialog(name) } break + case 'server_dup': + dialogStore.openDuplicateDialog(name) + break case 'server_remove': removeConnection(name) break diff --git a/frontend/src/consts/connection_type.js b/frontend/src/consts/connection_type.js index 6385a7b..844f135 100644 --- a/frontend/src/consts/connection_type.js +++ b/frontend/src/consts/connection_type.js @@ -1,3 +1,7 @@ +/** + * all types of connection item + * @enum {number} + */ export const ConnectionType = { Group: 0, Server: 1, diff --git a/frontend/src/consts/support_redis_type.js b/frontend/src/consts/support_redis_type.js index 99e60fc..5786b42 100644 --- a/frontend/src/consts/support_redis_type.js +++ b/frontend/src/consts/support_redis_type.js @@ -1,3 +1,7 @@ +/** + * all redis type + * @enum {string} + */ export const types = { STRING: 'STRING', HASH: 'HASH', @@ -7,6 +11,10 @@ export const types = { STREAM: 'STREAM', } +/** + * mark color for redis type + * @enum {string} + */ export const typesColor = { [types.STRING]: '#8256DC', [types.HASH]: '#0171F5', @@ -16,6 +24,10 @@ export const typesColor = { [types.STREAM]: '#F5C201', } +/** + * background mark color for redis type + * @enum {string} + */ export const typesBgColor = { [types.STRING]: '#F2EDFB', [types.HASH]: '#E4F0FC', diff --git a/frontend/src/consts/value_view_type.js b/frontend/src/consts/value_view_type.js index 1095ee4..bcc0582 100644 --- a/frontend/src/consts/value_view_type.js +++ b/frontend/src/consts/value_view_type.js @@ -1,3 +1,7 @@ +/** + * string view mode + * @enum {string} + */ export const types = { PLAIN_TEXT: 'Plain Text', JSON: 'JSON', diff --git a/frontend/src/stores/dialog.js b/frontend/src/stores/dialog.js index c05ea64..5254546 100644 --- a/frontend/src/stores/dialog.js +++ b/frontend/src/stores/dialog.js @@ -1,9 +1,20 @@ import { defineStore } from 'pinia' import useConnectionStore from './connections.js' +/** + * connection dialog type + * @enum {number} + */ +export const ConnDialogType = { + NEW: 0, + EDIT: 1, +} + const useDialogStore = defineStore('dialog', { state: () => ({ connDialogVisible: false, + /** @type {ConnDialogType} **/ + connType: ConnDialogType.NEW, connParam: null, groupDialogVisible: false, @@ -59,9 +70,10 @@ const useDialogStore = defineStore('dialog', { actions: { openNewDialog() { this.connParam = null + this.connType = ConnDialogType.NEW this.connDialogVisible = true }, - closeNewDialog() { + closeConnDialog() { this.connDialogVisible = false }, @@ -69,10 +81,21 @@ const useDialogStore = defineStore('dialog', { const connStore = useConnectionStore() const profile = await connStore.getConnectionProfile(name) this.connParam = profile || connStore.newDefaultConnection(name) + this.connType = ConnDialogType.EDIT this.connDialogVisible = true }, - closeEditDialog() { - this.connDialogVisible = false + + async openDuplicateDialog(name) { + const connStore = useConnectionStore() + const profile = await connStore.getConnectionProfile(name) + if (profile != null) { + profile.name += '2' + this.connParam = profile + } else { + this.connParam = connStore.newDefaultConnection(name) + } + this.connType = ConnDialogType.NEW + this.connDialogVisible = true }, openNewGroupDialog() {