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,26 +71,33 @@ export function useRestoreDeletedFile() {
const restoreDeletedFile = useCallback(
(selection: HistoryContextValue['selection']) => {
const { selectedFile } = selection
const { selectedFile, files } = selection
if (
selectedFile &&
selectedFile.pathname &&
isFileRemoved(selectedFile)
) {
sendMB('history-v2-restore-deleted')
const file = files.find(file => file.pathname === selectedFile.pathname)
if (file && isFileRemoved(file)) {
sendMB('history-v2-restore-deleted')
setState('restoring')
restoreFile(projectId, selectedFile).then(
(data: RestoreFileResponse) => {
setRestoredFileMetadata(data)
setState('waitingForFileTree')
},
error => {
setState('error')
handleError(error)
}
)
setState('restoring')
restoreFile(projectId, {
...selectedFile,
pathname: file.newPathname ?? file.pathname,
}).then(
(data: RestoreFileResponse) => {
setRestoredFileMetadata(data)
setState('waitingForFileTree')
},
error => {
setState('error')
handleError(error)
}
)
}
}
},
[handleError, projectId]