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

[stable25] Remember the last opened folder #3283

Merged
merged 3 commits into from
Oct 25, 2022
Merged
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
49 changes: 45 additions & 4 deletions cypress/e2e/attachments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ describe('Test all attachment insertion methods', () => {
before(() => {
initUserAndFiles(randUser, 'test.md', 'empty.md')

cy.createFolder('sub')
cy.createFolder('sub/a')
cy.createFolder('sub/b')

cy.uploadFile('github.png', 'image/png')
cy.uploadFile('github.png', 'image/png', 'sub/a/a.png')
cy.uploadFile('github.png', 'image/png', 'sub/b/b.png')

cy.nextcloudCreateUser(randUser2, 'password')
cy.shareFileToUser(randUser, 'password', 'test.md', randUser2)
Expand All @@ -168,9 +174,44 @@ describe('Test all attachment insertion methods', () => {

clickOnAttachmentAction(ACTION_INSERT_FROM_FILES)
.then(() => {
const requestAlias = 'insertPathRequest'
const requestAlias = 'insertPathRequest-a'
cy.intercept({ method: 'POST', url: '**/filepath' }).as(requestAlias)

cy.log('Go to sub folder (a)')
cy.get('#picker-filestable tr[data-entryname="sub"]').click()
cy.get('#picker-filestable tr[data-entryname="a"]').click()
cy.get('#picker-filestable tr[data-entryname="a.png"]').click()

cy.get('.oc-dialog > .oc-dialog-buttonrow button').click()

return waitForRequestAndCheckAttachment(requestAlias)
})
.then(() => clickOnAttachmentAction(ACTION_INSERT_FROM_FILES))
.then(() => {
const requestAlias = 'insertPathRequest-b'
cy.intercept({ method: 'POST', url: '**/filepath' }).as(requestAlias)

cy.log('Go back to sub folder')
cy.get('#oc-dialog-filepicker-content .dirtree [data-dir="/sub"] a').click()

cy.log('Go to sub folder (b)')
cy.get('#picker-filestable tr[data-entryname="b"]').click()
cy.get('#picker-filestable tr[data-entryname="b.png"]').click()

cy.get('.oc-dialog > .oc-dialog-buttonrow button').click()

return waitForRequestAndCheckAttachment(requestAlias)
})

.then(() => clickOnAttachmentAction(ACTION_INSERT_FROM_FILES))

.then(() => {
const requestAlias = 'insertPathRequest-root'
cy.intercept({ method: 'POST', url: '**/filepath' }).as(requestAlias)

cy.log('Go back to home')
cy.get('#oc-dialog-filepicker-content .dirtree > .crumb:first-child').click()

cy.log('Select the file in the filepicker')
cy.get('#picker-filestable tr[data-entryname="github.png"]').click()
cy.log('Click OK in the filepicker')
Expand All @@ -180,7 +221,7 @@ describe('Test all attachment insertion methods', () => {
})
})

it('Upload a local image file', () => {
it('Upload a local image file (table.png)', () => {
cy.openFile('test.md')
// in this case we almost could just attach the file to the input
// BUT we still need to click on the action because otherwise the command
Expand All @@ -196,7 +237,7 @@ describe('Test all attachment insertion methods', () => {
})
})

it('Upload a local media file', () => {
it('Upload a local media file (file.txt.gz)', () => {
cy.openFile('test.md')
// in this case we almost could just attach the file to the input
// BUT we still need to click on the action because otherwise the command
Expand Down Expand Up @@ -252,7 +293,7 @@ describe('Test all attachment insertion methods', () => {
.then((documentId) => {
const files = attachmentFileNameToId[documentId]

cy.expect(Object.keys(files)).to.have.lengthOf(3)
cy.expect(Object.keys(files)).to.have.lengthOf(5)
cy.openFolder('.attachments.' + documentId)
cy.screenshot()
for (const name in files) {
Expand Down
4 changes: 2 additions & 2 deletions js/editor-rich.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor-rich.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/editor.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/files-modal.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files-modal.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions js/text-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-files.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-public.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-text.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-text.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions js/text-viewer.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/text-viewer.js.map

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion src/components/Editor/MediaHandler.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ import {
STATE_UPLOADING,
} from './MediaHandler.provider.js'

const getDir = (val) => val.split('/').slice(0, -1).join('/')

export default {
name: 'MediaHandler',
mixins: [useEditorMixin, useFileMixin, useSyncServiceMixin],
Expand All @@ -79,6 +81,7 @@ export default {
},
data() {
return {
lastFilePath: null,
draggedOver: false,
// make it reactive to be used inject/provide
state: {
Expand All @@ -88,7 +91,7 @@ export default {
},
computed: {
initialFilePath() {
return this.$file.relativePath.split('/').slice(0, -1).join('/')
return this.lastFilePath ?? getDir(this.$file.relativePath)
},
},
methods: {
Expand Down Expand Up @@ -160,6 +163,8 @@ export default {
}, false, [], true, undefined, this.initialFilePath)
},
insertFromPath(filePath) {
this.lastFilePath = getDir(filePath)

this.state.isUploadingAttachments = true

return this.$syncService.insertAttachmentFile(filePath).then((response) => {
Expand Down