Skip to content

Commit

Permalink
fix(conflict): no conflict dialogue in read only mode
Browse files Browse the repository at this point in the history
Signed-off-by: Max <max@nextcloud.com>
  • Loading branch information
max-nextcloud committed Jul 24, 2024
1 parent dbf1ff7 commit 3fd2093
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 12 deletions.
44 changes: 43 additions & 1 deletion cypress/e2e/conflict.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const variants = [
variants.forEach(function({ fixture, mime }) {
const fileName = fixture
describe(`${mime} (${fileName})`, function() {
const getWrapper = () => cy.get('.viewer__content .text-editor__wrapper.has-conflicts')
const getWrapper = () => cy.get('.text-editor__wrapper.has-conflicts')

before(() => {
initUserAndFiles(user, fileName)
Expand All @@ -25,6 +25,34 @@ variants.forEach(function({ fixture, mime }) {
cy.login(user)
})

it('no actual conflict - just reload', function() {
// start with different content
cy.uploadFile('frontmatter.md', mime, fileName)
// just a read only session opened
cy.shareFile(`/${fileName}`)
.then((token) => {
cy.visit(`/s/${token}`)
})
cy.get('.text-editor__main')
.should('contain', 'Heading')
cy.intercept({ method: 'POST', url: '**/session/*/push' })
.as('push')
cy.wait('@push')
cy.uploadFile(fileName, mime)
cy.get('#editor-container .document-status', { timeout: 30000 })
.should('contain', 'session has expired')
// Reload button works
cy.get('#editor-container .document-status a.button')
.contains('Reload')
.click()
getWrapper()
.should('not.exist')
cy.getContent()
.should('contain', 'Hello world')
cy.getContent()
.should('not.contain', 'Heading')
})

it('displays conflicts', function() {
createConflict(fileName, mime)

Expand Down Expand Up @@ -77,6 +105,20 @@ variants.forEach(function({ fixture, mime }) {
cy.get('.text-editor__main')
.should('not.contain', 'cruel conflicting')
})

it('hides conflict in read only session', function() {
createConflict(fileName, mime)
cy.shareFile(`/${fileName}`)
.then((token) => {
cy.logout()
cy.visit(`/s/${token}`)
})
cy.get('.text-editor__main')
.should('contain', 'cruel conflicting')
getWrapper()
.should('not.exist')
})

})
})

Expand Down
8 changes: 6 additions & 2 deletions src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<DocumentStatus v-if="displayedStatus"
:idle="idle"
:lock="lock"
:is-resolving-conflict="isResolvingConflict"
:sync-error="syncError"
:has-connection-issue="hasConnectionIssue"
@reconnect="reconnect" />

<SkeletonLoading v-if="showLoadingSkeleton" />
<Wrapper v-if="displayed"
:sync-error="syncError"
:is-resolving-conflict="isResolvingConflict"
:has-connection-issue="hasConnectionIssue"
:content-loaded="contentLoaded"
:show-outline-outside="showOutlineOutside"
Expand Down Expand Up @@ -55,7 +56,7 @@
<ContentContainer v-show="contentLoaded"
ref="contentWrapper" />
</MainContainer>
<Reader v-if="hasSyncCollission"
<Reader v-if="isResolvingConflict"
:content="syncError.data.outsideChange"
:is-rich-editor="isRichEditor" />
</Wrapper>
Expand Down Expand Up @@ -258,6 +259,9 @@ export default {
isRichWorkspace() {
return this.richWorkspace
},
isResolvingConflict() {
return this.hasSyncCollission && !this.readOnly
},
hasSyncCollission() {
return this.syncError && this.syncError.type === ERROR_TYPE.SAVE_COLLISSION
},
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editor/DocumentStatus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</p>
</NcNoteCard>

<CollisionResolveDialog v-if="hasSyncCollission" :sync-error="syncError" />
<CollisionResolveDialog v-if="isResolvingConflict" :sync-error="syncError" />
</div>
</template>

Expand Down Expand Up @@ -72,6 +72,10 @@ export default {
type: Boolean,
require: true,
},
isResolvingConflict: {
type: Boolean,
require: true,
},
},

data() {
Expand Down
12 changes: 4 additions & 8 deletions src/components/Editor/Wrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<template>
<div class="text-editor__wrapper"
:class="{
'has-conflicts': hasSyncCollission,
'has-conflicts': isResolvingConflict,
'is-rich-workspace': $isRichWorkspace,
'is-rich-editor': $isRichEditor,
}">
Expand Down Expand Up @@ -42,9 +42,9 @@ export default {
},

props: {
syncError: {
type: Object,
default: null,
isResolvingConflict: {
type: Boolean,
require: true,
},
hasConnectionIssue: {
type: Boolean,
Expand All @@ -71,10 +71,6 @@ export default {
...mapState({
viewWidth: (state) => state.text.viewWidth,
}),

hasSyncCollission() {
return this.syncError && this.syncError.type === ERROR_TYPE.SAVE_COLLISSION
},
showOutline() {
return this.isAbleToShowOutline
? this.outline.visible
Expand Down

0 comments on commit 3fd2093

Please sign in to comment.