Skip to content
Snippets Groups Projects

Prepare common Vue app for Repository header area

All threads resolved!
Files
4
<script>
import { GlButton } from '@gitlab/ui';
import { escapeFileUrl } from '~/lib/utils/url_utility';
import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import { __ } from '~/locale';
import Shortcuts from '~/behaviors/shortcuts/shortcuts';
import { shouldDisableShortcuts } from '~/behaviors/shortcuts/shortcuts_toggle';
import { keysFor, START_SEARCH_PROJECT_FILE } from '~/behaviors/shortcuts/keybindings';
import { sanitize } from '~/lib/dompurify';
import { InternalEvents } from '~/tracking';
import { FIND_FILE_BUTTON_CLICK } from '~/tracking/constants';
import { escapeFileUrl, visitUrl } from '~/lib/utils/url_utility';
import { generateRefDestinationPath } from '~/repository/utils/ref_switcher_utils';
import RefSelector from '~/ref/components/ref_selector.vue';
import Breadcrumbs from '~/repository/components/header_area/breadcrumbs.vue';
import BlobControls from '~/repository/components/header_area/blob_controls.vue';
export default {
name: 'HeaderArea',
i18n: {
compare: __('Compare'),
findFile: __('Find file'),
history: __('History'),
},
buttonClassList: 'sm:gl-w-auto gl-w-full sm:gl-mt-0 gl-mt-3',
components: {
GlButton,
RefSelector,
Breadcrumbs,
BlobControls,
},
directives: {
GlTooltip: GlTooltipDirective,
},
inject: [
'canCollaborate',
'canEditTree',
@@ -25,9 +44,10 @@ export default {
'forkUploadBlobPath',
'uploadPath',
'newDirPath',
'projectRootPath',
'comparePath',
],
props: {
// for blob controls
projectPath: {
type: String,
required: true,
@@ -41,8 +61,20 @@ export default {
type: String,
required: true,
},
projectId: {
type: String,
required: true,
},
refSelectorValue: {
type: String,
required: false,
default: '',
},
},
computed: {
isTreeView() {
return this.$route.name === 'treePathDecoded';
},
historyPath() {
const url = new URL(window.location.href);
url.pathname = `${this.historyLink}/${
@@ -58,12 +90,44 @@ export default {
currentPath() {
return this.$route.params.path;
},
refSelectorQueryParams() {
return {
sort: 'updated_desc',
};
},
findFileTooltip() {
const { description } = START_SEARCH_PROJECT_FILE;
const key = this.findFileShortcutKey;
return shouldDisableShortcuts()
? null
: sanitize(`${description} <kbd class="flat gl-ml-1" aria-hidden=true>${key}</kbd>`);
},
findFileShortcutKey() {
return keysFor(START_SEARCH_PROJECT_FILE)[0];
},
},
methods: {
onInput(selectedRef) {
visitUrl(generateRefDestinationPath(this.projectRootPath, this.originalBranch, selectedRef));
},
handleFindFile() {
InternalEvents.trackEvent(FIND_FILE_BUTTON_CLICK);
Shortcuts.focusSearchFile();
},
},
};
</script>
<template>
<section>
<section class="gl-flex gl-flex-col gl-items-stretch gl-gap-5 sm:gl-flex-row">
<ref-selector
class="gl-max-w-26"
:project-id="projectId"
:value="refSelectorValue"
use-symbolic-ref-names
:query-params="refSelectorQueryParams"
@input="onInput"
/>
<breadcrumbs
:current-path="currentPath"
:ref-type="getRefType"
@@ -81,7 +145,35 @@ export default {
:upload-path="uploadPath"
:new-dir-path="newDirPath"
/>
<gl-button :href="historyPath">{{ __('History') }}</gl-button>
<!-- Tree controls -->
<div v-if="isTreeView" class="gl-mb-3 gl-flex gl-flex-wrap gl-gap-3 sm:gl-mb-0">
<!-- EE: = render_if_exists 'projects/tree/lock_link' -->
<!-- = render 'projects/buttons/compare' -->
<gl-button
v-if="comparePath"
data-testid="tree-compare-control"
:href="comparePath"
class="shortcuts-compare"
>{{ $options.i18n.compare }}</gl-button
>
<gl-button :href="historyPath" data-testid="tree-history-control">{{
$options.i18n.history
}}</gl-button>
<gl-button
v-gl-tooltip.html="findFileTooltip"
:aria-keyshortcuts="findFileShortcutKey"
data-testid="tree-find-file-control"
:class="$options.buttonClassList"
@click="handleFindFile"
>
{{ $options.i18n.findFile }}
</gl-button>
<!-- web ide for tree -->
<!-- code for tree + mobile panel -->
</div>
<!-- Blob controls -->
<blob-controls :project-path="projectPath" :ref-type="getRefType" />
</section>
</template>
Loading