diff options
Diffstat (limited to 'openecomp-ui/src/sdc-app/flows/SequenceDiagramModelHelper.js')
-rw-r--r-- | openecomp-ui/src/sdc-app/flows/SequenceDiagramModelHelper.js | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/openecomp-ui/src/sdc-app/flows/SequenceDiagramModelHelper.js b/openecomp-ui/src/sdc-app/flows/SequenceDiagramModelHelper.js index c83fdc91f0..23723dc91d 100644 --- a/openecomp-ui/src/sdc-app/flows/SequenceDiagramModelHelper.js +++ b/openecomp-ui/src/sdc-app/flows/SequenceDiagramModelHelper.js @@ -16,51 +16,54 @@ import emptyModel from './emptyModel.json'; function mergeLifelines(oldLifelines, newLifelines) { - let oldLifelinesMap = new Map(oldLifelines.map(lifeline => [lifeline.id, lifeline])); - let newLifelinesMap = new Map(newLifelines.map(lifeline => [lifeline.id, lifeline])); + let oldLifelinesMap = new Map( + oldLifelines.map(lifeline => [lifeline.id, lifeline]) + ); + let newLifelinesMap = new Map( + newLifelines.map(lifeline => [lifeline.id, lifeline]) + ); - let updatedLifelines = oldLifelines.map(lifeline => { - let newLifeline = newLifelinesMap.get(lifeline.id); - return { - ...lifeline, - name: newLifeline ? newLifeline.name : lifeline.name - }; - }); + let updatedLifelines = oldLifelines.map(lifeline => { + let newLifeline = newLifelinesMap.get(lifeline.id); + return { + ...lifeline, + name: newLifeline ? newLifeline.name : lifeline.name + }; + }); - let addedLifelines = newLifelines.filter(lifeline => !oldLifelinesMap.has(lifeline.id)); + let addedLifelines = newLifelines.filter( + lifeline => !oldLifelinesMap.has(lifeline.id) + ); - return [ - ...updatedLifelines, - ...addedLifelines - ]; + return [...updatedLifelines, ...addedLifelines]; } - const SequenceDiagramModelHelper = Object.freeze({ + createModel(options) { + return SequenceDiagramModelHelper.updateModel(emptyModel, options); + }, - createModel(options) { - return SequenceDiagramModelHelper.updateModel(emptyModel, options); - }, - - updateModel(model, options) { - const diagram = model.diagram; - const metadata = diagram.metadata || model.metadata; - const id = options.id || metadata.id; - const name = options.name || metadata.name; - const lifelines = options.lifelines ? mergeLifelines(diagram.lifelines, options.lifelines) : diagram.lifelines; + updateModel(model, options) { + const diagram = model.diagram; + const metadata = diagram.metadata || model.metadata; + const id = options.id || metadata.id; + const name = options.name || metadata.name; + const lifelines = options.lifelines + ? mergeLifelines(diagram.lifelines, options.lifelines) + : diagram.lifelines; - return { - diagram: { - ...diagram, - metadata: { - ...metadata, - id, - name - }, - lifelines - } - }; - } + return { + diagram: { + ...diagram, + metadata: { + ...metadata, + id, + name + }, + lifelines + } + }; + } }); export default SequenceDiagramModelHelper; |