AaronSadlerUK / Our.Umbraco.UmbNav

Drag and drop menu editor for Umbraco V8, V9 and V10+
MIT License
10 stars 15 forks source link

Adding a lablel in the tree causes System.Linq.EmptyPartition`1[UmbNav.Core.Models.UmbNavItem] to be returned #39

Closed mistyn8 closed 3 years ago

mistyn8 commented 3 years ago

Which exact Umbraco version are you using? For example: 8.7.0 - don't just write v8 or v9

Umb 9.0.0 umbNav 1.0.0.2

Bug summary

Adding a lablel in the tree causes System.Linq.EmptyPartition`1[UmbNav.Core.Models.UmbNavItem] to be returned when querying the property for rendering. raw json below if that helps?

[
  {
    "id": 2408,
    "udi": "umb://document/a437048758ac4f77be90d1cc748c0851",
    "key": "a4370487-58ac-4f77-be90-d1cc748c0851",
    "name": "4x4s, Cars & Vans",
    "description": "/4x4s-cars-vans/",
    "url": "/4x4s-cars-vans/",
    "children": [],
    "icon": "icon-store color-blue",
    "published": true,
    "naviHide": false,
    "culture": "undefined",
    "itemType": "link"
  },
  {
    "id": null,
    "udi": null,
    "description": null,
    "title": "General Information",
    "target": null,
    "noopener": false,
    "noreferrer": false,
    "anchor": null,
    "url": null,
    "children": [],
    "icon": "icon-tag",
    "includeChildNodes": false,
    "itemType": "nolink"
  }
]

Specifics

No response

Steps to reproduce

Add a label

Expected result / actual result

labels should be possible.

mistyn8 commented 3 years ago

the associated log error (maybe the valueConvertor?)

Failed to convert UmbNav {ex}
--
Newtonsoft.Json.JsonSerializationException: Error converting value {null} to type 'System.Int32'. Path '[1].id', line 17, position 14. ---> System.InvalidCastException: Null object cannot be converted to a value type. at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) --- End of inner exception stack trace --- at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings) at UmbNav.Core.ValueConverters.UmbNavV8ValueConverter.ConvertIntermediateToObject(IPublishedElement owner, IPublishedPropertyType propertyType, PropertyCacheLevel referenceCacheLevel, Object inter, Boolean preview)
AaronSadlerUK commented 3 years ago

I will take a look a little later on tonight when I finish work :)

mistyn8 commented 3 years ago

public int Id { get; set; } => public int? Id { get; set; } ??

I'll have a play to see if that's it.

AaronSadlerUK commented 3 years ago

When you clone down, if you mark the v9 test site as startup and run uSync import it should restore my test data =]

mistyn8 commented 3 years ago
[JsonProperty("id", NullValueHandling = NullValueHandling.Ignore)]
        [Obsolete("This is here purely for legacy reasons, please use the Key or Udi property as this is unreliable")]
        public int Id { get; set; } = 0;

Seems to allow rendering.. :-) although <span class="nav-link" rel="test" href="">Label goes here</span> might be the taghelper needs a tweak?

mistyn8 commented 3 years ago

ps Had to update the USync dependency to get the import to complete.

mistyn8 commented 3 years ago

Pull Request #40

AaronSadlerUK commented 3 years ago

Interesting the span shouldn't contain "href" that's for sure 😕

mistyn8 commented 3 years ago

updated the pull request with a tweak for labels :-)

AaronSadlerUK commented 3 years ago

@mistyn8 Great worked as expected!

I've released 1.0.3 should be on nuget shortly =]

Thanks!