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