Skip to content

Commit f3439d7

Browse files
committed
fix(DocumentStatus): Refactor and migrate to NcNoteCard
Fixes: #4905 Signed-off-by: Jonas <jonas@freesources.org>
1 parent f61fb6f commit f3439d7

4 files changed

Lines changed: 47 additions & 51 deletions

File tree

cypress/e2e/conflict.spec.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ variants.forEach(function({ fixture, mime }) {
5454
cy.get('#viewer .modal-header button.header-close').click()
5555
cy.get('#viewer').should('not.exist')
5656
cy.openFile(fileName)
57-
cy.get('.text-editor .document-status .icon-error')
57+
cy.get('.text-editor .document-status')
58+
.should('contain', 'Document has been changed outside of the editor.')
5859
getWrapper()
5960
.find('#read-only-editor')
6061
.should('contain', 'Hello world')

cypress/e2e/share.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ describe('Open test.md in viewer', function() {
151151
cy.login(recipient)
152152
cy.visit('/apps/files')
153153
cy.openFile('test.md')
154-
cy.getModal().find('.empty-content__name').should('contain', 'Failed to load file')
154+
cy.getModal().find('.document-status').should('contain', 'This file cannot be displayed as download is disabled by the share')
155155
cy.getModal().getContent().should('not.exist')
156156
})
157157
})

