From 1dc6361b5b1d10b30fdd6f93454e67861ed1db35 Mon Sep 17 00:00:00 2001 From: Ariel Kenan Date: Sun, 7 Apr 2019 12:16:37 +0300 Subject: [PATCH] fix artifact not updating with versioning Change-Id: Id343b73f600154eff7b52b643be3aeca3bdf23c9 Issue-ID: SDC-2223 Signed-off-by: Ariel Kenan --- .../version/composition/CompositionUpdate.js | 131 ++++++++++++++++++++ .../src/features/version/versionConstants.js | 10 ++ .../version/versionController/VersionController.js | 16 ++- .../versionController/VersionControllerView.jsx | 10 +- .../VersionControllerView_snapshot-test.js | 6 +- .../VersionControllerView_snapshot-test.js.snap | 134 ++++----------------- .../versionController/views/ActionButtons.js | 18 ++- .../src/features/version/versionReducer.js | 13 +- 8 files changed, 217 insertions(+), 121 deletions(-) create mode 100644 workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionUpdate.js diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionUpdate.js b/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionUpdate.js new file mode 100644 index 00000000..e5756eb5 --- /dev/null +++ b/workflow-designer-ui/src/main/frontend/src/features/version/composition/CompositionUpdate.js @@ -0,0 +1,131 @@ +/* +* Copyright © 2018 European Support Limited +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +*http://www.apache.org/licenses/LICENSE-2.0 +* + * Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { I18n } from 'react-redux-i18n'; + +import CustomModeler from 'features/version/composition/custom-modeler'; +import camundaModuleDescriptor from 'features/version/composition/custom-properties-provider/descriptors/camunda'; +import { setElementInputsOutputs } from 'features/version/composition/bpmnUtils.js'; + +import { connect } from 'react-redux'; +import { updateComposition } from 'features/version/composition/compositionActions'; +import { showErrorModalAction } from 'shared/modal/modalWrapperActions'; +import { getComposition } from 'features/version/composition/compositionSelectors'; +import { getWorkflowName } from 'features/workflow/workflowSelectors'; +import { activitiesSelector } from 'features/activities/activitiesSelectors'; +import { getInputOutputForComposition } from 'features/version/inputOutput/inputOutputSelectors'; + +class CompositionUpdate extends Component { + static propTypes = { + compositionUpdate: PropTypes.func, + showErrorModal: PropTypes.func, + composition: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]), + inputOutput: PropTypes.object, + activities: PropTypes.object, + certifyBack: PropTypes.func + }; + + constructor(props) { + super(props); + this.generatedId = 'bpmn-container' + Date.now(); + this.fileInput = React.createRef(); + this.bpmnContainer = React.createRef(); + } + + componentDidMount() { + const { composition, activities, inputOutput } = this.props; + + this.modeler = new CustomModeler({ + moddleExtensions: { + camunda: camundaModuleDescriptor + }, + workflow: { + activities: activities, + workflowInputOutput: inputOutput + } + }); + + this.setDiagramToBPMN(composition); + } + + setDiagramToBPMN = diagram => { + let modeler = this.modeler; + this.modeler.importXML(diagram, err => { + if (err) { + return this.props.showErrorModal( + I18n.t('workflow.composition.importErrorMsg') + ); + } + const canvas = modeler.get('canvas'); + const { businessObject } = canvas._rootElement; + + setElementInputsOutputs( + businessObject, + this.props.inputOutput, + this.modeler.get('moddle') + ); + + this.exportDiagramToStore(); + }); + }; + + exportDiagramToStore = () => { + this.modeler.saveXML({ format: true }, (err, xml) => { + if (err) { + return this.props.showErrorModal( + I18n.t('workflow.composition.saveErrorMsg') + ); + } + this.props.compositionUpdate(xml); + this.props.certifyBack(); + }); + }; + + render() { + return
; + } +} + +function mapStateToProps(state) { + return { + composition: getComposition(state), + name: getWorkflowName(state), + activities: activitiesSelector(state), + inputOutput: getInputOutputForComposition(state) + }; +} + +function mapDispatchToProps(dispatch) { + return { + compositionUpdate: composition => + dispatch(updateComposition(composition)), + showErrorModal: msg => + dispatch( + showErrorModalAction({ + title: I18n.t('workflow.composition.bpmnError'), + body: msg, + withButtons: true, + closeButtonText: I18n.t('buttons.okBtn') + }) + ) + }; +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(CompositionUpdate); diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionConstants.js b/workflow-designer-ui/src/main/frontend/src/features/version/versionConstants.js index 8c2b4225..5b945a02 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/version/versionConstants.js +++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionConstants.js @@ -20,6 +20,8 @@ export const FETCH_REQUESTED = 'workflow/version/FETCH_REQUESTED'; export const DETAILS_CHANGED = 'workflow/version/DETAILS_CHANGED'; export const FETCH_REQUESTED_FAILED = 'workflow/version/FETCH_REQUESTED_FAILED'; export const VERSION_STATE_CHANGED = 'workflow/version/VERSION_STATE_CHANGED'; +export const TOGGLE_COMPOSITION_UPDATE = + 'workflow/version/TOGGLE_COMPOSITION_UPDATE'; export const SET_OPERRATION_MODE = 'workflow/version/SET_OPERRATION_MODE'; export const workflowVersionFetchRequestedAction = createAction( @@ -41,8 +43,16 @@ export const versionStateChangedAction = createAction( payload => payload ); +export const toggleCompositionUpdate = createAction( + TOGGLE_COMPOSITION_UPDATE, + payload => ({ isCompositionUpdating: payload }) +); + export const setOperationModeAction = createAction(SET_OPERRATION_MODE); +export const getIsCompositionUpdating = state => + state.currentVersion.general.isCompositionUpdating; + export const versionState = { DRAFT: 'draft', CERTIFIED: 'certified' diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionController.js b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionController.js index 7f8769cc..8c37a0e3 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionController.js +++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionController.js @@ -21,8 +21,8 @@ import { getVersions, getSortedVersions } from 'features/workflow/overview/overviewSelectors'; -import { isWorkflowArchive } from 'features/workflow/workflowSelectors'; import { + isWorkflowArchive, getWorkflowId, getWorkflowName } from 'features/workflow/workflowSelectors'; @@ -30,11 +30,16 @@ import { saveParamsAction, certifyVersionAction } from 'features/version/versionController/versionControllerConstants'; -import { workflowVersionFetchRequestedAction } from '../versionConstants'; +import { + workflowVersionFetchRequestedAction, + toggleCompositionUpdate, + getIsCompositionUpdating +} from 'features/version/versionConstants'; import { getIsCertified } from 'features/version/general/generalSelectors'; import { getIOErrors } from 'features/version/inputOutput/inputOutputSelectors'; import { getCompositionHasErrors } from 'features/version/composition/compositionSelectors'; import { pluginContextSelector } from 'wfapp/pluginContext/pluginContextSelector'; + function mapStateToProps(state) { return { workflowName: getWorkflowName(state), @@ -45,7 +50,8 @@ function mapStateToProps(state) { isCertifyDisable: getIsCertified(state), isArchive: isWorkflowArchive(state), currentWorkflowVersion: state.currentVersion.general, - pluginContext: pluginContextSelector(state) + pluginContext: pluginContextSelector(state), + isCompositionUpdating: getIsCompositionUpdating(state) }; } @@ -55,7 +61,9 @@ function mapDispatchToProps(dispatch) { saveParamsToServer: params => dispatch(saveParamsAction(params)), certifyVersion: payload => dispatch(certifyVersionAction(payload)), changeVersion: payload => - dispatch(workflowVersionFetchRequestedAction(payload)) + dispatch(workflowVersionFetchRequestedAction(payload)), + toggleCompositionUpdate: payload => + dispatch(toggleCompositionUpdate(payload)) }; } diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx index ef5e1168..730d92fb 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx +++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/VersionControllerView.jsx @@ -45,7 +45,9 @@ export default class VersionControllerView extends Component { hasErrors: PropTypes.bool, isArchive: PropTypes.bool, operationMode: PropTypes.bool, - pluginContext: PropTypes.object + pluginContext: PropTypes.object, + isCompositionUpdating: PropTypes.bool, + toggleCompositionUpdate: PropTypes.func }; constructor(props) { @@ -118,7 +120,9 @@ export default class VersionControllerView extends Component { hasErrors, isCertifyDisable, isArchive, - operationMode + operationMode, + isCompositionUpdating, + toggleCompositionUpdate } = this.props; const isReadonly = isCertifyDisable || hasErrors || isArchive; return ( @@ -147,11 +151,13 @@ export default class VersionControllerView extends Component { )} {!operationMode && ( )}
diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/VersionControllerView_snapshot-test.js b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/VersionControllerView_snapshot-test.js index 5dfb5737..2bcfa300 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/VersionControllerView_snapshot-test.js +++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/VersionControllerView_snapshot-test.js @@ -16,7 +16,7 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import VersionControllerView from 'features/version/versionController/VersionControllerView'; +import VersionsContainer from 'features/version/versionController/views/VersionsContainer'; describe('Version Controller View Snapshot', () => { it('renders correctly', () => { @@ -27,6 +27,7 @@ describe('Version Controller View Snapshot', () => { description: 'Initial version, bug fix for previous version that fixed an exception when the port was occupied', status: 'Draft', + state: 'Draft', creationTime: 1530687330460, modificationTime: 1530687330575, archivedStatus: 'ACTIVE' @@ -37,6 +38,7 @@ describe('Version Controller View Snapshot', () => { description: 'Test version, bug fix for previous version that fixed an exception when the port was occupied', status: 'Draft', + state: 'Draft', creationTime: 1530687330461, modificationTime: 1530687330576, archivedStatus: 'ACTIVE', @@ -45,7 +47,7 @@ describe('Version Controller View Snapshot', () => { ]; const tree = renderer .create( - diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/__snapshots__/VersionControllerView_snapshot-test.js.snap b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/__snapshots__/VersionControllerView_snapshot-test.js.snap index 1c8ffba3..ea135fce 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/__snapshots__/VersionControllerView_snapshot-test.js.snap +++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionController/__tests__/__snapshots__/VersionControllerView_snapshot-test.js.snap @@ -2,122 +2,38 @@ exports[`Version Controller View Snapshot renders correctly 1`] = `
-
-
- -
-
-
-
-
-
+
@@ -72,7 +84,9 @@ ActionButtons.propTypes = { certifyDisabled: PropTypes.bool, onCertifyClick: PropTypes.func, onUndoClick: PropTypes.func, - saveDisabled: PropTypes.bool + saveDisabled: PropTypes.bool, + isCompositionUpdating: PropTypes.bool, + toggleCompositionUpdate: PropTypes.func }; export default ActionButtons; diff --git a/workflow-designer-ui/src/main/frontend/src/features/version/versionReducer.js b/workflow-designer-ui/src/main/frontend/src/features/version/versionReducer.js index c7fccd22..d05af2d7 100644 --- a/workflow-designer-ui/src/main/frontend/src/features/version/versionReducer.js +++ b/workflow-designer-ui/src/main/frontend/src/features/version/versionReducer.js @@ -16,9 +16,13 @@ import { SET_CURRENT_VERSION, DETAILS_CHANGED, - VERSION_STATE_CHANGED + VERSION_STATE_CHANGED, + TOGGLE_COMPOSITION_UPDATE } from 'features/version/versionConstants'; -const initialState = {}; + +const initialState = { + isCompositionUpdating: false +}; function versionReducer(state = initialState, action) { switch (action.type) { @@ -34,6 +38,11 @@ function versionReducer(state = initialState, action) { ...state, ...action.payload }; + case TOGGLE_COMPOSITION_UPDATE: + return { + ...state, + isCompositionUpdating: action.payload.isCompositionUpdating + }; default: return state; } -- 2.16.6