aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/src/newMenu/newFolder.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/src/newMenu/newFolder.ts')
-rw-r--r--apps/files/src/newMenu/newFolder.ts86
1 files changed, 46 insertions, 40 deletions
diff --git a/apps/files/src/newMenu/newFolder.ts b/apps/files/src/newMenu/newFolder.ts
index 37dcf6d3d89..f0f854d2801 100644
--- a/apps/files/src/newMenu/newFolder.ts
+++ b/apps/files/src/newMenu/newFolder.ts
@@ -1,23 +1,6 @@
/**
- * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { Entry, Node } from '@nextcloud/files'
@@ -25,13 +8,13 @@ import { basename } from 'path'
import { emit } from '@nextcloud/event-bus'
import { getCurrentUser } from '@nextcloud/auth'
import { Permission, Folder } from '@nextcloud/files'
-import { showSuccess } from '@nextcloud/dialogs'
+import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
-import FolderPlusSvg from '@mdi/svg/svg/folder-plus.svg?raw'
+import FolderPlusSvg from '@mdi/svg/svg/folder-plus-outline.svg?raw'
-import { getUniqueName } from '../utils/fileUtils.ts'
+import { newNodeName } from '../utils/newNodeDialog'
import logger from '../logger'
type createFolderResponse = {
@@ -59,27 +42,50 @@ const createNewFolder = async (root: Folder, name: string): Promise<createFolder
export const entry = {
id: 'newFolder',
displayName: t('files', 'New folder'),
- enabled: (context: Folder) => (context.permissions & Permission.CREATE) !== 0,
- iconSvgInline: FolderPlusSvg,
+ enabled: (context: Folder) => Boolean(context.permissions & Permission.CREATE) && Boolean(context.permissions & Permission.READ),
+
+ // Make the svg icon color match the primary element color
+ iconSvgInline: FolderPlusSvg.replace(/viewBox/gi, 'style="color: var(--color-primary-element)" viewBox'),
order: 0,
+
async handler(context: Folder, content: Node[]) {
- const contentNames = content.map((node: Node) => node.basename)
- const name = getUniqueName(t('files', 'New folder'), contentNames)
- const { fileid, source } = await createNewFolder(context, name)
+ const name = await newNodeName(t('files', 'New folder'), content)
+ if (name === null) {
+ return
+ }
+ try {
+ const { fileid, source } = await createNewFolder(context, name.trim())
+
+ // Create the folder in the store
+ const folder = new Folder({
+ source,
+ id: fileid,
+ mtime: new Date(),
+ owner: context.owner,
+ 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'],
+ },
+ })
- // Create the folder in the store
- const folder = new Folder({
- source,
- id: fileid,
- mtime: new Date(),
- owner: getCurrentUser()?.uid || null,
- permissions: Permission.ALL,
- root: context?.root || '/files/' + getCurrentUser()?.uid,
- })
+ // Show success
+ emit('files:node:created', folder)
+ showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) }))
+ logger.debug('Created new folder', { folder, source })
- showSuccess(t('files', 'Created new folder "{name}"', { name: basename(source) }))
- logger.debug('Created new folder', { folder, source })
- emit('files:node:created', folder)
- emit('files:node:rename', folder)
+ // Navigate to the new folder
+ window.OCP.Files.Router.goToRoute(
+ null, // use default route
+ { view: 'files', fileid: String(fileid) },
+ { dir: context.path },
+ )
+ } catch (error) {
+ logger.error('Creating new folder failed', { error })
+ showError('Creating new folder failed')
+ }
},
} as Entry