Merge pull request #29033 from overleaf/dp-histroy-current-version

Hide restore version option for current history version

GitOrigin-RevId: 1eecaced2d7423bf8e28ab97e27288691ab0b002
This commit is contained in:
David
2025-10-22 08:05:28 +00:00
committed by Copybot
parent 0409b27311
commit f3036e5979
4 changed files with 26 additions and 6 deletions
@@ -5,6 +5,7 @@ import { useCallback } from 'react'
import { ActiveDropdown } from '../../../hooks/use-dropdown-active-item'
import RestoreProject from './menu-item/restore-project'
import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
import { useHistoryContext } from '@/features/history/context/history-context'
type VersionDropdownContentProps = {
projectId: string
@@ -19,6 +20,9 @@ function HistoryDropdownContent({
closeDropdownForItem,
endTimestamp,
}: VersionDropdownContentProps) {
const { updatesInfo } = useHistoryContext()
const isCurrentVersion = version === updatesInfo.updates[0].toV
const closeDropdown = useCallback(() => {
closeDropdownForItem(version, 'moreOptions')
}, [closeDropdownForItem, version])
@@ -35,7 +39,7 @@ function HistoryDropdownContent({
version={version}
closeDropdown={closeDropdown}
/>
{permissions.write && (
{permissions.write && !isCurrentVersion && (
<RestoreProject
projectId={projectId}
version={version}
@@ -10,12 +10,16 @@ import useAsync from '../../../../shared/hooks/use-async'
import { useTranslation } from 'react-i18next'
function DiffView() {
const { selection, projectId, loadingFileDiffs } = useHistoryContext()
const { selection, projectId, loadingFileDiffs, updatesInfo } =
useHistoryContext()
const { isLoading, data, runAsync } = useAsync<DocDiffResponse>()
const { t } = useTranslation()
const { updateRange, selectedFile } = selection
const { showBoundary } = useErrorBoundary()
const isCurrentVersion =
!!updateRange && updatesInfo.updates[0].toV === updateRange.toV
useEffect(() => {
if (!updateRange || !selectedFile?.pathname || loadingFileDiffs) {
return
@@ -73,7 +77,11 @@ function DiffView() {
return (
<div className="doc-panel">
<div className="history-header toolbar-container">
<Toolbar diff={diff} selection={selection} />
<Toolbar
diff={diff}
selection={selection}
isCurrentVersion={isCurrentVersion}
/>
</div>
<div className="doc-container">
<Main diff={diff} isLoading={isLoading || loadingFileDiffs} />
@@ -13,14 +13,22 @@ import { usePermissionsContext } from '@/features/ide-react/context/permissions-
type ToolbarProps = {
diff: Nullable<Diff>
selection: HistoryContextValue['selection']
isCurrentVersion: boolean
}
export default function Toolbar({ diff, selection }: ToolbarProps) {
export default function Toolbar({
diff,
selection,
isCurrentVersion,
}: ToolbarProps) {
const { write } = usePermissionsContext()
const hasRestoreFileToVersion = useFeatureFlag('revert-file')
const showRestoreFileToVersionButton =
hasRestoreFileToVersion && selection.selectedFile && write
hasRestoreFileToVersion &&
selection.selectedFile &&
write &&
!isCurrentVersion
const showRestoreFileButton =
selection.selectedFile &&
@@ -16,7 +16,7 @@ const TestContainerWithoutErrorBoundary: FC<{
<EditorProviders layoutContext={layoutContext}>
<HistoryProvider>
<div className="history-react">
<Toolbar diff={diff} selection={selection} />
<Toolbar diff={diff} selection={selection} isCurrentVersion={false} />
</div>
</HistoryProvider>
</EditorProviders>