diff --git a/app/assets/javascripts/blob/components/blob_header.vue b/app/assets/javascripts/blob/components/blob_header.vue index 9793c5854651df8ff6b7b9b6f2606bf9b97a42fc..b0011ff365c47e1a71f9c0437daa6dade3273e10 100644 --- a/app/assets/javascripts/blob/components/blob_header.vue +++ b/app/assets/javascripts/blob/components/blob_header.vue @@ -38,11 +38,6 @@ export default { type: Object, required: true, }, - isBlobPage: { - type: Boolean, - required: false, - default: false, - }, hideViewerSwitcher: { type: Boolean, required: false, @@ -178,7 +173,7 @@ export default { diff --git a/app/assets/javascripts/repository/components/header_area/blob_controls.vue b/app/assets/javascripts/repository/components/header_area/blob_controls.vue index 4c704193e1830b01fdc2f893483d2bfdac9ce864..90ff00bd56b2479f1fb1d2e5db92d7df34bd7238 100644 --- a/app/assets/javascripts/repository/components/header_area/blob_controls.vue +++ b/app/assets/javascripts/repository/components/header_area/blob_controls.vue @@ -21,10 +21,15 @@ import { sanitize } from '~/lib/dompurify'; import { InternalEvents } from '~/tracking'; import { FIND_FILE_BUTTON_CLICK } from '~/tracking/constants'; import { updateElementsVisibility } from '~/repository/utils/dom'; +import { + showSingleFileEditorForkSuggestion, + showWebIdeForkSuggestion, +} from '~/repository/utils/fork_suggestion_utils'; import blobControlsQuery from '~/repository/queries/blob_controls.query.graphql'; +import userGitpodInfo from '~/repository/queries/user_gitpod_info.query.graphql'; import { getRefType } from '~/repository/utils/ref_type'; import OpenMrBadge from '~/repository/components/header_area/open_mr_badge.vue'; -import { TEXT_FILE_TYPE, DEFAULT_BLOB_INFO } from '../../constants'; +import { TEXT_FILE_TYPE, EMPTY_FILE, DEFAULT_BLOB_INFO } from '../../constants'; import OverflowMenu from './blob_overflow_menu.vue'; export default { @@ -40,6 +45,7 @@ export default { OpenMrBadge, GlButton, OverflowMenu, + WebIdeLink: () => import('ee_else_ce/vue_shared/components/web_ide_link.vue'), }, directives: { GlTooltip: GlTooltipDirective, @@ -63,8 +69,14 @@ export default { createAlert({ message: this.$options.i18n.errorMessage }); }, }, + currentUser: { + query: userGitpodInfo, + error() { + createAlert({ message: this.$options.i18n.errorMessage }); + }, + }, }, - inject: ['currentRef'], + inject: ['currentRef', 'gitpodEnabled'], provide() { return { blobInfo: computed(() => this.blobInfo ?? DEFAULT_BLOB_INFO.repository.blobs.nodes[0]), @@ -76,6 +88,10 @@ export default { type: String, required: true, }, + projectIdAsNumber: { + type: Number, + required: true, + }, refType: { type: String, required: false, @@ -90,6 +106,7 @@ export default { data() { return { project: {}, + currentUser: {}, }; }, computed: { @@ -105,6 +122,9 @@ export default { blobInfo() { return this.project?.repository?.blobs?.nodes[0] || {}; }, + userPermissions() { + return this.project?.userPermissions || DEFAULT_BLOB_INFO.userPermissions; + }, storageInfo() { const { storedExternally, externalStorage } = this.blobInfo; return { @@ -121,7 +141,11 @@ export default { return this.storageInfo.isLfs; }, isBinaryFileType() { - return this.isBinary || this.blobInfo.simpleViewer?.fileType !== TEXT_FILE_TYPE; + return ( + this.isBinary || + (this.blobInfo.simpleViewer?.fileType !== TEXT_FILE_TYPE && + this.blobInfo.simpleViewer?.fileType !== EMPTY_FILE) + ); }, rawPath() { return this.blobInfo.externalStorageUrl || this.blobInfo.rawPath; @@ -153,6 +177,23 @@ export default { const description = this.$options.i18n.permalinkTooltip; return this.formatTooltipWithShortcut(description, this.shortcuts.permalink); }, + showWebIdeLink() { + return !this.blobInfo.archived && this.blobInfo.editBlobPath; + }, + shouldShowSingleFileEditorForkSuggestion() { + return showSingleFileEditorForkSuggestion( + this.userPermissions, + this.isUsingLfs, + this.blobInfo.canModifyBlob, + ); + }, + shouldShowWebIdeForkSuggestion() { + return showWebIdeForkSuggestion( + this.userPermissions, + this.isUsingLfs, + this.blobInfo.canModifyBlobWithWebIde, + ); + }, }, watch: { showBlobControls(shouldShow) { @@ -230,10 +271,33 @@ export default { {{ $options.i18n.permalink }} + +