Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

feat(timeline): Content is optional and title mandatory - FRONT-2036 #598

Merged
merged 2 commits into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% set no_toggle_collapsed_case = false %}
{% set no_toggle_expanded_case = false %}
{% set no_icon_path_case = false %}
{% set no_item_title_case = false %}

{% if toggler %}
{% set no_toggle_collapsed_case = toggle_collapsed is empty %}
Expand All @@ -30,6 +31,9 @@
{% if item.label is not defined or item.label is empty %}
{% set no_item_timestamp_case = true %}
{% endif %}
{% if item.title is not defined or item.title is empty %}
{% set no_item_title_case = true %}
{% endif %}
{% endfor %}
{% endif %}

Expand All @@ -38,7 +42,8 @@
no_item_timestamp_case or
no_toggle_collapsed_case or
no_toggle_expanded_case or
no_icon_path_case %}
no_icon_path_case or
no_item_title_case %}

{% if no_items_case %}
{% set message = message ~ ' {{ items }} is mandatory, it needs to be defined as an array of objects.' %}
Expand All @@ -49,6 +54,9 @@
{% if no_item_timestamp_case %}
{% set message = message ~ ' Each item of the timeline should contain a {{ label }} property set and filled in as it represents the mandatory timestamp.' %}
{% endif %}
{% if no_item_title_case %}
{% set message = message ~ ' Each item of the timeline should contain a {{ title }} property set and filled in.' %}
{% endif %}
{% if no_toggle_collapsed_case %}
{% set message = message ~ ' The {{ toggle_collapsed }} property needs to be set and filled in as it represents the toggler button label.' %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/ec/packages/ec-component-timeline/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ npm install --save @ecl-twig/ec-component-timeline
- "id": (string) (default: '')
- "label": (string) (default: '')
- "title": (string) (default: '')
- "content": (block) (default: '')
- "content": (string) (default: '')
- **"icon_path"** (string) (default: ''): file containing the svg icons
- **"extra_classes"** (optional) (string) (default: '') Extra classes (space separated)
- **"extra_attributes"** (optional) (array) (default: []) Extra attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7268,11 +7268,6 @@ exports[`EC - Timeline with missing input data and debug enabled it returns the
>
17 November 2017
</div>
<div
class="ecl-timeline2__title"
>
Social Summit is open
</div>
<div
class="ecl-timeline2__content"
>
Expand Down Expand Up @@ -8000,7 +7995,7 @@ exports[`EC - Timeline with missing input data and debug enabled it returns the
<p
class="ecl-u-type-color-grey ecl-u-ml-m ecl-u-type-xs"
>
[timeline] - If the toggler is shown the {{ icon_path }} parameter needs to be set and filled in. Each item of the timeline should contain a {{ label }} property set and filled in as it represents the mandatory timestamp. The {{ toggle_collapsed }} property needs to be set and filled in as it represents the toggler button label. The {{ toggle_expanded }} property needs to be set and filled in as it represents the toggler button label.
[timeline] - If the toggler is shown the {{ icon_path }} parameter needs to be set and filled in. Each item of the timeline should contain a {{ label }} property set and filled in as it represents the mandatory timestamp. Each item of the timeline should contain a {{ title }} property set and filled in. The {{ toggle_collapsed }} property needs to be set and filled in as it represents the toggler button label. The {{ toggle_expanded }} property needs to be set and filled in as it represents the toggler button label.
</p>
</div>
</test>
Expand Down
16 changes: 9 additions & 7 deletions src/ec/packages/ec-component-timeline/ecl-timeline.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ Parameters:
- "from": (integer) (default: items.length) Item index after which to start hiding timeline items
- "to": (integer) (default: items.length) Item index after which to resume displaying timeline items
- "items" (array) (default: []):
- "id": (string) (default: '')
- "id": (string) (optional) (default: '')
- "label": (string) (default: '')
- "title": (string) (default: '')
- "content": (block) (default: '')
- "content": (string) (optional) (default: '')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it be an issue to define the content as a string only?
According to the usage page, users can put other type of content in it (media for instance)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, i'd say that in these docs on all our templates we refer to the data type, whatever this variable will contain it's going to be used as a string, not an array, not an object, not a boolean, in other words. But you are right that maybe we should treat this, as the other variables that are "allowed" or supposed to contain html (the ones that we were rendering with |raw) in a different way, because string in those cases might be confused with "plain text", we could say something like html markup marked as a safe string to somehow specify that it would be otherwise escaped in an environment with the twig autoescape on.

- "icon_path" (string) (default: ''): file containing the svg icons
- "extra_classes" (string) (default: '')
- "extra_attributes" (array) (default: []): format:
Expand Down Expand Up @@ -74,14 +74,16 @@ Parameters:
{% set extra_class = (loop.index > _display_amount and loop.revindex > _bottom_amount) ? ' ecl-timeline2__item--collapsed' : '' %}
<li
class="ecl-timeline2__item{{ extra_class }}"
{% if _item.id is defined and _item.id is not empty %}
{% if _item.id is defined and _item.id is not empty %}
id="{{ _item.id }}"
{% endif %}>
{% endif %}>
<div class="ecl-timeline2__label">{{ _item.label }}</div>
{% if _item.title is defined and _item.title is not empty %}
{% if _item.title is defined and _item.title is not empty %}
<div class="ecl-timeline2__title">{{ _item.title }}</div>
{% endif %}
<div class="ecl-timeline2__content">{{ _item.content|default('') }}</div>
{% endif %}
{% if _item.content is defined and _item.content is not empty %}
<div class="ecl-timeline2__content">{{ _item.content }}</div>
{% endif %}
</li>
{# Display the show more button if required. #}
{% if (_hide_amount > 0 and loop.revindex == _bottom_amount + 1) or (_hide_amount > 0 and _hide_to == 0 and loop.revindex == 1) %}
Expand Down
4 changes: 2 additions & 2 deletions src/ec/packages/ec-component-timeline/timeline.story.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const prepareTimeline = (data) => {
data.items.forEach((item, i) => {
const { id, label, title, content } = item;
item.label = text(`items[${i}].label`, label, tabLabels.required);
item.title = text(`items[${i}].title`, title, tabLabels.required);
item.id = text(`items[${i}].id`, id, tabLabels.optional);
item.title = text(`items[${i}].title`, title, tabLabels.optional);
item.content = he.decode(
text(`items[${i}].content`, content, tabLabels.required)
text(`items[${i}].content`, content, tabLabels.optional)
);
});

Expand Down
1 change: 1 addition & 0 deletions src/ec/packages/ec-component-timeline/timeline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ describe('EC - Timeline', () => {

const dataCompliance = { ...demoData, _compliance_: true };
dataCompliance.items[1].label = '';
dataCompliance.items[3].title = '';
dataCompliance.toggle_collapsed = '';
dataCompliance.toggle_expanded = '';
dataCompliance.icon_path = '';
Expand Down