-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39613 from nextcloud/feat/f2v/recent
- Loading branch information
Showing
25 changed files
with
495 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import { action } from './openInFilesAction' | ||
import { expect } from '@jest/globals' | ||
import { File, Folder, Permission } from '@nextcloud/files' | ||
import { DefaultType, FileAction } from '../../../files/src/services/FileAction' | ||
import type { Navigation } from '../../../files/src/services/Navigation' | ||
|
||
const view = { | ||
id: 'files', | ||
name: 'Files', | ||
} as Navigation | ||
|
||
const recentView = { | ||
id: 'recent', | ||
name: 'Recent', | ||
} as Navigation | ||
|
||
describe('Open in files action conditions tests', () => { | ||
test('Default values', () => { | ||
expect(action).toBeInstanceOf(FileAction) | ||
expect(action.id).toBe('open-in-files-recent') | ||
expect(action.displayName([], recentView)).toBe('Open in Files') | ||
expect(action.iconSvgInline([], recentView)).toBe('') | ||
expect(action.default).toBe(DefaultType.HIDDEN) | ||
expect(action.order).toBe(-1000) | ||
expect(action.inline).toBeUndefined() | ||
}) | ||
}) | ||
|
||
describe('Open in files action enabled tests', () => { | ||
test('Enabled with on valid view', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([], recentView)).toBe(true) | ||
}) | ||
|
||
test('Disabled on wrong view', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([], view)).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('Open in files action execute tests', () => { | ||
test('Open in files', async () => { | ||
const goToRouteMock = jest.fn() | ||
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } | ||
|
||
const file = new File({ | ||
id: 1, | ||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/foobar.txt', | ||
owner: 'admin', | ||
mime: 'text/plain', | ||
root: '/files/admin', | ||
permissions: Permission.ALL, | ||
}) | ||
|
||
const exec = await action.exec(file, view, '/') | ||
|
||
// Silent action | ||
expect(exec).toBe(null) | ||
expect(goToRouteMock).toBeCalledTimes(1) | ||
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo', openfile: true }) | ||
}) | ||
|
||
test('Open in files with folder', async () => { | ||
const goToRouteMock = jest.fn() | ||
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } | ||
|
||
const file = new Folder({ | ||
id: 1, | ||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/Bar', | ||
owner: 'admin', | ||
root: '/files/admin', | ||
permissions: Permission.ALL, | ||
}) | ||
|
||
const exec = await action.exec(file, view, '/') | ||
|
||
// Silent action | ||
expect(exec).toBe(null) | ||
expect(goToRouteMock).toBeCalledTimes(1) | ||
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo/Bar', openfile: true }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]> | ||
* | ||
* @author John Molakvoæ <[email protected]> | ||
* | ||
* @license AGPL-3.0-or-later | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
import { translate as t } from '@nextcloud/l10n' | ||
import { FileType, type Node } from '@nextcloud/files' | ||
|
||
import { registerFileAction, FileAction, DefaultType } from '../../../files/src/services/FileAction' | ||
|
||
/** | ||
* TODO: Move away from a redirect and handle | ||
* navigation straight out of the recent view | ||
*/ | ||
export const action = new FileAction({ | ||
id: 'open-in-files-recent', | ||
displayName: () => t('files', 'Open in Files'), | ||
iconSvgInline: () => '', | ||
|
||
enabled: (nodes, view) => view.id === 'recent', | ||
|
||
async exec(node: Node) { | ||
let dir = node.dirname | ||
if (node.type === FileType.Folder) { | ||
dir = dir + '/' + node.basename | ||
} | ||
|
||
window.OCP.Files.Router.goToRoute( | ||
null, // use default route | ||
{ view: 'files', fileid: node.fileid }, | ||
{ dir, fileid: node.fileid, openfile: true }, | ||
) | ||
return null | ||
}, | ||
|
||
// Before openFolderAction | ||
order: -1000, | ||
default: DefaultType.HIDDEN, | ||
}) | ||
|
||
registerFileAction(action) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.