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

Support for ToggleVisibility #243

Closed
arluko opened this issue Nov 17, 2023 · 9 comments · Fixed by #251
Closed

Support for ToggleVisibility #243

arluko opened this issue Nov 17, 2023 · 9 comments · Fixed by #251
Assignees
Labels
card format/adaptivecard Adaptive Card support documentation Improvements or additions to documentation enhancement New feature or request
Milestone

Comments

@arluko
Copy link

arluko commented Nov 17, 2023

First, thank a lot for this library. It made my job a lot easier but a little but crucial piece for my use-case is missing.

I would like to build an AdaptiveCard to achieve the following:

  • I have a card with some text and a link
  • When I click on the link I want to show more details
  • If I click again on the link I want to hide the details again

I have built an example which you can try out in the Preview mode of the designer:

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.5",
    "body": [
        {
            "type": "TextBlock",
            "text": "Something has failed",
            "wrap": true,
            "style": "heading"
        },
        {
            "id": "details",
            "type": "TextBlock",
            "text": "Lorem ipsum dolor sit amet ...",
            "wrap": true,
            "isVisible": false
        },
        {
            "type": "Container",
            "selectAction": {
                "type": "Action.ToggleVisibility",
                "targetElements": [
                    "details",
                    "showDetails",
                    "hideDetails"
                ]
            },
            "items": [
                {
                    "type": "TextBlock",
                    "id": "showDetails",
                    "color": "Accent",
                    "text": "Show details"
                },
                {
                    "type": "TextBlock",
                    "id": "hideDetails",
                    "color": "Accent",
                    "text": "Hide details",
                    "isVisible": false
                }
            ]
        }
    ]
}

The following pieces are currently missing:

  1. targetElements can not be set on the Action.ToggleVisibility (see schema)
  2. isVisible can not be set on an Container (see schema)

Note: isVisible can not only be set on Container but a lot more element but for my use-case a container should be enough.

Can you add support for these two properties?

@atc0005
Copy link
Owner

atc0005 commented Nov 18, 2023

Hi @arluko

Thank you for the detailed GH issue.

No promises on implementation time, but a quick review suggests this should be doable.

I will try to share a curl snippet and JSON file to test functionality in the near future so you can test delivering to your Teams instance. This will help confirm that the generated JSON payload will work as expected.

@atc0005
Copy link
Owner

atc0005 commented Nov 20, 2023

@arluko

Place this within a text file (e.g., gh-243-test-payload1.json):

{
    "type": "message",
    "attachments": [
        {
            "contentType": "application/vnd.microsoft.card.adaptive",
            "content": {
                "type": "AdaptiveCard",
                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
                "version": "1.5",
                "body": [
                    {
                        "type": "TextBlock",
                        "text": "Something has failed",
                        "wrap": true,
                        "style": "heading"
                    },
                    {
                        "id": "details",
                        "type": "TextBlock",
                        "text": "Lorem ipsum dolor sit amet ...",
                        "wrap": true,
                        "isVisible": false
                    },
                    {
                        "type": "Container",
                        "selectAction": {
                            "type": "Action.ToggleVisibility",
                            "targetElements": [
                                "details",
                                "showDetails",
                                "hideDetails"
                            ]
                        },
                        "items": [
                            {
                                "type": "TextBlock",
                                "id": "showDetails",
                                "color": "Accent",
                                "text": "Show details"
                            },
                            {
                                "type": "TextBlock",
                                "id": "hideDetails",
                                "color": "Accent",
                                "text": "Hide details",
                                "isVisible": false
                            }
                        ]
                    }
                ]
            }
        }
    ]
}

and use this snippet to deliver it (substituting the example webhook URL for your own):

webhook_url="https://example.webhook.office.com/webhookb2/a1269812-6d10-44b1-abc5-b84f93580ba0@9e7b80c7-d1eb-4b52-8582-76f921e416d9/IncomingWebhook/3fdd6767bae44ac58e5995547d66a4e4/f332c8d9-3397-4ac5-957b-b8e3fc465a8c"
curl \
    -X POST \
    -H "Content-type: application/json" \
    -d @/path/to/gh-243-test-payload1.json \
    "${webhook_url}"

@arluko
Copy link
Author

arluko commented Nov 20, 2023

@atc0005 I have tested your sample with curl and it works on my teams instance.

image

@atc0005
Copy link
Owner

atc0005 commented Nov 20, 2023

Thank you for testing and confirming the results.

@atc0005
Copy link
Owner

atc0005 commented Nov 30, 2023

I've been working on this, but it will take some time to work out the changes. I'll post again when there is something ready for testing/feedback.

@atc0005 atc0005 self-assigned this Dec 6, 2023
@atc0005 atc0005 added card format/adaptivecard Adaptive Card support enhancement New feature or request documentation Improvements or additions to documentation labels Dec 6, 2023
atc0005 added a commit that referenced this issue Dec 7, 2023
- add Element.Visible field
  - to control visibility of Elements
  - if not specified, this value defaults to true by omitting
    the field from the generated JSON payload
- add TargetElement type
- add Action.TargetElement field
  - to specify collection of TargetElement values
  - used to specify target Element values whose visibility
    state should be controlled by the Element whose Action
    the TargetElement field is associated with
