From 44d37a6d5b987091ef318e964f157ebdb9df3f54 Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Tue, 21 May 2024 21:16:41 +0800 Subject: [PATCH 1/2] feat(connector): support enable/disable connector --- .../Rule/connector/useHandleConnectorItem.ts | 29 +++++++++++++++++-- src/i18n/Base.js | 4 +++ src/views/RuleEngine/Connector/Connector.vue | 29 +++++++++++++++++-- .../RuleEngine/Connector/ConnectorDetail.vue | 23 +++++++++++++++ 4 files changed, 80 insertions(+), 5 deletions(-) diff --git a/src/hooks/Rule/connector/useHandleConnectorItem.ts b/src/hooks/Rule/connector/useHandleConnectorItem.ts index fa25e263d..d879984a5 100644 --- a/src/hooks/Rule/connector/useHandleConnectorItem.ts +++ b/src/hooks/Rule/connector/useHandleConnectorItem.ts @@ -1,14 +1,18 @@ import { postConnector, putConnector, + putConnectorEnable, getConnectorDetail as requestConnectorDetail, deleteConnector as requestDelConnector, reconnectConnector as requestReconnectConnector, } from '@/api/connector' import useTestConnector from '@/hooks/Rule/connector/useTestConnector' import useWebhookUtils from '@/hooks/Webhook/useWebhookUtils' +import useI18nTl from '@/hooks/useI18nTl' import useOperationConfirm from '@/hooks/useOperationConfirm' import { BridgeItem, Connector } from '@/types/rule' +import { ElMessage } from 'element-plus' +import { isFunction } from 'lodash' import { Ref, ref } from 'vue' import { useConnectorDataHandler } from '../useDataHandler' @@ -21,6 +25,7 @@ interface ConnectorHandlerResult { updateConnector: (data: Connector) => Promise deleteConnector: (id: string, withDep?: boolean) => Promise reconnectConnector: (id: string) => Promise + toggleConnectorEnable: (id: string, isEnable: boolean, sucCb?: () => void) => Promise handleDataForCopy: (data: Connector) => Connector isTesting: Ref testConnectivity: (data: NowConnector) => Promise @@ -84,6 +89,27 @@ export default (): ConnectorHandlerResult => { return requestReconnectConnector(id) } + const { operationWarning, confirmDel } = useOperationConfirm() + + const { t } = useI18nTl('RuleEngine') + const toggleConnectorEnable = async (id: string, isEnable: boolean, sucCb?: () => void) => { + const sucMessage = isEnable ? 'Base.enableSuccess' : 'Base.disabledSuccess' + try { + if (!isEnable) { + await operationWarning(t('Base.confirmDisabled')) + } + await putConnectorEnable(id, isEnable) + if (isFunction(sucCb)) { + sucCb() + } + ElMessage.success(t(sucMessage)) + return Promise.resolve() + } catch (error) { + console.error(error) + return Promise.reject() + } + } + const { isTesting, testConnectivity: testConnectorConnectivity } = useTestConnector() const testConnectivity = async (data: NowConnector): Promise => testConnectorConnectivity(data as Connector) @@ -92,8 +118,6 @@ export default (): ConnectorHandlerResult => { const associatedActionList = ref>([]) const currentDelType = ref('') - const { confirmDel } = useOperationConfirm() - const deleteTrueConnector = async (id: string) => { return confirmDel(() => deleteConnector(id)) } @@ -133,6 +157,7 @@ export default (): ConnectorHandlerResult => { updateConnector, deleteConnector, reconnectConnector, + toggleConnectorEnable, handleDataForCopy, isTesting, testConnectivity, diff --git a/src/i18n/Base.js b/src/i18n/Base.js index 7414d2833..3f7c61e58 100644 --- a/src/i18n/Base.js +++ b/src/i18n/Base.js @@ -315,6 +315,10 @@ export default { zh: '是否确认替换当前内容?', en: 'Are you sure you want to replace the current content?', }, + confirmDisabled: { + zh: '是否确认停用?', + en: 'Are you sure you want to disable?', + }, import: { zh: '导入', en: 'Import', diff --git a/src/views/RuleEngine/Connector/Connector.vue b/src/views/RuleEngine/Connector/Connector.vue index 92d3b185b..2a3c66a20 100644 --- a/src/views/RuleEngine/Connector/Connector.vue +++ b/src/views/RuleEngine/Connector/Connector.vue @@ -40,6 +40,22 @@ + + + @@ -69,8 +85,6 @@ > {{ $t('Base.setting') }} - - import { useBridgeTypeIcon, useConnectorTypeValue } from '@/hooks/Rule/bridge/useBridgeTypeValue' -import useHandleConnectorItem from '@/hooks/Rule/connector/useHandleConnectorItem' import useConnectorList from '@/hooks/Rule/connector/useConnectorList' +import useHandleConnectorItem from '@/hooks/Rule/connector/useHandleConnectorItem' import useWebhookUtils from '@/hooks/Webhook/useWebhookUtils' import useI18nTl from '@/hooks/useI18nTl' import { ConnectionStatus } from '@/types/enum' @@ -157,6 +171,7 @@ const isErrorStatus = ({ status }: Connector) => const { handleDeleteConnector, reconnectConnector, + toggleConnectorEnable, showDelTip, currentDelName, showDeleteWebhookAssociatedTip, @@ -182,6 +197,14 @@ const getDetailPageRoute = ({ id }: Connector) => ({ params: { id }, }) +const enableOrDisableConnector = async ({ enable, id }: Connector) => { + try { + await toggleConnectorEnable(id, !enable, getList) + } catch (error) { + // + } +} + const showCreateRuleDialog = ref(false) const createdConnector = ref(undefined) const createRuleWithConnector = async (connector: Connector) => { diff --git a/src/views/RuleEngine/Connector/ConnectorDetail.vue b/src/views/RuleEngine/Connector/ConnectorDetail.vue index 44623c024..eaed24a7e 100644 --- a/src/views/RuleEngine/Connector/ConnectorDetail.vue +++ b/src/views/RuleEngine/Connector/ConnectorDetail.vue @@ -15,6 +15,17 @@
+ + + { } } +const enableOrDisableConnector = async () => { + try { + const targetValue = !connectorData.value.enable + await toggleConnectorEnable(id.value, targetValue, () => { + connectorData.value.enable = targetValue + }) + } catch (error) { + // + } +} + const { handleConnectorDataForSaveAsCopy } = useConnectorDataHandler() const { pwdErrorWhenCoping, checkLikePwdField } = useCheckBeforeSaveAsCopy() const saveAsCopy = async () => { From efec06bf506f055a6793272a5c978f978ee86ebd Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Wed, 22 May 2024 09:40:37 +0800 Subject: [PATCH 2/2] test(schemas): update schemas --- src/types/schemas/clients.schemas.ts | 52 ---------------------------- src/types/schemas/metrics.schemas.ts | 3 ++ 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/src/types/schemas/clients.schemas.ts b/src/types/schemas/clients.schemas.ts index e46e39a30..5b97a97c9 100644 --- a/src/types/schemas/clients.schemas.ts +++ b/src/types/schemas/clients.schemas.ts @@ -243,45 +243,6 @@ export type DeleteClientsClientid404 = { message?: string } -export type GetClientsV2400Code = typeof GetClientsV2400Code[keyof typeof GetClientsV2400Code] - -// eslint-disable-next-line @typescript-eslint/no-redeclare -export const GetClientsV2400Code = { - INVALID_PARAMETER: 'INVALID_PARAMETER', -} as const - -export type GetClientsV2400 = { - code?: GetClientsV2400Code - message?: string -} - -export type GetClientsV2ConnState = typeof GetClientsV2ConnState[keyof typeof GetClientsV2ConnState] - -// eslint-disable-next-line @typescript-eslint/no-redeclare -export const GetClientsV2ConnState = { - connected: 'connected', - idle: 'idle', - disconnected: 'disconnected', -} as const - -export type GetClientsV2Params = { - cursor?: PublicCursorParameter - limit?: PublicLimitParameter - username?: string[] - ip_address?: string - conn_state?: GetClientsV2ConnState - clean_start?: boolean - proto_ver?: string - like_clientid?: string - like_username?: string - gte_created_at?: number | string - lte_created_at?: number | string - gte_connected_at?: number | string - lte_connected_at?: number | string - clientid?: string[] - fields?: EmqxMgmtApiClientsRequestedClientFieldsParameter -} - export type GetClientsClientidAuthorizationCache404Code = typeof GetClientsClientidAuthorizationCache404Code[keyof typeof GetClientsClientidAuthorizationCache404Code] @@ -331,8 +292,6 @@ export type PublicPageParameter = number export type PublicLimitParameter = number -export type PublicCursorParameter = string | 'none' - export type EmqxMgmtApiClientsRequestedClientFieldsParameterOneOfItem = typeof EmqxMgmtApiClientsRequestedClientFieldsParameterOneOfItem[keyof typeof EmqxMgmtApiClientsRequestedClientFieldsParameterOneOfItem] @@ -402,12 +361,6 @@ export type EmqxMgmtApiClientsRequestedClientFieldsParameter = | EmqxMgmtApiClientsRequestedClientFieldsParameterOneOfItem[] | 'all' -export interface PublicMetaWithCursor { - count?: number - hasnext: boolean - cursor?: string -} - export interface PublicMeta { page?: number limit?: number @@ -549,11 +502,6 @@ export interface EmqxMgmtApiClientsClient { seqno_q2_next?: number } -export interface EmqxMgmtApiClientsListClientsV2Response { - data?: EmqxMgmtApiClientsClient[] - meta?: PublicMetaWithCursor -} - export interface EmqxMgmtApiClientsClients { data?: EmqxMgmtApiClientsClient[] meta?: PublicMeta diff --git a/src/types/schemas/metrics.schemas.ts b/src/types/schemas/metrics.schemas.ts index 775d571c1..a38924a76 100644 --- a/src/types/schemas/metrics.schemas.ts +++ b/src/types/schemas/metrics.schemas.ts @@ -290,6 +290,7 @@ export interface EmqxDashboardMonitorApiSamplerCurrentNode { sent_msg_rate?: number validation_failed_rate?: number validation_succeeded_rate?: number + disconnected_durable_sessions?: number durable_subscriptions?: number subscriptions?: number topics?: number @@ -307,6 +308,7 @@ export interface EmqxDashboardMonitorApiSamplerCurrent { sent_msg_rate?: number validation_failed_rate?: number validation_succeeded_rate?: number + disconnected_durable_sessions?: number durable_subscriptions?: number subscriptions?: number topics?: number @@ -318,6 +320,7 @@ export interface EmqxDashboardMonitorApiSamplerCurrent { export interface EmqxDashboardMonitorApiSampler { time_stamp?: number + disconnected_durable_sessions?: number durable_subscriptions?: number subscriptions?: number topics?: number