From 4aa746a7593ce5fcbe553ba608df9bf16dcb88b4 Mon Sep 17 00:00:00 2001 From: Domagoj Kriskovic Date: Mon, 17 Jun 2024 15:14:58 +0200 Subject: [PATCH] [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 --- .../app/js/SummarizedUpdatesManager.js | 9 +++++++ .../web/frontend/extracted-translations.json | 1 + .../change-list/file-restore-change.tsx | 22 ++++++++++++++++ .../change-list/history-version.tsx | 13 +++++++--- .../features/history/services/types/shared.ts | 26 ++++++++++++------- .../stylesheets/app/editor/history-react.less | 4 +++ services/web/locales/en.json | 1 + 7 files changed, 62 insertions(+), 14 deletions(-) create mode 100644 services/web/frontend/js/features/history/components/change-list/file-restore-change.tsx diff --git a/services/project-history/app/js/SummarizedUpdatesManager.js b/services/project-history/app/js/SummarizedUpdatesManager.js index 7bc0840eba..c94074136b 100644 --- a/services/project-history/app/js/SummarizedUpdatesManager.js +++ b/services/project-history/app/js/SummarizedUpdatesManager.js @@ -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 } diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index 363f49811c..d174fc8665 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -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": "", diff --git a/services/web/frontend/js/features/history/components/change-list/file-restore-change.tsx b/services/web/frontend/js/features/history/components/change-list/file-restore-change.tsx new file mode 100644 index 0000000000..94fc30913f --- /dev/null +++ b/services/web/frontend/js/features/history/components/change-list/file-restore-change.tsx @@ -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) { + const { t } = useTranslation() + + if (!origin || origin.kind !== 'file-restore') { + return null + } + + return ( +
+ {t('file_action_restored', { + fileName: origin.path, + date: formatTime(origin.timestamp, 'Do MMMM, h:mm a'), + })} +
+ ) +} + +export default FileRestoreChange diff --git a/services/web/frontend/js/features/history/components/change-list/history-version.tsx b/services/web/frontend/js/features/history/components/change-list/history-version.tsx index 627f198e82..d0ee891afd 100644 --- a/services/web/frontend/js/features/history/components/change-list/history-version.tsx +++ b/services/web/frontend/js/features/history/components/change-list/history-version.tsx @@ -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} /> ))} - + {update.meta.origin?.kind === 'file-restore' ? ( + + ) : ( + + )} __fileName__ 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",