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

fix(files): do not show extension warning for folders renaming #50904

Merged
merged 2 commits into from
Feb 19, 2025
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
6 changes: 3 additions & 3 deletions apps/files/src/store/renaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import axios, { isAxiosError } from '@nextcloud/axios'
import { emit, subscribe } from '@nextcloud/event-bus'
import { NodeStatus } from '@nextcloud/files'
import { FileType, NodeStatus } from '@nextcloud/files'
import { DialogBuilder } from '@nextcloud/dialogs'
import { t } from '@nextcloud/l10n'
import { basename, dirname, extname } from 'path'
Expand Down Expand Up @@ -91,7 +91,7 @@
/**
* Execute the renaming.
* This will rename the node set as `renamingNode` to the configured new name `newName`.
* @return true if success, false if skipped (e.g. new and old name are the same)

Check warning on line 94 in apps/files/src/store/renaming.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Missing JSDoc @return type
* @throws Error if renaming fails, details are set in the error message
*/
async rename(): Promise<boolean> {
Expand All @@ -103,10 +103,10 @@
const oldName = this.renamingNode.basename
const oldEncodedSource = this.renamingNode.encodedSource

// Check for extension change
// Check for extension change for files
const oldExtension = extname(oldName)
const newExtension = extname(newName)
if (oldExtension !== newExtension) {
if (oldExtension !== newExtension && this.renamingNode.type === FileType.File) {
const proceed = await showWarningDialog(oldExtension, newExtension)
if (!proceed) {
return false
Expand Down
65 changes: 64 additions & 1 deletion cypress/e2e/files/files-renaming.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

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

describe('files: Rename nodes', { testIsolation: true }, () => {
let user: User
Expand Down Expand Up @@ -193,4 +193,67 @@ describe('files: Rename nodes', { testIsolation: true }, () => {
.findByRole('textbox', { name: 'Filename' })
.should('not.exist')
})

it('shows warning on extension change', () => {
getRowForFile('file.txt').should('be.visible')

triggerActionForFile('file.txt', 'rename')
getRowForFile('file.txt')
.findByRole('textbox', { name: 'Filename' })
.should('be.visible')
.type('{selectAll}file.md')
.should(haveValidity(''))
.type('{enter}')

// See warning dialog
cy.findByRole('dialog', { name: 'Change file extension' })
.should('be.visible')
.findByRole('button', { name: /use/i })
.click()

// See it is renamed
getRowForFile('file.md').should('be.visible')
})

it('shows warning on extension change and allow cancellation', () => {
getRowForFile('file.txt').should('be.visible')

triggerActionForFile('file.txt', 'rename')
getRowForFile('file.txt')
.findByRole('textbox', { name: 'Filename' })
.should('be.visible')
.type('{selectAll}file.md')
.should(haveValidity(''))
.type('{enter}')

// See warning dialog
cy.findByRole('dialog', { name: 'Change file extension' })
.should('be.visible')
.findByRole('button', { name: /keep/i })
.click()

// See it is not renamed
getRowForFile('file.txt').should('be.visible')
getRowForFile('file.md').should('not.exist')
})

it('does not show warning on folder renaming with a dot', () => {
createFolder('folder.2024')

getRowForFile('folder.2024').should('be.visible')

triggerActionForFile('folder.2024', 'rename')
getRowForFile('folder.2024')
.findByRole('textbox', { name: 'Folder name' })
.should('be.visible')
.type('{selectAll}folder.2025')
.should(haveValidity(''))
.type('{enter}')

// See warning dialog
cy.get('[role=dialog]').should('not.exist')

// See it is not renamed
getRowForFile('folder.2025').should('be.visible')
})
})
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

Loading