Use newPathname when restoring a renamed file from history (#15534)

GitOrigin-RevId: b8f6b7d6174f814db696002891addb961e76ac9c
This commit is contained in:
Alf Eaton 2023-11-03 11:06:19 +00:00 committed by Copybot
parent a5faeee707
commit 6b8dfaa782

View file

@ -71,17 +71,23 @@ export function useRestoreDeletedFile() {
const restoreDeletedFile = useCallback( const restoreDeletedFile = useCallback(
(selection: HistoryContextValue['selection']) => { (selection: HistoryContextValue['selection']) => {
const { selectedFile } = selection const { selectedFile, files } = selection
if ( if (
selectedFile && selectedFile &&
selectedFile.pathname && selectedFile.pathname &&
isFileRemoved(selectedFile) isFileRemoved(selectedFile)
) { ) {
const file = files.find(file => file.pathname === selectedFile.pathname)
if (file && isFileRemoved(file)) {
sendMB('history-v2-restore-deleted') sendMB('history-v2-restore-deleted')
setState('restoring') setState('restoring')
restoreFile(projectId, selectedFile).then(
restoreFile(projectId, {
...selectedFile,
pathname: file.newPathname ?? file.pathname,
}).then(
(data: RestoreFileResponse) => { (data: RestoreFileResponse) => {
setRestoredFileMetadata(data) setRestoredFileMetadata(data)
setState('waitingForFileTree') setState('waitingForFileTree')
@ -92,6 +98,7 @@ export function useRestoreDeletedFile() {
} }
) )
} }
}
}, },
[handleError, projectId] [handleError, projectId]
) )