From bbe3f4a88049707249fc215d593788e83377637b Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Mon, 15 Apr 2024 18:09:37 +0200 Subject: [PATCH] fix(files): Inherit some node attributes when creating new nodes to preserve shared state Signed-off-by: Ferdinand Thiessen --- .../components/FileEntry/FileEntryActions.vue | 8 +++----- apps/files/src/newMenu/newFolder.ts | 6 ++++++ apps/files/src/newMenu/newFromTemplate.ts | 14 +++++++++++--- apps/files/src/views/TemplatePicker.vue | 16 +++++++++++++++- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/apps/files/src/components/FileEntry/FileEntryActions.vue b/apps/files/src/components/FileEntry/FileEntryActions.vue index ff28369049b..6e5d78518f7 100644 --- a/apps/files/src/components/FileEntry/FileEntryActions.vue +++ b/apps/files/src/components/FileEntry/FileEntryActions.vue @@ -105,8 +105,7 @@ import NcActionSeparator from '@nextcloud/vue/dist/Components/NcActionSeparator. 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 ChevronRightIcon from 'vue-material-design-icons/ChevronRight.vue' -import Vue from 'vue' +import Vue, { defineComponent } from 'vue' import CustomElementRender from '../CustomElementRender.vue' import logger from '../../logger.js' @@ -114,12 +113,11 @@ import logger from '../../logger.js' // The registered actions list const actions = getFileActions() -export default Vue.extend({ +export default defineComponent({ name: 'FileEntryActions', components: { ArrowLeftIcon, - ChevronRightIcon, CustomElementRender, NcActionButton, NcActions, @@ -337,7 +335,7 @@ export default Vue.extend({ // Focus the previous menu action button this.$nextTick(() => { // Focus the action button - const menuAction = this.$refs[`action-${action.id}`][0] + const menuAction = this.$refs[`action-${action.id}`]?.[0] if (menuAction) { menuAction.$el.querySelector('button')?.focus() } diff --git a/apps/files/src/newMenu/newFolder.ts b/apps/files/src/newMenu/newFolder.ts index 64ab8004e78..5d378cab438 100644 --- a/apps/files/src/newMenu/newFolder.ts +++ b/apps/files/src/newMenu/newFolder.ts @@ -74,6 +74,12 @@ export const entry = { owner: getCurrentUser()?.uid || null, permissions: Permission.ALL, root: context?.root || '/files/' + getCurrentUser()?.uid, + // Include mount-type from parent folder as this is inherited + attributes: { + 'mount-type': context.attributes?.['mount-type'], + 'owner-id': context.attributes?.['owner-id'], + 'owner-display-name': context.attributes?.['owner-display-name'], + }, }) showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) })) diff --git a/apps/files/src/newMenu/newFromTemplate.ts b/apps/files/src/newMenu/newFromTemplate.ts index 42e24c59de0..8e3ec4821fa 100644 --- a/apps/files/src/newMenu/newFromTemplate.ts +++ b/apps/files/src/newMenu/newFromTemplate.ts @@ -36,7 +36,7 @@ import Vue, { defineAsyncComponent } from 'vue' const TemplatePickerVue = defineAsyncComponent(() => import('../views/TemplatePicker.vue')) let TemplatePicker: ComponentInstance & { open: (n: string, t: TemplateFile) => void } | null = null -const getTemplatePicker = async () => { +const getTemplatePicker = async (context: Folder) => { if (TemplatePicker === null) { // Create document root const mountingPoint = document.createElement('div') @@ -45,7 +45,15 @@ const getTemplatePicker = async () => { // Init vue app TemplatePicker = new Vue({ - render: (h) => h(TemplatePickerVue, { ref: 'picker' }), + render: (h) => h( + TemplatePickerVue, + { + ref: 'picker', + props: { + parent: context, + }, + }, + ), methods: { open(...args) { this.$refs.picker.open(...args) } }, el: mountingPoint, }) @@ -71,7 +79,7 @@ export function registerTemplateEntries() { }, order: 11, async handler(context: Folder, content: Node[]) { - const templatePicker = getTemplatePicker() + const templatePicker = getTemplatePicker(context) const name = await newNodeName(`${provider.label}${provider.extension}`, content, { label: t('files', 'Filename'), name: provider.label, diff --git a/apps/files/src/views/TemplatePicker.vue b/apps/files/src/views/TemplatePicker.vue index dce081f5733..e235a9e6054 100644 --- a/apps/files/src/views/TemplatePicker.vue +++ b/apps/files/src/views/TemplatePicker.vue @@ -90,6 +90,16 @@ export default defineComponent({ TemplatePreview, }, + props: { + /** + * The parent folder where to create the node + */ + parent: { + type: Object, + default: () => null, + }, + }, + data() { return { // Check empty template by default @@ -109,7 +119,7 @@ export default defineComponent({ nameWithoutExt() { // Strip extension from name if defined return !this.extension - ? this.name + ? this.name! : this.name!.slice(0, 0 - this.extension.length) }, @@ -236,6 +246,10 @@ export default defineComponent({ size: fileInfo.size, permissions: fileInfo.permissions, attributes: { + // Inherit some attributes from parent folder like the mount type and real owner + 'mount-type': this.parent?.attributes?.['mount-type'], + 'owner-id': this.parent?.attributes?.['owner-id'], + 'owner-display-name': this.parent?.attributes?.['owner-display-name'], ...fileInfo, 'has-preview': fileInfo.hasPreview, },