diff --git a/cypress/e2e/workspace.spec.js b/cypress/e2e/workspace.spec.js index b69c3a7f3a6..ddaa359adb6 100644 --- a/cypress/e2e/workspace.spec.js +++ b/cypress/e2e/workspace.spec.js @@ -62,20 +62,26 @@ describe('Workspace', function() { cy.get('a[href*="/apps/files/recent"]') .click() cy.get('#rich-workspace .ProseMirror') - .should('not.exist') + .should('not.visible') }) it('adds a Readme.md', function() { + const url = '**/remote.php/dav/files/**' + cy.intercept({ method: 'PUT', url }) + .as('addDescription') + cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`) cy.get('.files-fileList').should('not.contain', 'Readme.md') - cy.openWorkspace() - .type('Hello') - .should('contain', 'Hello') + + cy.get('.files-controls').first().within(() => { + cy.get('.button.new').click() + cy.get('.newFileMenu a.menuitem[data-action="rich-workspace-init"]').click() + cy.wait('@addDescription') + }) + openSidebar('Readme.md') - cy.log('Regression test for #2215') - cy.get('#rich-workspace .ProseMirror') + cy.get('#rich-workspace .text-editor .text-editor__wrapper') .should('be.visible') - .should('contain', 'Hello') }) it('formats text', function() { @@ -286,7 +292,6 @@ describe('Workspace', function() { cy.uploadFile('test.md', 'text/markdown', `${Cypress.currentTest.title}/Anleitung.md`) cy.visit(`apps/files?dir=/${encodeURIComponent(currentFolder)}`) cy.get('.files-fileList').should('contain', 'Anleitung.md') - cy.get('.empty-workspace').should('contain', 'Ajoutez des notes, listes ou liens') }) }) @@ -306,17 +311,17 @@ describe('Workspace', function() { }) it('click', () => { - cy.get('#rich-workspace .empty-workspace').click() + cy.openWorkspace().click() checkContent() }) it('enter', () => { - cy.get('#rich-workspace .empty-workspace').type('{enter}') + cy.openWorkspace().type('{enter}') checkContent() }) it('spacebar', () => { - cy.get('#rich-workspace .empty-workspace') + cy.openWorkspace() .trigger('keyup', { keyCode: 32, which: 32, diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 9b2a5226b80..c51d070f04a 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -342,7 +342,7 @@ Cypress.Commands.add('getActionEntry', { prevSubject: 'optional' }, (subject, na }) Cypress.Commands.add('getActionSubEntry', (name) => { - return cy.get('.action-item__popper .open').getActionEntry(name) + return cy.get('div[data-text-el="menubar"]').getActionEntry(name) }) Cypress.Commands.add('getContent', { prevSubject: 'optional' }, (subject) => { @@ -368,8 +368,9 @@ Cypress.Commands.add('clearContent', () => { }) Cypress.Commands.add('openWorkspace', () => { - cy.get('#rich-workspace .empty-workspace').click() - cy.getEditor().find('[data-text-el="editor-content-wrapper"]').click() + cy.createDescription() + cy.get('#rich-workspace .editor__content').click({ force: true }) + cy.getEditor().find('[data-text-el="editor-content-wrapper"]').click({ force: true }) return cy.getContent() }) @@ -394,6 +395,19 @@ Cypress.Commands.add('showHiddenFiles', () => { cy.get('.modal-container__close').click() }) +Cypress.Commands.add('createDescription', () => { + const url = '**/remote.php/dav/files/**' + cy.intercept({ method: 'PUT', url }) + .as('addDescription') + + cy.get('.files-fileList').should('not.contain', 'Readme.md') + cy.get('.files-controls').first().within(() => { + cy.get('.button.new').click() + cy.get('.newFileMenu a.menuitem[data-action="rich-workspace-init"]').click() + }) + cy.wait('@addDescription') +}) + Cypress.on( 'uncaught:exception', err => !err.message.includes('ResizeObserver loop limit exceeded'), diff --git a/src/helpers/files.js b/src/helpers/files.js index b95f06bcf4b..8cd19bd34ed 100644 --- a/src/helpers/files.js +++ b/src/helpers/files.js @@ -21,7 +21,7 @@ */ import { loadState } from '@nextcloud/initial-state' -import { subscribe } from '@nextcloud/event-bus' +import { emit, subscribe } from '@nextcloud/event-bus' import { openMimetypes } from './mime.js' import { getSharingToken } from './token.js' import RichWorkspace from '../views/RichWorkspace.vue' @@ -139,6 +139,39 @@ const registerFileActionFallback = () => { } +const newRichWorkspaceFileMenuPlugin = { + attach(menu) { + const fileList = menu.fileList + const descriptionFile = t('text', 'Readme') + '.' + loadState('text', 'default_file_extension') + // only attach to main file list, public view is not supported yet + if (fileList.id !== 'files' && fileList.id !== 'files.public') { + return + } + + // register the new menu entry + menu.addMenuEntry({ + id: 'rich-workspace-init', + displayName: t('text', 'Add description'), + templateName: descriptionFile, + iconClass: 'icon-rename', + fileType: 'file', + useInput: false, + actionHandler() { + return window.FileList + .createFile(descriptionFile, { scrollTo: false, animate: false }) + .then(() => emit('Text::showRichWorkspace')) + }, + shouldShow() { + return !fileList.findFile(descriptionFile) + }, + }) + }, +} + +const addMenuRichWorkspace = () => { + OC.Plugins.register('OCA.Files.NewFileMenu', newRichWorkspaceFileMenuPlugin) +} + const FilesWorkspacePlugin = { el: null, @@ -146,7 +179,6 @@ const FilesWorkspacePlugin = { if (fileList.id !== 'files' && fileList.id !== 'files.public') { return } - this.el = document.createElement('div') fileList.registerHeader({ id: 'workspace', @@ -160,7 +192,7 @@ const FilesWorkspacePlugin = { if (fileList.id !== 'files' && fileList.id !== 'files.public') { return } - + addMenuRichWorkspace() import('vue').then((module) => { const Vue = module.default this.el.id = 'files-workspace-wrapper' @@ -174,13 +206,11 @@ const FilesWorkspacePlugin = { }, store, }).$mount(this.el) - subscribe('files:navigation:changed', () => { // Expose if the default file list is active to the component // to only render the workspace if the file list is actually visible vm.active = OCA.Files.App.getCurrentFileList() === fileList }) - fileList.$el.on('urlChanged', data => { vm.path = data.dir.toString() }) diff --git a/src/views/RichWorkspace.vue b/src/views/RichWorkspace.vue index c0a86d1e9a4..4380fd3de27 100644 --- a/src/views/RichWorkspace.vue +++ b/src/views/RichWorkspace.vue @@ -21,18 +21,7 @@ -->