Skip to content

Commit

Permalink
V8/feature/ab4550 segments ui variant picker (#7676)
Browse files Browse the repository at this point in the history
* Fixes incorrect property inheritance logic

* Fixes crash in canVariantPublish when variant.language is null

* Adds variant display name in dropdown

* Logic for invariant properties updated to also support segment invariance

* Properties varied by segment only now properly saved when multiple variants are saved/published

* Logic for disabling property editors moved to function and corrected for all cases of culture/segment properties

* Fixes syntax error in less file

* Fixes empty variants returned from GetEmpty() for a ContentType set to vary by segment

* Replaced _.each with _.find to prevent having to loop through all variants and/or somehow open multiple.

It is not possible to break out of _.each using a return statement, it simply returns that current function
but _.each will continue calling the others after that.

* Added a null check on Culture prop which is now possibly null due to segments

* Makes sure segments are not completely removed when their value is null.

During save/publish, Umbraco first deletes all property data of a specific version
and then adds property values again. However, any segments that were created but had
an empty value would not be added again which meant the segments were entirely gone afterwards.

* GetSegments() updated to always return the default segment, not only when there are no segments at all.

This makes sure that even if there is no property data for the default segment in the database but only for
some segments, the default segment will still be returned here.
  • Loading branch information
PerplexDaniel authored Feb 18, 2020
1 parent 1a4e6e5 commit 5a5291d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
9 changes: 5 additions & 4 deletions src/Umbraco.Core/Persistence/Factories/PropertyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ public static IEnumerable<PropertyDataDto> BuildDtos(ContentVariation contentVar
// publishing = deal with edit and published values
foreach (var propertyValue in property.Values)
{
var isInvariantValue = propertyValue.Culture == null;
var isCultureValue = propertyValue.Culture != null && propertyValue.Segment == null;
var isInvariantValue = propertyValue.Culture == null && propertyValue.Segment == null;
var isCultureValue = propertyValue.Culture != null;
var isSegmentValue = propertyValue.Segment != null;

// deal with published value
if (propertyValue.PublishedValue != null && publishedVersionId > 0)
if ((propertyValue.PublishedValue != null || isSegmentValue) && publishedVersionId > 0)
propertyDataDtos.Add(BuildDto(publishedVersionId, property, languageRepository.GetIdByIsoCode(propertyValue.Culture), propertyValue.Segment, propertyValue.PublishedValue));

// deal with edit value
if (propertyValue.EditedValue != null)
if (propertyValue.EditedValue != null || isSegmentValue)
propertyDataDtos.Add(BuildDto(currentVersionId, property, languageRepository.GetIdByIsoCode(propertyValue.Culture), propertyValue.Segment, propertyValue.EditedValue));

// property.Values will contain ALL of it's values, both variant and invariant which will be populated if the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,14 @@
function requestSplitView(args) {
var culture = args.culture;
var segment = args.segment;
_.each(vm.content.variants, function (v) {
if ((!v.language || v.language.culture === culture) && v.segment === segment) {
openSplitView(v);
return;
}

var variant = _.find(vm.content.variants, function (v) {
return (!v.language || v.language.culture === culture) && v.segment === segment;
});

if (variant != null) {
openSplitView(variant);
}
}

/** Closes the split view */
Expand Down
8 changes: 7 additions & 1 deletion src/Umbraco.Web/Editors/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,13 @@ private void SaveAndNotify(ContentItemSave contentItem, Func<IContent, Operation
if (variantCount > 1)
{
var cultureErrors = ModelState.GetCulturesWithErrors(Services.LocalizationService, cultureForInvariantErrors);
foreach (var c in contentItem.Variants.Where(x => x.Save && !cultureErrors.Contains(x.Culture)).Select(x => x.Culture).ToArray())

var savedWithoutErrors = contentItem.Variants
.Where(x => x.Save && !cultureErrors.Contains(x.Culture) && x.Culture != null)
.Select(x => x.Culture)
.ToArray();

foreach (var c in savedWithoutErrors)
{
AddSuccessNotification(notifications, c,
Services.TextService.Localize("speechBubbles/editContentSavedHeader"),
Expand Down
20 changes: 7 additions & 13 deletions src/Umbraco.Web/Models/Mapping/ContentVariantMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,15 @@ private IEnumerable<Language> GetLanguages(MapperContext context)
/// </returns>
private IEnumerable<string> GetSegments(IContent content)
{
// The current segments of a content item are determined
// entirely on the current property values of the content.
var segments = content.Properties
.SelectMany(p => p.Values.Select(v => v.Segment))
.Distinct()
.ToList();
// The default segment (null) is always there,
// even when there is no property data at all yet
var segments = new List<string> { null };

if(segments.Count == 0)
{
// The default segment is always there,
// even when there is no property data at all yet
segments.Add(null);
}
// Add actual segments based on the property values
segments.AddRange(content.Properties.SelectMany(p => p.Values.Select(v => v.Segment)));

return segments;
// Do not return a segment more than once
return segments.Distinct();
}

private ContentVariantDisplay CreateVariantDisplay(MapperContext context, IContent content, Language language, string segment)
Expand Down

0 comments on commit 5a5291d

Please sign in to comment.