Commit 1e588f4d authored by Nick Thomas's avatar Nick Thomas

Use the Vue comparison selector on the repo compare show page

This control was originally designed for the index page, but we need it
on show as well.
parent f8c65db7
import Diff from '~/diff'; import Diff from '~/diff';
import GpgBadges from '~/gpg_badges'; import GpgBadges from '~/gpg_badges';
import initChangesDropdown from '~/init_changes_dropdown'; import initChangesDropdown from '~/init_changes_dropdown';
import initCompareSelector from '~/projects/compare';
initCompareSelector();
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
new Diff(); // eslint-disable-line no-new new Diff(); // eslint-disable-line no-new
......
...@@ -69,7 +69,7 @@ export default { ...@@ -69,7 +69,7 @@ export default {
this.loading = true; this.loading = true;
if (reset) { if (reset) {
this.selectedRevision = emptyDropdownText; this.selectedRevision = this.getDefaultBranch();
} }
return axios return axios
......
...@@ -21,7 +21,7 @@ class Projects::CompareController < Projects::ApplicationController ...@@ -21,7 +21,7 @@ class Projects::CompareController < Projects::ApplicationController
before_action :validate_refs! before_action :validate_refs!
before_action do before_action do
push_frontend_feature_flag(:compare_repo_dropdown) push_frontend_feature_flag(:compare_repo_dropdown, source_project, default_enabled: :yaml)
end end
feature_category :source_code_management feature_category :source_code_management
......
...@@ -28,4 +28,20 @@ module CompareHelper ...@@ -28,4 +28,20 @@ module CompareHelper
.new(current_user: current_user, source_project: source_project, project_feature: :repository) .new(current_user: current_user, source_project: source_project, project_feature: :repository)
.execute(include_routes: true) .execute(include_routes: true)
end end
def project_compare_selector_data(project, merge_request, params)
{
project_compare_index_path: project_compare_index_path(project),
refs_project_path: refs_project_path(project),
params_from: params[:from],
params_to: params[:to],
project_merge_request_path: merge_request.present? ? project_merge_request_path(project, merge_request) : '',
create_mr_path: create_mr_button? ? create_mr_path : ''
}.tap do |data|
if Feature.enabled?(:compare_repo_dropdown, project, default_enabled: :yaml)
data[:project_to] = { id: project.id, name: project.full_path }.to_json
data[:projects_from] = target_projects(project).map { |project| { id: project.id, name: project.full_path } }.to_json
end
end
end
end end
= form_tag project_compare_index_path(@project), method: :post, class: 'form-inline js-requires-input js-signature-container', data: { 'signatures-path' => signatures_namespace_project_compare_index_path } do
.form-group.dropdown.compare-form-group.to.js-compare-to-dropdown
.input-group.inline-input-group
%span.input-group-prepend
.input-group-text
= s_("CompareBranches|Source")
= hidden_field_tag :to, params[:to]
= button_tag type: 'button', title: params[:to], class: "btn gl-button form-control compare-dropdown-toggle js-compare-dropdown has-tooltip", required: true, data: { refs_url: refs_project_path(@project), toggle: "dropdown", target: ".js-compare-to-dropdown", selected: params[:to], field_name: :to } do
.dropdown-toggle-text.str-truncated.monospace.float-left= params[:to] || _("Select branch/tag")
= sprite_icon('chevron-down', css_class: 'float-right')
= render 'shared/ref_dropdown'
.compare-ellipsis.inline ...
.form-group.dropdown.compare-form-group.from.js-compare-from-dropdown
.input-group.inline-input-group
%span.input-group-prepend
.input-group-text
= s_("CompareBranches|Target")
= hidden_field_tag :from, params[:from]
= button_tag type: 'button', title: params[:from], class: "btn gl-button form-control compare-dropdown-toggle js-compare-dropdown has-tooltip", required: true, data: { refs_url: refs_project_path(@project), toggle: "dropdown", target: ".js-compare-from-dropdown", selected: params[:from], field_name: :from } do
.dropdown-toggle-text.str-truncated.monospace.float-left= params[:from] || _("Select branch/tag")
= sprite_icon('chevron-down', css_class: 'float-right')
= render 'shared/ref_dropdown'
&nbsp;
= button_tag s_("CompareBranches|Compare"), class: "btn gl-button btn-success commits-compare-btn"
- if @merge_request.present?
= link_to _("View open merge request"), project_merge_request_path(@project, @merge_request), class: 'gl-ml-3 btn'
- elsif create_mr_button?
= link_to _("Create merge request"), create_mr_path, class: 'gl-ml-3 btn gl-button'
...@@ -13,17 +13,4 @@ ...@@ -13,17 +13,4 @@
= html_escape(_("Changes are shown as if the %{b_open}source%{b_close} revision was being merged into the %{b_open}target%{b_close} revision.")) % { b_open: '<b>'.html_safe, b_close: '</b>'.html_safe } = html_escape(_("Changes are shown as if the %{b_open}source%{b_close} revision was being merged into the %{b_open}target%{b_close} revision.")) % { b_open: '<b>'.html_safe, b_close: '</b>'.html_safe }
.prepend-top-20 .prepend-top-20
- if Feature.enabled?(:compare_repo_dropdown) #js-compare-selector{ data: project_compare_selector_data(@project, @merge_request, params) }
#js-compare-selector{ data: { project_compare_index_path: project_compare_index_path(@project),
refs_project_path: refs_project_path(@project),
params_from: params[:from], params_to: params[:to],
project_merge_request_path: @merge_request.present? ? project_merge_request_path(@project, @merge_request) : '',
create_mr_path: create_mr_button? ? create_mr_path : '',
project_to: { id: @project.id, name: @project.full_path }.to_json,
projects_from: target_projects(@project).map { |project| { id:project.id, name: project.full_path } }.to_json } }
- else
#js-compare-selector{ data: { project_compare_index_path: project_compare_index_path(@project),
refs_project_path: refs_project_path(@project),
params_from: params[:from], params_to: params[:to],
project_merge_request_path: @merge_request.present? ? project_merge_request_path(@project, @merge_request) : '',
create_mr_path: create_mr_button? ? create_mr_path : '' } }
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
- page_title "#{params[:from]}...#{params[:to]}" - page_title "#{params[:from]}...#{params[:to]}"
.sub-header-block.no-bottom-space .sub-header-block.no-bottom-space
= render "form" .js-signature-container{ data: { 'signatures-path' => signatures_namespace_project_compare_index_path } }
#js-compare-selector{ data: project_compare_selector_data(@project, @merge_request, params) }
- if @commits.present? - if @commits.present?
= render "projects/commits/commit_list" = render "projects/commits/commit_list"
......
---
title: Restyle the repository compare show page
merge_request: 53523
author:
type: changed
...@@ -7548,15 +7548,6 @@ msgstr "" ...@@ -7548,15 +7548,6 @@ msgstr ""
msgid "CompareBranches|%{source_branch} and %{target_branch} are the same." msgid "CompareBranches|%{source_branch} and %{target_branch} are the same."
msgstr "" msgstr ""
msgid "CompareBranches|Compare"
msgstr ""
msgid "CompareBranches|Source"
msgstr ""
msgid "CompareBranches|Target"
msgstr ""
msgid "CompareBranches|There isn't anything to compare." msgid "CompareBranches|There isn't anything to compare."
msgstr "" msgstr ""
...@@ -26653,9 +26644,6 @@ msgstr "" ...@@ -26653,9 +26644,6 @@ msgstr ""
msgid "Select branch" msgid "Select branch"
msgstr "" msgstr ""
msgid "Select branch/tag"
msgstr ""
msgid "Select due date" msgid "Select due date"
msgstr "" msgstr ""
......
...@@ -24,7 +24,7 @@ RSpec.describe 'Merge Request button' do ...@@ -24,7 +24,7 @@ RSpec.describe 'Merge Request button' do
project.add_developer(user) project.add_developer(user)
end end
it 'shows Create merge request button' do it 'shows Create merge request button', :js do
href = project_new_merge_request_path( href = project_new_merge_request_path(
project, project,
merge_request: { merge_request: {
...@@ -83,7 +83,7 @@ RSpec.describe 'Merge Request button' do ...@@ -83,7 +83,7 @@ RSpec.describe 'Merge Request button' do
end end
context 'on own fork of project' do context 'on own fork of project' do
it 'shows Create merge request button' do it 'shows Create merge request button', :js do
href = project_new_merge_request_path( href = project_new_merge_request_path(
forked_project, forked_project,
merge_request: { merge_request: {
...@@ -120,7 +120,7 @@ RSpec.describe 'Merge Request button' do ...@@ -120,7 +120,7 @@ RSpec.describe 'Merge Request button' do
let(:fork_url) { project_compare_path(forked_project, from: 'master', to: 'feature') } let(:fork_url) { project_compare_path(forked_project, from: 'master', to: 'feature') }
end end
it 'shows the correct merge request button when viewing across forks' do it 'shows the correct merge request button when viewing across forks', :js do
sign_in(user) sign_in(user)
project.add_developer(user) project.add_developer(user)
......
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