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.
16 import React from 'react';
17 import i18n from 'nfvo-utils/i18n/i18n.js';
18 import union from 'lodash/union.js';
19 import Button from 'sdc-ui/lib/react/Button.js';
20 // import Checkbox from 'sdc-ui/lib/react/Checkbox.js';
21 import Input from 'nfvo-components/input/validation/Input.jsx';
22 import GridSection from 'nfvo-components/grid/GridSection.jsx';
23 import GridItem from 'nfvo-components/grid/GridItem.jsx';
24 import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
25 import Radio from 'sdc-ui/lib/react/Radio.js';
26 import equal from 'deep-equal';
27 import { ResolutionTypes } from './MergeEditorConstants.js';
29 class ConflictCategory extends React.Component {
31 resolution: ResolutionTypes.YOURS
34 getTitle(conflictType, conflictName) {
36 typeof conflictName === 'undefined' ||
37 conflictType === conflictName
39 return i18n(conflictType);
41 return `${i18n(conflictType)}: ${conflictName}`;
48 conflict: { id: conflictId, type, name },
50 item: { id: itemId, version },
53 let { resolution } = this.state;
54 const iconClass = isCollapsed ? 'merge-chevron' : 'merge-chevron right';
57 <div key={'conflictCategory_' + conflictId}>
58 <GridSection className="conflict-section">
61 className="collapsible-section"
62 onClick={collapseExpand}>
64 name={isCollapsed ? 'chevronDown' : 'chevronUp'}
65 iconClassName={iconClass}
67 <div className="conflict-title">
68 {this.getTitle(type, name)}
72 <GridItem className="yours">
74 name={'radio_' + conflictId}
75 checked={resolution === ResolutionTypes.YOURS}
79 resolution: ResolutionTypes.YOURS
82 data-test-id={'radio_' + conflictId + '_yours'}
85 <GridItem className="theirs">
87 name={'radio_' + conflictId}
88 checked={resolution === ResolutionTypes.THEIRS}
92 resolution: ResolutionTypes.THEIRS
95 data-test-id={'radio_' + conflictId + '_theirs'}
98 <GridItem className="resolve">
100 className="conflict-resolve-btn"
115 <div>{isCollapsed && this.props.children}</div>
121 class TextCompare extends React.Component {
123 // let rand = Math.random() * (3000 - 1) + 1;
132 let typeYours = typeof yours;
133 let typeTheirs = typeof theirs;
135 let parsedType = `${type}/${field}`.replace(/\/[0-9]+/g, '/index');
136 let level = type.split('/').length;
138 if (typeYours === 'boolean' || typeTheirs === 'boolean') {
139 yours = yours ? i18n('Yes') : i18n('No');
140 theirs = theirs ? i18n('Yes') : i18n('No');
143 /*if ((typeYours !== 'string' && typeYours !== 'undefined') || (typeTheirs !== 'string' && typeTheirs !== 'undefined')) {
144 return (<div className='merge-editor-text-field field-error'>{field} cannot be parsed for display</div>);
146 let isDiff = yours !== theirs;
149 ((!isDiff && conflictsOnly) ||
150 (yours === '' && theirs === '') ||
151 (typeYours === 'undefined' && typeTheirs === 'undefined'))
160 ? 'merge-editor-text-field diff'
161 : 'merge-editor-text-field'
163 <GridItem className="field-col grid-col-title" stretch>
167 } field-name level-${level} ${
168 isObjName ? 'field-object-name' : ''
173 <GridItem className="field-col grid-col-yours" stretch>
175 className={`field field-yours ${
176 !yours ? 'empty-field' : ''
178 {yours || (isObjName ? '' : '━━')}
181 <GridItem className="field-col grid-col-theirs" stretch>
183 className={`field field-theirs ${
184 !theirs ? 'empty-field' : ''
186 {theirs || (isObjName ? '' : '━━')}
195 class MergeEditorView extends React.Component {
197 collapsingSections: {},
212 <div className="merge-editor">
213 {conflictFiles && this.renderConflictTableTitles()}
214 <div className="merge-editor-body">
217 .sort((a, b) => a.type > b.type)
220 key={'conflict_' + file.id}
224 this.state.collapsingSections[file.id]
226 collapseExpand={() => {
227 this.updateCollapseState(file.id);
229 onResolveConflict={cDetails =>
236 conflicts[file.id] &&
238 conflicts[file.id].yours,
239 conflicts[file.id].theirs
241 return this.renderField(
244 conflicts[file.id].yours[field],
245 conflicts[file.id].theirs[
258 renderConflictTableTitles() {
260 <GridSection className="conflict-titles-section">
261 <GridItem>{i18n('Page')}</GridItem>
262 <GridItem className="yours">{i18n('Local (Me)')}</GridItem>
263 <GridItem className="theirs">{i18n('Last Committed')}</GridItem>
264 <GridItem className="resolve">
266 label={i18n('Show Conflicts Only')}
268 value={this.state.conflictsOnly}
269 onChange={e => this.setState({ conflictsOnly: e })}
276 // label={i18n('Show Conflicts Only')}
277 // value={this.state.conflictsOnly}
278 // checked={this.state.conflictsOnly}
279 // onChange={checked => this.setState({conflictsOnly: checked})} />
281 renderObjects(yours, theirs, fileType, field, id, resolution) {
282 if (equal(yours, theirs)) {
285 let { conflictsOnly } = this.state;
287 <div key={`obj_${fileType}/${field}_${id}`}>
291 conflictsOnly={conflictsOnly}
295 resolution={resolution}
297 <div className="field-objects">
299 {this.getUnion(yours, theirs).map(key =>
302 { type: `${fileType}/${field}`, id },
304 theirs && theirs[key]
313 renderList(yours = [], theirs = [], type, field, id, resolution) {
314 let theirsList = theirs.join(', ');
315 let yoursList = yours.join(', ');
316 let { conflictsOnly } = this.state;
319 key={'text_' + id + '_' + field}
324 conflictsOnly={conflictsOnly}
325 resolution={resolution}
330 renderField(field, file, yours, theirs, resolution) {
332 if (Array.isArray(yours)) {
333 return this.renderList(
341 } else if (typeof yours === 'object') {
342 return this.renderObjects(
352 if (Array.isArray(theirs)) {
353 return this.renderList(
361 } else if (typeof theirs === 'object') {
362 return this.renderObjects(
372 let { conflictsOnly } = this.state;
375 key={'text_' + file.id + '_' + field}
376 resolution={resolution}
381 conflictsOnly={conflictsOnly}
386 getUnion(yours = {}, theirs = {}) {
387 let yoursKeys = Object.keys(yours);
388 let theirsKeys = Object.keys(theirs);
389 let myUn = union(yoursKeys, theirsKeys);
390 return myUn; //.sort((a, b) => a > b);
393 updateCollapseState(conflictId) {
396 item: { id: itemId, version } /*conflicts*/
398 let isCollapsed = this.state.collapsingSections[conflictId];
399 // if (!isCollapsed && !(conflicts && conflictId in conflicts)) {
401 fetchConflict({ cid: conflictId, itemId, version });
404 collapsingSections: {
405 ...this.state.collapsingSections,
406 [conflictId]: !isCollapsed
412 export default MergeEditorView;