From f068898918869acfb919dfd2c1e26c9e5eea157c Mon Sep 17 00:00:00 2001 From: Kinplemelon Date: Thu, 11 Jul 2024 10:40:43 +0800 Subject: [PATCH] fix(msg transform): actions are not required in some cases --- .../Rule/transform/useMessageTransform.ts | 22 +++++++++++++++++- .../MessageTransform/TransformCreate.vue | 4 +++- .../MessageTransform/TransformDetail.vue | 7 +++--- .../components/OperationsTable.vue | 7 ++++-- .../components/TransformForm.vue | 23 +++++++++++-------- 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/hooks/Rule/transform/useMessageTransform.ts b/src/hooks/Rule/transform/useMessageTransform.ts index 871935598..8557d3e7e 100644 --- a/src/hooks/Rule/transform/useMessageTransform.ts +++ b/src/hooks/Rule/transform/useMessageTransform.ts @@ -1,7 +1,12 @@ import { getLabelFromValueInOptionList } from '@/common/tools' import useI18nTl from '@/hooks/useI18nTl' import { SchemaRegistryType } from '@/types/enum' -import { MessageTransformFailureAction, MessageTransformLogLevel } from '@/types/typeAlias' +import { + MessageTransform, + MessageTransformFailureAction, + MessageTransformLogLevel, +} from '@/types/typeAlias' +import { cloneDeep } from 'lodash' export type TypeMessageTransformFailureAction = typeof MessageTransformFailureAction[keyof typeof MessageTransformFailureAction] @@ -370,3 +375,18 @@ export const useMessageTransformForm = (): UseMessageTransformFormReturn => { detectCanSetToPayloadSub, } } + +export const handleTransformData = (): { + handleDataBeforeSubmit: (data: MessageTransform) => MessageTransform +} => { + const handleDataBeforeSubmit = (data: MessageTransform): MessageTransform => { + const ret = cloneDeep(data) + if (ret.operations.length === 0) { + Reflect.deleteProperty(ret, 'operations') + } + return ret + } + return { + handleDataBeforeSubmit, + } +} diff --git a/src/views/RuleEngine/MessageTransform/TransformCreate.vue b/src/views/RuleEngine/MessageTransform/TransformCreate.vue index e81aea78f..b5e404d73 100644 --- a/src/views/RuleEngine/MessageTransform/TransformCreate.vue +++ b/src/views/RuleEngine/MessageTransform/TransformCreate.vue @@ -25,6 +25,7 @@