All files / app/assets/javascripts/blob/components blob_header.vue

92.3% Statements 12/13
100% Branches 10/10
91.66% Functions 11/12
91.66% Lines 11/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190                8x                           38x           38x                                                                                                                                   58x             58x     59x     58x     56x     56x         1x 1x                                                                                                                                            
<script>
import DefaultActions from 'jh_else_ce/blob/components/blob_header_default_actions.vue';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import userInfoQuery from '../queries/user_info.query.graphql';
import applicationInfoQuery from '../queries/application_info.query.graphql';
import BlobFilepath from './blob_header_filepath.vue';
import ViewerSwitcher from './blob_header_viewer_switcher.vue';
import { SIMPLE_BLOB_VIEWER, BLAME_VIEWER } from './constants';
import TableOfContents from './table_contents.vue';
 
export default {
  components: {
    ViewerSwitcher,
    DefaultActions,
    BlobFilepath,
    TableOfContents,
    WebIdeLink: () => import('ee_else_ce/vue_shared/components/web_ide_link.vue'),
  },
  apollo: {
    currentUser: {
      query: userInfoQuery,
      error() {
        this.$emit('error');
      },
    },
    gitpodEnabled: {
      query: applicationInfoQuery,
      error() {
        this.$emit('error');
      },
    },
  },
  props: {
    blob: {
      type: Object,
      required: true,
    },
    hideDefaultActions: {
      type: Boolean,
      required: false,
      default: false,
    },
    hideViewerSwitcher: {
      type: Boolean,
      required: false,
      default: false,
    },
    isBinary: {
      type: Boolean,
      required: false,
      default: false,
    },
    activeViewerType: {
      type: String,
      required: false,
      default: SIMPLE_BLOB_VIEWER,
    },
    hasRenderError: {
      type: Boolean,
      required: false,
      default: false,
    },
    showPath: {
      type: Boolean,
      required: false,
      default: true,
    },
    overrideCopy: {
      type: Boolean,
      required: false,
      default: false,
    },
    showForkSuggestion: {
      type: Boolean,
      required: false,
      default: false,
    },
    projectPath: {
      type: String,
      required: false,
      default: '',
    },
    projectId: {
      type: String,
      required: false,
      default: '',
    },
    showBlameToggle: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      viewer: this.hideViewerSwitcher ? null : this.activeViewerType,
      gitpodEnabled: false,
    };
  },
  computed: {
    showDefaultActions() {
      return !this.hideDefaultActions;
    },
    showWebIdeLink() {
      return !this.blob.archived && this.blob.editBlobPath;
    },
    isEmpty() {
      return this.blob.rawSize === '0';
    },
    blobSwitcherDocIcon() {
      return this.blob.richViewer?.fileType === 'csv' ? 'table' : 'document';
    },
    projectIdAsNumber() {
      return getIdFromGraphQLId(this.projectId);
    },
  },
  watch: {
    viewer(newVal, oldVal) {
      if (newVal !== BLAME_VIEWER && newVal !== oldVal) {
        this.$emit('viewer-changed', newVal);
      }
    },
  },
  methods: {
    proxyCopyRequest() {
      this.$emit('copy');
    },
  },
};
</script>
<template>
  <div class="js-file-title file-title-flex-parent">
    <div class="gl-display-flex">
      <table-of-contents class="gl-pr-2" />
      <blob-filepath :blob="blob" :show-path="showPath">
        <template #filepath-prepend>
          <slot name="prepend"></slot>
        </template>
      </blob-filepath>
    </div>
 
    <div class="gl-display-flex gl-flex-wrap file-actions">
      <viewer-switcher
        v-if="!hideViewerSwitcher"
        v-model="viewer"
        :doc-icon="blobSwitcherDocIcon"
        :show-blame-toggle="showBlameToggle"
        :show-viewer-toggles="Boolean(blob.simpleViewer && blob.richViewer)"
        v-on="$listeners"
      />
 
      <web-ide-link
        v-if="showWebIdeLink"
        :show-edit-button="!isBinary"
        class="gl-mr-3"
        :edit-url="blob.editBlobPath"
        :web-ide-url="blob.ideEditPath"
        :needs-to-fork="showForkSuggestion"
        :show-pipeline-editor-button="Boolean(blob.pipelineEditorPath)"
        :pipeline-editor-url="blob.pipelineEditorPath"
        :gitpod-url="blob.gitpodBlobUrl"
        :show-gitpod-button="gitpodEnabled"
        :gitpod-enabled="currentUser && currentUser.gitpodEnabled"
        :project-path="projectPath"
        :project-id="projectIdAsNumber"
        :user-preferences-gitpod-path="currentUser && currentUser.preferencesGitpodPath"
        :user-profile-enable-gitpod-path="currentUser && currentUser.profileEnableGitpodPath"
        is-blob
        disable-fork-modal
        v-on="$listeners"
      />
 
      <slot name="actions"></slot>
 
      <default-actions
        v-if="showDefaultActions"
        :raw-path="blob.externalStorageUrl || blob.rawPath"
        :active-viewer="viewer"
        :has-render-error="hasRenderError"
        :is-binary="isBinary"
        :environment-name="blob.environmentFormattedExternalUrl"
        :environment-path="blob.environmentExternalUrlForRouteMap"
        :is-empty="isEmpty"
        :override-copy="overrideCopy"
        @copy="proxyCopyRequest"
      />
    </div>
  </div>
</template>