diff options
Diffstat (limited to 'app/assets/javascripts/diffs/components/diff_file.vue')
-rw-r--r-- | app/assets/javascripts/diffs/components/diff_file.vue | 89 |
1 files changed, 53 insertions, 36 deletions
diff --git a/app/assets/javascripts/diffs/components/diff_file.vue b/app/assets/javascripts/diffs/components/diff_file.vue index ed8455f0c1c..dde5ea81e9a 100644 --- a/app/assets/javascripts/diffs/components/diff_file.vue +++ b/app/assets/javascripts/diffs/components/diff_file.vue @@ -2,6 +2,7 @@ import { GlButton, GlLoadingIcon, GlSafeHtmlDirective as SafeHtml, GlSprintf } from '@gitlab/ui'; import { escape } from 'lodash'; import { mapActions, mapGetters, mapState } from 'vuex'; +import { IdState } from 'vendor/vue-virtual-scroller'; import createFlash from '~/flash'; import { hasDiff } from '~/helpers/diffs_helper'; import { diffViewerErrors } from '~/ide/constants'; @@ -19,7 +20,7 @@ import { } from '../constants'; import eventHub from '../event_hub'; import { DIFF_FILE, GENERIC_ERROR } from '../i18n'; -import { collapsedType, isCollapsed, getShortShaFromFile } from '../utils/diff_file'; +import { collapsedType, getShortShaFromFile } from '../utils/diff_file'; import DiffContent from './diff_content.vue'; import DiffFileHeader from './diff_file_header.vue'; @@ -34,7 +35,7 @@ export default { directives: { SafeHtml, }, - mixins: [glFeatureFlagsMixin()], + mixins: [glFeatureFlagsMixin(), IdState({ idProp: (vm) => vm.file.file_hash })], props: { file: { type: Object, @@ -68,12 +69,22 @@ export default { type: Boolean, required: true, }, + active: { + type: Boolean, + required: false, + default: true, + }, + preRender: { + type: Boolean, + required: false, + default: false, + }, }, - data() { + idState() { return { isLoadingCollapsedDiff: false, forkMessageVisible: false, - isCollapsed: isCollapsed(this.file), + hasToggled: false, }; }, i18n: { @@ -91,7 +102,7 @@ export default { return getShortShaFromFile(this.file); }, showLoadingIcon() { - return this.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed); + return this.idState.isLoadingCollapsedDiff || (!this.file.renderIt && !this.isCollapsed); }, hasDiff() { return hasDiff(this.file); @@ -152,45 +163,39 @@ export default { codequalityDiffForFile() { return this.codequalityDiff?.files?.[this.file.file_path] || []; }, + isCollapsed() { + if (collapsedType(this.file) !== DIFF_FILE_MANUAL_COLLAPSE) { + return this.viewDiffsFileByFile ? false : this.file.viewer?.automaticallyCollapsed; + } + + return this.file.viewer?.manuallyCollapsed; + }, }, watch: { 'file.id': { handler: function fileIdHandler() { + if (this.preRender) return; + this.manageViewedEffects(); }, }, 'file.file_hash': { handler: function hashChangeWatch(newHash, oldHash) { - this.isCollapsed = isCollapsed(this.file); - - if (newHash && oldHash && !this.hasDiff) { + if (newHash && oldHash && !this.hasDiff && !this.preRender) { this.requestDiff(); } }, - immediate: true, - }, - 'file.viewer.automaticallyCollapsed': { - handler: function autoChangeWatch(automaticValue) { - if (collapsedType(this.file) !== DIFF_FILE_MANUAL_COLLAPSE) { - this.isCollapsed = this.viewDiffsFileByFile ? false : automaticValue; - } - }, - immediate: true, - }, - 'file.viewer.manuallyCollapsed': { - handler: function manualChangeWatch(manualValue) { - if (manualValue !== null) { - this.isCollapsed = manualValue; - } - }, - immediate: true, }, }, created() { + if (this.preRender) return; + notesEventHub.$on(`loadCollapsedDiff/${this.file.file_hash}`, this.requestDiff); eventHub.$on(EVT_EXPAND_ALL_FILES, this.expandAllListener); }, mounted() { + if (this.preRender) return; + if (this.hasDiff) { this.postRender(); } @@ -198,6 +203,8 @@ export default { this.manageViewedEffects(); }, beforeDestroy() { + if (this.preRender) return; + eventHub.$off(EVT_EXPAND_ALL_FILES, this.expandAllListener); }, methods: { @@ -208,8 +215,14 @@ export default { 'setFileCollapsedByUser', ]), manageViewedEffects() { - if (this.reviewed && !this.isCollapsed && this.showLocalFileReviews) { + if ( + !this.idState.hasToggled && + this.reviewed && + !this.isCollapsed && + this.showLocalFileReviews + ) { this.handleToggle(); + this.idState.hasToggled = true; } }, expandAllListener() { @@ -252,11 +265,11 @@ export default { } }, requestDiff() { - this.isLoadingCollapsedDiff = true; + this.idState.isLoadingCollapsedDiff = true; this.loadCollapsedDiff(this.file) .then(() => { - this.isLoadingCollapsedDiff = false; + this.idState.isLoadingCollapsedDiff = false; this.setRenderIt(this.file); }) .then(() => { @@ -269,17 +282,17 @@ export default { ); }) .catch(() => { - this.isLoadingCollapsedDiff = false; + this.idState.isLoadingCollapsedDiff = false; createFlash({ message: this.$options.i18n.genericError, }); }); }, showForkMessage() { - this.forkMessageVisible = true; + this.idState.forkMessageVisible = true; }, hideForkMessage() { - this.forkMessageVisible = false; + this.idState.forkMessageVisible = false; }, }, }; @@ -287,7 +300,7 @@ export default { <template> <div - :id="file.file_hash" + :id="!preRender && active && file.file_hash" :class="{ 'is-active': currentDiffFileId === file.file_hash, 'comments-disabled': Boolean(file.brokenSymlink), @@ -313,7 +326,10 @@ export default { @showForkMessage="showForkMessage" /> - <div v-if="forkMessageVisible" class="js-file-fork-suggestion-section file-fork-suggestion"> + <div + v-if="idState.forkMessageVisible" + class="js-file-fork-suggestion-section file-fork-suggestion" + > <span v-safe-html="forkMessage" class="file-fork-suggestion-note"></span> <a :href="file.fork_path" @@ -330,12 +346,13 @@ export default { </div> <template v-else> <div - :id="`diff-content-${file.file_hash}`" + :id="!preRender && active && `diff-content-${file.file_hash}`" :class="hasBodyClasses.contentByHash" data-testid="content-area" > <gl-loading-icon v-if="showLoadingIcon" + size="sm" class="diff-content loading gl-my-0 gl-pt-3" data-testid="loader-icon" /> @@ -357,7 +374,7 @@ export default { </div> <template v-else> <div - v-show="showWarning" + v-if="showWarning" class="collapsed-file-warning gl-p-7 gl-bg-orange-50 gl-text-center gl-rounded-bottom-left-base gl-rounded-bottom-right-base" > <p class="gl-mb-5"> @@ -373,7 +390,7 @@ export default { </gl-button> </div> <diff-content - v-show="showContent" + v-if="showContent" :class="hasBodyClasses.content" :diff-file="file" :help-page-path="helpPagePath" |