From 7fdf733a64670fceefc3ded35cfa581e1c458179 Mon Sep 17 00:00:00 2001 From: Einav Weiss Keidar Date: Tue, 20 Mar 2018 14:45:40 +0200 Subject: Adding Prettier and fixing up eslint version Issue-ID: SDC-1094 Change-Id: Ie83ad95a03899345dd90235daf0323cbe3bc6afd Signed-off-by: Einav Weiss Keidar --- .../src/sdc-app/common/merge/MergeEditorView.jsx | 568 +++++++++++++-------- 1 file changed, 362 insertions(+), 206 deletions(-) (limited to 'openecomp-ui/src/sdc-app/common/merge/MergeEditorView.jsx') diff --git a/openecomp-ui/src/sdc-app/common/merge/MergeEditorView.jsx b/openecomp-ui/src/sdc-app/common/merge/MergeEditorView.jsx index 34d86419e7..a7e36a39fc 100644 --- a/openecomp-ui/src/sdc-app/common/merge/MergeEditorView.jsx +++ b/openecomp-ui/src/sdc-app/common/merge/MergeEditorView.jsx @@ -24,233 +24,389 @@ import GridItem from 'nfvo-components/grid/GridItem.jsx'; import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js'; import Radio from 'sdc-ui/lib/react/Radio.js'; import equal from 'deep-equal'; -import {ResolutionTypes} from './MergeEditorConstants.js'; +import { ResolutionTypes } from './MergeEditorConstants.js'; -class ConflictCategory extends React.Component { - state = { - resolution: ResolutionTypes.YOURS - }; +class ConflictCategory extends React.Component { + state = { + resolution: ResolutionTypes.YOURS + }; - getTitle(conflictType, conflictName) { - if (typeof conflictName === 'undefined' || conflictType === conflictName) { - return i18n(conflictType); - } else { - return `${i18n(conflictType)}: ${conflictName}`; - } - } + getTitle(conflictType, conflictName) { + if ( + typeof conflictName === 'undefined' || + conflictType === conflictName + ) { + return i18n(conflictType); + } else { + return `${i18n(conflictType)}: ${conflictName}`; + } + } - render() { - let {collapseExpand, conflict: {id: conflictId, type, name}, isCollapsed, item: {id: itemId, version}, onResolveConflict} = this.props; - let {resolution} = this.state; - const iconClass = isCollapsed ? 'merge-chevron' : 'merge-chevron right'; + render() { + let { + collapseExpand, + conflict: { id: conflictId, type, name }, + isCollapsed, + item: { id: itemId, version }, + onResolveConflict + } = this.props; + let { resolution } = this.state; + const iconClass = isCollapsed ? 'merge-chevron' : 'merge-chevron right'; - return ( -
- - -
- -
{this.getTitle(type, name)}
-
-
- - this.setState({resolution: ResolutionTypes.YOURS})} data-test-id={'radio_' + conflictId + '_yours'} /> - - - this.setState({resolution: ResolutionTypes.THEIRS})} data-test-id={'radio_' + conflictId + '_theirs'} /> - - - -
-
- {isCollapsed && this.props.children} -
-
- ); - } - -}; - -class TextCompare extends React.Component { - render() { - // let rand = Math.random() * (3000 - 1) + 1; - let {yours, theirs, field, type, isObjName, conflictsOnly} = this.props; - let typeYours = typeof yours; - let typeTheirs = typeof theirs; + return ( +
+ + +
+ +
+ {this.getTitle(type, name)} +
+
+
+ + + this.setState({ + resolution: ResolutionTypes.YOURS + }) + } + data-test-id={'radio_' + conflictId + '_yours'} + /> + + + + this.setState({ + resolution: ResolutionTypes.THEIRS + }) + } + data-test-id={'radio_' + conflictId + '_theirs'} + /> + + + + +
+
{isCollapsed && this.props.children}
+
+ ); + } +} - let parsedType = `${type}/${field}`.replace(/\/[0-9]+/g,'/index'); - let level = type.split('/').length; +class TextCompare extends React.Component { + render() { + // let rand = Math.random() * (3000 - 1) + 1; + let { + yours, + theirs, + field, + type, + isObjName, + conflictsOnly + } = this.props; + let typeYours = typeof yours; + let typeTheirs = typeof theirs; - if (typeYours === 'boolean' || typeTheirs === 'boolean') { - yours = yours ? i18n('Yes') : i18n('No'); - theirs = theirs ? i18n('Yes') : i18n('No'); - } + let parsedType = `${type}/${field}`.replace(/\/[0-9]+/g, '/index'); + let level = type.split('/').length; + if (typeYours === 'boolean' || typeTheirs === 'boolean') { + yours = yours ? i18n('Yes') : i18n('No'); + theirs = theirs ? i18n('Yes') : i18n('No'); + } - /*if ((typeYours !== 'string' && typeYours !== 'undefined') || (typeTheirs !== 'string' && typeTheirs !== 'undefined')) { + /*if ((typeYours !== 'string' && typeYours !== 'undefined') || (typeTheirs !== 'string' && typeTheirs !== 'undefined')) { return (
{field} cannot be parsed for display
); }*/ - let isDiff = yours !== theirs; - if (!isObjName && - ((!isDiff && conflictsOnly) || - (yours === '' && theirs === '') || - (typeYours === 'undefined' && typeTheirs === 'undefined') - ) - ) { - return null; - } + let isDiff = yours !== theirs; + if ( + !isObjName && + ((!isDiff && conflictsOnly) || + (yours === '' && theirs === '') || + (typeYours === 'undefined' && typeTheirs === 'undefined')) + ) { + return null; + } - return ( - - -
- {i18n(parsedType)} -
-
- -
{yours || (isObjName ? '' : '━━')}
-
- -
{theirs || (isObjName ? '' : '━━')}
-
- -
- ); - } -}; + return ( + + +
+ {i18n(parsedType)} +
+
+ +
+ {yours || (isObjName ? '' : '━━')} +
+
+ +
+ {theirs || (isObjName ? '' : '━━')} +
+
+ +
+ ); + } +} class MergeEditorView extends React.Component { - state = { - collapsingSections: {}, - conflictsOnly: false - }; + state = { + collapsingSections: {}, + conflictsOnly: false + }; - render() { - let {conflicts, item, conflictFiles, onResolveConflict, currentScreen, resolution} = this.props; + render() { + let { + conflicts, + item, + conflictFiles, + onResolveConflict, + currentScreen, + resolution + } = this.props; - return ( -
- {conflictFiles && this.renderConflictTableTitles()} -
- {conflictFiles && conflictFiles.sort((a, b) => a.type > b.type).map(file => ( - {this.updateCollapseState(file.id);}} - onResolveConflict={cDetails => onResolveConflict({...cDetails, currentScreen})}> - {(conflicts && conflicts[file.id]) && - this.getUnion(conflicts[file.id].yours, conflicts[file.id].theirs).map(field => { - return this.renderField(field, file, conflicts[file.id].yours[field], conflicts[file.id].theirs[field], resolution); - })} - ))} -
-
); - } + return ( +
+ {conflictFiles && this.renderConflictTableTitles()} +
+ {conflictFiles && + conflictFiles + .sort((a, b) => a.type > b.type) + .map(file => ( + { + this.updateCollapseState(file.id); + }} + onResolveConflict={cDetails => + onResolveConflict({ + ...cDetails, + currentScreen + }) + }> + {conflicts && + conflicts[file.id] && + this.getUnion( + conflicts[file.id].yours, + conflicts[file.id].theirs + ).map(field => { + return this.renderField( + field, + file, + conflicts[file.id].yours[field], + conflicts[file.id].theirs[ + field + ], + resolution + ); + })} + + ))} +
+
+ ); + } - renderConflictTableTitles() - { - return ( - - {i18n('Page')} - - - {i18n('Local (Me)')} - - - {i18n('Last Committed')} - - - this.setState({conflictsOnly: e}) } /> - - ); - } - // this.setState({conflictsOnly: checked})} /> + renderConflictTableTitles() { + return ( + + {i18n('Page')} + {i18n('Local (Me)')} + {i18n('Last Committed')} + + this.setState({ conflictsOnly: e })} + /> + + + ); + } + // this.setState({conflictsOnly: checked})} /> - renderObjects(yours, theirs, fileType, field, id, resolution) { - if (equal(yours, theirs)) { - return; - } - let {conflictsOnly} = this.state; - return ( -
- -
-
- {this.getUnion(yours, theirs).map(key => - this.renderField( - key, - {type: `${fileType}/${field}`, id}, - yours && yours[key], - theirs && theirs[key] - ) - )} -
-
-
- ); - } + renderObjects(yours, theirs, fileType, field, id, resolution) { + if (equal(yours, theirs)) { + return; + } + let { conflictsOnly } = this.state; + return ( +
+ +
+
+ {this.getUnion(yours, theirs).map(key => + this.renderField( + key, + { type: `${fileType}/${field}`, id }, + yours && yours[key], + theirs && theirs[key] + ) + )} +
+
+
+ ); + } - renderList(yours = [], theirs = [], type, field, id, resolution) { - let theirsList = theirs.join(', '); - let yoursList = yours.join(', '); - let {conflictsOnly} = this.state; - return (); - } + renderList(yours = [], theirs = [], type, field, id, resolution) { + let theirsList = theirs.join(', '); + let yoursList = yours.join(', '); + let { conflictsOnly } = this.state; + return ( + + ); + } - renderField(field, file, yours, theirs, resolution) { - if (yours) { - if (Array.isArray(yours)) { - return this.renderList(yours, theirs, file.type, field, file.id, resolution); - } - else if (typeof yours === 'object') { - return this.renderObjects(yours, theirs, file.type, field, file.id, resolution); - } - } else if (theirs) { - if (Array.isArray(theirs)) { - return this.renderList(yours, theirs, file.type, field, file.id, resolution); - } - else if (typeof theirs === 'object') { - return this.renderObjects(yours, theirs, file.type, field, file.id, resolution); - } - } - let {conflictsOnly} = this.state; - return (); - } + renderField(field, file, yours, theirs, resolution) { + if (yours) { + if (Array.isArray(yours)) { + return this.renderList( + yours, + theirs, + file.type, + field, + file.id, + resolution + ); + } else if (typeof yours === 'object') { + return this.renderObjects( + yours, + theirs, + file.type, + field, + file.id, + resolution + ); + } + } else if (theirs) { + if (Array.isArray(theirs)) { + return this.renderList( + yours, + theirs, + file.type, + field, + file.id, + resolution + ); + } else if (typeof theirs === 'object') { + return this.renderObjects( + yours, + theirs, + file.type, + field, + file.id, + resolution + ); + } + } + let { conflictsOnly } = this.state; + return ( + + ); + } - getUnion(yours = {},theirs = {}) { - let yoursKeys = Object.keys(yours); - let theirsKeys = Object.keys(theirs); - let myUn = union(yoursKeys, theirsKeys); - return myUn;//.sort((a, b) => a > b); - } + getUnion(yours = {}, theirs = {}) { + let yoursKeys = Object.keys(yours); + let theirsKeys = Object.keys(theirs); + let myUn = union(yoursKeys, theirsKeys); + return myUn; //.sort((a, b) => a > b); + } - updateCollapseState(conflictId) { - const {fetchConflict, item: {id: itemId, version}, /*conflicts*/} = this.props; - let isCollapsed = this.state.collapsingSections[conflictId]; - // if (!isCollapsed && !(conflicts && conflictId in conflicts)) { - if (!isCollapsed) { - fetchConflict({cid: conflictId, itemId, version}); - } - this.setState({ - collapsingSections: { - ...this.state.collapsingSections, - [conflictId]: !isCollapsed - } - }); - } + updateCollapseState(conflictId) { + const { + fetchConflict, + item: { id: itemId, version } /*conflicts*/ + } = this.props; + let isCollapsed = this.state.collapsingSections[conflictId]; + // if (!isCollapsed && !(conflicts && conflictId in conflicts)) { + if (!isCollapsed) { + fetchConflict({ cid: conflictId, itemId, version }); + } + this.setState({ + collapsingSections: { + ...this.state.collapsingSections, + [conflictId]: !isCollapsed + } + }); + } } export default MergeEditorView; -- cgit 1.2.3-korg