From ee29319b8395b8b7c5c77cc9e818a7f561c21853 Mon Sep 17 00:00:00 2001 From: Kevin Burnett <18027+burnettk@users.noreply.github.com> Date: Wed, 26 Jun 2024 18:02:21 +0000 Subject: [PATCH] Fix/message editor validator (#1825) * Add eventBus to customForm * Fix bpmnEvent Issue * Update spiffworkflow-frontend/src/components/messages/MessageEditor.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fixed linting issues w/ burnettk --------- Co-authored-by: =theaubmov Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: jasquat --- .../src/components/CustomForm.tsx | 26 +++++++++++++++++-- .../src/components/messages/MessageEditor.tsx | 22 ++++------------ .../src/routes/ProcessModelEditDiagram.tsx | 1 - 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/spiffworkflow-frontend/src/components/CustomForm.tsx b/spiffworkflow-frontend/src/components/CustomForm.tsx index 946b20ffb..ba79b117d 100644 --- a/spiffworkflow-frontend/src/components/CustomForm.tsx +++ b/spiffworkflow-frontend/src/components/CustomForm.tsx @@ -1,5 +1,5 @@ import validator from '@rjsf/validator-ajv8'; -import { ReactNode } from 'react'; +import { ReactNode, useEffect, useRef } from 'react'; import { RegistryFieldsType } from '@rjsf/utils'; import { Button } from '@carbon/react'; import { Form as MuiForm } from '@rjsf/mui'; @@ -23,7 +23,6 @@ type OwnProps = { formData: any; schema: any; uiSchema: any; - className?: string; disabled?: boolean; onChange?: any; @@ -34,6 +33,7 @@ type OwnProps = { submitButtonText?: string; reactJsonSchemaForm?: string; hideSubmitButton?: boolean; + bpmnEvent?: any; }; export default function CustomForm({ @@ -52,6 +52,7 @@ export default function CustomForm({ submitButtonText, reactJsonSchemaForm = 'carbon', hideSubmitButton = false, + bpmnEvent, }: OwnProps) { // set in uiSchema using the "ui:widget" key for a property const rjsfWidgets = { @@ -500,10 +501,31 @@ export default function CustomForm({ }; let childrenToUse = children; + const submitButtonRef = useRef(null); + + useEffect(() => { + if (bpmnEvent && submitButtonText) { + const triggerSaveEvent = (event: any) => { + if (submitButtonRef.current) { + submitButtonRef.current.click(); + } + event.stopPropagation(); + }; + + bpmnEvent.eventBus.on('spiff.message.save', triggerSaveEvent); + + return () => { + bpmnEvent.eventBus.off('spiff.message.save', triggerSaveEvent); + }; + } + return undefined; + }, [bpmnEvent, submitButtonText]); + if (submitButtonText) { childrenToUse = (