Skip to content

Commit 766140c

Browse files
committed
CMS: Popular Topics grid component
1 parent 825d151 commit 766140c

File tree

8 files changed

+1676
-138
lines changed

8 files changed

+1676
-138
lines changed

cms/dynamic_content/blocks.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
MINIMUM_ROWS_NUMBER_BLOCK_COUNT: int = 1
1515
MAXIMUM_ROWS_NUMBER_BLOCK_COUNT: int = 2
16+
17+
MINIMUM_POPULAR_TOPICS_HEADLINE_NUMBER_BLOCK_COUNT: int = 2
18+
MAXIMUM_POPULAR_TOPICS_HEADLINE_NUMBER_BLOCK_COUNT: int = 2
19+
1620
METRIC_NUMBER_BLOCK_DATE_PREFIX_DEFAULT_TEXT = "Up to"
1721

1822

@@ -45,6 +49,26 @@ class Meta:
4549
icon = "table"
4650

4751

52+
class PopularTopicsMetricNumberBlockTypes(blocks.StructBlock):
53+
title = blocks.TextBlock(required=True, help_text=help_texts.TITLE_FIELD)
54+
date_prefix = blocks.TextBlock(
55+
required=True,
56+
default=METRIC_NUMBER_BLOCK_DATE_PREFIX_DEFAULT_TEXT,
57+
help_text=help_texts.HEADLINE_DATE_PREFIX,
58+
)
59+
rows = HeadlineNumberBlockTypes(
60+
required=True,
61+
min_num=MINIMUM_POPULAR_TOPICS_HEADLINE_NUMBER_BLOCK_COUNT,
62+
max_num=MAXIMUM_POPULAR_TOPICS_HEADLINE_NUMBER_BLOCK_COUNT,
63+
help_text=help_texts.POPULAR_TOPICS_NUMBERS_ROW_FIELD.format(
64+
MAXIMUM_POPULAR_TOPICS_HEADLINE_NUMBER_BLOCK_COUNT
65+
),
66+
)
67+
68+
class Meta:
69+
icon = "table"
70+
71+
4872
class MetricNumberBlock(blocks.StreamBlock):
4973
column = MetricNumberBlockTypes()
5074

cms/dynamic_content/cards.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
HeadlineNumberBlockTypes,
1313
MetricNumberBlock,
1414
PageLinkChooserBlock,
15+
PopularTopicsMetricNumberBlockTypes,
1516
RelatedLinkBlock,
1617
SourceLinkBlock,
1718
)
@@ -46,6 +47,15 @@
4647

4748
MINIMUM_SEGMENTS_COUNT: int = 1
4849

50+
MINIMUM_POPULAR_TOPICS_FIRST_COLUMN_COUNT: int = 1
51+
MAXIMUM_POPULAR_TOPICS_FIRST_COLUMN_COUNT: int = 1
52+
53+
MINIMUM_POPULAR_TOPICS_TOP_RIGHT_CHART_COUNT: int = 1
54+
MAXIMUM_POPULAR_TOPICS_TOP_RIGHT_CHART_COUNT: int = 1
55+
56+
MINIMUM_POPULAR_TOPICS_BOTTOM_ROW_COLUMNS_COUNT: int = 1
57+
MAXIMUM_POPULAR_TOPICS_BOTTOM_ROW_COLUMNS_COUNT: int = 1
58+
4959
DEFAULT_SIMPLE_CHART_X_AXIS = "date"
5060
DEFAULT_SIMPLE_CHART_Y_AXIS = "metric"
5161

@@ -490,6 +500,49 @@ class ChartRowBlockTypes(blocks.StreamBlock):
490500
dual_category_chart_card = DualCategoryChartCard()
491501

492502

