Skip to content

Commit

Permalink
Merge pull request #3988 from nextcloud/backport/3972/stable26
Browse files Browse the repository at this point in the history
[stable26] Conflict fixes
  • Loading branch information
mejo- authored Mar 29, 2023
2 parents e6efe28 + 351cee2 commit 99f7e6a
Show file tree
Hide file tree
Showing 20 changed files with 157 additions and 64 deletions.
77 changes: 77 additions & 0 deletions cypress/e2e/conflict.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,81 @@ describe('Open test.md in viewer', function() {
.should('contain', 'cruel conflicting')
cy.screenshot()
})

it('resolves conflict using current editing session', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile('test.md', 'text/markdown')

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile('test.md')
cy.get('.text-editor .document-status .icon-error')
getWrapper()
.get('#read-only-editor h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'cruel conflicting')

cy.get('[data-cy="resolveThisVersion"]').click()

getWrapper()
.get('#read-only-editor')
.should('not.exist')

cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')

cy.get('.text-editor__main h2')
.should('contain', 'Hello world')
cy.get('.text-editor__main')
.should('contain', 'cruel conflicting')
})

it('resolves conflict using server version', function() {
cy.openFile(fileName)

cy.log('Inspect editor')
cy.getContent()
.type('Hello you cruel conflicting world')
cy.uploadFile('test.md', 'text/markdown')

cy.get('#viewer .modal-header button.header-close').click()
cy.get('#viewer').should('not.exist')
cy.openFile('test.md')
cy.get('.text-editor .document-status .icon-error')
getWrapper()
.get('#read-only-editor h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main h2')
.should('contain', 'Hello world')
getWrapper()
.get('.text-editor__main')
.should('contain', 'cruel conflicting')

getWrapper()
.get('[data-cy="resolveServerVersion"]')
.click()

getWrapper()
.get('#read-only-editor')
.should('not.exist')
cy.get('[data-cy="resolveThisVersion"]')
.should('not.exist')
cy.get('[data-cy="resolveServerVersion"]')
.should('not.exist')

cy.get('.text-editor__main h2')
.should('contain', 'Hello world')
cy.get('.text-editor__main')
.should('not.contain', 'cruel conflicting')
})
})
4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/text-editors.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-editors.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

