Skip to content

Commit b49f431

Browse files
committed
fix: use file picker component directly
Signed-off-by: Elizabeth Danzberger <[email protected]>
1 parent f897059 commit b49f431

File tree

4 files changed

+107
-52
lines changed

4 files changed

+107
-52
lines changed

cypress/e2e/integration.spec.js

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,70 @@ describe('Nextcloud integration', function() {
121121
cy.get('.modal-container__content').should('be.visible')
122122
})
123123

124-
it('Smart picker', function() {
125-
cy.get('@loleafletframe').within(() => {
126-
cy.get('#Insert-tab-label').click()
127-
cy.get('#insert-insert-remote-link-button').click()
124+
describe.only('Smart picker', function() {
125+
describe('Link to office document section', function() {
126+
beforeEach(function() {
127+
// Proc the smart picker from Collabora
128+
cy.get('@loleafletframe').within(() => {
129+
cy.get('#Insert-tab-label').click()
130+
cy.get('#insert-insert-remote-link-button').click()
131+
})
132+
133+
// Wait for the reference picker to show
134+
cy.get('.reference-picker-modal--content')
135+
.should('be.visible')
136+
.as('referencePickerContent')
137+
138+
// Select "Link to office document section"
139+
cy.get('@referencePickerContent')
140+
.find('input[id="provider-select-input"]')
141+
.as('smartPickerDropdown')
142+
cy.get('@smartPickerDropdown').click()
143+
cy.get('@referencePickerContent')
144+
.find('ul[aria-label="Options"]')
145+
.should('be.visible')
146+
.contains('Link to office document section')
147+
.click()
148+
149+
// Pick the fixture document
150+
cy.pickFile('document.odt')
151+
})
152+
153+
it('Can link to heading', function() {
154+
cy.get('.office-target-picker')
155+
.contains('Headings')
156+
.siblings()
157+
.first()
158+
.click()
159+
160+
cy.get('.office-target-picker__buttons')
161+
.contains('Link to office document section')
162+
.click()
163+
})
164+
165+
it('Can link to section', function() {
166+
cy.get('.office-target-picker')
167+
.contains('Sections')
168+
.siblings()
169+
.first()
170+
.click()
171+
172+
cy.get('.office-target-picker__buttons')
173+
.contains('Link to office document section')
174+
.click()
175+
})
176+
177+
it('Can link to image', function() {
178+
cy.get('.office-target-picker')
179+
.contains('Images')
180+
.siblings()
181+
.first()
182+
.click()
183+
184+
cy.get('.office-target-picker__buttons')
185+
.contains('Link to office document section')
186+
.click()
187+
})
128188
})
129-
cy.get('.reference-picker-modal--content').should('be.visible')
130189
})
131190
})

cypress/fixtures/document.odt

92 KB
Binary file not shown.

cypress/support/commands.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,12 @@ Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => {
365365
})
366366
})
367367
})
368+
369+
Cypress.Commands.add('pickFile', (filename) => {
370+
cy.get('.office-target-picker')
371+
.find(`tr[data-filename="${filename}"]`)
372+
.click()
373+
cy.get('.office-target-picker')
374+
.find('button[aria-label="Select file"]')
375+
.click()
376+
})

src/view/DocumentTargetPicker.vue

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55

66
<template>
77
<div v-if="filePath === null" class="office-target-picker">
8-
<div ref="picker" class="reference-file-picker" />
8+
<FilePicker :name="t('files', 'Select file or folder to link to')"
9+
:buttons="filePickerButtons"
10+
:allow-pick-directory="false"
11+
:multiselect="false"
12+
:mimetype-filter="validMimetypes"
13+
container=".office-target-picker" />
914
</div>
1015
<div v-else class="office-target-picker">
1116
<h2>{{ t('richdocuments', 'Link to office document section') }}</h2>
@@ -42,7 +47,8 @@
4247
</template>
4348

4449
<script>
45-
import { getFilePickerBuilder } from '@nextcloud/dialogs'
50+
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
51+
import { spawnDialog } from '@nextcloud/dialogs'
4652
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
4753
import axios from '@nextcloud/axios'
4854
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
@@ -59,6 +65,7 @@ export default {
5965
NcEmptyContent,
6066
NcListItem,
6167
NcLoadingIcon,
68+
FilePicker,
6269
TableOfContentsIcon,
6370
},
6471
props: {
@@ -77,37 +84,45 @@ export default {
7784
filePath: null,
7885
target: null,
7986
sections: null,
87+
filePickerButtons: [
88+
{
89+
label: t('richdocuments', 'Cancel'),
90+
callback: () => {
91+
this.$emit('cancel')
92+
},
93+
type: 'secondary',
94+
},
95+
{
96+
label: t('richdocuments', 'Select file'),
97+
callback: (files) => {
98+
const file = files[0]
99+
this.fileId = file.fileid
100+
this.filePath = file.path
101+
this.fetchReferences()
102+
},
103+
type: 'primary',
104+
},
105+
],
80106
}
81107
},
108+
computed: {
109+
validMimetypes() {
110+
return getCapabilities().mimetypes
111+
},
112+
},
82113
mounted() {
83-
this.openFilePicker()
84114
window.addEventListener('click', this.onWindowClick)
85115
},
86116
beforeDestroy() {
87117
window.removeEventListener('click', this.onWindowClick)
88118
},
89119
methods: {
120+
t,
90121
onWindowClick(e) {
91122
if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) {
92123
this.$emit('cancel')
93124
}
94125
},
95-
async openFilePicker() {
96-
await getFilePickerBuilder(t('files', 'Select file or folder to link to'))
97-
.setMimeTypeFilter(getCapabilities().mimetypes)
98-
.addButton({
99-
label: t('richdocuments', 'Insert image'),
100-
callback: (files) => {
101-
const file = files[0]
102-
this.fileId = file.fileid
103-
this.filePath = file.path
104-
this.fetchReferences()
105-
},
106-
})
107-
.setContainer(this.$refs.picker)
108-
.build()
109-
.pick()
110-
},
111126
setTarget(entry) {
112127
this.target = entry.id
113128
},
@@ -129,34 +144,6 @@ export default {
129144
</script>
130145

131146
<style scoped lang="scss">
132-
.reference-file-picker {
133-
flex-grow: 1;
134-
135-
&:deep(.oc-dialog) {
136-
transform: none !important;
137-
box-shadow: none !important;
138-
flex-grow: 1 !important;
139-
position: static !important;
140-
width: 100% !important;
141-
height: auto !important;
142-
padding: 0 !important;
143-
max-width: initial;
144-
145-
.oc-dialog-close {
146-
display: none;
147-
}
148-
149-
.oc-dialog-buttonrow.onebutton.aside {
150-
position: absolute;
151-
padding: 12px 32px;
152-
}
153-
154-
.oc-dialog-content {
155-
max-width: 100% !important;
156-
}
157-
}
158-
}
159-
160147
.office-target-picker {
161148
margin: calc(var(--default-grid-baseline) * 4);
162149
flex-grow: 1;

0 commit comments

Comments
 (0)