Skip to content

Commit

Permalink
fix: use latest versionNum when resolving with original
Browse files Browse the repository at this point in the history
  • Loading branch information
efloden committed Jul 2, 2018
1 parent d62c172 commit 3d2101f
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 62 deletions.
Expand Up @@ -129,12 +129,13 @@ public Response put(String localeId, TranslationData data) {
TranslationResult result = translationResults.get(0);
if (result.isVersionNumConflict()) {
HTextFlowTarget latest = result.getTranslatedTextFlowTarget();
requestData.setContents(latest.getContents());
// Include latest translator username, last changed date in response
String lastModifiedByUserName = latest.getLastModifiedBy()
!= null && latest.getLastModifiedBy().hasAccount()
? latest.getLastModifiedBy().getAccount().getUsername()
: "";
requestData.setContents(latest.getContents());
requestData.setRevision(latest.getVersionNum());
requestData.setLastModifiedBy(lastModifiedByUserName);
requestData.setLastModifiedDate(latest.getLastChanged());
return Response
Expand Down
Expand Up @@ -22,7 +22,8 @@ export const PENDING_SAVE_INITIATED = 'PENDING_SAVE_INITIATED'
export const SAVE_FINISHED = 'SAVE_FINISHED'
export const SAVE_FAILED = 'SAVE_FAILED'
export const SAVE_CONFLICT = 'SAVE_CONFLICT'
export const SAVE_CONFLICT_RESOLVED = 'SAVE_CONFLICT_RESOLVED'
export const SAVE_CONFLICT_RESOLVED_LATEST = 'SAVE_CONFLICT_RESOLVED_LATEST'
export const SAVE_CONFLICT_RESOLVED_ORIGINAL = 'SAVE_CONFLICT_RESOLVED_ORIGINAL'

export const TOGGLE_CONCURRENT_MODAL = 'TOGGLE_CONCURRENT_MODAL'

Expand Down
78 changes: 41 additions & 37 deletions server/zanata-frontend/src/app/editor/actions/phrases-actions.js
Expand Up @@ -17,7 +17,8 @@ import {
SAVE_FINISHED,
SAVE_FAILED,
SAVE_CONFLICT,
SAVE_CONFLICT_RESOLVED,
SAVE_CONFLICT_RESOLVED_LATEST,
SAVE_CONFLICT_RESOLVED_ORIGINAL,
TOGGLE_CONCURRENT_MODAL
} from './phrases-action-types'
import {
Expand Down Expand Up @@ -152,32 +153,31 @@ const saveConflict = createAction(SAVE_CONFLICT,
response
}))

const saveConflictResolved = createAction(SAVE_CONFLICT_RESOLVED,
(phraseId, saveInfo, response, resolution) => ({
const saveConflictResolvedLatest = createAction(SAVE_CONFLICT_RESOLVED_LATEST,
(phraseId, saveInfo, revision) => ({
phraseId,
saveInfo,
response,
resolution
revision
}))

const saveConflictResolvedOriginal =
createAction(SAVE_CONFLICT_RESOLVED_ORIGINAL,
(phraseId, saveInfo, revision) => ({
phraseId,
saveInfo,
revision
}))

export const toggleConcurrentModal = createAction(TOGGLE_CONCURRENT_MODAL)

export function saveResolveConflict (latest, original, resolution) {
export function saveResolveConflictLatest (latest, original) {
return (dispatch, getState) => {
const stateBefore = getState()
const latestData = {...latest, revision: (latest.revision + 1)}
const phrase = {
...latest,
...original,
translations: original.translations,
revision: (latest.revision + 1)
}
if (resolution === 'latest') {
dispatch(saveConflictResolved(
phrase.id, latestData, latest.revision, resolution)).then(
dispatch(saveConflictResolvedLatest(
original.id, latest, latest.revision)).then(
dispatch(fetchTransUnitHistory(
phrase.localeId,
phrase.id,
original.localeId,
original.id,
stateBefore.context.projectSlug,
stateBefore.context.versionSlug
)).then(
Expand All @@ -186,31 +186,35 @@ export function saveResolveConflict (latest, original, resolution) {
getState().context.lang)
)
)
} else if (resolution === 'original') {
savePhrase(latestData, phrase)
.then(response => {
if (isErrorResponse(response)) {
console.error('Failed to save phrase')
dispatch(saveFailed(phrase.id, phrase, response))
} else {
response.json().then(({ revision, status }) => {
dispatch(saveConflictResolved(
phrase.id, phrase, revision, resolution)).then(
dispatch(fetchTransUnitHistory(
phrase.localeId,
phrase.id,
stateBefore.context.projectSlug,
stateBefore.context.versionSlug
}
}

export function saveResolveConflictOriginal (latest, original) {
return (dispatch, getState) => {
const stateBefore = getState()
savePhrase(latest, original)
.then(response => {
if (isErrorResponse(response)) {
console.error('Failed to save phrase')
dispatch(saveFailed(latest.id, original, response))
} else {
response.json().then(({ revision, status }) => {
dispatch(saveConflictResolvedOriginal(
latest.id, original, revision)).then(
dispatch(fetchTransUnitHistory(
original.localeId,
latest.id,
stateBefore.context.projectSlug,
stateBefore.context.versionSlug
)).then(
fetchStatisticsInfo(dispatch, getState().context.projectSlug,
getState().context.versionSlug, getState().context.docId,
getState().context.lang)
)
)
})
}
})
}
})
}
})
}
}

Expand Down
Expand Up @@ -15,11 +15,6 @@ import 'antd/lib/modal/style/index.less'
import DateAndTimeDisplay from '../DateAndTimeDisplay'
import Textarea from 'react-textarea-autosize'

export enum resolution {
latest = 'latest',
original = 'original',
}

interface Latest {
content: string
id: number
Expand All @@ -42,7 +37,8 @@ interface Original {

interface ConcurrentModalProps {
closeConcurrentModal: () => void
saveResolveConflict: (latest: any, original: any, resolution: resolution) => void
saveResolveConflictLatest: (latest: any, original: any) => void
saveResolveConflictOriginal: (latest: any, original: any) => void
show: boolean
conflictData?: {
response: Latest,
Expand All @@ -53,13 +49,18 @@ interface ConcurrentModalProps {
class ConcurrentModal extends React.Component<ConcurrentModalProps, {}> {
public static propTypes = {
closeConcurrentModal: PropTypes.func,
saveResolveConflict: PropTypes.func.isRequired,
saveResolveConflictLatest: PropTypes.func.isRequired,
saveResolveConflictOriginal: PropTypes.func.isRequired,
conflictData: PropTypes.any,
show: PropTypes.bool.isRequired,
}
public render () {
const {
closeConcurrentModal, saveResolveConflict, show, conflictData
closeConcurrentModal,
saveResolveConflictLatest,
saveResolveConflictOriginal,
show,
conflictData
} = this.props
if (!conflictData) {
return null
Expand All @@ -71,10 +72,10 @@ class ConcurrentModal extends React.Component<ConcurrentModalProps, {}> {
const lastModifiedDate = new Date(latest.lastModifiedDate)
const onCancel = () => closeConcurrentModal()
const saveLatest = () => {
saveResolveConflict(latest, original, resolution.latest)
saveResolveConflictLatest(latest, original)
}
const saveOriginal = () => {
saveResolveConflict(latest, original, resolution.original)
saveResolveConflictOriginal(latest, original)
}
return (
/* eslint-disable max-len */
Expand Down
Expand Up @@ -46,7 +46,7 @@ class TransUnitTranslationHeader extends React.Component {
icon="rollback"
className={this.buttonClass}
onClick={this.props.undoEdit} />
</Tooltip>Tooltip>
</Tooltip>
</li>
)
}
Expand Down
16 changes: 11 additions & 5 deletions server/zanata-frontend/src/app/editor/containers/MainContent.js
Expand Up @@ -12,7 +12,9 @@ import {
fetchAllCriteria, toggleReviewModal
} from '../actions/review-trans-actions'
import {
toggleConcurrentModal, saveResolveConflict
toggleConcurrentModal,
saveResolveConflictLatest,
saveResolveConflictOriginal
} from '../actions/phrases-actions'
import { getCriteria } from '../reducers/review-trans-reducer'
import { MINOR, MAJOR, CRITICAL } from '../utils/reject-trans-util'
Expand All @@ -27,7 +29,8 @@ class MainContent extends React.Component {
static propTypes = {
activityVisible: PropTypes.bool.isRequired,
maximised: PropTypes.bool.isRequired,
saveResolveConflict: PropTypes.func.isRequired,
saveResolveConflictLatest: PropTypes.func.isRequired,
saveResolveConflictOriginal: PropTypes.func.isRequired,
showConflictModal: PropTypes.bool.isRequired,
showReviewModal: PropTypes.bool.isRequired,
phrases: PropTypes.arrayOf(PropTypes.object).isRequired,
Expand Down Expand Up @@ -108,7 +111,8 @@ class MainContent extends React.Component {
</div>
<ConcurrentModal
closeConcurrentModal={this.props.toggleConcurrentModal}
saveResolveConflict={this.props.saveResolveConflict}
saveResolveConflictLatest={this.props.saveResolveConflictLatest}
saveResolveConflictOriginal={this.props.saveResolveConflictOriginal}
conflictData={selectedPhrase.conflict}
show={this.props.showConflictModal}
/>
Expand Down Expand Up @@ -148,8 +152,10 @@ function mapStateToProps (state, _ownProps) {

function mapDispatchToProps (dispatch) {
return {
saveResolveConflict: (latest, original, resolution) => dispatch(
saveResolveConflict(latest, original, resolution)),
saveResolveConflictLatest: (latest, original) => dispatch(
saveResolveConflictLatest(latest, original)),
saveResolveConflictOriginal: (latest, original) => dispatch(
saveResolveConflictOriginal(latest, original)),
toggleConcurrentModal: () => dispatch(toggleConcurrentModal()),
toggleReviewModal: () => dispatch(toggleReviewModal()),
fetchAllCriteria: () => dispatch(fetchAllCriteria())
Expand Down
Expand Up @@ -27,7 +27,8 @@ import {
SAVE_FAILED,
SAVE_INITIATED,
SAVE_CONFLICT,
SAVE_CONFLICT_RESOLVED,
SAVE_CONFLICT_RESOLVED_LATEST,
SAVE_CONFLICT_RESOLVED_ORIGINAL,
SELECT_PHRASE,
SELECT_PHRASE_SPECIFIC_PLURAL,
TRANSLATION_TEXT_INPUT_CHANGED,
Expand Down Expand Up @@ -244,14 +245,14 @@ export const phraseReducer = handleActions({
}
}),

[SAVE_CONFLICT_RESOLVED]: (state, { getState, payload: {
phraseId, saveInfo, revision, resolution } }) =>
[SAVE_CONFLICT_RESOLVED_LATEST]: (state, { getState, payload: {
phraseId, saveInfo, revision } }) =>
update(state, {
notification: {
$set: {
severity: SEVERITY.INFO,
message: 'Concurrent edit successfully resolved',
description: `Using the ${resolution} edit`,
description: `Using the Latest edit`,
duration: 3.5
}
},
Expand All @@ -261,9 +262,33 @@ export const phraseReducer = handleActions({
conflict: { $set: undefined },
inProgressSave: { $set: undefined },
newTranslations: {
$set: resolution === 'original'
? state.detail[phraseId].newTranslations
: [saveInfo.content]
$set: [saveInfo.content]
},
translations: {
$set: [saveInfo.content]
}
}
}
}),

[SAVE_CONFLICT_RESOLVED_ORIGINAL]: (state, { getState, payload: {
phraseId, saveInfo, revision } }) =>
update(state, {
notification: {
$set: {
severity: SEVERITY.INFO,
message: 'Concurrent edit successfully resolved',
description: `Using the Original edit`,
duration: 3.5
}
},
detail: {
[phraseId]: {
revision: { $set: revision },
conflict: { $set: undefined },
inProgressSave: { $set: undefined },
translations: {
$set: state.detail[phraseId].newTranslations
}
}
}
Expand Down

0 comments on commit 3d2101f

Please sign in to comment.