26 changes: 19 additions & 7 deletions lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public function getSteps($documentId, $lastVersion): array {
* @throws NotPermittedException
* @throws Exception
*/
public function autosave(?File $file, int $documentId, int $version, ?string $autoaveDocument, ?string $documentState, bool $force = false, bool $manualSave = false, ?string $shareToken = null, ?string $filePath = null): Document {
public function autosave(?File $file, int $documentId, int $version, ?string $autoSaveDocument, ?string $documentState, bool $force = false, bool $manualSave = false, ?string $shareToken = null, ?string $filePath = null): Document {
/** @var Document $document */
$document = $this->documentMapper->find($documentId);

Expand All @@ -327,7 +327,7 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
}
}

if ($autoaveDocument === null) {
if ($autoSaveDocument === null) {
return $document;
}
// Do not save if version already saved
Expand All @@ -341,10 +341,10 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
return $document;
}

if (empty($autoaveDocument)) {
if (empty($autoSaveDocument)) {
$this->logger->debug('Saving empty document', [
'requestVersion' => $version,
'requestAutosaveDocument' => $autoaveDocument,
'requestAutosaveDocument' => $autoSaveDocument,
'requestDocumentState' => $documentState,
'document' => $document->jsonSerialize(),
'fileSizeBeforeSave' => $file->getSize(),
Expand All @@ -357,20 +357,32 @@ public function autosave(?File $file, int $documentId, int $version, ?string $au
]);
}

// Version changed but the content remains the same
if ($autoSaveDocument === $file->getContent()) {
if ($documentState) {
$this->writeDocumentState($file->getId(), $documentState);
}
$document->setLastSavedVersion($stepsVersion);
$document->setLastSavedVersionTime($file->getMTime());
$document->setLastSavedVersionEtag($file->getEtag());
$this->documentMapper->update($document);
return $document;
}

$this->cache->set('document-save-lock-' . $documentId, true, 10);
try {
$this->lockManager->runInScope(new LockContext(
$file,
ILock::TYPE_APP,
Application::APP_NAME
), function () use ($file, $autoaveDocument, $documentState) {
$file->putContent($autoaveDocument);
), function () use ($file, $autoSaveDocument, $documentState) {
$file->putContent($autoSaveDocument);
if ($documentState) {
$this->writeDocumentState($file->getId(), $documentState);
}
});
$document->setLastSavedVersion($stepsVersion);
$document->setLastSavedVersionTime(time());
$document->setLastSavedVersionTime($file->getMTime());
$document->setLastSavedVersionEtag($file->getEtag());
$this->documentMapper->update($document);
} catch (LockedException $e) {
Expand Down
41 changes: 29 additions & 12 deletions src/components/CollisionResolveDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,34 @@

<template>
<div id="resolve-conflicts" class="collision-resolve-dialog" :class="{'icon-loading': clicked }">
<button :disabled="clicked" @click="resolveThisVersion">
<NcButton :disabled="clicked" data-cy="resolveThisVersion" @click="resolveThisVersion">
{{ t('text', 'Use current version') }}
</button>
<button :disabled="clicked" @click="resolveServerVersion">
</NcButton>
<NcButton :disabled="clicked" data-cy="resolveServerVersion" @click="resolveServerVersion">
{{ t('text', 'Use the saved version') }}
</button>
</NcButton>
</div>
</template>

<script>
import { useEditorMixin, useSyncServiceMixin } from './Editor.provider.js'
import { NcButton } from '@nextcloud/vue'
import markdownit from './../markdownit/index.js'
export default {
name: 'CollisionResolveDialog',
components: {
NcButton,
},
mixins: [
useEditorMixin,
useSyncServiceMixin,
],
props: {
syncError: {
type: Object,
default: null,
}
},
data() {
return {
clicked: false,
Expand All @@ -42,11 +58,17 @@ export default {
methods: {
resolveThisVersion() {
this.clicked = true
this.$emit('resolve-use-this-version')
this.$syncService.forceSave()
this.$editor.setOptions({ editable: !this.readOnly })
this.$syncService.startSync()
},
resolveServerVersion() {
this.clicked = true
this.$emit('resolve-use-server-version')
const markdownItHtml = markdownit.render(this.syncError.data.outsideChange)
this.$editor.setOptions({ editable: !this.readOnly })
this.$editor.commands.setContent(markdownItHtml)
this.$syncService.forceSave()
this.$syncService.startSync()
},
},
}
Expand All @@ -55,17 +77,12 @@ export default {
<style scoped lang="scss">
#resolve-conflicts {
display: flex;
position: fixed;
z-index: 10000;
bottom: 0;
max-width: 900px;
width: 100vw;
width: 100%;
margin: auto;
padding: 20px 0;

button {
margin: auto;
box-shadow: 0 0 10px var(--color-box-shadow);
}
}
</style>
25 changes: 3 additions & 22 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
:sync-error="syncError"
:has-connection-issue="hasConnectionIssue"
@reconnect="reconnect" />

<Wrapper v-if="displayed"
:sync-error="syncError"
:has-connection-issue="hasConnectionIssue"
Expand Down Expand Up @@ -71,10 +72,6 @@
:content="syncError.data.outsideChange"
:is-rich-editor="isRichEditor" />
</Wrapper>

<CollisionResolveDialog v-if="hasSyncCollission && !readOnly"
@resolve-use-this-version="resolveUseThisVersion"
@resolve-use-server-version="resolveUseServerVersion" />
</div>
</template>

Expand Down Expand Up @@ -132,7 +129,6 @@ export default {
MenuBar,
Reader: () => import(/* webpackChunkName: "editor" */'./Reader.vue'),
Status,
CollisionResolveDialog: () => import(/* webpackChunkName: "editor" */'./CollisionResolveDialog.vue'),
},
mixins: [
isMobile,
Expand Down Expand Up @@ -423,18 +419,6 @@ export default {
.off('save', this.onSave)
},

resolveUseThisVersion() {
this.$syncService.forceSave()
this.$editor.setOptions({ editable: !this.readOnly })
},

resolveUseServerVersion() {
const markdownItHtml = markdownit.render(this.syncError.data.outsideChange)
this.$editor.setOptions({ editable: !this.readOnly })
this.$editor.commands.setContent(markdownItHtml)
this.$syncService.forceSave()
},

reconnect() {
this.contentLoaded = false
this.hasConnectionIssue = false
Expand Down Expand Up @@ -565,10 +549,6 @@ export default {
},

onChange({ document, sessions }) {
if (this.document.baseVersionEtag !== '' && document.baseVersionEtag !== this.document.baseVersionEtag) {
this.resolveUseServerVersion()
return
}
this.updateSessions.bind(this)(sessions)
this.document = document

Expand Down Expand Up @@ -893,8 +873,9 @@ export default {
.text-editor__wrapper.has-conflicts > .content-wrapper {
width: 50%;
#read-only-editor {
margin: 0px;
margin: 0px auto;
padding-top: 50px;
overflow: initial;
}
}

Expand Down
Loading

0 comments on commit 99f7e6a

Please sign in to comment.