Skip to content

Commit e7edf01

Browse files
committed
fix(attachments): check for editorApi attachments support
Signed-off-by: Jonas <jonas@freesources.org>
1 parent fc8271f commit e7edf01

5 files changed

Lines changed: 31 additions & 8 deletions

File tree

cypress/e2e/page-attachments.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ describe('Page attachments', function() {
4242
// Open attachment list
4343
cy.get('button.app-sidebar__toggle').click()
4444

45-
cy.get('.attachment-list-embedded').should('contain', 'test.png')
46-
cy.get('.attachment-list-not-embedded').should('not.exist')
45+
if (['stable31'].includes(Cypress.env('ncVersion'))) {
46+
cy.get('.attachment-list-not-embedded').should('contain', 'test.png')
47+
} else {
48+
cy.get('.attachment-list-embedded').should('contain', 'test.png')
49+
cy.get('.attachment-list-not-embedded').should('not.exist')
50+
}
4751

4852
// Close sidebar
4953
cy.get('button.app-sidebar__close').click({ force: true })
@@ -57,8 +61,12 @@ describe('Page attachments', function() {
5761
// Open attachment list
5862
cy.get('button.app-sidebar__toggle').click()
5963

60-
cy.get('.attachment-list-embedded').should('contain', 'test.png')
61-
cy.get('.attachment-list-not-embedded').should('not.exist')
64+
if (['stable31'].includes(Cypress.env('ncVersion'))) {
65+
cy.get('.attachment-list-not-embedded').should('contain', 'test.png')
66+
} else {
67+
cy.get('.attachment-list-embedded').should('contain', 'test.png')
68+
cy.get('.attachment-list-not-embedded').should('not.exist')
69+
}
6270

6371
// Delete image from editor
6472
cy.getEditor()

src/components/PageSidebar/AttachmentItem.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{{ t('collectives', 'View in page') }}
4040
</NcActionButton>
4141
<NcActionButton
42-
v-if="!isEmbedded && !isDeleted && !isInFolder && isTextEdit && currentCollectiveCanEdit"
42+
v-if="!isEmbedded && !isDeleted && !isInFolder && editorApiAttachments && isTextEdit && currentCollectiveCanEdit"
4343
:close-after-click="true"
4444
@click="onInsert">
4545
<template #icon>
@@ -118,6 +118,7 @@ import PencilOutlineIcon from 'vue-material-design-icons/PencilOutline.vue'
118118
import RestoreIcon from 'vue-material-design-icons/Restore.vue'
119119
import DownloadIcon from 'vue-material-design-icons/TrayArrowDown.vue'
120120
import { useNetworkState } from '../../composables/useNetworkState.ts'
121+
import { editorApiAttachments } from '../../constants.js'
121122
import { useCollectivesStore } from '../../stores/collectives.js'
122123
import { usePagesStore } from '../../stores/pages.js'
123124
import { useRootStore } from '../../stores/root.js'
@@ -164,6 +165,7 @@ export default {
164165
165166
computed: {
166167
...mapState(useRootStore, [
168+
'editorApiFlags',
167169
'isPublic',
168170
'shareTokenParam',
169171
]),
@@ -175,6 +177,10 @@ export default {
175177
'isTextEdit',
176178
]),
177179
180+
editorApiAttachments() {
181+
return this.editorApiFlags.includes(editorApiAttachments)
182+
},
183+
178184
isInFolder() {
179185
return this.attachment.type === 'folder'
180186
},

src/components/PageSidebar/SidebarTabAttachments.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
<!-- text attachments not in page list -->
7878
<div v-if="notEmbeddedAttachments.length">
79-
<div class="attachment-list-subheading">
79+
<div v-if="editorApiAttachments" class="attachment-list-subheading">
8080
<div>
8181
{{ t('collectives', 'Not in page') }}
8282
</div>
@@ -174,6 +174,7 @@ import AttachmentItem from './AttachmentItem.vue'
174174
import AttachmentRenameDialog from './AttachmentRenameDialog.vue'
175175
import OfflineContent from './OfflineContent.vue'
176176
import { useNetworkState } from '../../composables/useNetworkState.ts'
177+
import { editorApiAttachments } from '../../constants.js'
177178
import { useCollectivesStore } from '../../stores/collectives.js'
178179
import { usePagesStore } from '../../stores/pages.js'
179180
import { useRootStore } from '../../stores/root.js'
@@ -210,7 +211,7 @@ export default {
210211
},
211212
212213
computed: {
213-
...mapState(useRootStore, ['loading']),
214+
...mapState(useRootStore, ['editorApiFlags', 'loading']),
214215
215216
...mapState(useCollectivesStore, ['currentCollectiveCanEdit']),
216217
@@ -224,6 +225,10 @@ export default {
224225
'deletedAttachments',
225226
]),
226227
228+
editorApiAttachments() {
229+
return this.editorApiFlags.includes(editorApiAttachments)
230+
},
231+
227232
noAttachmentsDescription() {
228233
return t('collectives', 'Add attachments using drag and drop or via "Insert attachment" in the formatting menu.')
229234
},

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ export const pageModes = {
4747

4848
export const editorApiReaderFileId = 'READER_FILE_ID'
4949
export const editorApiUpdateReadonlyBarProps = 'UPDATE_READONLY_BAR_PROPS'
50+
export const editorApiAttachments = 'ATTACHMENTS'
5051

5152
export const sessionUpdateInterval = 90 // in seconds

src/stores/root.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { useLocalStorage } from '@vueuse/core'
77
import { defineStore } from 'pinia'
88
import { set } from 'vue'
9-
import { editorApiReaderFileId, editorApiUpdateReadonlyBarProps } from '../constants.js'
9+
import { editorApiReaderFileId, editorApiUpdateReadonlyBarProps, editorApiAttachments } from '../constants.js'
1010

1111
const STORE_PREFIX = 'collectives/pinia/root/'
1212

@@ -44,6 +44,9 @@ export const useRootStore = defineStore('root', {
4444
if (this.editorApiVersionCheck('1.2')) {
4545
flags.push(editorApiUpdateReadonlyBarProps)
4646
}
47+
if (this.editorApiVersionCheck('1.4')) {
48+
flags.push(editorApiAttachments)
49+
}
4750
return flags
4851
},
4952
},

0 commit comments

Comments
 (0)