cypress/e2e/sync.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ describe('Sync', () => {
7474
}).as('sessionRequests')
7575
cy.wait('@dead', { timeout: 30000 })
7676
cy.get('#editor-container .document-status', { timeout: 30000 })
77-
.should('contain', 'File could not be loaded')
77+
.should('contain', 'Document could not be loaded.')
7878
.then(() => {
7979
reconnect = true
8080
})
@@ -83,7 +83,7 @@ describe('Sync', () => {
8383
.as('syncAfterRecovery')
8484
cy.wait('@syncAfterRecovery', { timeout: 30000 })
8585
cy.get('#editor-container .document-status', { timeout: 30000 })
86-
.should('not.contain', 'File could not be loaded')
86+
.should('not.contain', 'Document could not be loaded.')
8787
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
8888
cy.wait('@syncAfterRecovery', { timeout: 10000 })
8989
cy.getContent().type('* more content added after the lost connection{enter}')
@@ -109,12 +109,12 @@ describe('Sync', () => {
109109

110110
cy.wait('@sessionRequests', { timeout: 30000 })
111111
cy.get('#editor-container .document-status', { timeout: 30000 })
112-
.should('contain', 'File could not be loaded')
112+
.should('contain', 'Document could not be loaded.')
113113

114114
cy.wait('@syncAfterRecovery', { timeout: 60000 })
115115

116116
cy.get('#editor-container .document-status', { timeout: 30000 })
117-
.should('not.contain', 'File could not be loaded')
117+
.should('not.contain', 'Document could not be loaded.')
118118
// FIXME: There seems to be a bug where typed words maybe lost if not waiting for the new session
119119
cy.wait('@syncAfterRecovery', { timeout: 10000 })
120120
cy.getContent().type('* more content added after the lost connection{enter}')

src/components/Editor/DocumentStatus.vue

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,34 @@
2222

2323
<template>
2424
<div class="document-status">
25-
<NcEmptyContent v-if="isLoadingError" :name="t('text', 'Failed to load file')" :description="syncError.data.data">
25+
<NcNoteCard v-if="hasWarning" type="warning">
26+
<p v-if="isLoadingError">
27+
{{ syncError.data.data }}
28+
<!-- Display reload button on PRECONDITION_FAILED response type -->
29+
<a v-if="syncError.data.status === 412" class="button primary" @click="reload">{{ t('text', 'Reload') }}</a>
30+
</p>
31+
<p v-else-if="hasSyncCollission">
32+
{{ t('text', 'Document has been changed outside of the editor. The changes cannot be applied') }}
33+
</p>
34+
<p v-else-if="hasConnectionIssue">
35+
{{ t('text', 'Document could not be loaded. Please check your internet connection.') }}
36+
<a class="button primary" @click="reconnect">{{ t('text', 'Reconnect') }}</a>
37+
</p>
38+
</NcNoteCard>
39+
<NcNoteCard v-else-if="idle" type="info">
40+
<p>
41+
{{ t('text', 'Document idle for {timeout} minutes, click to continue editing', { timeout: IDLE_TIMEOUT }) }}
42+
<a class="button primary" @click="reconnect">{{ t('text', 'Reconnect') }}</a>
43+
</p>
44+
</NcNoteCard>
45+
<NcNoteCard v-if="lock" type="info">
2646
<template #icon>
27-
<AlertOctagonOutline />
47+
<Lock :size="20" />
2848
</template>
29-
</NcEmptyContent>
30-
31-
<p v-else-if="idle" class="msg">
32-
{{ t('text', 'Document idle for {timeout} minutes, click to continue editing', { timeout: IDLE_TIMEOUT }) }} <a class="button primary" @click="reconnect">{{ t('text', 'Reconnect') }}</a>
33-
</p>
34-
35-
<p v-else-if="hasSyncCollission" class="msg icon-error">
36-
{{ t('text', 'The document has been changed outside of the editor. The changes cannot be applied.') }}
37-
</p>
38-
39-
<p v-else-if="hasConnectionIssue" class="msg">
40-
{{ t('text', 'File could not be loaded. Please check your internet connection.') }} <a class="button primary" @click="reconnect">{{ t('text', 'Reconnect') }}</a>
41-
</p>
42-
43-
<p v-if="lock" class="msg msg-locked">
44-
<Lock /> {{ t('text', 'This file is opened read-only as it is currently locked by {user}.', { user: lock.displayName }) }}
45-
</p>
49+
<p>
50+
{{ t('text', 'This file is opened read-only as it is currently locked by {user}.', { user: lock.displayName }) }}
51+
</p>
52+
</NcNoteCard>
4653

4754
<CollisionResolveDialog v-if="hasSyncCollission" :sync-error="syncError" />
4855
</div>
@@ -51,19 +58,17 @@
5158
<script>
5259
5360
import { ERROR_TYPE, IDLE_TIMEOUT } from './../../services/SyncService.js'
54-
import AlertOctagonOutline from 'vue-material-design-icons/AlertOctagonOutline.vue'
5561
import Lock from 'vue-material-design-icons/Lock.vue'
56-
import { NcEmptyContent } from '@nextcloud/vue'
62+
import { NcNoteCard } from '@nextcloud/vue'
5763
import CollisionResolveDialog from '../CollisionResolveDialog.vue'
5864
5965
export default {
6066
name: 'DocumentStatus',
6167
6268
components: {
6369
CollisionResolveDialog,
64-
AlertOctagonOutline,
6570
Lock,
66-
NcEmptyContent,
71+
NcNoteCard,
6772
},
6873
6974
props: {
@@ -79,6 +84,7 @@ export default {
7984
type: Object,
8085
default: null,
8186
},
87+
8288
hasConnectionIssue: {
8389
type: Boolean,
8490
require: true,
@@ -98,12 +104,18 @@ export default {
98104
isLoadingError() {
99105
return this.syncError && this.syncError.type === ERROR_TYPE.LOAD_ERROR
100106
},
107+
hasWarning() {
108+
return this.syncError || this.hasConnectionIssue
109+
},
101110
},
102111
103112
methods: {
104113
reconnect() {
105114
this.$emit('reconnect')
106115
},
116+
reload() {
117+
window.location.reload()
118+
},
107119
},
108120
109121
}
@@ -112,28 +124,11 @@ export default {
112124
<style scoped lang="scss">
113125
.document-status {
114126
position: sticky;
115-
top: 0;
116-
z-index: 10000;
117-
max-height: 50px;
127+
top: 16px;
128+
z-index: 100000;
129+
// max-height: 50px;
130+
max-width: var(--text-editor-max-width);
131+
margin: auto;
118132
background-color: var(--color-main-background);
119-
120-
.msg {
121-
padding: 12px;
122-
background-position: 8px center;
123-
color: var(--color-text-maxcontrast);
124-
125-
&.icon-error {
126-
padding-left: 30px;
127-
}
128-
129-
.button {
130-
margin-left: 8px;
131-
}
132-
133-
&.msg-locked .lock-icon {
134-
padding: 0 10px;
135-
float: left;
136-
}
137-
}
138133
}
139134
</style>

0 commit comments

Comments
 (0)