2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import React from 'react';
19 import Common from '../../../../../../common/Common';
21 import Message from './Message';
22 import MessageNew from './MessageNew';
25 * Messages container, facilitating DND.
26 * @param props lifeline element properties.
30 export default class Messages extends React.Component {
32 // ///////////////////////////////////////////////////////////////////////////////////////////////
36 * @param props element properties.
37 * @param context react context.
39 constructor(props, context) {
40 super(props, context);
43 this.setHoverIndex = this.setHoverIndex.bind(this);
44 this.getHoverIndex = this.getHoverIndex.bind(this);
47 // ///////////////////////////////////////////////////////////////////////////////////////////////
50 * Record last hover index as non-state.
53 setHoverIndex(index) {
54 this.hoverIndex = index;
57 // ///////////////////////////////////////////////////////////////////////////////////////////////
60 * Get last recorded hover index.
64 return this.hoverIndex;
67 // ///////////////////////////////////////////////////////////////////////////////////////////////
71 * @param dragIndex dragged item index; undefined if new.
72 * @param hoverIndex drop index.
74 onDrop(dragIndex, hoverIndex) {
75 if (hoverIndex >= 0) {
76 const application = this.props.application;
77 const model = application.getModel();
78 if (Common.isNumber(dragIndex)) {
79 if (dragIndex !== hoverIndex) {
80 model.reorderMessages(dragIndex, hoverIndex);
83 model.addMessage(hoverIndex);
86 application.renderDiagram();
90 // ///////////////////////////////////////////////////////////////////////////////////////////////
98 const model = this.props.application.getModel();
99 const diagram = model.unwrap().diagram;
101 // Render existing messages.
104 for (const step of diagram.steps) {
105 const message = step.message;
106 const from = model.getLifelineById(message.from);
107 const to = model.getLifelineById(message.to);
108 messages.push(<Message
109 key={`m${message.id}`}
110 application={this.props.application}
111 designer={this.props.designer}
113 active={this.props.activeMessageId === message.id}
117 index={messages.length}
124 messages.push(<MessageNew
126 designer={this.props.designer}
131 <div className="asdcs-designer-steps">
138 /** Element properties. */
139 Messages.propTypes = {
140 application: React.PropTypes.object.isRequired,
141 designer: React.PropTypes.object.isRequired,
142 activeMessageId: React.PropTypes.string,