[web] show file restored change in history (#18792)

* add RestoreFileOrigin in overleaf-editor-core

* support source to be an object

* use sourceOrOrigin as param

* rename to originOrSource so the priority is more clear

* get timestamp from version

* fix test

* include version and min_count in getUpdatesFromHistory

* extractOriginOrSource util function

* fix RestoreManagerTests

* [web] show restore file change in history

* make sure two restore operations are not merged

* dont summarize updates for different paths

GitOrigin-RevId: d890484760a7379716e8bd65dd28e353d293492f
This commit is contained in:
Domagoj Kriskovic 2024-06-17 15:14:58 +02:00 committed by Copybot
parent f265797bb1
commit 4aa746a759
7 changed files with 62 additions and 14 deletions

View file

@ -252,6 +252,15 @@ function _shouldMergeUpdate(update, summarizedUpdate, labels) {
if (update.meta.origin.kind !== summarizedUpdate.meta.origin.kind) {
return false
}
if (update.meta.origin.path !== summarizedUpdate.meta.origin.path) {
return false
}
if (
update.meta.origin.kind === 'file-restore' &&
update.meta.origin.timestamp !== summarizedUpdate.meta.origin.timestamp
) {
return false
}
} else {
return false
}

View file

@ -399,6 +399,7 @@
"file_action_deleted": "",
"file_action_edited": "",
"file_action_renamed": "",
"file_action_restored": "",
"file_already_exists": "",
"file_already_exists_in_this_location": "",
"file_name": "",

View file

@ -0,0 +1,22 @@
import { formatTime } from '@/features/utils/format-date'
import { useTranslation } from 'react-i18next'
import { LoadedUpdate } from '../../services/types/update'
function FileRestoreChange({ origin }: Pick<LoadedUpdate['meta'], 'origin'>) {
const { t } = useTranslation()
if (!origin || origin.kind !== 'file-restore') {
return null
}
return (
<div className="history-version-restore-file">
{t('file_action_restored', {
fileName: origin.path,
date: formatTime(origin.timestamp, 'Do MMMM, h:mm a'),
})}
</div>
)
}
export default FileRestoreChange

View file

@ -19,6 +19,7 @@ import HistoryDropdownContent from './dropdown/history-dropdown-content'
import CompareItems from './dropdown/menu-item/compare-items'
import CompareVersionDropdown from './dropdown/compare-version-dropdown'
import { CompareVersionDropdownContentAllHistory } from './dropdown/compare-version-dropdown-content'
import FileRestoreChange from './file-restore-change'
type HistoryVersionProps = {
update: LoadedUpdate
@ -164,10 +165,14 @@ function HistoryVersion({
label={label}
/>
))}
<Changes
pathnames={update.pathnames}
projectOps={update.project_ops}
/>
{update.meta.origin?.kind === 'file-restore' ? (
<FileRestoreChange origin={update.meta.origin} />
) : (
<Changes
pathnames={update.pathnames}
projectOps={update.project_ops}
/>
)}
<MetadataUsersList
users={update.meta.users}
origin={update.meta.origin}

View file

@ -13,14 +13,20 @@ export interface Meta {
end_ts: number
type?: 'external' // TODO
source?: 'git-bridge' // TODO
origin?: {
kind:
| 'dropbox'
| 'upload'
| 'git-bridge'
| 'github'
| 'history-resync'
| 'history-migration'
| 'file-restore'
}
origin?:
| {
kind:
| 'dropbox'
| 'upload'
| 'git-bridge'
| 'github'
| 'history-resync'
| 'history-migration'
}
| {
kind: 'file-restore'
path: string
timestamp: number
version: number
}
}

View file

@ -162,6 +162,10 @@ history-root {
list-style: none;
}
.history-version-restore-file {
margin-bottom: 8px;
}
.history-version-metadata-users {
display: inline;

View file

@ -588,6 +588,7 @@
"file_action_deleted": "Deleted",
"file_action_edited": "Edited",
"file_action_renamed": "Renamed",
"file_action_restored": "Restored __fileName__ from: __date__",
"file_already_exists": "A file or folder with this name already exists",
"file_already_exists_in_this_location": "An item named <0>__fileName__</0> already exists in this location. If you wish to move this file, rename or remove the conflicting file and try again.",
"file_name": "File Name",