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 @@