Rollback improvements (#13452)

* Rollback improvements - hide draft version, allow rolling back to last published version

* UX improvements to rollback, revert some overly complex logic in favor of better UX

* Ensure title update when changing rollback version

* Clean up

* Fix rollback playwright text
This commit is contained in:
Kenn Jacobsen
2022-11-23 10:04:21 +01:00
committed by GitHub
parent bce29f44f8
commit 63fa6f392c
25 changed files with 41 additions and 67 deletions

View File

@@ -73,11 +73,13 @@
getVersions();
}
function canRollback(version) {
return !version.currentDraftVersion;
}
function changeVersion(version) {
const canRollback = !version.currentDraftVersion && !version.currentPublishedVersion;
if (canRollback === false) {
if (canRollback(version) === false) {
return;
}
@@ -92,6 +94,7 @@
vm.loadingDiff = true;
const culture = $scope.model.node.variants.length > 1 ? vm.currentVersion.language.culture : null;
vm.previousVersion = null;
contentResource.getRollbackVersion(version.versionId, culture)
.then(function(data) {
vm.previousVersion = data;
@@ -99,8 +102,11 @@
vm.previousVersion.displayValue = version.displayValue + ' - ' + version.username;
createDiff(vm.currentVersion, vm.previousVersion);
const changed = (part) => part.added || part.removed;
vm.diffHasChanges = vm.diff.name.some(changed) || vm.diff.properties.some((property) => property.diff.some(changed));
vm.loadingDiff = false;
vm.rollbackButtonDisabled = false;
vm.rollbackButtonDisabled = !vm.diffHasChanges;
}, function () {
vm.loadingDiff = false;
});
@@ -131,11 +137,14 @@
// get current backoffice user and format dates
userService.getCurrentUser().then(function (currentUser) {
vm.previousVersions = data.items.map(version => {
var timestampFormatted = dateHelper.getLocalDate(version.versionDate, currentUser.locale, 'LLL');
version.displayValue = timestampFormatted;
return version;
});
vm.previousVersions = data.items
// we don't ever want to show the draft version in the rollback list
.filter(version => version.currentDraftVersion === false)
.map(version => {
var timestampFormatted = dateHelper.getLocalDate(version.versionDate, currentUser.locale, 'LLL');
version.displayValue = timestampFormatted;
return version;
});
});
});
}
@@ -173,7 +182,7 @@
// copy existing properties, so it doesn't manipulate existing properties on page
oldProperty = Utilities.copy(oldProperty);
property = Utilities.copy(property);
// we have to make properties storing values as object into strings (Grid, nested content, etc.)
if (property.value instanceof Object) {
property.value = JSON.stringify(property.value, null, 1);
@@ -188,14 +197,14 @@
// diff requires a string
property.value = property.value ? property.value + '' : '';
oldProperty.value = oldProperty.value ? oldProperty.value + '' : '';
const diffProperty = {
'alias': property.alias,
'label': property.label,
'diff': property.isObject ? Diff.diffJson(property.value, oldProperty.value) : Diff.diffWords(property.value, oldProperty.value),
'isObject': property.isObject || oldProperty.isObject
};
vm.diff.properties.push(diffProperty);
}
});

View File

@@ -21,7 +21,7 @@
<umb-box class="side-panel">
<umb-box-header title-key="rollback_versions">
<small>
<localize
<localize
key="rollback_pagination"
tokens="[vm.paginationCount.from, vm.paginationCount.to, vm.paginationCount.total]"
watch-tokens="true">
@@ -42,17 +42,12 @@
</div>
<div>
<div class="current-version">
<span class="bold"><localize key="rollback_currentVersion">Current version</localize>: </span>
<span>{{vm.currentVersion.name}} (<localize key="rollback_created">Created</localize>: {{vm.currentVersion.createDate}})</span>
</div>
<div class="umb-table umb-table--condensed">
<div class="umb-table-body">
<div class="umb-table-row umb-outline"
<div class="umb-table-row umb-outline -selectable cursor-pointer"
ng-repeat="version in vm.previousVersions track by version.versionId"
ng-class="{'-selectable cursor-pointer': !version.currentDraftVersion && !version.currentPublishedVersion,'-selected': version.versionId === vm.previousVersion.versionId }"
ng-class="{'-selected': version.versionId === vm.previousVersion.versionId }"
ng-click="vm.changeVersion(version)">
<div class="umb-table-cell dn"></div>
<div class="umb-table-cell black">
@@ -61,12 +56,11 @@
<div class="version-details">{{version.username}}</div>
<div class="version-details">
<localize ng-if="version.currentPublishedVersion" key="rollback_currentPublishedVersion">Current version</localize>
<localize ng-if="version.currentDraftVersion" key="rollback_currentDraftVersion">Current version</localize>
</div>
</div>
</div>
<div class="umb-table-cell umb-table-cell--auto-width">
<umb-button
<umb-button
style="margin-left: auto;"
button-style="outline"
type="button"
@@ -108,15 +102,18 @@
</umb-empty-state>
<div ng-if="vm.diff && !vm.loadingDiff" class="diff">
<small class="db" style="margin-bottom: 15px;">
<localize key="rollback_diffHelp">
This shows the differences between the current version and the selected version<br /><del>Red text</del> will be
<localize key="rollback_diffHelp" ng-if="vm.diffHasChanges">
This shows the differences between the current (draft) version and the selected version<br /><del>Red text</del> will be
removed in the selected version, <ins>green text</ins> will be added
</localize>
<localize key="rollback_noDiff" ng-if="!vm.diffHasChanges">
There are no differences between the current (draft) version and the selected version
</localize>
</small>
<table class="table table-condensed table-bordered">
<table class="table table-condensed table-bordered" ng-if="vm.diffHasChanges">
<tbody>
<tr>
<td class="bold">

View File

@@ -14,12 +14,6 @@
position: relative;
}
.current-version {
background: @gray-10;
padding: 15px;
margin-bottom: 12px;
}
.culture-select {
margin-bottom: 12px;
}
@@ -29,4 +23,4 @@
font-size: 13px;
}
}
}