[web] Rename "Revert file" to "Restore this version" (#19069)

* rename revert file to restore file

* rename file/function name

* rename split test

* fix formatting

* do not rename split test name

* fix typo

GitOrigin-RevId: e4e2eae622a270b3b6483348f441ddd424623f81
This commit is contained in:
Domagoj Kriskovic 2024-06-27 12:34:24 +02:00 committed by Copybot
parent c3c97d9fb9
commit cbda6b0bcc
9 changed files with 61 additions and 64 deletions

View file

@ -1101,19 +1101,18 @@
"resolved_comments": "", "resolved_comments": "",
"restore": "", "restore": "",
"restore_file": "", "restore_file": "",
"restore_file_confirmation_message": "",
"restore_file_confirmation_title": "",
"restore_file_error_message": "",
"restore_file_error_title": "",
"restore_file_version": "",
"restoring": "", "restoring": "",
"resync_completed": "", "resync_completed": "",
"resync_message": "", "resync_message": "",
"resync_project_history": "", "resync_project_history": "",
"retry_test": "", "retry_test": "",
"reverse_x_sort_order": "", "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": "", "revert_pending_plan_change": "",
"reverting": "",
"review": "", "review": "",
"review_your_peers_work": "", "review_your_peers_work": "",
"revoke": "", "revoke": "",

View file

@ -3,19 +3,19 @@ import { useMemo } from 'react'
import { Button, Modal } from 'react-bootstrap' import { Button, Modal } from 'react-bootstrap'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
type RevertFileConfirmModalProps = { type RestoreFileConfirmModalProps = {
show: boolean show: boolean
timestamp: number timestamp: number
onConfirm: () => void onConfirm: () => void
onHide: () => void onHide: () => void
} }
export function RevertFileConfirmModal({ export function RestoreFileConfirmModal({
show, show,
timestamp, timestamp,
onConfirm, onConfirm,
onHide, onHide,
}: RevertFileConfirmModalProps) { }: RestoreFileConfirmModalProps) {
const { t } = useTranslation() const { t } = useTranslation()
const date = useMemo(() => formatTime(timestamp, 'Do MMMM'), [timestamp]) const date = useMemo(() => formatTime(timestamp, 'Do MMMM'), [timestamp])
const time = useMemo(() => formatTime(timestamp, 'h:mm a'), [timestamp]) const time = useMemo(() => formatTime(timestamp, 'h:mm a'), [timestamp])
@ -23,10 +23,10 @@ export function RevertFileConfirmModal({
return ( return (
<Modal show={show} onHide={onHide}> <Modal show={show} onHide={onHide}>
<Modal.Header closeButton> <Modal.Header closeButton>
<Modal.Title>{t('revert_file_confirmation_title')}</Modal.Title> <Modal.Title>{t('restore_file_confirmation_title')}</Modal.Title>
</Modal.Header> </Modal.Header>
<Modal.Body> <Modal.Body>
{t('revert_file_confirmation_message', { date, time })} {t('restore_file_confirmation_message', { date, time })}
</Modal.Body> </Modal.Body>
<Modal.Footer> <Modal.Footer>
<Button bsStyle={null} className="btn-secondary" onClick={onHide}> <Button bsStyle={null} className="btn-secondary" onClick={onHide}>

View file

@ -1,7 +1,7 @@
import { Button, Modal } from 'react-bootstrap' import { Button, Modal } from 'react-bootstrap'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
export function RevertFileErrorModal({ export function RestoreFileErrorModal({
resetErrorBoundary, resetErrorBoundary,
}: { }: {
resetErrorBoundary: VoidFunction resetErrorBoundary: VoidFunction
@ -11,9 +11,9 @@ export function RevertFileErrorModal({
return ( return (
<Modal show onHide={resetErrorBoundary}> <Modal show onHide={resetErrorBoundary}>
<Modal.Header closeButton> <Modal.Header closeButton>
<Modal.Title>{t('revert_file_error_title')}</Modal.Title> <Modal.Title>{t('restore_file_error_title')}</Modal.Title>
</Modal.Header> </Modal.Header>
<Modal.Body>{t('revert_file_error_message')}</Modal.Body> <Modal.Body>{t('restore_file_error_message')}</Modal.Body>
<Modal.Footer> <Modal.Footer>
<Button <Button
bsStyle={null} bsStyle={null}

View file

@ -1,21 +1,21 @@
import { Button } from 'react-bootstrap' import { Button } from 'react-bootstrap'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import type { HistoryContextValue } from '../../../context/types/history-context-value' import type { HistoryContextValue } from '../../../context/types/history-context-value'
import { useRevertSelectedFile } from '@/features/history/context/hooks/use-revert-selected-file'
import withErrorBoundary from '@/infrastructure/error-boundary' import withErrorBoundary from '@/infrastructure/error-boundary'
import { RevertFileConfirmModal } from '../modals/revert-file-confirm-modal' import { RestoreFileConfirmModal } from '../modals/restore-file-confirm-modal'
import { useState } from 'react' import { useState } from 'react'
import { RevertFileErrorModal } from '../modals/revert-file-error-modal' import { RestoreFileErrorModal } from '../modals/restore-file-error-modal'
import { useRestoreSelectedFile } from '@/features/history/context/hooks/use-restore-selected-file'
type ToolbarRevertingFileButtonProps = { type ToolbarRevertingFileButtonProps = {
selection: HistoryContextValue['selection'] selection: HistoryContextValue['selection']
} }
function ToolbarRevertFileButton({ function ToolbarRestoreFileToVersionButton({
selection, selection,
}: ToolbarRevertingFileButtonProps) { }: ToolbarRevertingFileButtonProps) {
const { t } = useTranslation() const { t } = useTranslation()
const { revertSelectedFile, isLoading } = useRevertSelectedFile() const { restoreSelectedFile, isLoading } = useRestoreSelectedFile()
const [showConfirmModal, setShowConfirmModal] = useState(false) const [showConfirmModal, setShowConfirmModal] = useState(false)
if (!selection.updateRange || !selection.selectedFile) { if (!selection.updateRange || !selection.selectedFile) {
@ -24,26 +24,29 @@ function ToolbarRevertFileButton({
return ( return (
<> <>
<RevertFileConfirmModal <RestoreFileConfirmModal
show={showConfirmModal} show={showConfirmModal}
timestamp={selection.updateRange.toVTimestamp} timestamp={selection.updateRange.toVTimestamp}
onConfirm={() => { onConfirm={() => {
setShowConfirmModal(false) setShowConfirmModal(false)
revertSelectedFile(selection) restoreSelectedFile(selection)
}} }}
onHide={() => setShowConfirmModal(false)} onHide={() => setShowConfirmModal(false)}
/> />
<Button <Button
className="btn-secondary history-react-toolbar-revert-file-button" className="btn-secondary"
bsSize="xs" bsSize="xs"
bsStyle={null} bsStyle={null}
onClick={() => setShowConfirmModal(true)} onClick={() => setShowConfirmModal(true)}
disabled={isLoading} disabled={isLoading}
> >
{isLoading ? `${t('reverting')}` : t('revert_file')} {isLoading ? `${t('restoring')}` : t('restore_file_version')}
</Button> </Button>
</> </>
) )
} }
export default withErrorBoundary(ToolbarRevertFileButton, RevertFileErrorModal) export default withErrorBoundary(
ToolbarRestoreFileToVersionButton,
RestoreFileErrorModal
)

View file

@ -5,7 +5,7 @@ import ToolbarDatetime from './toolbar-datetime'
import ToolbarFileInfo from './toolbar-file-info' import ToolbarFileInfo from './toolbar-file-info'
import ToolbarRestoreFileButton from './toolbar-restore-file-button' import ToolbarRestoreFileButton from './toolbar-restore-file-button'
import { isFileRemoved } from '../../../utils/file-diff' 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' import { useFeatureFlag } from '@/shared/context/split-test-context'
type ToolbarProps = { type ToolbarProps = {
@ -14,14 +14,15 @@ type ToolbarProps = {
} }
export default function Toolbar({ diff, selection }: 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 = const showRestoreFileButton =
selection.selectedFile && selection.selectedFile &&
isFileRemoved(selection.selectedFile) && isFileRemoved(selection.selectedFile) &&
!showRevertFileButton !showRestoreFileToVersionButton
return ( return (
<div className="history-react-toolbar"> <div className="history-react-toolbar">
@ -32,8 +33,8 @@ export default function Toolbar({ diff, selection }: ToolbarProps) {
{showRestoreFileButton ? ( {showRestoreFileButton ? (
<ToolbarRestoreFileButton selection={selection} /> <ToolbarRestoreFileButton selection={selection} />
) : null} ) : null}
{showRevertFileButton ? ( {showRestoreFileToVersionButton ? (
<ToolbarRevertFileButton selection={selection} /> <ToolbarRestoreFileToVersionButton selection={selection} />
) : null} ) : null}
</div> </div>
) )

View file

@ -1,6 +1,6 @@
import { useIdeContext } from '../../../../shared/context/ide-context' import { useIdeContext } from '../../../../shared/context/ide-context'
import { useLayoutContext } from '../../../../shared/context/layout-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 { isFileRemoved } from '../../utils/file-diff'
import { useHistoryContext } from '../history-context' import { useHistoryContext } from '../history-context'
import type { HistoryContextValue } from '../types/history-context-value' 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 { useFileTreeData } from '@/shared/context/file-tree-data-context'
import { findInTree } from '@/features/file-tree/util/find-in-tree' import { findInTree } from '@/features/file-tree/util/find-in-tree'
import { useCallback, useEffect, useState } from 'react' 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' | 'idle'
| 'reverting' | 'restoring'
| 'waitingForFileTree' | 'waitingForFileTree'
| 'complete' | 'complete'
| 'error' | 'error'
| 'timedOut' | 'timedOut'
export function useRevertSelectedFile() { export function useRestoreSelectedFile() {
const { projectId } = useHistoryContext() const { projectId } = useHistoryContext()
const ide = useIdeContext() const ide = useIdeContext()
const { setView } = useLayoutContext() const { setView } = useLayoutContext()
const handleError = useErrorHandler() const handleError = useErrorHandler()
const { fileTreeData } = useFileTreeData() const { fileTreeData } = useFileTreeData()
const [state, setState] = useState<RevertState>('idle') const [state, setState] = useState<RestoreState>('idle')
const [revertedFileMetadata, setRevertedFileMetadata] = const [restoredFileMetadata, setRestoredFileMetadata] =
useState<RevertFileResponse | null>(null) useState<RestoreFileResponse | null>(null)
const isLoading = state === 'reverting' || state === 'waitingForFileTree' const isLoading = state === 'restoring' || state === 'waitingForFileTree'
useEffect(() => { useEffect(() => {
if (state === 'waitingForFileTree' && revertedFileMetadata) { if (state === 'waitingForFileTree' && restoredFileMetadata) {
const result = findInTree(fileTreeData, revertedFileMetadata.id) const result = findInTree(fileTreeData, restoredFileMetadata.id)
if (result) { if (result) {
setState('complete') setState('complete')
const { _id: id } = result.entity const { _id: id } = result.entity
@ -42,7 +42,7 @@ export function useRevertSelectedFile() {
// Once Angular is gone, these can be replaced with calls to context // Once Angular is gone, these can be replaced with calls to context
// methods // methods
if (revertedFileMetadata.type === 'doc') { if (restoredFileMetadata.type === 'doc') {
ide.editorManager.openDocId(id) ide.editorManager.openDocId(id)
} else { } else {
ide.binaryFilesManager.openFileWithId(id) ide.binaryFilesManager.openFileWithId(id)
@ -52,7 +52,7 @@ export function useRevertSelectedFile() {
}, [ }, [
state, state,
fileTreeData, fileTreeData,
revertedFileMetadata, restoredFileMetadata,
ide.editorManager, ide.editorManager,
ide.binaryFilesManager, ide.binaryFilesManager,
setView, setView,
@ -63,7 +63,7 @@ export function useRevertSelectedFile() {
const timer = window.setTimeout(() => { const timer = window.setTimeout(() => {
setState('timedOut') setState('timedOut')
handleError(new Error('timed out')) handleError(new Error('timed out'))
}, REVERT_FILE_TIMEOUT) }, RESTORE_FILE_TIMEOUT)
return () => { return () => {
window.clearTimeout(timer) window.clearTimeout(timer)
@ -71,7 +71,7 @@ export function useRevertSelectedFile() {
} }
}, [handleError, state]) }, [handleError, state])
const revertSelectedFile = useCallback( const restoreSelectedFile = useCallback(
(selection: HistoryContextValue['selection']) => { (selection: HistoryContextValue['selection']) => {
const { selectedFile, files } = selection const { selectedFile, files } = selection
@ -84,11 +84,11 @@ export function useRevertSelectedFile() {
if (!toVersion) { if (!toVersion) {
return return
} }
setState('reverting') setState('restoring')
revertFile(projectId, file.pathname, toVersion).then( restoreFileToVersion(projectId, file.pathname, toVersion).then(
(data: RevertFileResponse) => { (data: RestoreFileResponse) => {
setRevertedFileMetadata(data) setRestoredFileMetadata(data)
setState('waitingForFileTree') setState('waitingForFileTree')
}, },
error => { error => {
@ -102,5 +102,5 @@ export function useRevertSelectedFile() {
[handleError, projectId] [handleError, projectId]
) )
return { revertSelectedFile, isLoading } return { restoreSelectedFile, isLoading }
} }

View file

@ -8,7 +8,6 @@ import { FetchUpdatesResponse } from './types/update'
import { Label } from './types/label' import { Label } from './types/label'
import { DocDiffResponse } from './types/doc' import { DocDiffResponse } from './types/doc'
import { RestoreFileResponse } from './types/restore-file' import { RestoreFileResponse } from './types/restore-file'
import { RevertFileResponse } from './types/revert-file'
const BATCH_SIZE = 10 const BATCH_SIZE = 10
@ -96,12 +95,12 @@ export function restoreFile(projectId: string, selectedFile: FileRemoved) {
}) })
} }
export function revertFile( export function restoreFileToVersion(
projectId: string, projectId: string,
pathname: string, pathname: string,
version: number version: number
) { ) {
return postJSON<RevertFileResponse>(`/project/${projectId}/revert_file`, { return postJSON<RestoreFileResponse>(`/project/${projectId}/revert_file`, {
body: { body: {
version, version,
pathname, pathname,

View file

@ -1,4 +0,0 @@
export type RevertFileResponse = {
id: string
type: 'doc' | 'file'
}

View file

@ -1616,6 +1616,11 @@
"resolved_comments": "Resolved comments", "resolved_comments": "Resolved comments",
"restore": "Restore", "restore": "Restore",
"restore_file": "Restore file", "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", "restoring": "Restoring",
"restricted": "Restricted", "restricted": "Restricted",
"restricted_no_permission": "Restricted, sorry you dont have permission to load this page.", "restricted_no_permission": "Restricted, sorry you dont have permission to load this page.",
@ -1625,13 +1630,7 @@
"retry_test": "Retry test", "retry_test": "Retry test",
"return_to_login_page": "Return to Login page", "return_to_login_page": "Return to Login page",
"reverse_x_sort_order": "Reverse __x__ sort order", "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", "revert_pending_plan_change": "Revert scheduled plan change",
"reverting": "Reverting",
"review": "Review", "review": "Review",
"review_your_peers_work": "Review your peers work", "review_your_peers_work": "Review your peers work",
"revoke": "Revoke", "revoke": "Revoke",