diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index 8d998621db..3769b05e32 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -1101,19 +1101,18 @@ "resolved_comments": "", "restore": "", "restore_file": "", + "restore_file_confirmation_message": "", + "restore_file_confirmation_title": "", + "restore_file_error_message": "", + "restore_file_error_title": "", + "restore_file_version": "", "restoring": "", "resync_completed": "", "resync_message": "", "resync_project_history": "", "retry_test": "", "reverse_x_sort_order": "", - "revert_file": "", - "revert_file_confirmation_message": "", - "revert_file_confirmation_title": "", - "revert_file_error_message": "", - "revert_file_error_title": "", "revert_pending_plan_change": "", - "reverting": "", "review": "", "review_your_peers_work": "", "revoke": "", diff --git a/services/web/frontend/js/features/history/components/diff-view/modals/revert-file-confirm-modal.tsx b/services/web/frontend/js/features/history/components/diff-view/modals/restore-file-confirm-modal.tsx similarity index 78% rename from services/web/frontend/js/features/history/components/diff-view/modals/revert-file-confirm-modal.tsx rename to services/web/frontend/js/features/history/components/diff-view/modals/restore-file-confirm-modal.tsx index 778e9d02b8..eb28ec71f6 100644 --- a/services/web/frontend/js/features/history/components/diff-view/modals/revert-file-confirm-modal.tsx +++ b/services/web/frontend/js/features/history/components/diff-view/modals/restore-file-confirm-modal.tsx @@ -3,19 +3,19 @@ import { useMemo } from 'react' import { Button, Modal } from 'react-bootstrap' import { useTranslation } from 'react-i18next' -type RevertFileConfirmModalProps = { +type RestoreFileConfirmModalProps = { show: boolean timestamp: number onConfirm: () => void onHide: () => void } -export function RevertFileConfirmModal({ +export function RestoreFileConfirmModal({ show, timestamp, onConfirm, onHide, -}: RevertFileConfirmModalProps) { +}: RestoreFileConfirmModalProps) { const { t } = useTranslation() const date = useMemo(() => formatTime(timestamp, 'Do MMMM'), [timestamp]) const time = useMemo(() => formatTime(timestamp, 'h:mm a'), [timestamp]) @@ -23,10 +23,10 @@ export function RevertFileConfirmModal({ return ( - {t('revert_file_confirmation_title')} + {t('restore_file_confirmation_title')} - {t('revert_file_confirmation_message', { date, time })} + {t('restore_file_confirmation_message', { date, time })} ) } -export default withErrorBoundary(ToolbarRevertFileButton, RevertFileErrorModal) +export default withErrorBoundary( + ToolbarRestoreFileToVersionButton, + RestoreFileErrorModal +) 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 92cbbe565e..ce352582e2 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 @@ -5,7 +5,7 @@ import ToolbarDatetime from './toolbar-datetime' import ToolbarFileInfo from './toolbar-file-info' import ToolbarRestoreFileButton from './toolbar-restore-file-button' import { isFileRemoved } from '../../../utils/file-diff' -import ToolbarRevertFileButton from './toolbar-revert-file-button' +import ToolbarRestoreFileToVersionButton from './toolbar-restore-file-to-version-button' import { useFeatureFlag } from '@/shared/context/split-test-context' type ToolbarProps = { @@ -14,14 +14,15 @@ type ToolbarProps = { } export default function Toolbar({ diff, selection }: ToolbarProps) { - const hasRevertFile = useFeatureFlag('revert-file') + const hasRestoreFileToVersion = useFeatureFlag('revert-file') - const showRevertFileButton = hasRevertFile && selection.selectedFile + const showRestoreFileToVersionButton = + hasRestoreFileToVersion && selection.selectedFile const showRestoreFileButton = selection.selectedFile && isFileRemoved(selection.selectedFile) && - !showRevertFileButton + !showRestoreFileToVersionButton return (
@@ -32,8 +33,8 @@ export default function Toolbar({ diff, selection }: ToolbarProps) { {showRestoreFileButton ? ( ) : null} - {showRevertFileButton ? ( - + {showRestoreFileToVersionButton ? ( + ) : null}
) 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-restore-selected-file.ts similarity index 70% rename from services/web/frontend/js/features/history/context/hooks/use-revert-selected-file.ts rename to services/web/frontend/js/features/history/context/hooks/use-restore-selected-file.ts index 545819a14f..0355f0a107 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-restore-selected-file.ts @@ -1,6 +1,6 @@ import { useIdeContext } from '../../../../shared/context/ide-context' import { useLayoutContext } from '../../../../shared/context/layout-context' -import { revertFile } from '../../services/api' +import { restoreFileToVersion } from '../../services/api' import { isFileRemoved } from '../../utils/file-diff' import { useHistoryContext } from '../history-context' import type { HistoryContextValue } from '../types/history-context-value' @@ -8,33 +8,33 @@ import { useErrorHandler } from 'react-error-boundary' import { useFileTreeData } from '@/shared/context/file-tree-data-context' import { findInTree } from '@/features/file-tree/util/find-in-tree' import { useCallback, useEffect, useState } from 'react' -import { RevertFileResponse } from '@/features/history/services/types/revert-file' +import { RestoreFileResponse } from '../../services/types/restore-file' -const REVERT_FILE_TIMEOUT = 3000 +const RESTORE_FILE_TIMEOUT = 3000 -type RevertState = +type RestoreState = | 'idle' - | 'reverting' + | 'restoring' | 'waitingForFileTree' | 'complete' | 'error' | 'timedOut' -export function useRevertSelectedFile() { +export function useRestoreSelectedFile() { const { projectId } = useHistoryContext() const ide = useIdeContext() const { setView } = useLayoutContext() const handleError = useErrorHandler() const { fileTreeData } = useFileTreeData() - const [state, setState] = useState('idle') - const [revertedFileMetadata, setRevertedFileMetadata] = - useState(null) + const [state, setState] = useState('idle') + const [restoredFileMetadata, setRestoredFileMetadata] = + useState(null) - const isLoading = state === 'reverting' || state === 'waitingForFileTree' + const isLoading = state === 'restoring' || state === 'waitingForFileTree' useEffect(() => { - if (state === 'waitingForFileTree' && revertedFileMetadata) { - const result = findInTree(fileTreeData, revertedFileMetadata.id) + if (state === 'waitingForFileTree' && restoredFileMetadata) { + const result = findInTree(fileTreeData, restoredFileMetadata.id) if (result) { setState('complete') const { _id: id } = result.entity @@ -42,7 +42,7 @@ export function useRevertSelectedFile() { // Once Angular is gone, these can be replaced with calls to context // methods - if (revertedFileMetadata.type === 'doc') { + if (restoredFileMetadata.type === 'doc') { ide.editorManager.openDocId(id) } else { ide.binaryFilesManager.openFileWithId(id) @@ -52,7 +52,7 @@ export function useRevertSelectedFile() { }, [ state, fileTreeData, - revertedFileMetadata, + restoredFileMetadata, ide.editorManager, ide.binaryFilesManager, setView, @@ -63,7 +63,7 @@ export function useRevertSelectedFile() { const timer = window.setTimeout(() => { setState('timedOut') handleError(new Error('timed out')) - }, REVERT_FILE_TIMEOUT) + }, RESTORE_FILE_TIMEOUT) return () => { window.clearTimeout(timer) @@ -71,7 +71,7 @@ export function useRevertSelectedFile() { } }, [handleError, state]) - const revertSelectedFile = useCallback( + const restoreSelectedFile = useCallback( (selection: HistoryContextValue['selection']) => { const { selectedFile, files } = selection @@ -84,11 +84,11 @@ export function useRevertSelectedFile() { if (!toVersion) { return } - setState('reverting') + setState('restoring') - revertFile(projectId, file.pathname, toVersion).then( - (data: RevertFileResponse) => { - setRevertedFileMetadata(data) + restoreFileToVersion(projectId, file.pathname, toVersion).then( + (data: RestoreFileResponse) => { + setRestoredFileMetadata(data) setState('waitingForFileTree') }, error => { @@ -102,5 +102,5 @@ export function useRevertSelectedFile() { [handleError, projectId] ) - return { revertSelectedFile, isLoading } + return { restoreSelectedFile, isLoading } } diff --git a/services/web/frontend/js/features/history/services/api.ts b/services/web/frontend/js/features/history/services/api.ts index 3da4e86380..d5bc82ce4e 100644 --- a/services/web/frontend/js/features/history/services/api.ts +++ b/services/web/frontend/js/features/history/services/api.ts @@ -8,7 +8,6 @@ import { FetchUpdatesResponse } from './types/update' import { Label } from './types/label' import { DocDiffResponse } from './types/doc' import { RestoreFileResponse } from './types/restore-file' -import { RevertFileResponse } from './types/revert-file' const BATCH_SIZE = 10 @@ -96,12 +95,12 @@ export function restoreFile(projectId: string, selectedFile: FileRemoved) { }) } -export function revertFile( +export function restoreFileToVersion( projectId: string, pathname: string, version: number ) { - return postJSON(`/project/${projectId}/revert_file`, { + return postJSON(`/project/${projectId}/revert_file`, { body: { version, pathname, diff --git a/services/web/frontend/js/features/history/services/types/revert-file.ts b/services/web/frontend/js/features/history/services/types/revert-file.ts deleted file mode 100644 index 1cc52a9f49..0000000000 --- a/services/web/frontend/js/features/history/services/types/revert-file.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type RevertFileResponse = { - id: string - type: 'doc' | 'file' -} diff --git a/services/web/locales/en.json b/services/web/locales/en.json index c9dcbe9206..27f5ae8a0e 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -1616,6 +1616,11 @@ "resolved_comments": "Resolved comments", "restore": "Restore", "restore_file": "Restore file", + "restore_file_confirmation_message": "Your current file will restore to the version from __date__ at __time__.", + "restore_file_confirmation_title": "Restore this version?", + "restore_file_error_message": "There was a problem restoring the file version. Please try again in a few moments. If the problem continues please contact us.", + "restore_file_error_title": "Restore File Error", + "restore_file_version": "Restore this version", "restoring": "Restoring", "restricted": "Restricted", "restricted_no_permission": "Restricted, sorry you don’t have permission to load this page.", @@ -1625,13 +1630,7 @@ "retry_test": "Retry test", "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", - "reverting": "Reverting", "review": "Review", "review_your_peers_work": "Review your peers’ work", "revoke": "Revoke",