503+
class PopularTopicsLeftColumnBlockTypes(blocks.StreamBlock):
504+
weather_health_alert_card = WeatherHealthAlertsCard()
505+
chart_card_with_description = ChartWithDescriptionCard()
506+
507+
class Meta:
508+
icon = "standalone_chart"
509+
510+
511+
class PopularTopicsRightColumnTopRowBlockTypes(blocks.StreamBlock):
512+
chart_card = ChartCard()
513+
514+
class Meta:
515+
icon = "standalone_chart"
516+
517+
518+
class PopularTopicsRightColumnBottomRowBlockTypes(blocks.StreamBlock):
519+
headline_metric_card = PopularTopicsMetricNumberBlockTypes()
520+
521+
class Meta:
522+
icon = "table"
523+
524+
525+
class PopularTopicsCard(blocks.StructBlock):
526+
left_column = PopularTopicsLeftColumnBlockTypes(
527+
min_num=MINIMUM_POPULAR_TOPICS_FIRST_COLUMN_COUNT,
528+
max_num=MAXIMUM_POPULAR_TOPICS_FIRST_COLUMN_COUNT,
529+
help_text=help_texts.POPULAR_TOPICS_LEFT_COLUMN,
530+
)
531+
right_column_top_row = PopularTopicsRightColumnTopRowBlockTypes(
532+
min_num=MINIMUM_POPULAR_TOPICS_TOP_RIGHT_CHART_COUNT,
533+
max_num=MAXIMUM_POPULAR_TOPICS_TOP_RIGHT_CHART_COUNT,
534+
help_text=help_texts.POPULAR_TOPICS_RIGHT_COLUMN_TOP_ROW,
535+
)
536+
right_column_bottom_row = PopularTopicsRightColumnBottomRowBlockTypes(
537+
min_num=MINIMUM_POPULAR_TOPICS_BOTTOM_ROW_COLUMNS_COUNT,
538+
max_num=MAXIMUM_POPULAR_TOPICS_BOTTOM_ROW_COLUMNS_COUNT,
539+
help_text=help_texts.POPULAR_TOPICS_RIGHT_COLUMN_BOTTOM_ROW,
540+
)
541+
542+
class Meta:
543+
icon = "standalone_chart"
544+
545+
493546
class ChartRowCard(blocks.StructBlock):
494547
columns = ChartRowBlockTypes(
495548
min_num=MINIMUM_COLUMNS_CHART_COLUMNS_COUNT,

cms/dynamic_content/help_texts.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
So by moving 1 column component above the other, that component will be rendered in the column left of the other.
55
"""
66

7+
POPULAR_TOPICS_LEFT_COLUMN: str = """
8+
This will be used to display a full height card on the left column.
9+
Choose either a weather health alerts card or a chart card with description.
10+
"""
11+
12+
POPULAR_TOPICS_RIGHT_COLUMN_TOP_ROW: str = """
13+
This will be used to display a chart card in the top row of the second (right) column.
14+
Exactly one chart style card must be added here.
15+
"""
16+
17+
POPULAR_TOPICS_RIGHT_COLUMN_BOTTOM_ROW: str = """
18+
This will be used to display the two headline metric cards with trend data in the bottom right
19+
row of the second column.
20+
"""
21+
22+
POPULAR_TOPICS_NUMBERS_ROW_FIELD: str = """
23+
This row only allows {} columns to be added within this component.
24+
Each columns can be used to add a number block.
25+
This can be a headline number or a trend number.
26+
The two column block will be rendered on the bottom right of the popular topics component.
27+
"""
28+
729
HEADLINE_COLUMNS_IN_CHART_CARD: str = """
830
Add up to {} headline or trend number column components within this space.
931
Note that these figures will be displayed within the card, and above the chart itself.

cms/dynamic_content/sections.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ContentCards(StreamBlock):
1818
text_card = cards.TextCard()
1919
chart_row_card = cards.ChartRowCard()
2020
headline_numbers_row_card = cards.HeadlineNumbersRowCard()
21+
popular_topics_card = cards.PopularTopicsCard()
2122
global_filter_card = GlobalFilterCard(
2223
help_text=help_texts.GLOBAL_FILTER_COMPONENT,
2324
)
@@ -40,6 +41,7 @@ class ContentCardsSectionWithLink(StreamBlock):
4041
chart_card_section = cards.ChartCardSection()
4142
headline_numbers_row_card = cards.HeadlineNumbersRowCard()
4243
weather_health_alert_card = cards.WeatherHealthAlertsCard()
44+
popular_topics_card = cards.PopularTopicsCard()
4345

4446

4547
class Section(StructBlock):

0 commit comments

Comments
 (0)