leekelleher / umbraco-contentment

Contentment for Umbraco - a state of happiness and satisfaction
https://marketplace.umbraco.com/package/umbraco.community.contentment
Mozilla Public License 2.0
157 stars 72 forks source link

Data picker not rendering in UI builder actions #374

Closed brannmark closed 10 months ago

brannmark commented 10 months ago

Which Contentment version are you using?

4.6.0

Which Umbraco version are you using? For example: 10.3.2 - don't just write v10

13.0.3

Bug summary

Datatype with a data picker in a custom UI builder action doesn't work. It does not render as supposed to.

Throw following error: image

Using this code for custom action:

using Umbraco.UIBuilder.Configuration;
using Umbraco.UIBuilder.Configuration.Actions;
using Umbraco.UIBuilder.Configuration.Builders;
using Umbraco.UIBuilder.Services;
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;

namespace MyProj.Actions.BulkActions
{
    public class TestAction : Umbraco.UIBuilder.Configuration.Actions.Action<TestActionSetting, ActionResult>
    {
        public override string Icon => "icon-edit";
        public override string Alias => "test";
        public override string Name => "Test";
        public override bool ConfirmAction => false;
        private readonly Lazy<UIBuilderConfig> _config;
        private readonly Lazy<EntityService> _entityService;
        private readonly Lazy<IHostingEnvironment> _hostingEnv;

        public TestAction(Lazy<UIBuilderConfig> config, Lazy<EntityService> entityService, Lazy<IHostingEnvironment> hostingEnv)
        {
            _config = config;
            _entityService = entityService;
            _hostingEnv = hostingEnv;
        }

        public override void Configure(SettingsConfigBuilder<TestActionSetting> settingsConfig)
        {
            settingsConfig.AddFieldset("Content", fieldsetConfig =>
            {
                fieldsetConfig.AddField(m => m.TestProperty).SetDataType("Test");
            });
        }

        public override ActionResult Execute(string collectionAlias, object[] entityIds, TestActionSetting settings)
        {
            return new ActionResult(true, new ActionNotification("Test action executed"));
        }

        public override bool IsVisible(ActionVisibilityContext ctx)
        {
            if (ctx.ActionType == ActionType.Row || ctx.ActionType == ActionType.Bulk)
            {
                return true;
            }

            return false;
        }
    }

    public class TestActionSetting
    {
        public string TestProperty { get; set; } = string.Empty;
    }
}

Datatype: image

Collection: image

Rendering: image

Steps to reproduce

1, Create a datatype using Data Picker

  1. Create a custom action for UI Builder
  2. Create a customer Settings Model
  3. Add datatype with data picker to the settings model in configure
  4. Add action to an UI Builder collection
  5. Click on action
  6. See property but no editor rendered.

Expected result / actual result

Expected editor to be rendered.

Do you have Umbraco ModelsBuilder enabled?

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

leekelleher commented 10 months ago

Hi @brannmark, thanks for raising this. I still haven't tried out UI Builder yet, so I'm still unsure about how much of the Contentment editors (of any other 3rd party packages) are supported.

The JavaScript error you get appears to be related to this line... https://github.com/leekelleher/umbraco-contentment/blob/743a8d82d5bcfcef6200828e5fc28a55a874f059/src/Umbraco.Community.Contentment/DataEditors/DataPicker/data-picker.js#L44 Which suggests that UI Builder isn't populating the editorState.getCurrent(), so the Data Picker isn't aware of the current page.

I'll look to patch this in the Data Picker, so it has a fallback value.

This should also be raised the UI Builder issue tracker, similar to the previous issue you encountered in #368.

brannmark commented 10 months ago

Added an issue to UI Builder Issues also now. Thanks for a great support!

brannmark commented 10 months ago

Tried adding the action so its trigger on a item which then has an id in the url. Then it renders as supposed to. image

brannmark commented 10 months ago

It works to render when used on a single item. But when a value is picked and you try to execute the action it fails catastrophic. Kills the IIS express, no log errors what so ever. image

brannmark commented 10 months ago

image

The preform action fails and kills the IIS server. Might be that ID problem when the Contentment data picker should be loaded on execute perhaps?

brannmark commented 10 months ago

Seams like the IIS crash is not a Contentment problem but an Umbraco/UI builder problem as built in actions with settings also fails on execute. https://github.com/umbraco/Umbraco.UIBuilder.Issues/issues/84