{
+ setShowConfirmModal(false)
+ revertSelectedFile(selection)
+ }}
+ onHide={() => setShowConfirmModal(false)}
+ />
+
+ >
)
}
-function ToolbarRevertErrorModal({
- resetErrorBoundary,
-}: {
- resetErrorBoundary: VoidFunction
-}) {
- const { t } = useTranslation()
-
- return (
-
-
- {t('revert_file_error_title')}
-
- {t('revert_file_error_message')}
-
-
-
-
- )
-}
-
-export default withErrorBoundary(
- ToolbarRevertFileButton,
- ToolbarRevertErrorModal
-)
+export default withErrorBoundary(ToolbarRevertFileButton, RevertFileErrorModal)
diff --git a/services/web/frontend/js/features/history/components/diff-view/toolbar/toolbar.tsx b/services/web/frontend/js/features/history/components/diff-view/toolbar/toolbar.tsx
index 261608b863..92cbbe565e 100644
--- a/services/web/frontend/js/features/history/components/diff-view/toolbar/toolbar.tsx
+++ b/services/web/frontend/js/features/history/components/diff-view/toolbar/toolbar.tsx
@@ -14,15 +14,14 @@ type ToolbarProps = {
}
export default function Toolbar({ diff, selection }: ToolbarProps) {
- const hasRevertFiles = useFeatureFlag('revert-files')
+ const hasRevertFile = useFeatureFlag('revert-file')
+
+ const showRevertFileButton = hasRevertFile && selection.selectedFile
const showRestoreFileButton =
- selection.selectedFile && isFileRemoved(selection.selectedFile)
-
- const showRevertFileButton =
- hasRevertFiles &&
selection.selectedFile &&
- !isFileRemoved(selection.selectedFile)
+ isFileRemoved(selection.selectedFile) &&
+ !showRevertFileButton
return (
diff --git a/services/web/frontend/js/features/history/context/hooks/use-revert-selected-file.ts b/services/web/frontend/js/features/history/context/hooks/use-revert-selected-file.ts
index d6bd2d5992..545819a14f 100644
--- a/services/web/frontend/js/features/history/context/hooks/use-revert-selected-file.ts
+++ b/services/web/frontend/js/features/history/context/hooks/use-revert-selected-file.ts
@@ -75,14 +75,15 @@ export function useRevertSelectedFile() {
(selection: HistoryContextValue['selection']) => {
const { selectedFile, files } = selection
- if (
- selectedFile &&
- selectedFile.pathname &&
- !isFileRemoved(selectedFile)
- ) {
+ if (selectedFile && selectedFile.pathname) {
const file = files.find(file => file.pathname === selectedFile.pathname)
- const toVersion = selection.updateRange?.toV
- if (file && !isFileRemoved(file) && toVersion) {
+
+ if (file) {
+ const deletedAtV = isFileRemoved(file) ? file.deletedAtV : undefined
+ const toVersion = deletedAtV ?? selection.updateRange?.toV
+ if (!toVersion) {
+ return
+ }
setState('reverting')
revertFile(projectId, file.pathname, toVersion).then(
diff --git a/services/web/locales/en.json b/services/web/locales/en.json
index 3bdca2e0d5..fa9fb173b6 100644
--- a/services/web/locales/en.json
+++ b/services/web/locales/en.json
@@ -1549,6 +1549,8 @@
"return_to_login_page": "Return to Login page",
"reverse_x_sort_order": "Reverse __x__ sort order",
"revert_file": "Revert file",
+ "revert_file_confirmation_message": "Your current file will revert to the version from __date__ at __time__.",
+ "revert_file_confirmation_title": "Restore this version?",
"revert_file_error_message": "There was a problem reverting the file version. Please try again in a few moments. If the problem continues please contact us.",
"revert_file_error_title": "Revert File Error",
"revert_pending_plan_change": "Revert scheduled plan change",