From 8e0aa685ce3224230a0db2f71ffc6ec003b77cf4 Mon Sep 17 00:00:00 2001 From: ilkin-overleaf <100852799+ilkin-overleaf@users.noreply.github.com> Date: Tue, 11 Apr 2023 11:35:33 +0300 Subject: [PATCH] Merge pull request #12549 from overleaf/ii-history-react-list-of-all-versions [web] All versions of history entries GitOrigin-RevId: 7365ac4913c115b3b2872a3713d893463719c15e --- .../web/frontend/extracted-translations.json | 13 ++ .../change-list/all-history-list.tsx | 22 +++ .../components/change-list/change-list.tsx | 17 +- .../components/change-list/changes.tsx | 39 +++++ .../change-list/history-version.tsx | 49 ++++++ .../components/change-list/label-badges.tsx | 96 +++++++++++ .../components/change-list/labels-list.tsx | 5 + .../history/components/change-list/main.tsx | 5 - .../change-list/metadata-users-list.tsx | 54 ++++++ .../history/components/change-list/origin.tsx | 19 +++ .../history/context/history-context.tsx | 158 +++++++++++++++--- .../context/types/history-context-value.ts | 14 +- .../js/features/history/services/api.ts | 11 +- .../features/history/services/types/shared.ts | 13 +- .../features/history/services/types/update.ts | 31 +++- .../utils/highlights-from-diff-response.ts | 4 +- .../features/history/utils/history-details.ts | 40 +++++ .../js/features/history/utils/label.ts | 60 +++++++ .../frontend/js/features/utils/format-date.js | 4 +- .../stories/history/toggle-switch.stories.tsx | 2 +- .../stylesheets/app/editor/history-react.less | 126 +++++++++++++- .../web/frontend/stylesheets/core/mixins.less | 8 + .../frontend/stylesheets/core/variables.less | 1 + services/web/locales/en.json | 1 + 24 files changed, 735 insertions(+), 57 deletions(-) create mode 100644 services/web/frontend/js/features/history/components/change-list/all-history-list.tsx create mode 100644 services/web/frontend/js/features/history/components/change-list/changes.tsx create mode 100644 services/web/frontend/js/features/history/components/change-list/history-version.tsx create mode 100644 services/web/frontend/js/features/history/components/change-list/label-badges.tsx create mode 100644 services/web/frontend/js/features/history/components/change-list/labels-list.tsx delete mode 100644 services/web/frontend/js/features/history/components/change-list/main.tsx create mode 100644 services/web/frontend/js/features/history/components/change-list/metadata-users-list.tsx create mode 100644 services/web/frontend/js/features/history/components/change-list/origin.tsx create mode 100644 services/web/frontend/js/features/history/utils/history-details.ts create mode 100644 services/web/frontend/js/features/history/utils/label.ts diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index a85966ac07..5b5496619c 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -38,6 +38,7 @@ "all_projects": "", "also": "", "an_error_occurred_when_verifying_the_coupon_code": "", + "anonymous": "", "anyone_with_link_can_edit": "", "anyone_with_link_can_view": "", "approaching_compile_timeout_limit_upgrade_for_more_compile_time": "", @@ -246,6 +247,10 @@ "faster_compiles_feedback_seems_same": "", "faster_compiles_feedback_seems_slower": "", "faster_compiles_feedback_thanks": "", + "file_action_created": "", + "file_action_deleted": "", + "file_action_edited": "", + "file_action_renamed": "", "file_already_exists": "", "file_already_exists_in_this_location": "", "file_name": "", @@ -347,6 +352,12 @@ "hide_document_preamble": "", "hide_outline": "", "history": "", + "history_entry_origin_dropbox": "", + "history_entry_origin_git": "", + "history_entry_origin_github": "", + "history_entry_origin_upload": "", + "history_label_created_by": "", + "history_label_project_current_state": "", "history_view_a11y_description": "", "history_view_all": "", "history_view_labels": "", @@ -551,6 +562,7 @@ "other_output_files": "", "overall_theme": "", "overleaf": "", + "overleaf_history_system": "", "overleaf_labs": "", "overwrite": "", "owned_by_x": "", @@ -947,6 +959,7 @@ "x_price_per_year": "", "year": "", "yes_move_me_to_personal_plan": "", + "you": "", "you_already_have_a_subscription": "", "you_are_a_manager_and_member_of_x_plan_as_member_of_group_subscription_y_administered_by_z": "", "you_are_a_manager_of_commons_at_institution_x": "", diff --git a/services/web/frontend/js/features/history/components/change-list/all-history-list.tsx b/services/web/frontend/js/features/history/components/change-list/all-history-list.tsx new file mode 100644 index 0000000000..ee97b6a237 --- /dev/null +++ b/services/web/frontend/js/features/history/components/change-list/all-history-list.tsx @@ -0,0 +1,22 @@ +import { Fragment } from 'react' +import { useHistoryContext } from '../../context/history-context' +import HistoryVersion from './history-version' + +function AllHistoryList() { + const { updates } = useHistoryContext() + + return ( + <> + {updates.map((update, index) => ( + + {update.meta.first_in_day && index > 0 && ( +
+ )} + +
+ ))} + + ) +} + +export default AllHistoryList diff --git a/services/web/frontend/js/features/history/components/change-list/change-list.tsx b/services/web/frontend/js/features/history/components/change-list/change-list.tsx index f93018de73..4aad40c733 100644 --- a/services/web/frontend/js/features/history/components/change-list/change-list.tsx +++ b/services/web/frontend/js/features/history/components/change-list/change-list.tsx @@ -1,10 +1,11 @@ import usePersistedState from '../../../../shared/hooks/use-persisted-state' import ToggleSwitch from './toggle-switch' -import Main from './main' +import AllHistoryList from './all-history-list' +import LabelsList from './labels-list' import { useHistoryContext } from '../../context/history-context' function ChangeList() { - const { projectId, isError } = useHistoryContext() + const { projectId, error } = useHistoryContext() const [labelsOnly, setLabelsOnly] = usePersistedState( `history.userPrefs.showOnlyLabels.${projectId}`, false @@ -12,14 +13,16 @@ function ChangeList() { return ( ) } diff --git a/services/web/frontend/js/features/history/components/change-list/changes.tsx b/services/web/frontend/js/features/history/components/change-list/changes.tsx new file mode 100644 index 0000000000..5ac4825b07 --- /dev/null +++ b/services/web/frontend/js/features/history/components/change-list/changes.tsx @@ -0,0 +1,39 @@ +import { useTranslation } from 'react-i18next' +import { getProjectOpDoc } from '../../utils/history-details' +import { LoadedUpdate } from '../../services/types/update' + +type ChangesProps = { + pathNames: LoadedUpdate['pathnames'] + projectOps: LoadedUpdate['project_ops'] +} + +function Changes({ pathNames, projectOps }: ChangesProps) { + const { t } = useTranslation() + + return ( +
    + {pathNames.map(pathName => ( +
  1. +
    + {t('file_action_edited')} +
    +
    {pathName}
    +
  2. + ))} + {projectOps.map((op, index) => ( +
  3. +
    + {op.rename && t('file_action_renamed')} + {op.add && t('file_action_created')} + {op.remove && t('file_action_deleted')} +
    +
    + {getProjectOpDoc(op)} +
    +
  4. + ))} +
+ ) +} + +export default Changes 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 new file mode 100644 index 0000000000..fc2beb1391 --- /dev/null +++ b/services/web/frontend/js/features/history/components/change-list/history-version.tsx @@ -0,0 +1,49 @@ +import LabelBadges from './label-badges' +import Changes from './changes' +import MetadataUsersList from './metadata-users-list' +import Origin from './origin' +import { useUserContext } from '../../../../shared/context/user-context' +import { relativeDate, formatTime } from '../../../utils/format-date' +import { LoadedUpdate } from '../../services/types/update' + +type HistoryEntryProps = { + update: LoadedUpdate +} + +function HistoryVersion({ update }: HistoryEntryProps) { + const { id: currentUserId } = useUserContext() + + return ( +
+ {update.meta.first_in_day && ( + + )} +
+
+ + + + + +
+
+
+ ) +} + +export default HistoryVersion diff --git a/services/web/frontend/js/features/history/components/change-list/label-badges.tsx b/services/web/frontend/js/features/history/components/change-list/label-badges.tsx new file mode 100644 index 0000000000..4958142489 --- /dev/null +++ b/services/web/frontend/js/features/history/components/change-list/label-badges.tsx @@ -0,0 +1,96 @@ +import { Fragment } from 'react' +import { useTranslation } from 'react-i18next' +import Icon from '../../../../shared/components/icon' +import Tooltip from '../../../../shared/components/tooltip' +import { useHistoryContext } from '../../context/history-context' +import { isPseudoLabel } from '../../utils/label' +import { formatDate } from '../../../../utils/dates' +import { orderBy } from 'lodash' +import { Label, PseudoCurrentStateLabel } from '../../services/types/update' + +type LabelBadgesProps = { + showTooltip: boolean + currentUserId: string + labels: Array