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

refactor(files): Update @nextcloud/files to v3.5.1 #45929

Merged
merged 5 commits into from
Jun 23, 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
3 changes: 1 addition & 2 deletions apps/files/src/actions/moveOrCopyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { MoveCopyResult } from './moveOrCopyActionUtils'
import { isAxiosError } from '@nextcloud/axios'
import { FilePickerClosed, getFilePickerBuilder, showError } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { Permission, FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind } from '@nextcloud/files'
import { FileAction, FileType, NodeStatus, davGetClient, davRootPath, davResultToNode, davGetDefaultPropfind, getUniqueName } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import { openConflictPicker, hasConflict } from '@nextcloud/upload'
import { basename, join } from 'path'
Expand All @@ -22,7 +22,6 @@ import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw'
import { MoveCopyAction, canCopy, canMove, getQueue } from './moveOrCopyActionUtils'
import { getContents } from '../services/Files'
import logger from '../logger'
import { getUniqueName } from '../utils/fileUtils'

/**
* Return the action that is possible for the given nodes
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const action = new FileAction({
id: 'open-folder',
displayName(files: Node[]) {
// Only works on single node
const displayName = files[0].attributes.displayName || files[0].basename
const displayName = files[0].attributes.displayname || files[0].basename
return t('files', 'Open folder {displayName}', { displayName })
},
iconSvgInline: () => FolderSvg,
Expand Down
22 changes: 13 additions & 9 deletions apps/files/src/components/BreadCrumbs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<script lang="ts">
import type { Node } from '@nextcloud/files'
import type { FileSource } from '../types.ts'

import { basename } from 'path'
import { defineComponent } from 'vue'
Expand All @@ -45,6 +46,7 @@ import NcBreadcrumb from '@nextcloud/vue/dist/Components/NcBreadcrumb.js'
import NcBreadcrumbs from '@nextcloud/vue/dist/Components/NcBreadcrumbs.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'

import { useNavigation } from '../composables/useNavigation'
import { onDropInternalFiles, dataTransferToFileTree, onDropExternalFiles } from '../services/DropService'
import { showError } from '@nextcloud/dialogs'
import { useDragAndDropStore } from '../store/dragging.ts'
Expand All @@ -54,7 +56,6 @@ import { useSelectionStore } from '../store/selection.ts'
import { useUploaderStore } from '../store/uploader.ts'
import filesListWidthMixin from '../mixins/filesListWidth.ts'
import logger from '../logger'
import type { FileSource } from '../types.ts'

export default defineComponent({
name: 'BreadCrumbs',
Expand Down Expand Up @@ -82,21 +83,20 @@ export default defineComponent({
const pathsStore = usePathsStore()
const selectionStore = useSelectionStore()
const uploaderStore = useUploaderStore()
const { currentView } = useNavigation()

return {
draggingStore,
filesStore,
pathsStore,
selectionStore,
uploaderStore,

currentView,
}
},

computed: {
currentView() {
return this.$navigation.active
},

dirs(): string[] {
const cumulativePath = (acc: string) => (value: string) => (acc += `${value}/`)
// Generate a cumulative path for each path segment: ['/', '/foo', '/foo/bar', ...] etc
Expand Down Expand Up @@ -150,17 +150,17 @@ export default defineComponent({
getNodeFromSource(source: FileSource): Node | undefined {
return this.filesStore.getNode(source)
},
getFileSourceFromPath(path: string): FileSource | undefined {
return this.pathsStore.getPath(this.currentView?.id, path)
getFileSourceFromPath(path: string): FileSource | null {
return (this.currentView && this.pathsStore.getPath(this.currentView.id, path)) ?? null
},
getDirDisplayName(path: string): string {
if (path === '/') {
return this.$navigation?.active?.name || t('files', 'Home')
}

const source: FileSource | undefined = this.getFileSourceFromPath(path)
const source: FileSource | null = this.getFileSourceFromPath(path)
const node: Node | undefined = source ? this.getNodeFromSource(source) : undefined
return node?.attributes?.displayName || basename(path)
return node?.attributes?.displayname || basename(path)
},

onClick(to) {
Expand All @@ -170,6 +170,10 @@ export default defineComponent({
},

onDragOver(event: DragEvent, path: string) {
if (!event.dataTransfer) {
return
}

// Cannot drop on the current directory
if (path === this.dirs[this.dirs.length - 1]) {
event.dataTransfer.dropEffect = 'none'
Expand Down
22 changes: 14 additions & 8 deletions apps/files/src/components/DragAndDropNotice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { Folder, Permission } from '@nextcloud/files'
import type { Folder } from '@nextcloud/files'
import { Permission } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { UploadStatus } from '@nextcloud/upload'
import { defineComponent, type PropType } from 'vue'

import TrayArrowDownIcon from 'vue-material-design-icons/TrayArrowDown.vue'

import logger from '../logger.js'
import { useNavigation } from '../composables/useNavigation'
import { dataTransferToFileTree, onDropExternalFiles } from '../services/DropService'
import logger from '../logger.js'

export default defineComponent({
name: 'DragAndDropNotice',
Expand All @@ -46,22 +48,26 @@ export default defineComponent({

props: {
currentFolder: {
type: Folder,
type: Object as PropType<Folder>,
required: true,
},
},

setup() {
const { currentView } = useNavigation()

return {
currentView,
}
},

data() {
return {
dragover: false,
}
},

computed: {
currentView() {
return this.$navigation.active
},

/**
* Check if the current folder has create permissions
*/
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/DragAndDropPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default Vue.extend({
summary(): string {
if (this.isSingleNode) {
const node = this.nodes[0]
return node.attributes?.displayName || node.basename
return node.attributes?.displayname || node.basename
}

return getSummaryFor(this.nodes)
Expand Down
16 changes: 11 additions & 5 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@

<script lang="ts">
import { defineComponent } from 'vue'
import { Permission, formatFileSize } from '@nextcloud/files'
import { formatFileSize } from '@nextcloud/files'
import moment from '@nextcloud/moment'

import { useNavigation } from '../composables/useNavigation'
import { useActionsMenuStore } from '../store/actionsmenu.ts'
import { useDragAndDropStore } from '../store/dragging.ts'
import { useFilesStore } from '../store/files.ts'
Expand Down Expand Up @@ -140,12 +141,16 @@ export default defineComponent({
const filesStore = useFilesStore()
const renamingStore = useRenamingStore()
const selectionStore = useSelectionStore()
const { currentView } = useNavigation()

return {
actionsMenuStore,
draggingStore,
filesStore,
renamingStore,
selectionStore,

currentView,
}
},

Expand Down Expand Up @@ -179,21 +184,22 @@ export default defineComponent({
},

size() {
const size = parseInt(this.source.size, 10)
if (typeof size !== 'number' || isNaN(size) || size < 0) {
const size = this.source.size
if (!size || size < 0) {
return this.t('files', 'Pending')
}
return formatFileSize(size, true)
},

sizeOpacity() {
const maxOpacitySize = 10 * 1024 * 1024

const size = parseInt(this.source.size, 10)
const size = this.source.size
if (!size || isNaN(size) || size < 0) {
return {}
}

const ratio = Math.round(Math.min(100, 100 * Math.pow((this.source.size / maxOpacitySize), 2)))
const ratio = Math.round(Math.min(100, 100 * Math.pow((size / maxOpacitySize), 2)))
return {
color: `color-mix(in srgb, var(--color-main-text) ${ratio}%, var(--color-text-maxcontrast))`,
}
Expand Down
24 changes: 16 additions & 8 deletions apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,22 @@
</template>

<script lang="ts">
import type { PropType } from 'vue'
import type { PropType, ShallowRef } from 'vue'
import type { FileAction, Node, View } from '@nextcloud/files'

import { DefaultType, FileAction, Node, NodeStatus, View, getFileActions } from '@nextcloud/files'
import { DefaultType, NodeStatus, getFileActions } from '@nextcloud/files'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import { defineComponent } from 'vue'

import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
import NcActionSeparator from '@nextcloud/vue/dist/Components/NcActionSeparator.js'
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
import NcLoadingIcon from '@nextcloud/vue/dist/Components/NcLoadingIcon.js'
import ArrowLeftIcon from 'vue-material-design-icons/ArrowLeft.vue'
import Vue, { defineComponent } from 'vue'

import { useNavigation } from '../../composables/useNavigation'
import CustomElementRender from '../CustomElementRender.vue'
import logger from '../../logger.js'

Expand Down Expand Up @@ -132,6 +134,15 @@ export default defineComponent({
},
},

setup() {
const { currentView } = useNavigation()

return {
// The file list is guaranteed to be only shown with active view
currentView: currentView as ShallowRef<View>,
}
},

data() {
return {
openedSubmenu: null as FileAction | null,
Expand All @@ -143,9 +154,6 @@ export default defineComponent({
// Remove any trailing slash but leave root slash
return (this.$route?.query?.dir?.toString() || '/').replace(/^(.+)\/$/, '$1')
},
currentView(): View {
return this.$navigation.active as View
},
isLoading() {
return this.source.status === NodeStatus.LOADING
},
Expand Down Expand Up @@ -269,7 +277,7 @@ export default defineComponent({
try {
// Set the loading marker
this.$emit('update:loading', action.id)
Vue.set(this.source, 'status', NodeStatus.LOADING)
this.$set(this.source, 'status', NodeStatus.LOADING)

const success = await action.exec(this.source, this.currentView, this.currentDir)

Expand All @@ -289,7 +297,7 @@ export default defineComponent({
} finally {
// Reset the loading marker
this.$emit('update:loading', '')
Vue.set(this.source, 'status', undefined)
this.$set(this.source, 'status', undefined)

// If that was a submenu, we just go back after the action
if (isSubmenu) {
Expand Down
17 changes: 9 additions & 8 deletions apps/files/src/components/FileEntry/FileEntryName.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>

<script lang="ts">
import type { Node, View } from '@nextcloud/files'
import type { Node } from '@nextcloud/files'
import type { PropType } from 'vue'

import { showError, showSuccess } from '@nextcloud/dialogs'
Expand All @@ -46,10 +46,11 @@ import { FileType, NodeStatus, Permission } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { translate as t } from '@nextcloud/l10n'
import axios, { isAxiosError } from '@nextcloud/axios'
import Vue, { defineComponent } from 'vue'
import { defineComponent } from 'vue'

import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'

import { useNavigation } from '../../composables/useNavigation'
import { useRenamingStore } from '../../store/renaming.ts'
import logger from '../../logger.js'

Expand Down Expand Up @@ -90,17 +91,17 @@ export default defineComponent({
},

setup() {
const { currentView } = useNavigation()
const renamingStore = useRenamingStore()

return {
currentView,

renamingStore,
}
},

computed: {
currentView(): View {
return this.$navigation.active as View
},

isRenaming() {
return this.renamingStore.renamingNode === this.source
},
Expand Down Expand Up @@ -282,7 +283,7 @@ export default defineComponent({
}

// Set loading state
Vue.set(this.source, 'status', NodeStatus.LOADING)
this.$set(this.source, 'status', NodeStatus.LOADING)

// Update node
this.source.rename(newName)
Expand Down Expand Up @@ -327,7 +328,7 @@ export default defineComponent({
// Unknown error
showError(t('files', 'Could not rename "{oldName}"', { oldName }))
} finally {
Vue.set(this.source, 'status', undefined)
this.$set(this.source, 'status', undefined)
}
},

Expand Down
5 changes: 5 additions & 0 deletions apps/files/src/components/FileEntryGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<script lang="ts">
import { defineComponent } from 'vue'

import { useNavigation } from '../composables/useNavigation'
import { useActionsMenuStore } from '../store/actionsmenu.ts'
import { useDragAndDropStore } from '../store/dragging.ts'
import { useFilesStore } from '../store/files.ts'
Expand Down Expand Up @@ -93,12 +94,16 @@ export default defineComponent({
const filesStore = useFilesStore()
const renamingStore = useRenamingStore()
const selectionStore = useSelectionStore()
const { currentView } = useNavigation()

return {
actionsMenuStore,
draggingStore,
filesStore,
renamingStore,
selectionStore,

currentView,
}
},

Expand Down
Loading
Loading