Skip to content

Commit ba19e7c

Browse files
committed
Add primary and non-primary fact block builders
- Introduced `PrimaryFactBlock()` and `NonPrimaryFactBlock()` functions to create fact blocks with configurable primary status - Simplified fact block creation by extracting common logic into a shared implementation - Supports creating fact blocks with flexible title and value configurations
1 parent 221d8a3 commit ba19e7c

File tree

2,704 files changed

+5296
-5241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,704 files changed

+5296
-5241
lines changed

elementary/messages/block_builders.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,24 @@ def SummaryLineBlock(
8787
return LineBlock(inlines=text_blocks)
8888

8989

90+
def NonPrimaryFactBlock(fact: Tuple[LineBlock, LineBlock]) -> FactBlock:
91+
title, value = fact
92+
return FactBlock(
93+
title=title,
94+
value=value,
95+
primary=False,
96+
)
97+
98+
99+
def PrimaryFactBlock(fact: Tuple[LineBlock, LineBlock]) -> FactBlock:
100+
title, value = fact
101+
return FactBlock(
102+
title=title,
103+
value=value,
104+
primary=True,
105+
)
106+
107+
90108
def FactsBlock(
91109
*,
92110
facts: Sequence[

elementary/monitor/alerts/alert_messages/builder.py

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
BoldTextLineBlock,
66
BulletListBlock,
77
FactsBlock,
8+
ItalicTextLineBlock,
89
JsonCodeBlock,
910
LinkLineBlock,
11+
NonPrimaryFactBlock,
12+
PrimaryFactBlock,
1013
SummaryLineBlock,
14+
TextLineBlock,
1115
)
1216
from elementary.messages.blocks import (
1317
CodeBlock,
1418
DividerBlock,
1519
ExpandableBlock,
20+
FactListBlock,
1621
HeaderBlock,
1722
Icon,
1823
InlineBlock,
@@ -217,23 +222,54 @@ def _get_details_blocks(
217222
]
218223
)
219224
)
220-
facts = []
225+
fact_blocks = []
221226
if table:
222-
facts.append(("Table", table))
227+
fact_blocks.append(
228+
PrimaryFactBlock(
229+
(TextLineBlock(text="Table"), TextLineBlock(text=table))
230+
)
231+
)
223232
if column:
224-
facts.append(("Column", column))
233+
fact_blocks.append(
234+
NonPrimaryFactBlock(
235+
(TextLineBlock(text="Column"), TextLineBlock(text=column))
236+
)
237+
)
225238

226-
facts.append(("Tags", ", ".join(tags) if tags else "No tags"))
227-
facts.append(("Owners", ", ".join(owners) if owners else "No owners"))
228-
facts.append(
229-
("Subscribers", ", ".join(subscribers) if subscribers else "No subscribers")
239+
tags_line = (
240+
TextLineBlock(text=", ".join(tags))
241+
if tags
242+
else ItalicTextLineBlock(text="No tags")
243+
)
244+
owners_line = (
245+
TextLineBlock(text=", ".join(owners))
246+
if owners
247+
else ItalicTextLineBlock(text="No owners")
248+
)
249+
subscribers_line = (
250+
TextLineBlock(text=", ".join(subscribers))
251+
if subscribers
252+
else ItalicTextLineBlock(text="No subscribers")
253+
)
254+
fact_blocks.append(NonPrimaryFactBlock((TextLineBlock(text="Tags"), tags_line)))
255+
fact_blocks.append(
256+
NonPrimaryFactBlock((TextLineBlock(text="Owners"), owners_line))
257+
)
258+
fact_blocks.append(
259+
NonPrimaryFactBlock((TextLineBlock(text="Subscribers"), subscribers_line))
230260
)
231261

232262
if description:
233-
facts.append(("Description", description))
263+
fact_blocks.append(
264+
PrimaryFactBlock(
265+
(TextLineBlock(text="Description"), TextLineBlock(text=description))
266+
)
267+
)
234268
if path:
235-
facts.append(("Path", path))
236-
blocks.append(FactsBlock(facts=facts))
269+
fact_blocks.append(
270+
PrimaryFactBlock((TextLineBlock(text="Path"), TextLineBlock(text=path)))
271+
)
272+
blocks.append(FactListBlock(facts=fact_blocks))
237273
return blocks
238274

239275
def _get_result_blocks(
@@ -333,7 +369,7 @@ def _get_model_alert_config_blocks(
333369
facts = []
334370
if materialization:
335371
facts.append(("Materialization", materialization))
336-
if full_refresh is not None:
372+
if full_refresh:
337373
facts.append(("Full Refresh", "Yes" if full_refresh else "No"))
338374
return [FactsBlock(facts=facts)]
339375

@@ -368,6 +404,7 @@ def _get_alert_list_line(
368404
if len(owners) == 1:
369405
inlines.append(TextBlock(text=f"Owner: {owners.pop()}"))
370406
else:
407+
# order owners by alphabetical order
371408
owners.sort()
372409
inlines.append(TextBlock(text=f"Owners: {', '.join(owners)}"))
373410

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-False_table-True_error-False_sample-False.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
},
4444
{
4545
"title": "Tags",
46-
"value": "No tags"
46+
"value": "_No tags_"
4747
},
4848
{
4949
"title": "Owners",
50-
"value": "No owners"
50+
"value": "_No owners_"
5151
},
5252
{
5353
"title": "Subscribers",
54-
"value": "No subscribers"
54+
"value": "_No subscribers_"
5555
}
5656
]
5757
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-False_table-True_error-False_sample-True.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
},
4444
{
4545
"title": "Tags",
46-
"value": "No tags"
46+
"value": "_No tags_"
4747
},
4848
{
4949
"title": "Owners",
50-
"value": "No owners"
50+
"value": "_No owners_"
5151
},
5252
{
5353
"title": "Subscribers",
54-
"value": "No subscribers"
54+
"value": "_No subscribers_"
5555
}
5656
]
5757
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-False_table-True_error-True_sample-False.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
},
4444
{
4545
"title": "Tags",
46-
"value": "No tags"
46+
"value": "_No tags_"
4747
},
4848
{
4949
"title": "Owners",
50-
"value": "No owners"
50+
"value": "_No owners_"
5151
},
5252
{
5353
"title": "Subscribers",
54-
"value": "No subscribers"
54+
"value": "_No subscribers_"
5555
}
5656
]
5757
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-False_table-True_error-True_sample-True.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
},
4444
{
4545
"title": "Tags",
46-
"value": "No tags"
46+
"value": "_No tags_"
4747
},
4848
{
4949
"title": "Owners",
50-
"value": "No owners"
50+
"value": "_No owners_"
5151
},
5252
{
5353
"title": "Subscribers",
54-
"value": "No subscribers"
54+
"value": "_No subscribers_"
5555
}
5656
]
5757
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-True_table-False_error-False_sample-False.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
"facts": [
4040
{
4141
"title": "Tags",
42-
"value": "No tags"
42+
"value": "_No tags_"
4343
},
4444
{
4545
"title": "Owners",
4646
"value": "owner1, owner2"
4747
},
4848
{
4949
"title": "Subscribers",
50-
"value": "No subscribers"
50+
"value": "_No subscribers_"
5151
}
5252
]
5353
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-True_table-False_error-False_sample-True.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
"facts": [
4040
{
4141
"title": "Tags",
42-
"value": "No tags"
42+
"value": "_No tags_"
4343
},
4444
{
4545
"title": "Owners",
4646
"value": "owner1, owner2"
4747
},
4848
{
4949
"title": "Subscribers",
50-
"value": "No subscribers"
50+
"value": "_No subscribers_"
5151
}
5252
]
5353
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-True_table-False_error-True_sample-False.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
"facts": [
4040
{
4141
"title": "Tags",
42-
"value": "No tags"
42+
"value": "_No tags_"
4343
},
4444
{
4545
"title": "Owners",
4646
"value": "owner1, owner2"
4747
},
4848
{
4949
"title": "Subscribers",
50-
"value": "No subscribers"
50+
"value": "_No subscribers_"
5151
}
5252
]
5353
}

tests/unit/alerts/alert_messages/fixtures/adaptive_card_dbt_test_alert_status-None_link-False_description-False_tags-False_owners-True_table-False_error-True_sample-True.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@
3939
"facts": [
4040
{
4141
"title": "Tags",
42-
"value": "No tags"
42+
"value": "_No tags_"
4343
},
4444
{
4545
"title": "Owners",
4646
"value": "owner1, owner2"
4747
},
4848
{
4949
"title": "Subscribers",
50-
"value": "No subscribers"
50+
"value": "_No subscribers_"
5151
}
5252
]
5353
}

0 commit comments

Comments
 (0)