From 796fad258a5e7415bf33ed39b0ca68f3a2f7ed5b Mon Sep 17 00:00:00 2001 From: gpalade Date: Thu, 2 Nov 2023 10:13:10 +0200 Subject: [PATCH] start handlers --- gql-bff/src/features/workflow/resolvers.js | 10 +++++++- gql-bff/src/features/workflow/schema.graphql | 3 ++- .../static/locales/en/translations.json | 3 ++- .../static/locales/fr/translations.json | 3 ++- .../static/locales/ro/translations.json | 3 ++- react-ui/src/features/common/constants.js | 2 +- .../designer/components/UtilitiesBar.js | 16 ++++++++---- .../workflow/edit/components/Workflow.js | 14 ++++++++++- .../edit/components/WorkflowContainer.js | 9 +++---- .../workflow/edit/components/WorkflowJson.js | 2 +- .../modals/GeneralSettingsDialog.js | 1 + .../workflow/edit/queries/WorkflowQuery.js | 25 +++++++++++++++++++ 12 files changed, 72 insertions(+), 19 deletions(-) diff --git a/gql-bff/src/features/workflow/resolvers.js b/gql-bff/src/features/workflow/resolvers.js index 3907d00..c5133e0 100644 --- a/gql-bff/src/features/workflow/resolvers.js +++ b/gql-bff/src/features/workflow/resolvers.js @@ -18,7 +18,15 @@ const workflowResolvers = { const { dataSources, tenant } = context; const workflow = await dataSources.workflowApi.getWorkflow(name, version); - if (!isMultiTenant) return workflow; + const conductorHandlers = + await dataSources.eventHandlerApi.getEventHandlerList(); + const startHandlers = conductorHandlers.filter((a) => + a.actions.some( + (x) => + x.action === "start_workflow" && x?.start_workflow?.name === name + ) + ); + if (!isMultiTenant) return { ...workflow, startHandlers }; const wfTenantId = getTenantIdFromDescription(workflow?.description); if (userCanSeeResource(wfTenantId, tenant?.id)) { diff --git a/gql-bff/src/features/workflow/schema.graphql b/gql-bff/src/features/workflow/schema.graphql index d35b05c..5c5d685 100644 --- a/gql-bff/src/features/workflow/schema.graphql +++ b/gql-bff/src/features/workflow/schema.graphql @@ -1,5 +1,6 @@ extend type WorkflowDef { - readOnly: Boolean + readOnly: Boolean, + startHandlers: [EventHandler] } type ExportWorkflows { diff --git a/react-ui/public/static/locales/en/translations.json b/react-ui/public/static/locales/en/translations.json index 0a47b4c..688ae60 100644 --- a/react-ui/public/static/locales/en/translations.json +++ b/react-ui/public/static/locales/en/translations.json @@ -332,7 +332,8 @@ "Export": "Export as JSON", "Delete": "Delete selection", "Execute": "Execute workflow", - "GeneralSettings": "General settings" + "GeneralSettings": "General settings", + "StartHandler": "Start Event Handlers" }, "Tour": { "BadgeContent": "{{curr}} of {{tot}}", diff --git a/react-ui/public/static/locales/fr/translations.json b/react-ui/public/static/locales/fr/translations.json index ee81c77..c4192bf 100644 --- a/react-ui/public/static/locales/fr/translations.json +++ b/react-ui/public/static/locales/fr/translations.json @@ -306,7 +306,8 @@ "Export": "Exporter au format JSON", "Delete": "Supprimer la sélection", "Execute": "Exécuter le workflow", - "GeneralSettings": "Paramètres généraux" + "GeneralSettings": "Paramètres généraux", + "StartHandler": "Start Event Handlers" }, "Tour": { "BadgeContent": "{{curr}} sur {{tot}}", diff --git a/react-ui/public/static/locales/ro/translations.json b/react-ui/public/static/locales/ro/translations.json index 9beb4ba..6c63b10 100644 --- a/react-ui/public/static/locales/ro/translations.json +++ b/react-ui/public/static/locales/ro/translations.json @@ -307,7 +307,8 @@ "Export": "Exporta ca JSON", "Delete": "Sterge selectia", "Execute": "Executa fluxul", - "GeneralSettings": "Setari generale" + "GeneralSettings": "Setari generale", + "StartHandler": "Start Event Handlers" }, "Tour": { "BadgeContent": "{{curr}} din {{tot}}", diff --git a/react-ui/src/features/common/constants.js b/react-ui/src/features/common/constants.js index c2cd48a..a2e80fb 100644 --- a/react-ui/src/features/common/constants.js +++ b/react-ui/src/features/common/constants.js @@ -13,4 +13,4 @@ export const sortingDirection = { DESC: 'DESC' } -export const fieldsToBeRemoved = ['__typename', 'historyId', 'readOnly'] +export const fieldsToBeRemoved = ['__typename', 'historyId', 'readOnly', 'startHandlers'] diff --git a/react-ui/src/features/designer/components/UtilitiesBar.js b/react-ui/src/features/designer/components/UtilitiesBar.js index 03eac74..358510b 100644 --- a/react-ui/src/features/designer/components/UtilitiesBar.js +++ b/react-ui/src/features/designer/components/UtilitiesBar.js @@ -11,14 +11,14 @@ import { Redo, DescriptionOutlined, SettingsOutlined -} from '@mui/icons-material' + } from '@mui/icons-material' import PlayCircleIcon from '@mui/icons-material/PlayCircleOutline' +import StartIcon from '@mui/icons-material/Start'; import PolylineIcon from '@mui/icons-material/Polyline' import AbcIcon from '@mui/icons-material/Abc' import { Grid } from '@mui/material' import { useTranslation } from 'react-i18next' import styles from '../styles/styles' - const useStyles = makeStyles(styles) const UtilitiesBar = ({ @@ -33,7 +33,8 @@ const UtilitiesBar = ({ onUndo, onRedo, viewType, - handleViewType + handleViewType, + onViewStartHandler }) => { const { t } = useTranslation() const classes = useStyles() @@ -107,8 +108,12 @@ const UtilitiesBar = ({ )} + + + + - + @@ -132,7 +137,8 @@ UtilitiesBar.propTypes = { onUndo: PropTypes.func.isRequired, onRedo: PropTypes.func.isRequired, viewType: PropTypes.string.isRequired, - handleViewType: PropTypes.func.isRequired + handleViewType: PropTypes.func.isRequired, + onViewStartHandler: PropTypes.func.isRequired } export default UtilitiesBar diff --git a/react-ui/src/features/workflow/edit/components/Workflow.js b/react-ui/src/features/workflow/edit/components/Workflow.js index b70fa14..0ffe03b 100644 --- a/react-ui/src/features/workflow/edit/components/Workflow.js +++ b/react-ui/src/features/workflow/edit/components/Workflow.js @@ -27,8 +27,9 @@ import SideMenu from './sideMenu/SideMenu' import PreviewJsonDialog from './modals/PreviewJsonDialog' import { defaultFileName } from 'features/workflow/common/constants' import workflowConfig from 'features/designer/constants/WorkflowConfig' -import { useToast } from '@totalsoft/rocket-ui' +import { useToast, Dialog } from '@totalsoft/rocket-ui' import WorkflowJson from './WorkflowJson' +import JsonViewer from 'features/common/components/JsonViewer' const Workflow = ({ loading, isNew, resetWorkflow, isDirty, workflowLens, diagram, setIsDirty, taskDefs }) => { const { t } = useTranslation() @@ -47,7 +48,9 @@ const Workflow = ({ loading, isNew, resetWorkflow, isDirty, workflowLens, diagra const [settingsDialog, setSettingsDialog] = useState(false) const [previewDialog, setPreviewDialog] = useState(false) const [currentWorkflow, setCurrentWorkflow] = useState(null) + const [startHandlersDialog, showStartHandlersDialog] = useState(false) + const toggleStartHandlersDialog = useCallback(() => showStartHandlersDialog(current => !current), []) const workflow = workflowLens |> get const { engine } = diagram @@ -268,6 +271,7 @@ const Workflow = ({ loading, isNew, resetWorkflow, isDirty, workflowLens, diagra onRedo={handleRedo} viewType={viewType} handleViewType={handleChangeViewType} + onViewStartHandler={toggleStartHandlersDialog} /> {viewType === 'draw' && ( @@ -303,6 +307,14 @@ const Workflow = ({ loading, isNew, resetWorkflow, isDirty, workflowLens, diagra workflowLens={workflowLens} /> + + } + /> ) } diff --git a/react-ui/src/features/workflow/edit/components/WorkflowContainer.js b/react-ui/src/features/workflow/edit/components/WorkflowContainer.js index 796967d..586766a 100644 --- a/react-ui/src/features/workflow/edit/components/WorkflowContainer.js +++ b/react-ui/src/features/workflow/edit/components/WorkflowContainer.js @@ -74,7 +74,7 @@ const WorkflowContainer = () => { const [nameDialog, showNameDialog] = useState(false) const [tourDialog, showTourDialog] = useState(false) const [startTourDialog, showStartTourDialog] = useState(false) - + const toggleNameDialog = useCallback(() => showNameDialog(current => !current), []) const toggleTourDialog = useCallback(() => showTourDialog(current => !current), []) const toggleStartTourDialog = useCallback(() => showStartTourDialog(current => !current), []) @@ -175,7 +175,7 @@ const WorkflowContainer = () => { showError(err) } } - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps }, [ createOrUpdateWorkflow, engine, @@ -237,10 +237,7 @@ const WorkflowContainer = () => { parseObjectParameters(node.inputs, skipParametersByParsing) node.options.name = inputs?.inputs?.name - if ( - inputs?.inputs.type === nodeConfig.DECISION.type && - (isPropertyDirty('inputs.decisionCases', inputsDirtyInfo)) - ) { + if (inputs?.inputs.type === nodeConfig.DECISION.type && isPropertyDirty('inputs.decisionCases', inputsDirtyInfo)) { const cases = keys(inputs?.inputs?.decisionCases) decisionCasesToPorts(node, cases) } diff --git a/react-ui/src/features/workflow/edit/components/WorkflowJson.js b/react-ui/src/features/workflow/edit/components/WorkflowJson.js index a1eba6b..64a62f8 100644 --- a/react-ui/src/features/workflow/edit/components/WorkflowJson.js +++ b/react-ui/src/features/workflow/edit/components/WorkflowJson.js @@ -77,7 +77,7 @@ const WorkflowJson = ({ loading, workflow, onChangeJson }) => { value={JSON.stringify( workflow, (key, value) => { - if (key === '__typename') return + if (key === '__typename' || key === 'startHandlers') return return value }, '\t' diff --git a/react-ui/src/features/workflow/edit/components/modals/GeneralSettingsDialog.js b/react-ui/src/features/workflow/edit/components/modals/GeneralSettingsDialog.js index d67fff4..7523a3b 100644 --- a/react-ui/src/features/workflow/edit/components/modals/GeneralSettingsDialog.js +++ b/react-ui/src/features/workflow/edit/components/modals/GeneralSettingsDialog.js @@ -12,6 +12,7 @@ const GeneralSettingsDialog = ({ open, onClose, onYes, workflowLens }) => { {t('General.Buttons.Save')} diff --git a/react-ui/src/features/workflow/edit/queries/WorkflowQuery.js b/react-ui/src/features/workflow/edit/queries/WorkflowQuery.js index ff99fcf..95f920a 100644 --- a/react-ui/src/features/workflow/edit/queries/WorkflowQuery.js +++ b/react-ui/src/features/workflow/edit/queries/WorkflowQuery.js @@ -5,6 +5,31 @@ export const WORKFLOW_QUERY = gql` query getWorkflow($name: String!, $version: Int!, $skip: Boolean!) { getWorkflow(name: $name, version: $version) @skip(if: $skip) { ...partialWorkflowDef + startHandlers { + name + active + event + condition + actions { + action + completeTask { + output + workflowId + taskRefName + } + failTask { + output + workflowId + taskRefName + } + startWorkflow { + name + version + input + } + expandInlineJSON + } + } tasks { ...workflowTask forkTasks {