Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(component): messageBox componentization, and unified style #388

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/composables/config/useDeleteDriver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useI18n } from 'vue-i18n'
import { EmqxMessageBox, EmqxMessage } from '@emqx/emqx-ui'
import { EmqxMessage } from '@emqx/emqx-ui'
import { MessageBoxConfirm } from '@/utils/element'
import { deleteDriver } from '@/api/config'
import type { DriverItemInList } from '@/types/config'
import { PluginKind, NodeCatogery } from '@/types/enums'
Expand All @@ -8,12 +9,7 @@ export default () => {
const { t } = useI18n()
const delDriver = async ({ name }: DriverItemInList) => {
try {
await EmqxMessageBox({
title: t('common.operateConfirm'),
message: t('common.confirmDelete'),
type: 'warning',
confirmButtonText: t('common.confirmButtonText'),
})
await MessageBoxConfirm()
await deleteDriver(name)
EmqxMessage.success(t('common.operateSuccessfully'))
return Promise.resolve()
Expand Down
24 changes: 8 additions & 16 deletions src/composables/config/useGroupList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import type { Ref } from 'vue'
import { ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { EmqxMessageBox, EmqxMessage } from '@emqx/emqx-ui'
import { EmqxMessage } from '@emqx/emqx-ui'
import { MessageBoxConfirm } from '@/utils/element'
import { queryGroupList, deleteGroup, queryTagList } from '@/api/config'
import type { GroupData } from '@/types/config'
import { OmitArrayFields } from '@/utils/utils'
Expand Down Expand Up @@ -53,11 +54,8 @@ export default () => {
}

const delGroup = async ({ name }: GroupDataInTable) => {
await EmqxMessageBox({
title: t('common.operateConfirm'),
message: t('common.confirmDelete'),
confirmButtonText: t('common.confirmButtonText'),
})
await MessageBoxConfirm()

await deleteGroup(node.value, name)
EmqxMessage.success(t('common.operateSuccessfully'))
getGroupList()
Expand All @@ -70,20 +68,14 @@ export default () => {
}

const batchDeleteGroup = async () => {
await EmqxMessageBox({
title: t('common.operateConfirm'),
message: t('common.confirmDelete'),
confirmButtonText: t('common.confirmButtonText'),
})
await MessageBoxConfirm()

delGroupList(groupCheckedList.value)
}

const clearGroup = async () => {
await EmqxMessageBox({
title: t('common.operateConfirm'),
message: t('common.confirmClear'),
confirmButtonText: t('common.confirmButtonText'),
})
await MessageBoxConfirm(t('common.confirmClear'))

delGroupList(groupList.value)
}

Expand Down
11 changes: 4 additions & 7 deletions src/composables/config/usePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ref } from 'vue'
import type { Ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { EmqxMessage, EmqxMessageBox } from '@emqx/emqx-ui'
import { EmqxMessage } from '@emqx/emqx-ui'
import { MessageBoxConfirm } from '@/utils/element'
import { addPlugin, deletePlugin, queryPluginList } from '@/api/config'
import { createCommonErrorMessage } from '@/utils/utils'
// import { PluginType } from '@/types/enums'
Expand Down Expand Up @@ -131,12 +132,8 @@ export const useDeletePlugin = () => {
const { t } = useI18n()
const delPlugin = async ({ name }: CreatedPlugin) => {
try {
await EmqxMessageBox({
title: t('common.operateConfirm'),
message: t('common.confirmDelete'),
type: 'warning',
confirmButtonText: t('common.confirmButtonText'),
})
await MessageBoxConfirm()

await deletePlugin(name)
EmqxMessage.success(t('common.operateSuccessfully'))
return Promise.resolve()
Expand Down
9 changes: 4 additions & 5 deletions src/composables/config/useSubscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { addSubscription, deleteSubscription, queryGroupList, querySubscription
import type { GroupData, SubscriptionData, SubscriptionDataForm } from '@/types/config'
import type { Ref } from 'vue'
import { ref, computed, nextTick } from 'vue'
import { EmqxMessageBox, EmqxMessage } from '@emqx/emqx-ui'
import { EmqxMessage } from '@emqx/emqx-ui'
import { MessageBoxConfirm } from '@/utils/element'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import useSouthDriver from './useSouthDriver'
Expand Down Expand Up @@ -51,10 +52,8 @@ export const useSubscriptionList = () => {

const unsubscribe = async (confirmText: string, data: SubscriptionData | Array<SubscriptionData>) => {
try {
await EmqxMessageBox.confirm(confirmText, t('common.operateConfirm'), {
confirmButtonText: t('common.confirmButtonText'),
cancelButtonText: t('common.cancelButtonText'),
})
await MessageBoxConfirm(confirmText)

if (Array.isArray(data)) {
const requestList = data.map((groupItem: SubscriptionData) => deleteSubscription(groupItem))
await Promise.all(requestList)
Expand Down
22 changes: 8 additions & 14 deletions src/composables/config/useTagList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { Ref } from 'vue'
import { ref, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import { useRoute } from 'vue-router'
import { EmqxMessage, EmqxMessageBox } from '@emqx/emqx-ui'
import { EmqxMessage } from '@emqx/emqx-ui'
import { MessageBoxConfirm } from '@/utils/element'
import usePaging from '@/composables/usePaging'
import { OmitArrayFields } from '@/utils/utils'
import { debounce } from 'lodash'
Expand Down Expand Up @@ -105,19 +106,15 @@ export default () => {
}

const delTag = async (item: TagDataInTable) => {
await EmqxMessageBox.confirm(t('common.confirmDelete'), t('common.operateConfirm'), {
confirmButtonText: t('common.confirmButtonText'),
cancelButtonText: t('common.cancelButtonText'),
})
await MessageBoxConfirm()

const delList = OmitArrayFields([item], ['checked'])
deleteTagList(delList)
}

const batchDeleteTag = async () => {
await EmqxMessageBox.confirm(t('common.confirmDelete'), t('common.operateConfirm'), {
confirmButtonText: t('common.confirmButtonText'),
cancelButtonText: t('common.cancelButtonText'),
})
await MessageBoxConfirm()

deleteTagList(tagCheckedList.value)
}

Expand All @@ -127,11 +124,8 @@ export default () => {
}

const clearTag = async () => {
await EmqxMessageBox({
title: t('common.operateConfirm'),
message: t('common.confirmClear'),
confirmButtonText: t('common.confirmButtonText'),
})
await MessageBoxConfirm(t('common.confirmClear'))

deleteTagList(totalData.value)
}

Expand Down
15 changes: 15 additions & 0 deletions src/utils/element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ElMessageBox } from 'element-plus'
import i18n from '@/i18n/index'
import type { MessageType } from 'element-plus/lib/el-message-box/src/message-box.type'

export const MessageBoxConfirm = (
content: string = i18n.global.t('common.confirmDelete'),
title: string = i18n.global.t('common.operateConfirm'),
type: MessageType = 'warning',
) => {
return ElMessageBox.confirm(content, title, {
confirmButtonText: i18n.global.t('common.confirmButtonText'),
cancelButtonText: i18n.global.t('common.cancelButtonText'),
type,
})
}