import React, { PureComponent } from 'react'; import Dialog from '@mui/material/Dialog'; import DialogTitle from '@mui/material/DialogTitle'; import DialogContent from '@mui/material/DialogContent'; import DialogActions from '@mui/material/DialogActions'; import Button from '@mui/material/Button'; import Typography from '@mui/material/Typography'; import DriveFileRenameOutlineRoundedIcon from '@mui/icons-material/DriveFileRenameOutlineRounded'; import SingleLineTextEdit from 'dashgui/SingleLineTextEdit'; export default class VfsRenameDialog extends PureComponent { constructor(props) { super(props); this.state = { targetPath: props.item?.path || '', error: '', }; } componentDidUpdate(prevProps) { if (!prevProps.open && this.props.open) { this.setState({ targetPath: this.props.item?.path || '', error: '', }); } } handleSubmit = (e) => { e?.preventDefault(); const raw = this.state.targetPath.trim(); if (!raw) { this.setState({ error: 'Bitte gib einen neuen Namen bzw. Pfad ein.' }); return; } if (raw.includes('..') || raw.includes('\\')) { this.setState({ error: 'Ungültige Zeichen im Pfad.' }); return; } const cleanNew = raw.replace(/^[/\\]+/, '').replace(/[/\\]+$/, ''); const cleanOld = String(this.props.item?.path || '').replace(/^[/\\]+/, '').replace(/[/\\]+$/, ''); if (cleanNew === cleanOld) { this.props.onClose?.(); return; } this.props.onRename?.(cleanOld, cleanNew); }; render() { const { open, onClose, isRenaming, item } = this.props; const { targetPath, error } = this.state; const isDir = Boolean(item?.isDirectory); return ( theme.zIndex.modal + 20 }} PaperProps={{ sx: { borderRadius: 3, p: 1 }, }} > {isDir ? 'Ordner umbenennen' : 'Datei umbenennen'}
this.setState({ targetPath: nextVal, error: '' })} error={Boolean(error)} helperText={error} disabled={isRenaming} />
); } }