Commit d16bec0b authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '349406-make-dashboard-translatable' into 'master'

Externalize strings for translation on dashboard

See merge request gitlab-org/gitlab!77432
parents 10709882 006ae2d6
import $ from 'jquery'; import $ from 'jquery';
import { sprintf, __ } from '~/locale';
import AccessorUtilities from './lib/utils/accessor'; import AccessorUtilities from './lib/utils/accessor';
import { loadCSSFile } from './lib/utils/css_utils'; import { loadCSSFile } from './lib/utils/css_utils';
export default class ProjectSelectComboButton { export default class ProjectSelectComboButton {
constructor(select) { constructor(select) {
this.projectSelectInput = $(select); this.projectSelectInput = $(select);
this.newItemBtn = $('.new-project-item-link'); this.newItemBtn = $('.js-new-project-item-link');
this.resourceType = this.newItemBtn.data('type'); this.resourceType = this.newItemBtn.data('type');
this.resourceLabel = this.newItemBtn.data('label'); this.resourceLabel = this.newItemBtn.data('label');
this.formattedText = this.deriveTextVariants(); this.formattedText = this.deriveTextVariants();
...@@ -80,9 +81,18 @@ export default class ProjectSelectComboButton { ...@@ -80,9 +81,18 @@ export default class ProjectSelectComboButton {
setNewItemBtnAttributes(project) { setNewItemBtnAttributes(project) {
if (project) { if (project) {
this.newItemBtn.attr('href', project.url); this.newItemBtn.attr('href', project.url);
this.newItemBtn.text(`${this.formattedText.defaultTextPrefix} in ${project.name}`); this.newItemBtn.text(
sprintf(__('New %{type} in %{project}'), {
type: this.resourceLabel,
project: project.name,
}),
);
} else { } else {
this.newItemBtn.text(`Select project to create ${this.formattedText.presetTextSuffix}`); this.newItemBtn.text(
sprintf(__('Select project to create %{type}'), {
type: this.formattedText.presetTextSuffix,
}),
);
} }
} }
...@@ -99,15 +109,12 @@ export default class ProjectSelectComboButton { ...@@ -99,15 +109,12 @@ export default class ProjectSelectComboButton {
} }
deriveTextVariants() { deriveTextVariants() {
const defaultTextPrefix = this.resourceLabel;
// the trailing slice call depluralizes each of these strings (e.g. new-issues -> new-issue) // the trailing slice call depluralizes each of these strings (e.g. new-issues -> new-issue)
const localStorageItemType = `new-${this.resourceType.split('_').join('-').slice(0, -1)}`; const localStorageItemType = `new-${this.resourceType.split('_').join('-').slice(0, -1)}`;
const presetTextSuffix = this.resourceType.split('_').join(' ').slice(0, -1); const presetTextSuffix = this.resourceType.split('_').join(' ').slice(0, -1);
return { return {
localStorageItemType, // new-issue / new-merge-request localStorageItemType, // new-issue / new-merge-request
defaultTextPrefix, // New issue / New merge request
presetTextSuffix, // issue / merge request presetTextSuffix, // issue / merge request
}; };
} }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
- if current_user - if current_user
.page-title-controls .page-title-controls
= render 'shared/new_project_item_select', path: 'issues/new', label: "New issue", with_feature_enabled: 'issues', type: :issues = render 'shared/new_project_item_select', path: 'issues/new', label: _("issue"), with_feature_enabled: 'issues', type: :issues
.top-area .top-area
= render 'shared/issuable/nav', type: :issues, display_count: !@no_filters_set = render 'shared/issuable/nav', type: :issues, display_count: !@no_filters_set
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- if current_user - if current_user
.page-title-controls.ml-0.mb-3.ml-sm-auto.mb-sm-0 .page-title-controls.ml-0.mb-3.ml-sm-auto.mb-sm-0
= render 'shared/new_project_item_select', path: 'merge_requests/new', label: "New merge request", with_feature_enabled: 'merge_requests', type: :merge_requests = render 'shared/new_project_item_select', path: 'merge_requests/new', label: _("merge request"), with_feature_enabled: 'merge_requests', type: :merge_requests
.top-area .top-area
= render 'shared/issuable/nav', type: :merge_requests, display_count: !@no_filters_set = render 'shared/issuable/nav', type: :merge_requests, display_count: !@no_filters_set
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
- if @can_bulk_update - if @can_bulk_update
= render_if_exists 'shared/issuable/bulk_update_button', type: :issues = render_if_exists 'shared/issuable/bulk_update_button', type: :issues
= render 'shared/new_project_item_select', path: 'issues/new', label: "New issue", type: :issues, with_feature_enabled: 'issues', with_shared: false, include_projects_in_subgroups: true = render 'shared/new_project_item_select', path: 'issues/new', label: _("issue"), type: :issues, with_feature_enabled: 'issues', with_shared: false, include_projects_in_subgroups: true
= render 'shared/issuable/search_bar', type: :issues = render 'shared/issuable/search_bar', type: :issues
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
- if @can_bulk_update - if @can_bulk_update
= render_if_exists 'shared/issuable/bulk_update_button', type: :merge_requests = render_if_exists 'shared/issuable/bulk_update_button', type: :merge_requests
= render 'shared/new_project_item_select', path: 'merge_requests/new', label: "New merge request", type: :merge_requests, with_feature_enabled: 'merge_requests', with_shared: false, include_projects_in_subgroups: true = render 'shared/new_project_item_select', path: 'merge_requests/new', label: _("merge request"), type: :merge_requests, with_feature_enabled: 'merge_requests', with_shared: false, include_projects_in_subgroups: true
= render 'shared/issuable/search_bar', type: :merge_requests = render 'shared/issuable/search_bar', type: :merge_requests
......
- if any_projects?(@projects) - if any_projects?(@projects)
.project-item-select-holder.btn-group.gl-ml-auto.gl-mr-auto.gl-relative.gl-overflow-hidden{ class: 'gl-display-flex!' } .project-item-select-holder.btn-group.gl-ml-auto.gl-mr-auto.gl-relative.gl-overflow-hidden{ class: 'gl-display-flex!' }
%a.btn.gl-button.btn-confirm.new-project-item-link.block-truncated.qa-new-project-item-link{ href: '', data: { label: local_assigns[:label], type: local_assigns[:type] }, class: "gl-m-0!" } %a.btn.gl-button.btn-confirm.js-new-project-item-link.block-truncated.qa-new-project-item-link{ href: '', data: { label: local_assigns[:label], type: local_assigns[:type] }, class: "gl-m-0!" }
= loading_icon(color: 'light') = loading_icon(color: 'light')
= project_select_tag :project_path, class: "project-item-select gl-absolute! gl-visibility-hidden", data: { include_groups: local_assigns[:include_groups], order_by: 'last_activity_at', relative_path: local_assigns[:path], with_shared: local_assigns[:with_shared], include_projects_in_subgroups: local_assigns[:include_projects_in_subgroups] }, with_feature_enabled: local_assigns[:with_feature_enabled] = project_select_tag :project_path, class: "project-item-select gl-absolute! gl-visibility-hidden", data: { include_groups: local_assigns[:include_groups], order_by: 'last_activity_at', relative_path: local_assigns[:path], with_shared: local_assigns[:with_shared], include_projects_in_subgroups: local_assigns[:include_projects_in_subgroups] }, with_feature_enabled: local_assigns[:with_feature_enabled]
%button.btn.dropdown-toggle.btn-confirm.btn-md.gl-button.gl-dropdown-toggle.dropdown-toggle-split.new-project-item-select-button.qa-new-project-item-select-button.gl-p-0.gl-w-100{ class: "gl-m-0!", 'aria-label': _('Toggle project select') } %button.btn.dropdown-toggle.btn-confirm.btn-md.gl-button.gl-dropdown-toggle.dropdown-toggle-split.new-project-item-select-button.qa-new-project-item-select-button.gl-p-0.gl-w-100{ class: "gl-m-0!", 'aria-label': _('Toggle project select') }
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
- if has_button - if has_button
.text-center .text-center
- if project_select_button - if project_select_button
= render 'shared/new_project_item_select', path: 'issues/new', label: _('New issue'), type: :issues, with_feature_enabled: 'issues' = render 'shared/new_project_item_select', path: 'issues/new', label: _('issue'), type: :issues, with_feature_enabled: 'issues'
- elsif show_new_issue_link?(@project) - elsif show_new_issue_link?(@project)
= link_to _('New issue'), button_path, class: 'gl-button btn btn-confirm', id: 'new_issue_link' = link_to _('New issue'), button_path, class: 'gl-button btn btn-confirm', id: 'new_issue_link'
......
...@@ -40,6 +40,6 @@ ...@@ -40,6 +40,6 @@
- if has_button - if has_button
.text-center .text-center
- if project_select_button - if project_select_button
= render 'shared/new_project_item_select', path: 'merge_requests/new', label: _('New merge request'), type: :merge_requests, with_feature_enabled: 'merge_requests' = render 'shared/new_project_item_select', path: 'merge_requests/new', label: _('merge request'), type: :merge_requests, with_feature_enabled: 'merge_requests'
- else - else
= link_to _('New merge request'), button_path, class: 'gl-button btn btn-confirm', title: _('New merge request'), id: 'new_merge_request_link' = link_to _('New merge request'), button_path, class: 'gl-button btn btn-confirm', title: _('New merge request'), id: 'new_merge_request_link'
...@@ -23484,6 +23484,9 @@ msgstr "" ...@@ -23484,6 +23484,9 @@ msgstr ""
msgid "New %{issueType}" msgid "New %{issueType}"
msgstr "" msgstr ""
msgid "New %{type} in %{project}"
msgstr ""
msgid "New Application" msgid "New Application"
msgstr "" msgstr ""
...@@ -31987,6 +31990,9 @@ msgstr "" ...@@ -31987,6 +31990,9 @@ msgstr ""
msgid "Select project to choose zone" msgid "Select project to choose zone"
msgstr "" msgstr ""
msgid "Select project to create %{type}"
msgstr ""
msgid "Select project to create issue" msgid "Select project to create issue"
msgstr "" msgstr ""
......
...@@ -71,7 +71,7 @@ RSpec.describe 'Dashboard Issues' do ...@@ -71,7 +71,7 @@ RSpec.describe 'Dashboard Issues' do
find('#select2-drop-mask', visible: false) find('#select2-drop-mask', visible: false)
execute_script("$('#select2-drop-mask').remove();") execute_script("$('#select2-drop-mask').remove();")
find('.new-project-item-link').click find('.js-new-project-item-link').click
expect(page).to have_current_path("#{project_path}/-/issues/new") expect(page).to have_current_path("#{project_path}/-/issues/new")
......
...@@ -41,7 +41,7 @@ RSpec.describe 'Dashboard > Milestones' do ...@@ -41,7 +41,7 @@ RSpec.describe 'Dashboard > Milestones' do
first('.select2-result-label').click first('.select2-result-label').click
end end
find('.new-project-item-link').click find('.js-new-project-item-link').click
expect(current_path).to eq(new_group_milestone_path(group)) expect(current_path).to eq(new_group_milestone_path(group))
end end
......
...@@ -67,7 +67,7 @@ RSpec.describe 'Group merge requests page' do ...@@ -67,7 +67,7 @@ RSpec.describe 'Group merge requests page' do
end end
it 'shows projects only with merge requests feature enabled', :js do it 'shows projects only with merge requests feature enabled', :js do
find('.new-project-item-link').click find('.js-new-project-item-link').click
page.within('.select2-results') do page.within('.select2-results') do
expect(page).to have_content(project.name_with_namespace) expect(page).to have_content(project.name_with_namespace)
......
<div class="project-item-select-holder"> <div class="project-item-select-holder">
<input class="project-item-select" data-group-id="12345" data-relative-path="issues/new" /> <input class="project-item-select" data-group-id="12345" data-relative-path="issues/new" />
<a class="new-project-item-link" data-label="New issue" data-type="issues" href=""> <a class="js-new-project-item-link" data-label="issue" data-type="issues" href="">
<span class="gl-spinner"></span> <span class="gl-spinner"></span>
</a> </a>
<a class="new-project-item-select-button"> <a class="new-project-item-select-button">
......
...@@ -28,7 +28,7 @@ describe('Project Select Combo Button', () => { ...@@ -28,7 +28,7 @@ describe('Project Select Combo Button', () => {
loadFixtures(fixturePath); loadFixtures(fixturePath);
testContext.newItemBtn = document.querySelector('.new-project-item-link'); testContext.newItemBtn = document.querySelector('.js-new-project-item-link');
testContext.projectSelectInput = document.querySelector('.project-item-select'); testContext.projectSelectInput = document.querySelector('.project-item-select');
}); });
...@@ -120,7 +120,6 @@ describe('Project Select Combo Button', () => { ...@@ -120,7 +120,6 @@ describe('Project Select Combo Button', () => {
const returnedVariants = testContext.method(); const returnedVariants = testContext.method();
expect(returnedVariants.localStorageItemType).toBe('new-merge-request'); expect(returnedVariants.localStorageItemType).toBe('new-merge-request');
expect(returnedVariants.defaultTextPrefix).toBe('New merge request');
expect(returnedVariants.presetTextSuffix).toBe('merge request'); expect(returnedVariants.presetTextSuffix).toBe('merge request');
}); });
...@@ -131,7 +130,6 @@ describe('Project Select Combo Button', () => { ...@@ -131,7 +130,6 @@ describe('Project Select Combo Button', () => {
const returnedVariants = testContext.method(); const returnedVariants = testContext.method();
expect(returnedVariants.localStorageItemType).toBe('new-issue'); expect(returnedVariants.localStorageItemType).toBe('new-issue');
expect(returnedVariants.defaultTextPrefix).toBe('New issue');
expect(returnedVariants.presetTextSuffix).toBe('issue'); expect(returnedVariants.presetTextSuffix).toBe('issue');
}); });
}); });
......
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