Commit 0828e47b authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '198458-make-merge-ref-diffs-the-default-comparison-mode' into 'master'

Make merge-ref diffs the default comparison mode

Closes #198458

See merge request gitlab-org/gitlab!34472
parents 3c20647e 92fb6061
......@@ -11,17 +11,26 @@ export const diffCompareDropdownTargetVersions = (state, getters) => {
// startVersion only exists if the user has selected a version other
// than "base" so if startVersion is null then base must be selected
const diffHead = parseBoolean(getParameterByName('diff_head'));
const defaultMergeRefForDiffs = window.gon?.features?.defaultMergeRefForDiffs || false;
const diffHeadParam = getParameterByName('diff_head');
const diffHead = parseBoolean(diffHeadParam) || (!diffHeadParam && defaultMergeRefForDiffs);
const isBaseSelected = !state.startVersion && !diffHead;
const isHeadSelected = !state.startVersion && diffHead;
let baseVersion = null;
const baseVersion = {
versionName: state.targetBranchName,
version_index: DIFF_COMPARE_BASE_VERSION_INDEX,
href: state.mergeRequestDiff.base_version_path,
isBase: true,
selected: isBaseSelected,
};
if (
!defaultMergeRefForDiffs ||
(defaultMergeRefForDiffs && !state.mergeRequestDiff.head_version_path)
) {
baseVersion = {
versionName: state.targetBranchName,
version_index: DIFF_COMPARE_BASE_VERSION_INDEX,
href: state.mergeRequestDiff.base_version_path,
isBase: true,
selected:
isBaseSelected || (defaultMergeRefForDiffs && !state.mergeRequestDiff.head_version_path),
};
}
const headVersion = {
versionName: state.targetBranchName,
......@@ -40,7 +49,11 @@ export const diffCompareDropdownTargetVersions = (state, getters) => {
};
};
return [...state.mergeRequestDiffs.slice(1).map(formatVersion), baseVersion, headVersion];
return [
...state.mergeRequestDiffs.slice(1).map(formatVersion),
baseVersion,
state.mergeRequestDiff.head_version_path && headVersion,
].filter(a => a);
};
export const diffCompareDropdownSourceVersions = (state, getters) => {
......
......@@ -41,6 +41,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
push_frontend_feature_flag(:merge_request_widget_graphql, @project)
push_frontend_feature_flag(:unified_diff_lines, @project)
push_frontend_feature_flag(:highlight_current_diff_row, @project)
push_frontend_feature_flag(:default_merge_ref_for_diffs, @project)
end
before_action do
......@@ -457,6 +458,10 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
params = request.query_parameters
params[:view] = cookies[:diff_view] if params[:view].blank? && cookies[:diff_view].present?
if Feature.enabled?(:default_merge_ref_for_diffs, project)
params = params.merge(diff_head: true)
end
diffs_metadata_project_json_merge_request_path(project, merge_request, 'json', params)
end
end
......
......@@ -70,10 +70,13 @@
= render 'projects/commit/pipelines_list', disable_initialization: true, endpoint: pipelines_project_merge_request_path(@project, @merge_request)
- if mr_action === "diffs"
- add_page_startup_api_call @endpoint_metadata_url
- params = request.query_parameters
- if Feature.enabled?(:default_merge_ref_for_diffs, @project)
- params = params.merge(diff_head: true)
= render "projects/merge_requests/tabs/pane", name: "diffs", id: "js-diffs-app", class: "diffs", data: { "is-locked": @merge_request.discussion_locked?,
endpoint: diffs_project_merge_request_path(@project, @merge_request, 'json', request.query_parameters),
endpoint: diffs_project_merge_request_path(@project, @merge_request, 'json', params),
endpoint_metadata: @endpoint_metadata_url,
endpoint_batch: diffs_batch_project_json_merge_request_path(@project, @merge_request, 'json', request.query_parameters),
endpoint_batch: diffs_batch_project_json_merge_request_path(@project, @merge_request, 'json', params),
endpoint_coverage: @coverage_path,
help_page_path: suggest_changes_help_path,
current_user_data: @current_user_data,
......
......@@ -87,6 +87,22 @@ RSpec.describe Projects::MergeRequestsController do
end
end
context 'with `default_merge_ref_for_diffs` feature flag enabled' do
before do
stub_feature_flags(default_merge_ref_for_diffs: true)
go
end
it 'adds the diff_head parameter' do
expect(assigns["endpoint_metadata_url"]).to eq(
diffs_metadata_project_json_merge_request_path(
project,
merge_request,
'json',
diff_head: true))
end
end
context 'when diff is missing' do
render_views
......
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