Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/zipp-3.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Ashiq committed Sep 16, 2024
2 parents 441450c + d19382b commit ba40daa
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cms/dynamic_content/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
MAXIMUM_ROWS_NUMBER_BLOCK_COUNT: int = 2


class TrendNumberBlockType(blocks.StreamBlock):
trend_number = TrendNumberComponent(help_text=help_texts.TREND_BLOCK_FIELD)

class Meta:
icon = "trend_down"


class HeadlineNumberBlockTypes(blocks.StreamBlock):
headline_number = HeadlineNumberComponent(help_text=help_texts.HEADLINE_BLOCK_FIELD)
trend_number = TrendNumberComponent(help_text=help_texts.TREND_BLOCK_FIELD)
Expand Down
60 changes: 58 additions & 2 deletions cms/dynamic_content/cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

from cms.common.models import AVAILABLE_RICH_TEXT_FEATURES
from cms.dynamic_content import help_texts
from cms.dynamic_content.blocks import HeadlineNumberBlockTypes, MetricNumberBlock
from cms.dynamic_content.components import ChartComponent, HeadlineChartComponent
from cms.dynamic_content.blocks import (
HeadlineNumberBlockTypes,
MetricNumberBlock,
TrendNumberBlockType,
)
from cms.dynamic_content.components import (
ChartComponent,
HeadlineChartComponent,
SimplifiedChartComponent,
)
from cms.metrics_interface.field_choices_callables import get_possible_axis_choices


Expand All @@ -25,6 +33,12 @@ class Meta:
MINIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 1
MAXIMUM_COLUMNS_CHART_COLUMNS_COUNT: int = 2

MAXIMUM_TOPIC_TREND_CARD_CHARTS: int = 1
MAXIMUM_TREND_NUMBER: int = 1

DEFAULT_SIMPLE_CHART_X_AXIS = "date"
DEFAULT_SIMPLE_CHART_Y_AXIS = "metric"


class HeadlineNumbersRowCard(blocks.StructBlock):
columns = MetricNumberBlock(
Expand Down Expand Up @@ -71,6 +85,47 @@ class Meta:
icon = "chart_with_headline_and_trend_card"


class TropicTrendChartAndLink(blocks.StructBlock):
title = blocks.TextBlock(required=True, help_text=help_texts.TITLE_FIELD)
body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD)
tag_manager_event_id = blocks.CharBlock(
required=False,
help_text=help_texts.TAG_MANAGER_EVENT_ID_FIELD,
label="Tag manager event ID",
)
topic_page = blocks.PageChooserBlock(
page_type="topic.TopicPage",
required=True,
help_text=help_texts.TOPIC_PAGE_FIELD,
)
x_axis = blocks.ChoiceBlock(
required=True,
choices=get_possible_axis_choices,
help_text=help_texts.REQUIRED_CHART_X_AXIS,
default=DEFAULT_SIMPLE_CHART_X_AXIS,
ready_only=True,
)
y_axis = blocks.ChoiceBlock(
required=True,
choices=get_possible_axis_choices,
help_text=help_texts.REQUIRED_CHART_Y_AXIS,
default=DEFAULT_SIMPLE_CHART_Y_AXIS,
)
chart = SimplifiedChartComponent(
help_text=help_texts.CHART_BLOCK_FIELD,
required=True,
max_num=MAXIMUM_TOPIC_TREND_CARD_CHARTS,
)
trend_number = TrendNumberBlockType(
required=True,
max_num=MAXIMUM_TREND_NUMBER,
help_text=help_texts.TREND_BLOCK_FIELD,
)

class Meta:
icon = "chart_with_headline_and_trend_card"


class ChartCard(blocks.StructBlock):
title = blocks.TextBlock(required=True, help_text=help_texts.TITLE_FIELD)
body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD)
Expand Down Expand Up @@ -111,6 +166,7 @@ class ChartRowBlockTypes(blocks.StreamBlock):
chart_card = ChartCard()
headline_chart_card = HeadlineChartCard()
chart_with_headline_and_trend_card = ChartWithHeadlineAndTrendCard()
topic_trend_chart_and_link = TropicTrendChartAndLink()


class ChartRowCard(blocks.StructBlock):
Expand Down
7 changes: 7 additions & 0 deletions cms/dynamic_content/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Meta:
icon = "standalone_chart"


class SimplifiedChartComponent(blocks.StreamBlock):
plot = elements.SimplifiedChartPlotElement()

class Meta:
icon = "standalone_chart"


class HeadlineNumberComponent(elements.BaseMetricsElement):
body = blocks.TextBlock(required=False, help_text=help_texts.OPTIONAL_BODY_FIELD)

Expand Down
9 changes: 9 additions & 0 deletions cms/dynamic_content/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DEFAULT_AGE = "all"
DEFAULT_STRATUM = "default"
DEFAULT_HEADLINE_CHART_TYPE = "bar"
DEFAULT_SIMPLIFIED_CHART_TYPE = "line_single_simplified"


class BaseMetricsElement(blocks.StructBlock):
Expand Down Expand Up @@ -142,3 +143,11 @@ class HeadlineChartPlotElement(BaseMetricsElement):

class Meta:
icon = "chart_plot"


class SimplifiedChartPlotElement(BaseMetricsElement):
metric = blocks.ChoiceBlock(
required=True,
choices=get_all_timeseries_metric_names,
help_text=help_texts.METRIC_FIELD,
)
8 changes: 8 additions & 0 deletions cms/dynamic_content/help_texts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
for that plot.
"""

TOPIC_PAGE_FIELD: str = """
The related topic page you want to link to.
"""

HEADLINE_BLOCK_FIELD: str = """
This component will display a key headline number type metric.
You can also optionally add a body of text to accompany that headline number.
Expand Down Expand Up @@ -183,6 +187,10 @@
If nothing is provided, `metric value` will be used by default.
"""

REQUIRED_CHART_Y_AXIS: str = """
A required choice of what to display along the y-axis of the chart.
"""

USE_SMOOTH_LINES: str = """
If set to true, draws the plot as a spline line, resulting in smooth curves between data points.
If set to false, draws the plot as a linear line,
Expand Down

0 comments on commit ba40daa

Please sign in to comment.