Skip to content
Snippets Groups Projects

Prepare common Vue app for Repository header area

All threads resolved!
2 files
+ 97
12
Compare changes
  • Side-by-side
  • Inline
Files
2
<script>
import { GlButton } from '@gitlab/ui';
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';
@@ -8,12 +15,20 @@ import BlobControls from '~/repository/components/header_area/blob_controls.vue'
export default {
name: 'HeaderArea',
i18n: {
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',
@@ -31,7 +46,6 @@ export default {
'projectRootPath',
],
props: {
// for blob controls
projectPath: {
type: String,
required: true,
@@ -56,6 +70,9 @@ export default {
},
},
computed: {
isTreeView() {
return this.$route.name === 'treePathDecoded';
},
historyPath() {
const url = new URL(window.location.href);
url.pathname = `${this.historyLink}/${
@@ -76,18 +93,33 @@ export default {
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
@@ -111,7 +143,28 @@ 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">
<!-- = render_if_exists 'projects/tree/lock_link' -->
<!-- = render 'projects/buttons/compare' -->
<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