- add ISelectAction.TargetElements field
  - same purpose as Action.TargetElement field
- add missing validation for Element.SelectAction field
  for Element of ColumnSet type
- add missing validation for Element.SelectAction field
  for Element of Container type
- add Column.AddSelectAction method
  - accepts Action or ISelectAction value
- update ISelectAction.Validate method
  - add missing validation for ISelectAction.Fallback field
  - add validation for ISelectAction.TargetElements field
    for Action.ToggleVisibility type
- update Action.Validate method
  - convert validation logic to use validator package
- add Action.AddTargetElement method
  - accepts multiple Element values
  - allows explicitly setting target Element visibility
- add Action.AddVisibleTargetElement method
  - convienence method to explicitly enable visibility for target
    Element values
- add Action.AddHiddenTargetElement method
  - convienence method to explicitly disable visibility for target
    Element values
- add Action.AddTargetElementID method
  - accepts multiple Element ID values
  - allows explicitly setting target Element visibility
- add new helper "constructor" functions
  - NewHiddenerContainer
  - NewColumn
  - NewColumnSet
  - NewHiddenTextBlock
  - NewActionToggleVisibility
- update Container.AddAction
  - add note to doc comments directing reader to
    Container.AddSelectAction for adding an Action to be used when the
    Container is tapped or selected
- add Container.AddSelectAction method
  - accepts Action or ISelectAction value
- add examples
  - add toggle-visibility-column-action
  - add toggle-visibility-container-action
  - add toggle-visibility-multiple-buttons
  - add toggle-visibility-single-button

refs GH-243
refs GH-239
@atc0005
Copy link
Owner

atc0005 commented Dec 7, 2023

@arluko The initial prototype support can be found in the v2.9.0-alpha.1 release here:

Examples are included.

Feedback is welcome.

@atc0005 atc0005 added this to the v2.9.0 milestone Dec 7, 2023
@arluko
Copy link
Author

arluko commented Dec 14, 2023

@atc0005 I have tested the v2.9.0-alpha.1 release and it works for my use-case. Thanks a lot for the fast implementation. When can we expect a v2.9.0 release with this feature?

@atc0005
Copy link
Owner

atc0005 commented Dec 14, 2023

Hi @arluko ,

Thanks for testing and providing feedback.

As I worked on these changes I ran into several places in the code that I would have liked to change to make integrating the new support easier, to make the steps feel more natural, but that would require an API change and thus a version bump to v3.

I would like to avoid that here if possible; I would like to wait a bit longer and gather additional feedback before including this code as part of the next stable release.

While this initial implementation is subject to change (to fix any discovered problems), the tag I shared will remain in case you wish to move forward with the existing behavior in your application(s) while we wait on others to respond.

@arluko
Copy link
Author

arluko commented Dec 14, 2023

@atc0005 I have restructured my card (for now) to work without the toggle visibility feature, so I am not really dependent on a immediate release with this feature. If there is a release sometime in the future with this functionality, I will integrate it, but in the meantime I have a working solution.

atc0005 added a commit that referenced this issue Jan 25, 2024
- add Element.Visible field
  - to control visibility of Elements
  - if not specified, this value defaults to true by omitting
    the field from the generated JSON payload
- add TargetElement type
- add Action.TargetElement field
  - to specify collection of TargetElement values
  - used to specify target Element values whose visibility
    state should be controlled by the Element whose Action
    the TargetElement field is associated with
- add ISelectAction.TargetElements field
  - same purpose as Action.TargetElement field
- add missing validation for Element.SelectAction field
  for Element of ColumnSet type
- add missing validation for Element.SelectAction field
  for Element of Container type
- add Column.AddSelectAction method
  - accepts Action or ISelectAction value
- update ISelectAction.Validate method
  - add missing validation for ISelectAction.Fallback field
  - add validation for ISelectAction.TargetElements field
    for Action.ToggleVisibility type
- update Action.Validate method
  - convert validation logic to use validator package
- add Action.AddTargetElement method
  - accepts multiple Element values
  - allows explicitly setting target Element visibility
- add Action.AddVisibleTargetElement method
  - convienence method to explicitly enable visibility for target
    Element values
- add Action.AddHiddenTargetElement method
  - convienence method to explicitly disable visibility for target
    Element values
- add Action.AddTargetElementID method
  - accepts multiple Element ID values
  - allows explicitly setting target Element visibility
- add new helper "constructor" functions
  - NewHiddenerContainer
  - NewColumn
  - NewColumnSet
  - NewHiddenTextBlock
  - NewActionToggleVisibility
- update Container.AddAction
  - add note to doc comments directing reader to
    Container.AddSelectAction for adding an Action to be used when the
    Container is tapped or selected
- add Container.AddSelectAction method
  - accepts Action or ISelectAction value
- add examples
  - add toggle-visibility-column-action
  - add toggle-visibility-container-action
  - add toggle-visibility-multiple-buttons
  - add toggle-visibility-single-button

refs GH-243
refs GH-239
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
card format/adaptivecard Adaptive Card support documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants