diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-18 11:17:02 +0300 |
commit | b39512ed755239198a9c294b6a45e65c05900235 (patch) | |
tree | d234a3efade1de67c46b9e5a38ce813627726aa7 /app/assets/javascripts/repository | |
parent | d31474cf3b17ece37939d20082b07f6657cc79a9 (diff) |
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'app/assets/javascripts/repository')
4 files changed, 69 insertions, 16 deletions
diff --git a/app/assets/javascripts/repository/components/blob_content_viewer.vue b/app/assets/javascripts/repository/components/blob_content_viewer.vue index bf4f19504f0..7999b916e0f 100644 --- a/app/assets/javascripts/repository/components/blob_content_viewer.vue +++ b/app/assets/javascripts/repository/components/blob_content_viewer.vue @@ -8,7 +8,7 @@ import createFlash from '~/flash'; import axios from '~/lib/utils/axios_utils'; import { isLoggedIn, handleLocationHash } from '~/lib/utils/common_utils'; import { __ } from '~/locale'; -import { redirectTo } from '~/lib/utils/url_utility'; +import { redirectTo, getLocationHash } from '~/lib/utils/url_utility'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import WebIdeLink from '~/vue_shared/components/web_ide_link.vue'; import CodeIntelligence from '~/code_navigation/components/app.vue'; @@ -63,6 +63,28 @@ export default { }; }, result() { + const urlHash = getLocationHash(); + const plain = this.$route?.query?.plain; + + // When the 'plain' URL param is present, its value determines which viewer to render: + // - when 0 and the rich viewer is available we render with it + // - otherwise we render the simple viewer + if (plain !== undefined) { + if (plain === '0' && this.hasRichViewer) { + this.switchViewer(RICH_BLOB_VIEWER); + } else { + this.switchViewer(SIMPLE_BLOB_VIEWER); + } + return; + } + + // If there is a code line hash in the URL we render with the simple viewer + if (urlHash && urlHash.startsWith('L')) { + this.switchViewer(SIMPLE_BLOB_VIEWER); + return; + } + + // By default, if present, use the rich viewer to render this.switchViewer(this.hasRichViewer ? RICH_BLOB_VIEWER : SIMPLE_BLOB_VIEWER); }, error() { @@ -173,6 +195,21 @@ export default { return this.blobInfo.storedExternally && this.blobInfo.externalStorage === LFS_STORAGE; }, }, + watch: { + // Watch the URL 'plain' query value to know if the viewer needs changing. + // This is the case when the user switches the viewer and then goes back + // through the hystory. + '$route.query.plain': { + handler(plainValue) { + this.switchViewer( + this.hasRichViewer && (plainValue === undefined || plainValue === '0') + ? RICH_BLOB_VIEWER + : SIMPLE_BLOB_VIEWER, + plainValue !== undefined, + ); + }, + }, + }, methods: { onError() { this.useFallback = true; @@ -189,15 +226,10 @@ export default { axios .get(`${this.blobInfo.webPath}?format=json&viewer=${type}`) .then(async ({ data: { html, binary } }) => { - if (type === SIMPLE_BLOB_VIEWER) { - this.isRenderingLegacyTextViewer = true; + this.isRenderingLegacyTextViewer = true; + if (type === SIMPLE_BLOB_VIEWER) { this.legacySimpleViewer = html; - - window.requestIdleCallback(() => { - this.isRenderingLegacyTextViewer = false; - new LineHighlighter(); // eslint-disable-line no-new - }); } else { this.legacyRichViewer = html; } @@ -205,6 +237,14 @@ export default { this.isBinary = binary; this.isLoadingLegacyViewer = false; + window.requestIdleCallback(() => { + this.isRenderingLegacyTextViewer = false; + + if (type === SIMPLE_BLOB_VIEWER) { + new LineHighlighter(); // eslint-disable-line no-new + } + }); + await this.$nextTick(); handleLocationHash(); // Ensures that we scroll to the hash when async content is loaded }) @@ -220,6 +260,22 @@ export default { this.loadLegacyViewer(); } }, + updateRouteQuery() { + const plain = this.activeViewerType === SIMPLE_BLOB_VIEWER ? '1' : '0'; + + if (this.$route?.query?.plain === plain) { + return; + } + + this.$router.push({ + path: this.$route.path, + query: { ...this.$route.query, plain }, + }); + }, + handleViewerChanged(newViewer) { + this.switchViewer(newViewer); + this.updateRouteQuery(); + }, editBlob(target) { if (this.showForkSuggestion) { this.setForkTarget(target); @@ -251,7 +307,7 @@ export default { :has-render-error="hasRenderError" :show-path="false" :override-copy="glFeatures.highlightJs" - @viewer-changed="switchViewer" + @viewer-changed="handleViewerChanged" @copy="onCopy" > <template #actions> diff --git a/app/assets/javascripts/repository/components/last_commit.vue b/app/assets/javascripts/repository/components/last_commit.vue index 9f2cf8505d3..7f408485326 100644 --- a/app/assets/javascripts/repository/components/last_commit.vue +++ b/app/assets/javascripts/repository/components/last_commit.vue @@ -196,12 +196,9 @@ export default { </gl-link> </div> <gl-button-group class="gl-ml-4 js-commit-sha-group"> - <gl-button - label - class="gl-font-monospace" - data-testid="last-commit-id-label" - v-text="showCommitId" - /> + <gl-button label class="gl-font-monospace" data-testid="last-commit-id-label">{{ + showCommitId + }}</gl-button> <clipboard-button :text="commit.sha" :title="__('Copy commit SHA')" diff --git a/app/assets/javascripts/repository/constants.js b/app/assets/javascripts/repository/constants.js index 0e80f306638..77d3a517d28 100644 --- a/app/assets/javascripts/repository/constants.js +++ b/app/assets/javascripts/repository/constants.js @@ -94,7 +94,6 @@ export const LFS_STORAGE = 'lfs'; */ export const LEGACY_FILE_TYPES = [ 'gemfile', - 'gemspec', 'composer_json', 'podfile', 'podspec', diff --git a/app/assets/javascripts/repository/queries/blob_info.query.graphql b/app/assets/javascripts/repository/queries/blob_info.query.graphql index 8baee80e5d6..45a7793e559 100644 --- a/app/assets/javascripts/repository/queries/blob_info.query.graphql +++ b/app/assets/javascripts/repository/queries/blob_info.query.graphql @@ -27,6 +27,7 @@ query getBlobInfo( fileType language path + blamePath editBlobPath gitpodBlobUrl ideEditPath |