AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

[JavaScript SDK Web][Adaptive Card Designer] [Designer does not render custom elements registered in adaptive cards]

Open Trish92 opened this issue 5 years ago • 27 comments

Web JS SDK

What platform is your issue or question related to? (Delete other platforms).

  • [ ] JavaScript

Author or host

All

Version of SDK

What version are you using? Latest

Details

Explain your issue. If you just have a question, please post on StackOverflow instead.

https://docs.microsoft.com/en-us/adaptive-cards/sdk/rendering-cards/javascript/extensibility

This documentation shows an example to show a progress bar and create your own action But how do I then show those in the designer ? Where can I find documentation for the same?

For the ProgressBarPeer, this is my class type : export class ProgressBarPeer extends ACDesigner.TypedCardElementPeer

This is what I sent to registerPeer : ACDesigner.CardDesignerSurface.cardElementPeerRegistry.registerPeer( ProgressBar, ProgressBarPeer, "Elements", 'acd-icon-columnSet' ); If I use AC.TextBlock instead of my own custom component ProgressBar I do see changes in the properties as defined in my ProgressBarPeer

Please let me know what maybe missing to see the ProgressBar under elements in the designer. I am using all the latest npm packages. I am attaching as evidence my registry that contains an action and an element with their peers. It would be great if there was some more documentation and an example for adding an action and an element to the designer. Thanks.

image

#5240 image

Trish92 avatar Apr 12 '21 15:04 Trish92

https://stackoverflow.com/questions/66680403/adding-custom-card-elements-into-the-adaptive-card-designer

Trish92 avatar Apr 12 '21 15:04 Trish92

@dclaux - can you please investigate and respond back with the right action we should take?

jonmill avatar Apr 15 '21 20:04 jonmill

You can reproduce this easily by using your own ProgressBar example and the TextBlockPeer file. I would appreciate any resolution you can provide cause this is very important at the moment for us. This project is amazing, we love the extensibility of it. Thank you so much!

Trish92 avatar Apr 15 '21 21:04 Trish92

#5240

Trish92 avatar Apr 15 '21 21:04 Trish92

I'm not sure how I can help you without seeing your code. Every single element in the designer is implemented exactly as you would if you were to create your own custom element. It requires an element registered with the renderer, and a designer peer registered with the designer. I am working on a custom element myself right with n associated designer peer and things work as expected.

We do lack proper documentation at the moment on how to extend the designer, we'll get to that. Please share you ProgressBarPeer implementation as well as the code you use to register both the ProgressBar element and the peer in order for me to be able to diagnose. Also make sure that the target version selected in the designer isn't lower than the version for which your element/peer are registered.

dclaux avatar Apr 15 '21 21:04 dclaux

ProgressBar.txt

Trish92 avatar Apr 15 '21 22:04 Trish92

If I use this same peer and register Adaptive.RichTextBlock or some other component I do see the property sheet as implemented in the ProgressBarPeer file :
ACDesigner.CardDesignerSurface.cardElementPeerRegistry.registerPeer(Adaptive.RichTextBlock,ProgressBarPeer,"Elements","acd-icon-columnSet"); When I check what the designerPeerRegistration has when I do this the sourceType is a function and not a class !

Trish92 avatar Apr 15 '21 22:04 Trish92

AC.GlobalRegistry.elements.register(ProgressBar.JsonTypeName, ProgressBar, AC.Versions.v1_3); ACDesigner.CardDesignerSurface.cardElementPeerRegistry.registerPeer( ProgressBar, ProgressBarPeer, 'Elements', 'acd-icon-columnSet' );;

I did play around with the versions cause that was the only thing that stood out to me that could be wrong. This is a typescript and react project.

If I had seen a gap in the code I would have raised a Pull request cause this feature has been my number 1 priority since two months. I believe I may just be missing some piece of code and would appreciate your support. Thanks.

Trish92 avatar Apr 15 '21 22:04 Trish92

ProgressBar's properties are title and value. Your ProgressBarPeer declares wrapProperty, fontTypeProperty, sizeProperty, etc. These properties are irrelevant to ProgressBar. Your peer needs to declare properties for title and value.

dclaux avatar Apr 15 '21 23:04 dclaux

image I still dont see a progress bar element in the designer but if I use Adaptive.RichTextBlock then I do see my added value and title properties

Trish92 avatar Apr 16 '21 00:04 Trish92

image Difference between ProgressBar and another component

Trish92 avatar Apr 16 '21 00:04 Trish92

Sorry I am confused as to what you're showing or what you're trying to explain.

To add support for a specific element in the designer, you need to implement a peer that declares the properties of the element you want to see in the property editor. For ProgressBar you need a ProgressBarPeer that declares title and value properties and you need to add those properties to the property sheet in populatePropertySheet. That's really about it.

dclaux avatar Apr 16 '21 00:04 dclaux

I did do that but was unable to render the Progress bar element in the Elements section of the designer. But If I replace the ProgressBar that I made with Adaptive.RichTextBlock that Peer file does work and you can see a Title and Value property on the property sheet

Trish92 avatar Apr 16 '21 00:04 Trish92

Are you registering the ProgressBar element in the initialize method of your HostContainer?

dclaux avatar Apr 16 '21 00:04 dclaux

nope that maybe the problem

This is all I am doing

let hostContainers: any = ACDesigner.defaultMicrosoftHosts;

// Optional: add the default Microsoft Host Apps (see docs below)
hostContainers = [];

this.designer = new ACDesigner.CardDesigner(hostContainers);

Do you have an implementation handy? I am registering it at the start of the application before rendering the designer and adaptive card and I do see the component rendering in the adaptive card, just not in the designer. Which means both progress bar and progress bar peer work independently.

Trish92 avatar Apr 16 '21 00:04 Trish92

We really do need documentation, I'll try to find some time soon.

In the designer, which elements are supported (and thus displayed) is tied to the selected "host app". Under the covers, a host app is implemented by creating a class that extends the abstract HostContainer class. That base class declares its own element and action registries.

If you do not pass any host container to the constructor of the designer, it uses a default host container that only exposes built-in elements. If you need to use custom elements (and/or actions) in the designer you need to provide your own host container implementation, and the initialize method of that host container is where you can register your custom elements/actions.

It's very simple:

class YourHostContainer extends DefaultContainer {
    initialize() {
        super.initialize();

        this.elementsRegistry.register(ProgressBar.JsonTypeName, ProgressBar);
    }
}

let designer = new CardDesigner([ new YourHostContainer("your container name", "<path-to-its-css-stylesheet>") ]);

dclaux avatar Apr 16 '21 02:04 dclaux

Actually, you should even be able to do this, which is simpler:

let hostContainer = new DefaultContainer("your container name", "<path-to-its-css-stylesheet>");
hostContainer.elementsRegistry.register(ProgressBar.JsonTypeName, ProgressBar);

let designer = new CardDesigner([ hostContainer ]);

dclaux avatar Apr 16 '21 03:04 dclaux

Amazing ! Worked, thank you so very much !

let hostContainer = new ACDesigner.DefaultContainer("MyHost", "../../styles/custom-styles.css"); hostContainer.elementsRegistry.register(ProgressBar.JsonTypeName, ProgressBar); this.designer = new ACDesigner.CardDesigner([hostContainer]);

You already have most of it documented :)

Trish92 avatar Apr 16 '21 03:04 Trish92