Skip to content

Commit 99579f0

Browse files
committed
fix(files): do not show extension warning for folders renaming
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent ff86bac commit 99579f0

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

apps/files/src/store/renaming.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { RenamingStore } from '../types'
77

88
import axios, { isAxiosError } from '@nextcloud/axios'
99
import { emit, subscribe } from '@nextcloud/event-bus'
10-
import { NodeStatus } from '@nextcloud/files'
10+
import { FileType, NodeStatus } from '@nextcloud/files'
1111
import { DialogBuilder } from '@nextcloud/dialogs'
1212
import { t } from '@nextcloud/l10n'
1313
import { basename, dirname, extname } from 'path'
@@ -103,10 +103,10 @@ export const useRenamingStore = function(...args) {
103103
const oldName = this.renamingNode.basename
104104
const oldEncodedSource = this.renamingNode.encodedSource
105105

106-
// Check for extension change
106+
// Check for extension change for files
107107
const oldExtension = extname(oldName)
108108
const newExtension = extname(newName)
109-
if (oldExtension !== newExtension) {
109+
if (oldExtension !== newExtension && this.renamingNode.type === FileType.File) {
110110
const proceed = await showWarningDialog(oldExtension, newExtension)
111111
if (!proceed) {
112112
return false

cypress/e2e/files/files-renaming.cy.ts

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
import type { User } from '@nextcloud/cypress'
7-
import { calculateViewportHeight, getRowForFile, haveValidity, renameFile, triggerActionForFile } from './FilesUtils'
7+
import { calculateViewportHeight, createFolder, getRowForFile, haveValidity, renameFile, triggerActionForFile } from './FilesUtils'
88

99
describe('files: Rename nodes', { testIsolation: true }, () => {
1010
let user: User
@@ -193,4 +193,67 @@ describe('files: Rename nodes', { testIsolation: true }, () => {
193193
.findByRole('textbox', { name: 'Filename' })
194194
.should('not.exist')
195195
})
196+
197+
it('shows warning on extension change', () => {
198+
getRowForFile('file.txt').should('be.visible')
199+
200+
triggerActionForFile('file.txt', 'rename')
201+
getRowForFile('file.txt')
202+
.findByRole('textbox', { name: 'Filename' })
203+
.should('be.visible')
204+
.type('{selectAll}file.md')
205+
.should(haveValidity(''))
206+
.type('{enter}')
207+
208+
// See warning dialog
209+
cy.findByRole('dialog', { name: 'Change file extension' })
210+
.should('be.visible')
211+
.findByRole('button', { name: /use/i })
212+
.click()
213+
214+
// See it is renamed
215+
getRowForFile('file.md').should('be.visible')
216+
})
217+
218+
it('shows warning on extension change and allow cancellation', () => {
219+
getRowForFile('file.txt').should('be.visible')
220+
221+
triggerActionForFile('file.txt', 'rename')
222+
getRowForFile('file.txt')
223+
.findByRole('textbox', { name: 'Filename' })
224+
.should('be.visible')
225+
.type('{selectAll}file.md')
226+
.should(haveValidity(''))
227+
.type('{enter}')
228+
229+
// See warning dialog
230+
cy.findByRole('dialog', { name: 'Change file extension' })
231+
.should('be.visible')
232+
.findByRole('button', { name: /keep/i })
233+
.click()
234+
235+
// See it is not renamed
236+
getRowForFile('file.txt').should('be.visible')
237+
getRowForFile('file.md').should('not.exist')
238+
})
239+
240+
it('does not show warning on folder renaming with a dot', () => {
241+
createFolder('folder.2024')
242+
243+
getRowForFile('folder.2024').should('be.visible')
244+
245+
triggerActionForFile('folder.2024', 'rename')
246+
getRowForFile('folder.2024')
247+
.findByRole('textbox', { name: 'Folder name' })
248+
.should('be.visible')
249+
.type('{selectAll}folder.2025')
250+
.should(haveValidity(''))
251+
.type('{enter}')
252+
253+
// See warning dialog
254+
cy.get('[role=dialog]').should('not.exist')
255+
256+
// See it is not renamed
257+
getRowForFile('folder.2025').should('be.visible')
258+
})
196259
})

0 commit comments

Comments
 (0)