microsoft / AdaptiveCards

A new way for developers to exchange card content in a common and consistent way.
https://adaptivecards.io
MIT License
1.72k stars 543 forks source link

[Feature Request] Tables support in .NET SDK #7226

Open rchowtakuri opened 2 years ago

rchowtakuri commented 2 years ago

Problem Statement

We are trying to represent the information in a tabular format. But we couldn't find support for Table, TableCell components in .NET adaptive cards library.

Proposed solution

Support Table related components for the .NET library

Alternatives or Workarounds

Alternatively, to represent the data in tabular format, we are using ColumnSet components to render it in adaptive cards. But, as adaptive cards started supporting separate components to render Table related information, we want to have this extended to .NET as well so that we can use it on our side.

olucafont6 commented 2 years ago

To add a little more background, Table support got added in this release, but only to the .NET Templating library, and not the regular AdaptiveCards .NET library: https://github.com/microsoft/AdaptiveCards/releases/tag/21.09

We didn't see anything about adding this support on the roadmap (https://github.com/microsoft/AdaptiveCards/projects/32), so wanted to check if this was something you guys were planning on adding eventually. We also weren't sure if the non-templating .NET library was still being prioritized, or if you were planning on just adding functionality to the templating library going forward.

rchowtakuri commented 1 year ago

Hi @paulcam206 @jwoo-msft We saw that tables support has been extended for the .NET library as part of 3.0.0. Thanks for adding. But we observed a kinda bug related to TableCell. When we create an instance of TableCell, it's type is defaulted to Container instead of TableCell. I think it's because of the missing override Type field in TableCell class. Is this expected?

Reproducer:

using AdaptiveCards;
using System;
using System.Collections.Generic;
using System.Linq;

namespace TablesSupport
{
    class Program
    {
        private static AdaptiveTableCell CreateTableCell(AdaptiveElement adaptiveElement)
        {
            var tableCell = new AdaptiveTableCell()
            {
                //Type = AdaptiveTableCell.TypeName
            };
            tableCell.Add(adaptiveElement);
            return tableCell;
        }

        private static AdaptiveTableRow CreateTableRow()
        {
            var tableRow = new AdaptiveTableRow();
            var textBlock = new AdaptiveTextBlock("Text");
            tableRow.Cells.Add(CreateTableCell(textBlock));
            return tableRow;
        }

        private static AdaptiveTable CreateTable()
        {
            AdaptiveTable table = new AdaptiveTable
            {
                Columns = Enumerable.Repeat(new AdaptiveTableColumnDefinition { Width = 1 }, 1).ToList(),
                Rows = new List<AdaptiveTableRow>()
            };
            table.Rows.Add(CreateTableRow());
            return table;
        }
        static void Main(string[] args)
        {
            AdaptiveCard card = new AdaptiveCard();
            card.Body.Add(CreateTable());
            Console.WriteLine(card.ToJson());
        }
    }
}

We had the following workaround setting the type explicitly with it's typename Work Around:

var tableCell = new AdaptiveTableCell()
{
    Type = AdaptiveTableCell.TypeName
};
jwoo-msft commented 3 months ago

Thank you for highlighting this issue. It seems to have inadvertently slipped through the cracks. This PR dates back a few years, and I don't precisely remember the rationale behind it. If I were to speculate, I'd say table support was introduced to ensure that the .NET library could parse the v1.5 payload, despite there being no plans to support table rendering explicitly. With the default container type, a TableCell could, at the very least, be rendered by a Container. Given the lack of rendering support, I'm curious about the current usage of the Table?

rchowtakuri commented 3 months ago

@jwoo-msft Yeah, we're able to achieve our usecase using Table support that got added and already rolled out to our clients. Consequently, we can close this particular issue and refer to https://github.com/microsoft/AdaptiveCards/issues/8520 that has been raised as separate issue.