mirror of
https://github.com/nextcloud/server.git
synced 2024-07-30 08:15:57 +02:00
fix(files): Update favorites navigation list on folder renames
Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
parent
bdbf00cd8d
commit
f1c50472d8
1
apps/files/src/eventbus.d.ts
vendored
1
apps/files/src/eventbus.d.ts
vendored
@ -5,6 +5,7 @@ declare module '@nextcloud/event-bus' {
|
|||||||
// mapping of 'event name' => 'event type'
|
// mapping of 'event name' => 'event type'
|
||||||
'files:favorites:removed': Node
|
'files:favorites:removed': Node
|
||||||
'files:favorites:added': Node
|
'files:favorites:added': Node
|
||||||
|
'files:node:renamed': Node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
import { basename } from 'path'
|
import { basename } from 'path'
|
||||||
import { expect } from '@jest/globals'
|
import { expect } from '@jest/globals'
|
||||||
import { Folder, Navigation, getNavigation } from '@nextcloud/files'
|
import { Folder, Navigation, getNavigation } from '@nextcloud/files'
|
||||||
import eventBus from '@nextcloud/event-bus'
|
import eventBus, { emit } from '@nextcloud/event-bus'
|
||||||
import * as initialState from '@nextcloud/initial-state'
|
import * as initialState from '@nextcloud/initial-state'
|
||||||
|
|
||||||
import { action } from '../actions/favoriteAction'
|
import { action } from '../actions/favoriteAction'
|
||||||
@ -63,9 +63,10 @@ describe('Favorites view definition', () => {
|
|||||||
const favoritesView = Navigation.views.find(view => view.id === 'favorites')
|
const favoritesView = Navigation.views.find(view => view.id === 'favorites')
|
||||||
const favoriteFoldersViews = Navigation.views.filter(view => view.parent === 'favorites')
|
const favoriteFoldersViews = Navigation.views.filter(view => view.parent === 'favorites')
|
||||||
|
|
||||||
expect(eventBus.subscribe).toHaveBeenCalledTimes(2)
|
expect(eventBus.subscribe).toHaveBeenCalledTimes(3)
|
||||||
expect(eventBus.subscribe).toHaveBeenNthCalledWith(1, 'files:favorites:added', expect.anything())
|
expect(eventBus.subscribe).toHaveBeenNthCalledWith(1, 'files:favorites:added', expect.anything())
|
||||||
expect(eventBus.subscribe).toHaveBeenNthCalledWith(2, 'files:favorites:removed', expect.anything())
|
expect(eventBus.subscribe).toHaveBeenNthCalledWith(2, 'files:favorites:removed', expect.anything())
|
||||||
|
expect(eventBus.subscribe).toHaveBeenNthCalledWith(3, 'files:node:renamed', expect.anything())
|
||||||
|
|
||||||
// one main view and no children
|
// one main view and no children
|
||||||
expect(Navigation.views.length).toBe(1)
|
expect(Navigation.views.length).toBe(1)
|
||||||
@ -196,4 +197,43 @@ describe('Dynamic update of favourite folders', () => {
|
|||||||
expect(favoritesView).toBeDefined()
|
expect(favoritesView).toBeDefined()
|
||||||
expect(favoriteFoldersViews.length).toBe(0)
|
expect(favoriteFoldersViews.length).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Renaming a favorite folder updates the navigation', async () => {
|
||||||
|
jest.spyOn(eventBus, 'emit')
|
||||||
|
jest.spyOn(initialState, 'loadState').mockReturnValue([])
|
||||||
|
jest.spyOn(favoritesService, 'getContents').mockReturnValue(Promise.resolve({ folder: {} as Folder, contents: [] }))
|
||||||
|
|
||||||
|
registerFavoritesView()
|
||||||
|
const favoritesView = Navigation.views.find(view => view.id === 'favorites')
|
||||||
|
const favoriteFoldersViews = Navigation.views.filter(view => view.parent === 'favorites')
|
||||||
|
|
||||||
|
// one main view and no children
|
||||||
|
expect(Navigation.views.length).toBe(1)
|
||||||
|
expect(favoritesView).toBeDefined()
|
||||||
|
expect(favoriteFoldersViews.length).toBe(0)
|
||||||
|
|
||||||
|
// expect(eventBus.emit).toHaveBeenCalledTimes(2)
|
||||||
|
|
||||||
|
// Create new folder to favorite
|
||||||
|
const folder = new Folder({
|
||||||
|
id: 1,
|
||||||
|
source: 'http://localhost/remote.php/dav/files/admin/Foo/Bar',
|
||||||
|
owner: 'admin',
|
||||||
|
})
|
||||||
|
|
||||||
|
// Exec the action
|
||||||
|
await action.exec(folder, favoritesView, '/')
|
||||||
|
expect(eventBus.emit).toHaveBeenNthCalledWith(1, 'files:favorites:added', folder)
|
||||||
|
|
||||||
|
// Create a folder with the same id but renamed
|
||||||
|
const renamedFolder = new Folder({
|
||||||
|
id: 1,
|
||||||
|
source: 'http://localhost/remote.php/dav/files/admin/Foo/Bar.renamed',
|
||||||
|
owner: 'admin',
|
||||||
|
})
|
||||||
|
|
||||||
|
// Exec the rename action
|
||||||
|
emit('files:node:renamed', renamedFolder)
|
||||||
|
expect(eventBus.emit).toHaveBeenNthCalledWith(2, 'files:node:renamed', renamedFolder)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -123,6 +123,21 @@ export default () => {
|
|||||||
removePathFromFavorites(node.path)
|
removePathFromFavorites(node.path)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update favourites navigation when a folder is renamed
|
||||||
|
*/
|
||||||
|
subscribe('files:node:renamed', (node: Node) => {
|
||||||
|
if (node.type !== FileType.Folder) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node.attributes.favorite !== 1) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
updateNodeFromFavorites(node as Folder)
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort the favorites paths array and
|
* Sort the favorites paths array and
|
||||||
* update the order property of the existing views
|
* update the order property of the existing views
|
||||||
@ -174,4 +189,17 @@ export default () => {
|
|||||||
Navigation.remove(id)
|
Navigation.remove(id)
|
||||||
updateAndSortViews()
|
updateAndSortViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update a folder from the favorites paths array and update the views
|
||||||
|
const updateNodeFromFavorites = function(node: Folder) {
|
||||||
|
const favoriteFolder = favoriteFolders.find((folder) => folder.fileid === node.fileid)
|
||||||
|
|
||||||
|
// Skip if it does not exists
|
||||||
|
if (favoriteFolder === undefined) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
removePathFromFavorites(favoriteFolder.path)
|
||||||
|
addToFavorites(node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
4
dist/files-init.js
vendored
4
dist/files-init.js
vendored
File diff suppressed because one or more lines are too long
2
dist/files-init.js.map
vendored
2
dist/files-init.js.map
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user