Skip to content

Commit 52a3a89

Browse files
authored
WD-31253 - Fix details endpoint failure (#5464)
* Reapply "WD-17150 - aliases section in snap details (#5356)" (#5457) This reverts commit 5775d22. * WD-31253 - Add catch to avoid page failing if details errors Add empty channel to avoid errors if 'latest/stable' has no revisions * WD-31253 - Add tests
1 parent ac12365 commit 52a3a89

4 files changed

Lines changed: 276 additions & 110 deletions

File tree

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ canonicalwebteam.discourse==7.0.0
66
canonicalwebteam.blog==6.6.0
77
canonicalwebteam.search==2.1.2
88
canonicalwebteam.image-template==1.9.0
9-
canonicalwebteam.store-api==7.3.7
9+
canonicalwebteam.store-api==7.3.8
1010
canonicalwebteam.launchpad==0.9.0
1111
django-openid-auth==0.17
1212
Flask-OpenID==1.3.0

templates/store/snap-details/_details.html

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,65 @@ <h5 class="p-muted-heading">Source code</h5>
7676
<hr>
7777
{% endif %}
7878

79+
{%- if aliases -%}
80+
{%- set show_more = "Show more" -%}
81+
{%- set show_less = "Show less" -%}
82+
83+
{#-
84+
# The list starts displaying maximum 3 elements with the rest hidden.
85+
# With the script provided and the link element rendered the user can toggle
86+
# displaying and hiding all the aliases.
87+
-#}
88+
<h5 class="p-muted-heading">Command &rsaquo; Alias</h5>
89+
<ul class="p-list js-expandable-list">
90+
{%- set aliases_len = aliases|length -%}
91+
{%- set default_visible_aliases = 3 -%}
92+
{%- for alias in aliases -%}
93+
{%- set invisible_class = "" -%}
94+
{%- if loop.index > default_visible_aliases -%}
95+
{%- set invisible_class = "js-hidable u-hide" -%}
96+
{%- endif -%}
97+
<li class="p-list__item {{ invisible_class }}">
98+
{{ alias[0]|safe }} &rsaquo; {{ alias[1]|safe }}
99+
</li>
100+
{%- endfor -%}
101+
{%- if aliases_len > default_visible_aliases -%}
102+
<li class="p-list__item">
103+
<a class="js-toggle-full-list" href="#" title="Display more/less aliases">
104+
{{ show_more }}
105+
</a>
106+
</li>
107+
{%- endif -%}
108+
</ul>
109+
<hr>
110+
111+
<script>
112+
// Handle aliases "show more" button
113+
const list = document.querySelector(".js-expandable-list");
114+
const showMoreButton = document.querySelector(".js-toggle-full-list");
115+
let hasAllElementsDisplayed = false;
116+
117+
const updateAliasesListUI = (displayAllElements, elements) => {
118+
// change button
119+
showMoreButton.innerHTML = displayAllElements ? "{{ show_less }}" : "{{ show_more }}";
120+
// toggle hide classes
121+
for (const element of elements) {
122+
element.classList.toggle('u-hide', !displayAllElements);
123+
}
124+
}
125+
126+
if (list && showMoreButton) {
127+
const listElements = list.querySelectorAll(".js-hidable");
128+
showMoreButton.addEventListener("click", (e) => {
129+
e.preventDefault();
130+
// switch toggle
131+
hasAllElementsDisplayed = !hasAllElementsDisplayed;
132+
updateAliasesListUI(hasAllElementsDisplayed, listElements);
133+
});
134+
}
135+
</script>
136+
{%- endif -%}
137+
79138
{% if links["issues"] %}
80139
<h5 class="p-muted-heading">Report a bug</h5>
81140
<ul class="p-list">

0 commit comments

Comments
 (0)