Skip to content

Commit 4d3be0a

Browse files
committed
Partial revert of #17854 (#18040)
1 parent bbd3431 commit 4d3be0a

File tree

7 files changed

+30
-137
lines changed

7 files changed

+30
-137
lines changed
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Text.Json.Serialization;
2-
31
namespace Umbraco.Cms.Core.PropertyEditors;
42

53
/// <summary>
@@ -15,10 +13,4 @@ public class SliderConfiguration
1513

1614
[ConfigurationField("maxVal")]
1715
public decimal MaximumValue { get; set; }
18-
19-
[ConfigurationField("initVal1")]
20-
public decimal InitialValue1 { get; set; }
21-
22-
[ConfigurationField("initVal2")]
23-
public decimal InitialValue2 { get; set; }
2416
}

src/Umbraco.Core/PropertyEditors/TrueFalseConfiguration.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/Umbraco.Core/PropertyEditors/TrueFalseConfigurationEditor.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/Umbraco.Core/PropertyEditors/ValueConverters/SliderValueConverter.cs

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,16 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType
4949
/// <inheritdoc />
5050
public override object? ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object? source, bool preview)
5151
{
52-
SliderConfiguration? configuration = propertyType.DataType.ConfigurationAs<SliderConfiguration>();
53-
bool isRange = IsRange(configuration);
52+
bool isRange = IsRange(propertyType);
5453

5554
var sourceString = source?.ToString();
5655

57-
// If source is null, the returned value depends on the configured initial values.
58-
if (string.IsNullOrEmpty(sourceString))
59-
{
60-
return isRange
61-
? new Range<decimal>
62-
{
63-
Minimum = configuration?.InitialValue1 ?? 0M,
64-
Maximum = configuration?.InitialValue2 ?? 0M
65-
}
66-
: configuration?.InitialValue1 ?? 0M;
67-
}
68-
6956
return isRange
7057
? HandleRange(sourceString)
7158
: HandleDecimal(sourceString);
7259
}
7360

