Commit fb09e391 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/230511/autoExpandCollapsedDiffsInSingleFileMode' into 'master'

Auto expand collapsed diffs when in single diff file mode

Closes #230511

See merge request gitlab-org/gitlab!37832
parents fc182138 8a39540a
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { mapActions, mapGetters, mapState } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { escape } from 'lodash'; import { escape } from 'lodash';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import createFlash from '~/flash'; import createFlash from '~/flash';
import { hasDiff } from '~/helpers/diffs_helper'; import { hasDiff } from '~/helpers/diffs_helper';
...@@ -16,6 +17,7 @@ export default { ...@@ -16,6 +17,7 @@ export default {
DiffContent, DiffContent,
GlLoadingIcon, GlLoadingIcon,
}, },
mixins: [glFeatureFlagsMixin()],
props: { props: {
file: { file: {
type: Object, type: Object,
...@@ -89,8 +91,25 @@ export default { ...@@ -89,8 +91,25 @@ export default {
this.setFileCollapsed({ filePath: this.file.file_path, collapsed: newVal }); this.setFileCollapsed({ filePath: this.file.file_path, collapsed: newVal });
}, },
'file.file_hash': {
handler: function watchFileHash() {
if (
this.glFeatures.autoExpandCollapsedDiffs &&
this.viewDiffsFileByFile &&
this.file.viewer.collapsed
) {
this.isCollapsed = false;
this.handleLoadCollapsedDiff();
} else {
this.isCollapsed = this.file.viewer.collapsed || false;
}
},
immediate: true,
},
'file.viewer.collapsed': function setIsCollapsed(newVal) { 'file.viewer.collapsed': function setIsCollapsed(newVal) {
this.isCollapsed = newVal; if (!this.viewDiffsFileByFile && !this.glFeatures.autoExpandCollapsedDiffs) {
this.isCollapsed = newVal;
}
}, },
}, },
created() { created() {
......
...@@ -36,6 +36,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo ...@@ -36,6 +36,7 @@ class Projects::MergeRequestsController < Projects::MergeRequests::ApplicationCo
push_frontend_feature_flag(:multiline_comments, @project) push_frontend_feature_flag(:multiline_comments, @project)
push_frontend_feature_flag(:file_identifier_hash) push_frontend_feature_flag(:file_identifier_hash)
push_frontend_feature_flag(:batch_suggestions, @project, default_enabled: true) push_frontend_feature_flag(:batch_suggestions, @project, default_enabled: true)
push_frontend_feature_flag(:auto_expand_collapsed_diffs, @project)
end end
before_action do before_action do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'User views diffs file-by-file', :js do
let(:merge_request) do
create(:merge_request, source_branch: 'squash-large-files', source_project: project, target_project: project)
end
let(:project) { create(:project, :repository) }
let(:user) { create(:user, view_diffs_file_by_file: true) }
before do
allow(Gitlab::Git::Diff).to receive(:size_limit).and_return(100.kilobytes)
allow(Gitlab::Git::Diff).to receive(:collapse_limit).and_return(10.kilobytes)
project.add_developer(user)
sign_in(user)
visit(diffs_project_merge_request_path(project, merge_request, anchor: '5091f7b9dd6202e37eaedd73d7b75d82f25fdb61'))
wait_for_requests
end
it 'shows diffs file-by-file' do
page.within('#diffs') do
expect(page).not_to have_content('This diff is collapsed')
click_button 'Next'
expect(page).not_to have_content('This diff is collapsed')
end
end
end
...@@ -128,6 +128,26 @@ describe('DiffFile', () => { ...@@ -128,6 +128,26 @@ describe('DiffFile', () => {
}); });
}); });
it('should auto-expand collapsed files when viewDiffsFileByFile is true', done => {
vm.$destroy();
window.gon = {
features: { autoExpandCollapsedDiffs: true },
};
vm = createComponentWithStore(Vue.extend(DiffFileComponent), createStore(), {
file: JSON.parse(JSON.stringify(diffFileMockDataUnreadable)),
canCurrentUserFork: false,
viewDiffsFileByFile: true,
}).$mount();
vm.$nextTick(() => {
expect(vm.$el.innerText).not.toContain('This diff is collapsed');
window.gon = {};
done();
});
});
it('should be collapsed for renamed files', done => { it('should be collapsed for renamed files', done => {
vm.renderIt = true; vm.renderIt = true;
vm.isCollapsed = false; vm.isCollapsed = false;
......
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