From b0752217a425dfb1f6836a09783e3cd43ebe190c Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 23 Oct 2020 13:09:07 -0600 Subject: [PATCH 01/13] Add `manuallyCollapsed` flag to Diff Files Of course, this means that there's a bunch of logic to coordinate the new flag with the original - `automaticallyCollapsed` - flag. In addition: the UI is updated to use the new flag whenever it's been set, but to continue to fall back to the old flag. This is primarily facilitated by a new helper utility for diff files to do the resolution in a single centralized place. Of note: the diff_file is updated to depend on the global store as the authoritative source of determining whether the file is collapsed or not. The previous version kept a local `isCollapsed` in sync with the global store, which introduced a huge amount of interwoven complexity. The update ingests the resolved collapsed state from the store when various observed properties update instead of inverting that flow. This is a full refactor of file collapsing. Because the previous version was a single flag, then modified with a user preference (file-by-file), there were some issues including a THIRD possible way that collapsing works. This update slightly simplifies how collapsing works by depending more heavily on the two flags stored in state and only modifying them with the user preference when necessary. --- .../javascripts/diffs/components/app.vue | 11 +-- .../diffs/components/compare_versions.vue | 2 +- .../diffs/components/diff_file.vue | 95 ++++++++++++------- .../diffs/components/diff_file_header.vue | 6 +- app/assets/javascripts/diffs/constants.js | 4 + app/assets/javascripts/diffs/diff_file.js | 24 ++++- app/assets/javascripts/diffs/store/actions.js | 18 +++- app/assets/javascripts/diffs/store/getters.js | 28 +++++- .../javascripts/diffs/store/mutations.js | 34 +++++-- .../notes/components/diff_with_note.vue | 6 +- 10 files changed, 167 insertions(+), 61 deletions(-) diff --git a/app/assets/javascripts/diffs/components/app.vue b/app/assets/javascripts/diffs/components/app.vue index 085f951147f8ca..7895407cef0541 100644 --- a/app/assets/javascripts/diffs/components/app.vue +++ b/app/assets/javascripts/diffs/components/app.vue @@ -124,7 +124,6 @@ export default { return { treeWidth, diffFilesLength: 0, - collapsedWarningDismissed: false, }; }, computed: { @@ -206,11 +205,7 @@ export default { visible = this.$options.alerts.ALERT_OVERFLOW_HIDDEN; } else if (this.isDiffHead && this.hasConflicts) { visible = this.$options.alerts.ALERT_MERGE_CONFLICT; - } else if ( - this.hasCollapsedFile && - !this.collapsedWarningDismissed && - !this.viewDiffsFileByFile - ) { + } else if (this.hasCollapsedFile.automatic && !this.viewDiffsFileByFile) { visible = this.$options.alerts.ALERT_COLLAPSED_FILES; } @@ -429,9 +424,6 @@ export default { this.toggleShowTreeList(false); } }, - dismissCollapsedWarning() { - this.collapsedWarningDismissed = true; - }, }, minTreeWidth: MIN_TREE_WIDTH, maxTreeWidth: MAX_TREE_WIDTH, @@ -464,7 +456,6 @@ export default {
{ this.isLoadingCollapsedDiff = false; - this.isCollapsed = false; this.setRenderIt(this.file); }) .then(() => { @@ -167,6 +190,7 @@ export default { :class="{ 'is-active': currentDiffFileId === file.file_hash, 'comments-disabled': Boolean(file.brokenSymlink), + 'has-body': showBody, }" :data-path="file.new_path" class="diff-file file-holder" @@ -200,22 +224,23 @@ export default {
diff --git a/app/assets/javascripts/diffs/components/diff_file_header.vue b/app/assets/javascripts/diffs/components/diff_file_header.vue index b08b9df13a43d8..ea7112689c1440 100644 --- a/app/assets/javascripts/diffs/components/diff_file_header.vue +++ b/app/assets/javascripts/diffs/components/diff_file_header.vue @@ -18,6 +18,7 @@ import { __, s__, sprintf } from '~/locale'; import { diffViewerModes } from '~/ide/constants'; import DiffStats from './diff_stats.vue'; import { scrollToElement } from '~/lib/utils/common_utils'; +import { isCollapsed } from '../diff_file'; import { DIFF_FILE_HEADER } from '../i18n'; export default { @@ -125,6 +126,9 @@ export default { isUsingLfs() { return this.diffFile.stored_externally && this.diffFile.external_storage === 'lfs'; }, + isCollapsed() { + return isCollapsed(this.diffFile, { fileByFile: this.viewDiffsFileByFile }); + }, collapseIcon() { return this.expanded ? 'chevron-down' : 'chevron-right'; }, @@ -334,7 +338,7 @@ export default { -