74-
private static Range<decimal> HandleRange(string sourceString)
61+
private static Range<decimal> HandleRange(string? sourceString)
7562
{
7663
if (sourceString is null)
7764
{
@@ -105,8 +92,13 @@ private static Range<decimal> HandleRange(string sourceString)
10592
return new Range<decimal>();
10693
}
10794

108-
private static decimal HandleDecimal(string sourceString)
95+
private static decimal HandleDecimal(string? sourceString)
10996
{
97+
if (string.IsNullOrEmpty(sourceString))
98+
{
99+
return default;
100+
}
101+
110102
// This used to be a range slider, so we'll assign the minimum value as the new value
111103
if (sourceString.Contains(','))
112104
{
@@ -131,9 +123,7 @@ private static decimal HandleDecimal(string sourceString)
131123
private static bool TryParseDecimal(string? representation, out decimal value)
132124
=> decimal.TryParse(representation, NumberStyles.Number, CultureInfo.InvariantCulture, out value);
133125

134-
private static bool IsRange(IPublishedPropertyType propertyType)
135-
=> IsRange(propertyType.DataType.ConfigurationAs<SliderConfiguration>());
136126

137-
private static bool IsRange(SliderConfiguration? configuration)
138-
=> configuration?.EnableRange == true;
127+
private static bool IsRange(IPublishedPropertyType propertyType)
128+
=> propertyType.DataType.ConfigurationAs<SliderConfiguration>()?.EnableRange == true;
139129
}

src/Umbraco.Core/PropertyEditors/ValueConverters/YesNoValueConverter.cs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType
1818
{
1919
if (source is null)
2020
{
21-
return null;
21+
return false;
2222
}
2323

2424
// in xml a boolean is: string
@@ -59,17 +59,4 @@ public override PropertyCacheLevel GetPropertyCacheLevel(IPublishedPropertyType
5959
// false for any other value
6060
return false;
6161
}
62-
63-
/// <inheritdoc />
64-
public override object? ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel cacheLevel, object? source, bool preview)
65-
{
66-
// If source is null, whether we return true or false depends on the configured default value (initial state).
67-
if (source is null)
68-
{
69-
TrueFalseConfiguration? configuration = propertyType.DataType.ConfigurationAs<TrueFalseConfiguration>();
70-
return configuration?.InitialState ?? false;
71-
}
72-
73-
return (bool)source;
74-
}
7562
}

src/Umbraco.Infrastructure/PropertyEditors/TrueFalsePropertyEditor.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// Copyright (c) Umbraco.
22
// See LICENSE for more details.
33

4-
using Microsoft.Extensions.DependencyInjection;
5-
using Umbraco.Cms.Core.DependencyInjection;
64
using Umbraco.Cms.Core.IO;
75
using Umbraco.Cms.Core.Models;
86
using Umbraco.Cms.Core.Models.Editors;
@@ -20,37 +18,17 @@ namespace Umbraco.Cms.Core.PropertyEditors;
2018
ValueEditorIsReusable = true)]
2119
public class TrueFalsePropertyEditor : DataEditor
2220
{
23-
private readonly IIOHelper _ioHelper;
24-
2521
/// <summary>
2622
/// Initializes a new instance of the <see cref="TrueFalsePropertyEditor" /> class.
2723
/// </summary>
28-
[Obsolete("Please use the constructor taking all parameters. This constructor will be removed in V17.")]
2924
public TrueFalsePropertyEditor(IDataValueEditorFactory dataValueEditorFactory)
30-
: this(
31-
dataValueEditorFactory,
32-
StaticServiceProvider.Instance.GetRequiredService<IIOHelper>())
33-
{
34-
}
35-
36-
/// <summary>
37-
/// Initializes a new instance of the <see cref="TrueFalsePropertyEditor" /> class.
38-
/// </summary>
39-
public TrueFalsePropertyEditor(IDataValueEditorFactory dataValueEditorFactory, IIOHelper ioHelper)
4025
: base(dataValueEditorFactory)
41-
{
42-
_ioHelper = ioHelper;
43-
SupportsReadOnly = true;
44-
}
26+
=> SupportsReadOnly = true;
4527

4628
/// <inheritdoc />
4729
protected override IDataValueEditor CreateValueEditor()
4830
=> DataValueEditorFactory.Create<TrueFalsePropertyValueEditor>(Attribute!);
4931

50-
/// <inheritdoc />
51-
protected override IConfigurationEditor CreateConfigurationEditor() =>
52-
new TrueFalseConfigurationEditor(_ioHelper);
53-
5432
internal class TrueFalsePropertyValueEditor : DataValueEditor
5533
{
5634
public TrueFalsePropertyValueEditor(

tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/PropertyEditorValueConverterTests.cs

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Umbraco.Cms.Core.PropertyEditors.ValueConverters;
1010
using Umbraco.Cms.Core.Strings;
1111
using Umbraco.Cms.Infrastructure.Serialization;
12-
using Umbraco.Cms.Tests.Common.Builders;
1312

1413
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.PropertyEditors;
1514

@@ -47,54 +46,30 @@ public void CanConvertDatePickerPropertyEditor(string date, bool expected)
4746
}
4847
}
4948

50-
[TestCase("TRUE", null, true)]
51-
[TestCase("True", null, true)]
52-
[TestCase("true", null, true)]
53-
[TestCase("1", null, true)]
54-
[TestCase(1, null, true)]
55-
[TestCase(true, null, true)]
56-
[TestCase("FALSE", null, false)]
57-
[TestCase("False", null, false)]
58-
[TestCase("false", null, false)]
59-
[TestCase("0", null, false)]
60-
[TestCase(0, null, false)]
61-
[TestCase(false, null, false)]
62-
[TestCase("", null, false)]
63-
[TestCase("blah", null, false)]
64-
[TestCase(null, false, false)]
65-
[TestCase(null, true, true)]
66-
public void CanConvertTrueFalsePropertyEditor(object value, bool initialStateConfigurationValue, bool expected)
49+
[TestCase("TRUE", true)]
50+
[TestCase("True", true)]
51+
[TestCase("true", true)]
52+
[TestCase("1", true)]
53+
[TestCase(1, true)]
54+
[TestCase(true, true)]
55+
[TestCase("FALSE", false)]
56+
[TestCase("False", false)]
57+
[TestCase("false", false)]
58+
[TestCase("0", false)]
59+
[TestCase(0, false)]
60+
[TestCase(false, false)]
61+
[TestCase("", false)]
62+
[TestCase(null, false)]
63+
[TestCase("blah", false)]
64+
public void CanConvertYesNoPropertyEditor(object value, bool expected)
6765
{
68-
var publishedDataType = CreatePublishedDataType(initialStateConfigurationValue);
69-
70-
var publishedPropertyTypeMock = new Mock<IPublishedPropertyType>();
71-
publishedPropertyTypeMock
72-
.SetupGet(p => p.DataType)
73-
.Returns(publishedDataType);
74-
7566
var converter = new YesNoValueConverter();
76-
var intermediateResult = converter.ConvertSourceToIntermediate(null, publishedPropertyTypeMock.Object, value, false);
77-
var result = converter.ConvertIntermediateToObject(null, publishedPropertyTypeMock.Object, PropertyCacheLevel.Element, intermediateResult, false);
67+
var result =
68+
converter.ConvertSourceToIntermediate(null, null, value, false); // does not use type for conversion
7869

7970
Assert.AreEqual(expected, result);
8071
}
8172

82-
private static PublishedDataType CreatePublishedDataType(bool initialStateConfigurationValue)
83-
{
84-
var dataTypeConfiguration = new TrueFalseConfiguration
85-
{
86-
InitialState = initialStateConfigurationValue
87-
};
88-
89-
var dateTypeMock = new Mock<IDataType>();
90-
dateTypeMock.SetupGet(x => x.Id).Returns(1000);
91-
dateTypeMock.SetupGet(x => x.EditorAlias).Returns(global::Umbraco.Cms.Core.Constants.PropertyEditors.Aliases.Boolean);
92-
dateTypeMock.SetupGet(x => x.EditorUiAlias).Returns("Umb.PropertyEditorUi.Toggle");
93-
dateTypeMock.SetupGet(x => x.ConfigurationObject).Returns(dataTypeConfiguration);
94-
95-
return new PublishedDataType(dateTypeMock.Object.Id, dateTypeMock.Object.EditorAlias, dateTypeMock.Object.EditorUiAlias, new Lazy<object>(() => dataTypeConfiguration));
96-
}
97-
9873
[TestCase("[\"apples\"]", new[] { "apples" })]
9974
[TestCase("[\"apples\",\"oranges\"]", new[] { "apples", "oranges" })]
10075
[TestCase("[\"apples\",\"oranges\",\"pears\"]", new[] { "apples", "oranges", "pears" })]

0 commit comments

Comments
 (0)