Quit navigating history when checking out latest save

This commit is contained in:
AlexandreSi
2023-12-15 11:16:31 +01:00
parent 3a70315388
commit 3e32f7278e
3 changed files with 16 additions and 6 deletions

View File

@@ -134,6 +134,11 @@ const VersionHistory = React.memo<Props>(
const isNotTheCurrentlyOpenedVersion =
!!openedVersionStatus &&
openedVersionStatus.version.id !== options.version.id;
const isComingBackToLatestVersionAfterNavigating =
!!openedVersionStatus &&
latestVersion &&
latestVersion.id === options.version.id;
return [
{
label: i18n._(
@@ -144,7 +149,9 @@ const VersionHistory = React.memo<Props>(
},
},
{
label: i18n._(t`Open version`),
label: isComingBackToLatestVersionAfterNavigating
? i18n._(t`Come back to latest version`)
: i18n._(t`Open version`),
click: () => {
onCheckoutVersion(options.version);
},

View File

@@ -284,11 +284,9 @@ const useVersionHistory = ({
});
return;
}
if (
checkedOutVersionStatus &&
checkedOutVersionStatus.version.id === latestVersionId
) {
if (checkedOutVersionStatus && version.id === latestVersionId) {
await onQuitVersionHistory();
setVersionHistoryPanelOpen(false);
return;
}
preventEffectsRunningRef.current = true;

View File

@@ -158,15 +158,20 @@ export const Default = () => {
const projectServiceMock = new MockAdapter(projectApiAxiosClient, {
delayResponse: 1000,
});
const latestVersion = versions[0];
const onCheckoutVersion = React.useCallback(
async (version: FilledCloudProjectVersion) => {
if (version.id === latestVersion.id) {
setOpenedVersionStatus(null);
return;
}
setOpenedVersionStatus({
version,
status: 'opened',
});
},
[]
[latestVersion.id]
);
const onSaveCurrentlyOpenedVersion = React.useCallback(