Commit f8b53ad7 authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'mle/338012-click-breadcrumb' into 'master'

Make breadcrumb toggle inline

See merge request gitlab-org/gitlab!72754
parents 18c49fe8 647c3fe1
import $ from 'jquery'; import $ from 'jquery';
import { hide } from '~/tooltips';
export const addTooltipToEl = (el) => { export const addTooltipToEl = (el) => {
const textEl = el.querySelector('.js-breadcrumb-item-text'); const textEl = el.querySelector('.js-breadcrumb-item-text');
...@@ -19,16 +18,23 @@ export default () => { ...@@ -19,16 +18,23 @@ export default () => {
.filter((el) => !el.classList.contains('dropdown')) .filter((el) => !el.classList.contains('dropdown'))
.map((el) => el.querySelector('a')) .map((el) => el.querySelector('a'))
.filter((el) => el); .filter((el) => el);
const $expander = $('.js-breadcrumbs-collapsed-expander'); const $expanderBtn = $('.js-breadcrumbs-collapsed-expander');
topLevelLinks.forEach((el) => addTooltipToEl(el)); topLevelLinks.forEach((el) => addTooltipToEl(el));
$expander.closest('.dropdown').on('show.bs.dropdown hide.bs.dropdown', (e) => { $expanderBtn.on('click', () => {
const $el = $('.js-breadcrumbs-collapsed-expander', e.currentTarget); const detailItems = $('.breadcrumbs-detail-item');
const hiddenClass = 'gl-display-none!';
$el.toggleClass('open'); $.each(detailItems, (_key, item) => {
$(item).toggleClass(hiddenClass);
});
// remove the ellipsis
$('li.expander').remove();
hide($el); // set focus on first breadcrumb item
$('.breadcrumb-item-text').first().focus();
}); });
} }
}; };
...@@ -27,10 +27,10 @@ module BreadcrumbsHelper ...@@ -27,10 +27,10 @@ module BreadcrumbsHelper
end end
end end
def add_to_breadcrumb_dropdown(link, location: :before) def add_to_breadcrumb_collapsed_links(link, location: :before)
@breadcrumb_dropdown_links ||= {} @breadcrumb_collapsed_links ||= {}
@breadcrumb_dropdown_links[location] ||= [] @breadcrumb_collapsed_links[location] ||= []
@breadcrumb_dropdown_links[location] << link @breadcrumb_collapsed_links[location] << link
end end
def push_to_schema_breadcrumb(text, link) def push_to_schema_breadcrumb(text, link)
......
...@@ -39,7 +39,7 @@ module GroupsHelper ...@@ -39,7 +39,7 @@ module GroupsHelper
sorted_ancestors(group).with_route.reverse_each.with_index do |parent, index| sorted_ancestors(group).with_route.reverse_each.with_index do |parent, index|
if index > 0 if index > 0
add_to_breadcrumb_dropdown(group_title_link(parent, hidable: false, show_avatar: true, for_dropdown: true), location: :before) add_to_breadcrumb_collapsed_links(group_title_link(parent), location: :before)
else else
full_title << breadcrumb_list_item(group_title_link(parent, hidable: false)) full_title << breadcrumb_list_item(group_title_link(parent, hidable: false))
end end
...@@ -47,7 +47,7 @@ module GroupsHelper ...@@ -47,7 +47,7 @@ module GroupsHelper
push_to_schema_breadcrumb(simple_sanitize(parent.name), group_path(parent)) push_to_schema_breadcrumb(simple_sanitize(parent.name), group_path(parent))
end end
full_title << render("layouts/nav/breadcrumbs/collapsed_dropdown", location: :before, title: _("Show parent subgroups")) full_title << render("layouts/nav/breadcrumbs/collapsed_inline_list", location: :before, title: _("Show all breadcrumbs"))
full_title << breadcrumb_list_item(group_title_link(group)) full_title << breadcrumb_list_item(group_title_link(group))
push_to_schema_breadcrumb(simple_sanitize(group.name), group_path(group)) push_to_schema_breadcrumb(simple_sanitize(group.name), group_path(group))
......
...@@ -9,7 +9,7 @@ module WikiHelper ...@@ -9,7 +9,7 @@ module WikiHelper
if page.persisted? if page.persisted?
titles << page.human_title titles << page.human_title
breadcrumb_title(page.human_title) breadcrumb_title(page.human_title)
wiki_breadcrumb_dropdown_links(page.slug) wiki_breadcrumb_collapsed_links(page.slug)
end end
titles << action if action titles << action if action
...@@ -39,14 +39,14 @@ module WikiHelper ...@@ -39,14 +39,14 @@ module WikiHelper
.join(' / ') .join(' / ')
end end
def wiki_breadcrumb_dropdown_links(page_slug) def wiki_breadcrumb_collapsed_links(page_slug)
page_slug_split = page_slug.split('/') page_slug_split = page_slug.split('/')
page_slug_split.pop(1) page_slug_split.pop(1)
current_slug = "" current_slug = ""
page_slug_split page_slug_split
.map do |dir_or_page| .map do |dir_or_page|
current_slug = "#{current_slug}#{dir_or_page}/" current_slug = "#{current_slug}#{dir_or_page}/"
add_to_breadcrumb_dropdown link_to(WikiPage.unhyphenize(dir_or_page).capitalize, wiki_page_path(@wiki, current_slug)), location: :after add_to_breadcrumb_collapsed_links link_to(WikiPage.unhyphenize(dir_or_page).capitalize, wiki_page_path(@wiki, current_slug)), location: :after
end end
end end
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
- if @breadcrumbs_extra_links - if @breadcrumbs_extra_links
- @breadcrumbs_extra_links.each do |extra| - @breadcrumbs_extra_links.each do |extra|
= breadcrumb_list_item link_to(extra[:text], extra[:link]) = breadcrumb_list_item link_to(extra[:text], extra[:link])
= render "layouts/nav/breadcrumbs/collapsed_dropdown", location: :after = render "layouts/nav/breadcrumbs/collapsed_inline_list", location: :after
- unless @skip_current_level_breadcrumb - unless @skip_current_level_breadcrumb
%li %li
%h2.breadcrumbs-sub-title{ data: { qa_selector: 'breadcrumb_sub_title_content' } } %h2.breadcrumbs-sub-title{ data: { qa_selector: 'breadcrumb_sub_title_content' } }
......
- dropdown_location = local_assigns.fetch(:location, nil) - dropdown_location = local_assigns.fetch(:location, nil)
- button_tooltip = local_assigns.fetch(:title, _("Show parent pages")) - button_tooltip = local_assigns.fetch(:title, _("Show all breadcrumbs"))
- if defined?(@breadcrumb_dropdown_links) && @breadcrumb_dropdown_links.key?(dropdown_location) - if defined?(@breadcrumb_collapsed_links) && @breadcrumb_collapsed_links.key?(dropdown_location)
%li.dropdown %li.expander
%button.text-expander.has-tooltip.js-breadcrumbs-collapsed-expander{ type: "button", data: { toggle: "dropdown", container: "body" }, "aria-label": button_tooltip, title: button_tooltip } %button.text-expander.has-tooltip.js-breadcrumbs-collapsed-expander{ type: "button", data: { container: "body" }, "aria-label": button_tooltip, title: button_tooltip }
= sprite_icon("ellipsis_h", size: 12) = sprite_icon("ellipsis_h", size: 12)
= sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle") = sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle")
.dropdown-menu - @breadcrumb_collapsed_links[dropdown_location].each_with_index do |link, index|
%ul %li{ :class => "gl-display-none! breadcrumbs-detail-item" }
- @breadcrumb_dropdown_links[dropdown_location].each_with_index do |link, index| = link
%li{ style: "text-indent: #{[index * 16, 60].min}px;" }= link = sprite_icon("angle-right", size: 8, css_class: "breadcrumbs-list-angle")
...@@ -31614,6 +31614,9 @@ msgstr "" ...@@ -31614,6 +31614,9 @@ msgstr ""
msgid "Show all activity" msgid "Show all activity"
msgstr "" msgstr ""
msgid "Show all breadcrumbs"
msgstr ""
msgid "Show all issues." msgid "Show all issues."
msgstr "" msgstr ""
...@@ -31668,12 +31671,6 @@ msgstr "" ...@@ -31668,12 +31671,6 @@ msgstr ""
msgid "Show one file at a time" msgid "Show one file at a time"
msgstr "" msgstr ""
msgid "Show parent pages"
msgstr ""
msgid "Show parent subgroups"
msgstr ""
msgid "Show the Closed list" msgid "Show the Closed list"
msgstr "" msgstr ""
......
...@@ -92,7 +92,7 @@ RSpec.describe GroupsHelper do ...@@ -92,7 +92,7 @@ RSpec.describe GroupsHelper do
shared_examples 'correct ancestor order' do shared_examples 'correct ancestor order' do
it 'outputs the groups in the correct order' do it 'outputs the groups in the correct order' do
expect(subject) expect(subject)
.to match(%r{<li style="text-indent: 16px;"><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m) .to match(%r{<li><a.*>#{deep_nested_group.name}.*</li>.*<a.*>#{very_deep_nested_group.name}</a>}m)
end end
end end
......
...@@ -8,7 +8,7 @@ RSpec.describe WikiHelper do ...@@ -8,7 +8,7 @@ RSpec.describe WikiHelper do
it 'sets the title for the show action' do it 'sets the title for the show action' do
expect(helper).to receive(:breadcrumb_title).with(page.human_title) expect(helper).to receive(:breadcrumb_title).with(page.human_title)
expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug) expect(helper).to receive(:wiki_breadcrumb_collapsed_links).with(page.slug)
expect(helper).to receive(:page_title).with(page.human_title, 'Wiki') expect(helper).to receive(:page_title).with(page.human_title, 'Wiki')
expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki)) expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
...@@ -17,7 +17,7 @@ RSpec.describe WikiHelper do ...@@ -17,7 +17,7 @@ RSpec.describe WikiHelper do
it 'sets the title for a custom action' do it 'sets the title for a custom action' do
expect(helper).to receive(:breadcrumb_title).with(page.human_title) expect(helper).to receive(:breadcrumb_title).with(page.human_title)
expect(helper).to receive(:wiki_breadcrumb_dropdown_links).with(page.slug) expect(helper).to receive(:wiki_breadcrumb_collapsed_links).with(page.slug)
expect(helper).to receive(:page_title).with('Edit', page.human_title, 'Wiki') expect(helper).to receive(:page_title).with('Edit', page.human_title, 'Wiki')
expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki)) expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
...@@ -27,7 +27,7 @@ RSpec.describe WikiHelper do ...@@ -27,7 +27,7 @@ RSpec.describe WikiHelper do
it 'sets the title for an unsaved page' do it 'sets the title for an unsaved page' do
expect(page).to receive(:persisted?).and_return(false) expect(page).to receive(:persisted?).and_return(false)
expect(helper).not_to receive(:breadcrumb_title) expect(helper).not_to receive(:breadcrumb_title)
expect(helper).not_to receive(:wiki_breadcrumb_dropdown_links) expect(helper).not_to receive(:wiki_breadcrumb_collapsed_links)
expect(helper).to receive(:page_title).with('Wiki') expect(helper).to receive(:page_title).with('Wiki')
expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki)) expect(helper).to receive(:add_to_breadcrumbs).with('Wiki', helper.wiki_path(page.wiki))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment