Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable30] fix: use file picker component directly #4028

Draft
wants to merge 4 commits into
base: stable30
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 43 additions & 5 deletions cypress/e2e/integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,49 @@ describe('Nextcloud integration', function() {
cy.get('.modal-container__content').should('be.visible')
})

it('Smart picker', function() {
cy.get('@loleafletframe').within(() => {
cy.get('#Insert-tab-label').click()
cy.get('#insert-insert-remote-link-button').click()
describe('Smart picker', function() {
describe('Link to office document section', function() {
beforeEach(function() {
// Proc the smart picker from Collabora
cy.get('@loleafletframe').within(() => {
cy.get('#Insert-tab-label').click()
cy.get('#insert-insert-remote-link-button').click()
})

// Wait for the reference picker to show
cy.get('.reference-picker-modal--content')
.should('be.visible')
.as('referencePickerContent')

// Select "Link to office document section"
cy.get('@referencePickerContent')
.find('input[id="provider-select-input"]')
.as('smartPickerDropdown')
cy.get('@smartPickerDropdown').click()
cy.get('@referencePickerContent')
.find('ul[aria-label="Options"]')
.should('be.visible')
.contains('Link to office document section')
.click()

// Pick the fixture document
cy.pickFile('document.odt')
})

it('Can link to heading', function() {
cy.get('[data-cy-section-label="Headings"]').children().first().click()
cy.get('[data-cy-link-to-section=""]').click()
})

it('Can link to section', function() {
cy.get('[data-cy-section-label="Sections"]').children().first().click()
cy.get('[data-cy-link-to-section=""]').click()
})

it('Can link to image', function() {
cy.get('[data-cy-section-label="Images"]').children().first().click()
cy.get('[data-cy-link-to-section=""]').click()
})
})
cy.get('.reference-picker-modal--content').should('be.visible')
})
})
Binary file modified cypress/fixtures/document.odt
Binary file not shown.
9 changes: 9 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,12 @@ Cypress.Commands.add('verifyTemplateFields', (fields, fileId) => {
})
})
})

Cypress.Commands.add('pickFile', (filename) => {
cy.get('.office-target-picker')
.find(`tr[data-filename="${filename}"]`)
.click()
cy.get('.office-target-picker')
.find('button[aria-label="Select file"]')
.click()
})
87 changes: 38 additions & 49 deletions src/view/DocumentTargetPicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

<template>
<div v-if="filePath === null" class="office-target-picker">
<div ref="picker" class="reference-file-picker" />
<FilePicker :name="t('files', 'Select file or folder to link to')"
:buttons="filePickerButtons"
:allow-pick-directory="false"
:multiselect="false"
:mimetype-filter="validMimetypes"
container=".office-target-picker" />
</div>
<div v-else class="office-target-picker">
<h2>{{ t('richdocuments', 'Link to office document section') }}</h2>
Expand All @@ -19,7 +24,7 @@
<template v-else>
<div v-for="section in sections" :key="section.label">
<h3>{{ section.label }}</h3>
<ul>
<ul :data-cy-section-label="section.label">
<NcListItem v-for="entry in section.entries"
:key="entry.id"
:name="entry.name"
Expand All @@ -33,7 +38,10 @@
</div>
</template>
<div v-if="sections.length !== 0" class="office-target-picker__buttons">
<NcButton type="primary" :disabled="!target" @click="submit()">
<NcButton data-cy-link-to-section=""
type="primary"
:disabled="!target"
@click="submit()">
{{ t('richdocuments', 'Link to office document section') }}
</NcButton>
</div>
Expand All @@ -42,7 +50,7 @@
</template>

<script>
import { getFilePickerBuilder } from '@nextcloud/dialogs'
import { FilePickerVue as FilePicker } from '@nextcloud/dialogs/filepicker.js'
import { generateUrl, generateOcsUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
Expand All @@ -59,6 +67,7 @@ export default {
NcEmptyContent,
NcListItem,
NcLoadingIcon,
FilePicker,
TableOfContentsIcon,
},
props: {
Expand All @@ -77,37 +86,45 @@ export default {
filePath: null,
target: null,
sections: null,
filePickerButtons: [
{
label: t('richdocuments', 'Cancel'),
callback: () => {
this.$emit('cancel')
},
type: 'secondary',
},
{
label: t('richdocuments', 'Select file'),
callback: (files) => {
const file = files[0]
this.fileId = file.fileid
this.filePath = file.path
this.fetchReferences()
},
type: 'primary',
},
],
}
},
computed: {
validMimetypes() {
return getCapabilities().mimetypes
},
},
mounted() {
this.openFilePicker()
window.addEventListener('click', this.onWindowClick)
},
beforeDestroy() {
window.removeEventListener('click', this.onWindowClick)
},
methods: {
t,
onWindowClick(e) {
if (e.target.tagName === 'A' && e.target.classList.contains('oc-dialog-close')) {
this.$emit('cancel')
}
},
async openFilePicker() {
await getFilePickerBuilder(t('files', 'Select file or folder to link to'))
.setMimeTypeFilter(getCapabilities().mimetypes)
.addButton({
label: t('richdocuments', 'Insert image'),
callback: (files) => {
const file = files[0]
this.fileId = file.fileid
this.filePath = file.path
this.fetchReferences()
},
})
.setContainer(this.$refs.picker)
.build()
.pick()
},
setTarget(entry) {
this.target = entry.id
},
Expand All @@ -129,34 +146,6 @@ export default {
</script>

<style scoped lang="scss">
.reference-file-picker {
flex-grow: 1;

&:deep(.oc-dialog) {
transform: none !important;
box-shadow: none !important;
flex-grow: 1 !important;
position: static !important;
width: 100% !important;
height: auto !important;
padding: 0 !important;
max-width: initial;

.oc-dialog-close {
display: none;
}

.oc-dialog-buttonrow.onebutton.aside {
position: absolute;
padding: 12px 32px;
}

.oc-dialog-content {
max-width: 100% !important;
}
}
}

.office-target-picker {
margin: calc(var(--default-grid-baseline) * 4);
flex-grow: 1;
Expand Down
Loading