Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't open select boxes for custom entities that have relations on other custom entities #222

Closed
Qonstrukt opened this issue Jul 4, 2018 · 7 comments
Labels
Milestone

Comments

@Qonstrukt
Copy link

I'm not sure this is a new issue, but I've noticed it now I'm trying to implement blog posts with a selectable author and category.

When editing an existing blog post it's impossible to open the select box to make another choice.
When creating a new blog post it only seems to become impossible when I've selected an image to accompany the blog post. Since it's required that might also be the reason I can't open the select boxes anymore when editing a post.

I've tried in Safari and Chrome, both trigger no JavaScript errors. So I don't really have a clue where to look for answers.

@HeyJoel
Copy link
Member

HeyJoel commented Jul 4, 2018

Hi, I'm trying to replicate this issue in the SimpleSite sample project by adding a CategoryId property to the blog post data model:

public class BlogPostDataModel : ICustomEntityDataModel
{
    [MaxLength(1000)]
    [Required]
    [Display(Description = "A description for display in search results and in the details page meta description.")]
    [MultiLineText]
    public string ShortDescription { get; set; }

    [Image(MinWidth = 460, MinHeight = 460)]
    [Display(Name = "Thumbnail Image", Description = "Square image that displays against the blog in the listing page.")]
    public int ThumbnailImageAssetId { get; set; }

    [Display(Name = "Categories", Description = "Drag and drop to customize the category ordering.")]
    [CustomEntityCollection(CategoryCustomEntityDefinition.DefinitionCode, IsOrderable = true)]
    public ICollection<int> CategoryIds { get; set; }

    [Display(Name = "Category")]
    [CustomEntity(CategoryCustomEntityDefinition.DefinitionCode)]
    public int CategoryId { get; set; }
}

I can't seem to replicate the issue though, is that a simplar property definition to the one you're using?

@HeyJoel
Copy link
Member

HeyJoel commented Jul 5, 2018

I wondered if having two custom entity properties might triger the error so I added an author to my definition and also marked the fields as required (although this is also inferred from the use of int or int? anyway).

public class BlogPostDataModel : ICustomEntityDataModel
{
    [MaxLength(1000)]
    [Required]
    [Display(Description = "A description for display in search results and in the details page meta description.")]
    [MultiLineText]
    public string ShortDescription { get; set; }

    [Image(MinWidth = 460, MinHeight = 460)]
    [Display(Name = "Thumbnail Image", Description = "Square image that displays against the blog in the listing page.")]
    public int ThumbnailImageAssetId { get; set; }

    [Display(Name = "Categories", Description = "Drag and drop to customize the category ordering.")]
    [CustomEntityCollection(CategoryCustomEntityDefinition.DefinitionCode, IsOrderable = true)]
    public ICollection<int> CategoryIds { get; set; }

    [Required]
    [Display(Name = "Category")]
    [CustomEntity(CategoryCustomEntityDefinition.DefinitionCode)]
    public int CategoryId { get; set; }

    [Required]
    [Display(Name = "Author")]
    [CustomEntity(AuthorCustomEntityDefinition.DefinitionCode)]
    public int AuthorId { get; set; }
}

I still don't see the error. I wonder if maybe there is a problem accessing the custom entity search api when the select box opens? You should see an XHR request to Admin/Api/custom-entity-definitions/{CustomEntityDefinitionCode}/custom-entities when you click to open the select box. Is that being triggered successfully?

Also, which version are you using? 0.3.2?

@Qonstrukt
Copy link
Author

I'll try and make a good repro this weekend!
Apparently there's something particular that triggers the issue.
Thanks for looking into it!

@Qonstrukt
Copy link
Author

Qonstrukt commented Jul 11, 2018

It was such good weather this weekend that I've spent most of it in my pool. 😉
But I've checked what's happening under water, and it's doing the XHR request to retrieve custom entities, but it turns up empty.
Could this be caused by the fact that my BlogPost has AutoPublish => false and HasLocale => true, while the BlogAuthor has AutoPublish => true and HasLocale => false?

[Edit]
Ok that was actually it, I've changed both custom entities to HasLocale => true and added locales to them and now it works as it should.

It might be an idea to treat custom entities that have HasLocale => false different from localised entities that have no market specified. Because in that last case I can imagine you do't want them to appear. But in case a custom entity has no localisation possibility, they should always all be visible, for all queries that have a LocaleId specified. (I ran into this issue in my own mapping code as well for some other entities IIRC.)

@HeyJoel
Copy link
Member

HeyJoel commented Jul 11, 2018

Good spot, yes locales would be the likely culprit as that's all functionality that still needs to be worked on.

What you suggest is the intended functionality, so this is a bug and I imagine it is something to do with some misbehaving auto-locale filtering that is trying to automatically filter your author based on the blog locale, but not taking into account that the author is a non-localized entity.

I'll investigate a more as part of v0.4. Is the work around acceptable for now? v0.4 is a little way off yet.

@Qonstrukt
Copy link
Author

That's ok, this works for now. 👍

@HeyJoel HeyJoel added the bug label Jul 11, 2018
@HeyJoel HeyJoel added this to the 0.4 milestone Jul 11, 2018
HeyJoel added a commit that referenced this issue Aug 1, 2018
…ations on other custom entities" by ignoring locale filtering for CE search queries when the CE does not support locales.
@HeyJoel
Copy link
Member

HeyJoel commented Aug 1, 2018

Fixed in v0.4 release.

@HeyJoel HeyJoel closed this as completed Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants