Skip to content

Commit 11fe1ca

Browse files
susnuxbackportbot[bot]
authored andcommitted
fix(files): Inherit some node attributes when creating new nodes to preserve shared state
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de> [skip ci]
1 parent 3091c31 commit 11fe1ca

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

apps/files/src/components/FileEntry/FileEntryActions.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,11 @@ import logger from '../../logger.js'
112112
// The registered actions list
113113
const actions = getFileActions()
114114
115-
export default Vue.extend({
115+
export default defineComponent({
116116
name: 'FileEntryActions',
117117
118118
components: {
119119
ArrowLeftIcon,
120-
ChevronRightIcon,
121120
CustomElementRender,
122121
NcActionButton,
123122
NcActions,
@@ -335,7 +334,7 @@ export default Vue.extend({
335334
// Focus the previous menu action button
336335
this.$nextTick(() => {
337336
// Focus the action button
338-
const menuAction = this.$refs[`action-${action.id}`][0]
337+
const menuAction = this.$refs[`action-${action.id}`]?.[0]
339338
if (menuAction) {
340339
menuAction.$el.querySelector('button')?.focus()
341340
}

apps/files/src/newMenu/newFolder.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export const entry = {
7474
owner: getCurrentUser()?.uid || null,
7575
permissions: Permission.ALL,
7676
root: context?.root || '/files/' + getCurrentUser()?.uid,
77+
// Include mount-type from parent folder as this is inherited
78+
attributes: {
79+
'mount-type': context.attributes?.['mount-type'],
80+
'owner-id': context.attributes?.['owner-id'],
81+
'owner-display-name': context.attributes?.['owner-display-name'],
82+
},
7783
})
7884

7985
showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) }))

apps/files/src/newMenu/newFromTemplate.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import Vue, { defineAsyncComponent } from 'vue'
3636
const TemplatePickerVue = defineAsyncComponent(() => import('../views/TemplatePicker.vue'))
3737
let TemplatePicker: ComponentInstance & { open: (n: string, t: TemplateFile) => void } | null = null
3838

39-
const getTemplatePicker = async () => {
39+
const getTemplatePicker = async (context: Folder) => {
4040
if (TemplatePicker === null) {
4141
// Create document root
4242
const mountingPoint = document.createElement('div')
@@ -45,7 +45,15 @@ const getTemplatePicker = async () => {
4545

4646
// Init vue app
4747
TemplatePicker = new Vue({
48-
render: (h) => h(TemplatePickerVue, { ref: 'picker' }),
48+
render: (h) => h(
49+
TemplatePickerVue,
50+
{
51+
ref: 'picker',
52+
props: {
53+
parent: context,
54+
},
55+
},
56+
),
4957
methods: { open(...args) { this.$refs.picker.open(...args) } },
5058
el: mountingPoint,
5159
})
@@ -71,7 +79,7 @@ export function registerTemplateEntries() {
7179
},
7280
order: 11,
7381
async handler(context: Folder, content: Node[]) {
74-
const templatePicker = getTemplatePicker()
82+
const templatePicker = getTemplatePicker(context)
7583
const name = await newNodeName(`${provider.label}${provider.extension}`, content, {
7684
label: t('files', 'Filename'),
7785
name: provider.label,

apps/files/src/views/TemplatePicker.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ export default defineComponent({
9090
TemplatePreview,
9191
},
9292
93+
props: {
94+
/**
95+
* The parent folder where to create the node
96+
*/
97+
parent: {
98+
type: Object,
99+
default: () => null,
100+
},
101+
},
102+
93103
data() {
94104
return {
95105
// Check empty template by default
@@ -109,7 +119,7 @@ export default defineComponent({
109119
nameWithoutExt() {
110120
// Strip extension from name if defined
111121
return !this.extension
112-
? this.name
122+
? this.name!
113123
: this.name!.slice(0, 0 - this.extension.length)
114124
},
115125
@@ -236,6 +246,10 @@ export default defineComponent({
236246
size: fileInfo.size,
237247
permissions: fileInfo.permissions,
238248
attributes: {
249+
// Inherit some attributes from parent folder like the mount type and real owner
250+
'mount-type': this.parent?.attributes?.['mount-type'],
251+
'owner-id': this.parent?.attributes?.['owner-id'],
252+
'owner-display-name': this.parent?.attributes?.['owner-display-name'],
239253
...fileInfo,
240254
'has-preview': fileInfo.hasPreview,
241255
},

0 commit comments

Comments
 (0)