Skip to content

Commit 4914af4

Browse files
authored
Merge pull request #1795 from elementary-data/ele-3960-adaptive-cards
Ele 3960 adaptive cards
2 parents 98cef8a + 63e198c commit 4914af4

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

elementary/messages/block_builders.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import List, Optional, Tuple, Union
2+
from typing import List, Optional, Sequence, Tuple, Union
33

44
from .blocks import (
55
CodeBlock,
@@ -16,7 +16,7 @@
1616
)
1717

1818
SimpleInlineBlock = Union[str, Icon]
19-
SimpleLineBlock = Union[str, Icon, List[SimpleInlineBlock]]
19+
SimpleLineBlock = Union[str, Icon, Sequence[SimpleInlineBlock]]
2020

2121

2222
def _build_inline_block(
@@ -28,9 +28,9 @@ def _build_inline_block(
2828
def _build_inlines(
2929
content: SimpleLineBlock, style: Optional[TextStyle] = None
3030
) -> List[InlineBlock]:
31-
if isinstance(content, list):
32-
return [_build_inline_block(line, style) for line in content]
33-
return [_build_inline_block(content)]
31+
if isinstance(content, (str, Icon)):
32+
return [_build_inline_block(content, style)]
33+
return [_build_inline_block(line, style) for line in content]
3434

3535

3636
def BulletListBlock(
@@ -73,7 +73,7 @@ def LinkLineBlock(*, text: str, url: str) -> LineBlock:
7373

7474
def SummaryLineBlock(
7575
*,
76-
summary: List[Tuple[SimpleLineBlock, SimpleLineBlock]],
76+
summary: Sequence[Tuple[SimpleLineBlock, SimpleLineBlock]],
7777
include_empty_values: bool = False,
7878
) -> LineBlock:
7979
text_blocks: List[InlineBlock] = []
@@ -89,7 +89,7 @@ def SummaryLineBlock(
8989

9090
def FactsBlock(
9191
*,
92-
facts: List[
92+
facts: Sequence[
9393
Tuple[
9494
SimpleLineBlock,
9595
SimpleLineBlock,

elementary/messages/blocks.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List, Optional, Union
33

44
from pydantic import BaseModel
5+
from typing_extensions import Literal
56

67

78
class Icon(Enum):
@@ -25,6 +26,7 @@ class TextStyle(Enum):
2526

2627

2728
class BaseBlock(BaseModel):
29+
type: str
2830
pass
2931

3032

@@ -33,35 +35,41 @@ class BaseInlineTextBlock(BaseBlock):
3335

3436

3537
class TextBlock(BaseInlineTextBlock):
38+
type: Literal["text"] = "text"
3639
text: str
3740
style: Optional[TextStyle] = None
3841

3942

4043
class LinkBlock(BaseInlineTextBlock):
44+
type: Literal["link"] = "link"
4145
text: str
4246
url: str
4347

4448

4549
class IconBlock(BaseInlineTextBlock):
50+
type: Literal["icon"] = "icon"
4651
icon: Icon
4752

4853

4954
InlineBlock = Union[TextBlock, LinkBlock, IconBlock]
5055

5156

5257
class HeaderBlock(BaseBlock):
58+
type: Literal["header"] = "header"
5359
text: str
5460

5561

5662
class CodeBlock(BaseBlock):
63+
type: Literal["code"] = "code"
5764
text: str
5865

5966

6067
class DividerBlock(BaseBlock):
61-
pass
68+
type: Literal["divider"] = "divider"
6269

6370

6471
class LineBlock(BaseBlock):
72+
type: Literal["line"] = "line"
6573
inlines: List[InlineBlock]
6674
sep: str = " "
6775

@@ -71,19 +79,22 @@ class BaseLinesBlock(BaseBlock):
7179

7280

7381
class LinesBlock(BaseLinesBlock):
74-
pass
82+
type: Literal["lines"] = "lines"
7583

7684

7785
class FactBlock(BaseBlock):
86+
type: Literal["fact"] = "fact"
7887
title: LineBlock
7988
value: LineBlock
8089

8190

8291
class FactListBlock(BaseBlock):
92+
type: Literal["fact_list"] = "fact_list"
8393
facts: List[FactBlock]
8494

8595

8696
class ExpandableBlock(BaseBlock):
97+
type: Literal["expandable"] = "expandable"
8798
title: str
8899
body: List["InExpandableBlock"]
89100
expanded: bool = False
@@ -98,4 +109,5 @@ class ExpandableBlock(BaseBlock):
98109
"ExpandableBlock",
99110
]
100111

101-
ExpandableBlock.model_rebuild()
112+
# Update forward references for recursive types
113+
ExpandableBlock.update_forward_refs()

elementary/messages/message_body.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ class MessageBody(BaseModel):
3434
color: Optional[Color] = None
3535

3636

37-
MessageBody.model_rebuild()
37+
MessageBody.update_forward_refs()

0 commit comments

Comments
 (0)