AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

[Templating Feature] Allow an array of AdaptiveCards as template

Open anna-dingler opened this issue 3 years ago • 1 comments

Related Issue

Fixes #7779

Description

The JS templating library can now accept an array of AdaptiveCards as the template.

Changes in templating

After expanding the template, we check if the remaining object is an array. If the object is an array of length 1, we return the AdaptiveCard. If the array is of length 0 or greater than 1, we log an error and return undefined.

Changes in Designer

If the given card payload is an array of AdpativeCards, we disable design mode and only show the rendered card in preview mode. This is because templating is only applied in preview mode.

Sample Card

[
    {
        "type": "AdaptiveCard",
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "version": "1.5",
        "$when": "${test}",
        "body": [
            {
                "type": "TextBlock",
                "text": "To be displayed if test === true",
                "wrap": true
            }
        ]
    },
    {
        "type": "AdaptiveCard",
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
        "version": "1.5",
        "$when": "${!test}",
        "body": [
            {
                "type": "TextBlock",
                "text": "To be displayed if test === false",
                "wrap": true
            }
        ]
    }
]

Data

{
    "test": false
}

How Verified

  1. Added three templating unit-test (simple TextBlock, Container vs. Carousel, failure to test template error).
  2. Verified manually in the designer.
  3. Verified the new UI adjusts to high contrast.

Future work

Templating expansion warnings/errors need to be displayed in the designer (#7442)

anna-dingler avatar Aug 31 '22 21:08 anna-dingler

Hi @anna-dingler. This pull request has had no recent activity for the past 5 days . Please take the necessary actions (review, address feedback or commit if reviewed already) to move this along.

ghost avatar Sep 13 '22 16:09 ghost

I'm not understanding this. The templating engine has always accepted an array of anything (not just cards, the template engine is 100% generic and independent from AC aside from its package name) as a template.

dclaux avatar Sep 23 '22 16:09 dclaux

I'm not understanding this. The templating engine has always accepted an array of anything (not just cards, the template engine is 100% generic and independent from AC aside from its package name) as a template.

@dclaux I misnamed this PR. The changes are focused on ensuring that the templating library always outputs an object (ideally an AdaptiveCard, but templating is independent as you noted above).

We haven't decided if we want to take this change in general, but we're keeping it here for now.

anna-dingler avatar Sep 23 '22 16:09 anna-dingler

The templating engine should not return an object if it is fed with a template that has a top level array. It should produce an array. It should be the responsibility of the consuming application to extract what it needs to extract from the produced array. Alternatively, the consuming application could extract objects from the array and feed each one to the templating engine independently.

dclaux avatar Sep 23 '22 20:09 dclaux

Also re: "if the given card payload is an array" - that is simply not possible: an Adaptive Card cannot be expressed as an array. It must be expressed as an object. An array would never pass validation against the AC schema.

dclaux avatar Sep 23 '22 20:09 dclaux

Closing since we are not adding this feature right now.

anna-dingler avatar Nov 28 '22 21:11 anna-dingler

Staleness reset by anna-dingler

ghost avatar Nov 28 '22 21:11 ghost