summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/branches/list.vue
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/ide/components/branches/list.vue')
-rw-r--r--app/assets/javascripts/ide/components/branches/list.vue111
1 files changed, 111 insertions, 0 deletions
diff --git a/app/assets/javascripts/ide/components/branches/list.vue b/app/assets/javascripts/ide/components/branches/list.vue
new file mode 100644
index 00000000000..2d987053fef
--- /dev/null
+++ b/app/assets/javascripts/ide/components/branches/list.vue
@@ -0,0 +1,111 @@
+<script>
+import { mapActions, mapGetters, mapState } from 'vuex';
+import _ from 'underscore';
+import LoadingIcon from '../../../vue_shared/components/loading_icon.vue';
+import Item from './item.vue';
+
+export default {
+ components: {
+ LoadingIcon,
+ Item,
+ },
+ props: {
+
+ },
+ data() {
+ return {
+ search: '',
+ };
+ },
+ computed: {
+ ...mapState('branches', ['branches', 'isLoading']),
+ ...mapState(['currentBranchId', 'currentProjectId']),
+ hasBranches() {
+ return this.branches.length !== 0;
+ },
+ hasNoSearchResults() {
+ return this.search !== '' && !this.hasBranches;
+ },
+ },
+ watch: {
+ isLoading: {
+ handler: 'focusSearch',
+ },
+ },
+ mounted() {
+ this.loadBranches();
+ },
+ methods: {
+ ...mapActions('branches', ['fetchBranches', 'openBranch']),
+ loadBranches() {
+ this.fetchBranches({ type: this.type, search: this.search });
+ },
+ viewBranch(item) {
+ this.openBranch({
+ projectPath: item.projectPathWithNamespace,
+ id: item.iid,
+ });
+ },
+ searchBranches: _.debounce(function debounceSearch() {
+ this.loadBranches();
+ }, 250),
+ focusSearch() {
+ if (!this.isLoading) {
+ this.$nextTick(() => {
+ this.$refs.searchInput.focus();
+ });
+ }
+ },
+ },
+};
+</script>
+
+<template>
+ <div>
+ <div class="dropdown-input mt-3 pb-3 mb-0 border-bottom">
+ <input
+ ref="searchInput"
+ :placeholder="__('Search branches')"
+ v-model="search"
+ type="search"
+ class="dropdown-input-field"
+ @input="searchBranches"
+ />
+ <i
+ aria-hidden="true"
+ class="fa fa-search dropdown-input-search"
+ ></i>
+ </div>
+ <div class="dropdown-content ide-branches-dropdown-content d-flex">
+ <loading-icon
+ v-if="isLoading"
+ class="mt-3 mb-3 align-self-center ml-auto mr-auto"
+ size="2"
+ />
+ <ul
+ v-else
+ class="mb-3 w-100"
+ >
+ <template v-if="hasBranches">
+ <li
+ v-for="branchName in branches"
+ :key="branchName"
+ >
+ <item
+ :item="{ name: branchName }"
+ :current-id="currentBranchId"
+ :current-project-id="currentProjectId"
+ @click="viewBranch"
+ />
+ </li>
+ </template>
+ <li
+ v-else
+ class="ide-nav-list-empty d-flex align-items-center justify-content-center"
+ >
+ {{ __('No branches found') }}
+ </li>
+ </ul>
+ </div>
+ </div>
+</template>