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

fix(files): Make sure files are opened when using open-in-files action(s) or at lease are scrolled into view #45611

Merged
merged 5 commits into from
Jun 8, 2024
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
4 changes: 2 additions & 2 deletions apps/files/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('Open in files action execute tests', () => {
// Silent action
expect(exec).toBe(null)
expect(goToRouteMock).toBeCalledTimes(1)
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo' })
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo', openfile: 'true' })
})

test('Open in files with folder', async () => {
Expand All @@ -79,6 +79,6 @@ describe('Open in files action execute tests', () => {
// Silent action
expect(exec).toBe(null)
expect(goToRouteMock).toBeCalledTimes(1)
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo/Bar' })
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo/Bar', openfile: 'true' })
})
})
2 changes: 1 addition & 1 deletion apps/files/src/actions/openInFilesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const action = new FileAction({
window.OCP.Files.Router.goToRoute(
null, // use default route
{ view: 'files', fileid: node.fileid },
{ dir },
{ dir, openfile: 'true' },
)
return null
},
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const action = new FileAction({
window.OCP.Files.Router.goToRoute(
null,
{ view: view.id, fileid: node.fileid },
{ dir },
{ ...window.OCP.Files.Router.query, dir },
true,
)

Expand Down
10 changes: 5 additions & 5 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ export default defineComponent({
return this.enabledActions
.filter(action => action.parent)
.reduce((arr, action) => {
if (!arr[action.parent]) {
arr[action.parent] = []
if (!arr[action.parent!]) {
arr[action.parent!] = []
}
arr[action.parent].push(action)
arr[action.parent!].push(action)
return arr
}, {} as Record<string, FileAction>)
}, {} as Record<string, FileAction[]>)
},

openedMenu: {
Expand All @@ -238,7 +238,7 @@ export default defineComponent({
},

mountType() {
return this.source._attributes['mount-type']
return this.source.attributes['mount-type']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅😅😅😅

},
},

Expand Down
6 changes: 4 additions & 2 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { PropType } from 'vue'
import type { ComponentPublicInstance, PropType } from 'vue'

import { showError } from '@nextcloud/dialogs'
import { FileType, Permission, Folder, File as NcFile, NodeStatus, Node, View } from '@nextcloud/files'
Expand All @@ -18,6 +18,7 @@ import { getDragAndDropPreview } from '../utils/dragUtils.ts'
import { hashCode } from '../utils/hashUtils.ts'
import { dataTransferToFileTree, onDropExternalFiles, onDropInternalFiles } from '../services/DropService.ts'
import logger from '../logger.js'
import FileEntryActions from '../components/FileEntry/FileEntryActions.vue'

Vue.directive('onClickOutside', vOnClickOutside)

Expand Down Expand Up @@ -212,7 +213,8 @@ export default defineComponent({
return false
}

this.$refs.actions.execDefaultAction(event)
const actions = this.$refs.actions as ComponentPublicInstance<typeof FileEntryActions>
actions.execDefaultAction(event)
},

openDetailsIfAvailable(event) {
Expand Down
24 changes: 24 additions & 0 deletions apps/files/src/components/VirtualList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,17 @@ export default Vue.extend({
return Math.floor(this.filesListWidth / this.itemWidth)
},

/**
* Index of the first item to be rendered
*/
startIndex() {
return Math.max(0, this.index - this.bufferItems)
},

/**
* Number of items to be rendered at the same time
* For list view this is the same as `rowCount`, for grid view this is `rowCount` * `columnCount`
*/
shownItems() {
// If in grid mode, we need to multiply the number of rows by the number of columns
if (this.gridMode) {
Expand All @@ -157,6 +165,7 @@ export default Vue.extend({

return this.rowCount
},

renderedItems(): RecycledPoolItem[] {
if (!this.isReady) {
return []
Expand Down Expand Up @@ -185,20 +194,35 @@ export default Vue.extend({
})
},

/**
* The total number of rows that are available
*/
totalRowCount() {
return Math.floor(this.dataSources.length / this.columnCount)
},

tbodyStyle() {
const isOverScrolled = this.startIndex + this.rowCount > this.dataSources.length
const lastIndex = this.dataSources.length - this.startIndex - this.shownItems
const hiddenAfterItems = Math.floor(Math.min(this.dataSources.length - this.startIndex, lastIndex) / this.columnCount)
return {
paddingTop: `${Math.floor(this.startIndex / this.columnCount) * this.itemHeight}px`,
paddingBottom: isOverScrolled ? 0 : `${hiddenAfterItems * this.itemHeight}px`,
minHeight: `${this.totalRowCount * this.itemHeight + this.beforeHeight}px`,
}
},
},
watch: {
scrollToIndex(index) {
this.scrollTo(index)
},

totalRowCount() {
if (this.scrollToIndex) {
this.$nextTick(() => this.scrollTo(this.scrollToIndex))
}
},

columnCount(columnCount, oldColumnCount) {
if (oldColumnCount === 0) {
// We're initializing, the scroll position
Expand Down
2 changes: 1 addition & 1 deletion apps/files_sharing/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ describe('Open in files action execute tests', () => {
// Silent action
expect(exec).toBe(null)
expect(goToRouteMock).toBeCalledTimes(1)
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo' })
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { dir: '/Foo', openfile: 'true' })
})
})
2 changes: 1 addition & 1 deletion apps/files_sharing/src/actions/openInFilesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const action = new FileAction({
window.OCP.Files.Router.goToRoute(
null, // use default route
{ view: 'files', fileid: node.fileid },
{ dir: node.dirname },
{ dir: node.dirname, openfile: 'true' },
)
return null
},
Expand Down
6 changes: 3 additions & 3 deletions dist/files-init.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/files-main.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/files_sharing-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-init.js.map

Large diffs are not rendered by default.

Loading