umbraco / Umbraco.UIBuilder.Issues

Back office UI builder for Umbraco
3 stars 2 forks source link

Upgrade from 13.0.3 to 13.1.0-rc1 breaks existing custom repository #91

Closed Padbury closed 8 months ago

Padbury commented 8 months ago

Describe the bug I have a very simple, only partially implemented custom repository that works fine in 13.0.3 but as soon as I update to 13.1.0-rc1 all attempts to view an entity result in the following error: UdiConverter cannot convert from System.String.

Steps To Reproduce

  1. Create a simple custom repository
  2. Add a small list view to a collection
  3. Wire up the ui builder: such as:

    builder.AddUIBuilder(cfg =>
    {
       cfg.AddSectionAfter("media", "Store", sectionConfig => sectionConfig
               .Tree(treeConfig => treeConfig
                   .AddCollection<EditableProduct>(x => x.Id, "Products", "Products", "A product entity", "icon-frame-alt", "icon-frame-alt", collectionConfig => collectionConfig
                       .SetNameProperty(p => p.Name)
                       .ListView(listViewConfig => listViewConfig
                           .AddField(p => p.Code).SetHeading("Code")
                       )
                       .SetRepositoryType<ProductBackofficeRepository>()
                       .Editor(editorConfig => editorConfig
                           .AddTab("General", tabConfig => tabConfig
                               .AddFieldset("Details", x => x
                               .AddField(p => p.Code).SetDataType("Textstring").MakeRequired().SetDescription("The product code")  
                               )    
                           )
                       )
                   )
               )
           );
    
    });

Expected behavior Entity is shown without an error

Screenshots Capture

Environment (please complete the following information):

Additional context I created a super simple custom repo that only (currently) implements the GetImpl and the GetPagedImpl functions. In the previous version of the UIBuilder (13.0.3) this worked fine, however it didn't properly support the Richtext Editor. However, reading around, the RTE issue is fixed with this rc. Upgrading the version required an additional function to be implemented on the custom repo (SaveRelationImpl) which I added, but as unimplemented. However, on updating, I get the attached error when attempting to view on of the returned entities. In attempting to debug this, I ended up with a super simple class of this:

public class EditableProduct { public int Id { get; set; } public string Code { get; set; } = null!; public string Name{ get; set; } = null!; }

Reverting back to 13.0.3 fixes this issue but then if I try to add an RTE to my model, the RTE doesn't render. So caught between two issues.

Thanks

acoumb commented 8 months ago

Hi @Padbury ,

Could you share your custom repository as well? I have tried your use case using the default UI Builder repository, and I haven't encountered the issue you've reported (you can check my test here). image image

Regarding the RTE issue, this was addressed by the CMS team with version 13.1 of Umbraco. Could you update your website and try again?

Thank you, Adrian

Padbury commented 8 months ago

Hiya,

Thanks for reviewing. Here's my repo though it's only implementing a couple of the functions (and even then it's not finished) but it will give you an idea of what I've got. The flow doesn't get as far as the repo though. I popped in some breakpoints and the constructor isn't getting hit. However, if you were unable to replicate then it's possible it's something else externally, such as a package, that might be causing the issue. I'll investigate further today. Here's my repo anyway.

Thanks again

public class ProductBackofficeRepository(RepositoryContext context, IProductService productService, IMapper mapper) : Repository<EditableProduct, int>(context)
  {
      protected override void DeleteImpl(int id)
      {
          throw new NotImplementedException();
      }

      protected override IEnumerable<EditableProduct> GetAllImpl(Expression<Func<EditableProduct, bool>>? whereClause = null, Expression<Func<EditableProduct, object>>? orderBy = null, SortDirection orderByDirection = SortDirection.Ascending)
      {
          throw new NotImplementedException();
      }

      protected override long GetCountImpl(Expression<Func<EditableProduct, bool>> whereClause)
      {
          throw new NotImplementedException();
      }

      protected override int GetIdImpl(EditableProduct entity)
      {
          throw new NotImplementedException();
      }

      protected override EditableProduct GetImpl(int id)
      {
          return mapper.Map<EditableProduct>(productService.Get(id));
      }

      protected override PagedResult<EditableProduct> GetPagedImpl(int pageNumber, int pageSize, Expression<Func<EditableProduct, bool>>? whereClause = null, Expression<Func<EditableProduct, object>>? orderBy = null, SortDirection orderByDirection = SortDirection.Ascending)
      {
          var products = productService.Fetch(pageNumber, pageSize, ProductSortOrder.Name, false, "");
          var i = new PagedResult<EditableProduct>(products?.TotalResults ?? 0, pageNumber, pageSize)
          {
              Items = mapper.Map<List<EditableProduct>>(products)
          };
          return i;
      }

      protected override IEnumerable<TJunctionEntity> GetRelationsByParentIdImpl<TJunctionEntity>(int parentId, string relationAlias)
      {
          throw new NotImplementedException();
      }

      protected override EditableProduct SaveImpl(EditableProduct entity)
      {
          throw new NotImplementedException();
      }

      protected override TJunctionEntity SaveRelationImpl<TJunctionEntity>(TJunctionEntity entity)
      {
          throw new NotImplementedException();
      }
  }
acoumb commented 8 months ago

I managed eventually to simulate something and got the error thrown, I will investigate it and prepare a fix for it.

Thanks for the help

acoumb commented 8 months ago

@Padbury version 13.1.0-rc2 is out with a fix to your reported issue.

Thank you for your help with this, Adrian