summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ci/pipeline_editor/components/file_nav/pipeline_editor_file_nav.vue
blob: 7368d1a3a91767dd2d94e05630eb04d45dc7608f (plain)
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
<script>
import { GlButton } from '@gitlab/ui';
import getAppStatus from '~/ci/pipeline_editor/graphql/queries/client/app_status.query.graphql';
import { EDITOR_APP_STATUS_EMPTY, EDITOR_APP_STATUS_LOADING } from '../../constants';
import FileTreePopover from '../popovers/file_tree_popover.vue';
import BranchSwitcher from './branch_switcher.vue';

export default {
  components: {
    BranchSwitcher,
    FileTreePopover,
    GlButton,
  },
  props: {
    hasUnsavedChanges: {
      type: Boolean,
      required: false,
      default: false,
    },
    isNewCiConfigFile: {
      type: Boolean,
      required: false,
      default: false,
    },
    shouldLoadNewBranch: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  apollo: {
    appStatus: {
      query: getAppStatus,
      update(data) {
        return data.app.status;
      },
    },
  },
  computed: {
    isAppLoading() {
      return this.appStatus === EDITOR_APP_STATUS_LOADING;
    },
    showFileTreeToggle() {
      return !this.isNewCiConfigFile && this.appStatus !== EDITOR_APP_STATUS_EMPTY;
    },
  },
  methods: {
    onFileTreeBtnClick() {
      this.$emit('toggle-file-tree');
    },
  },
};
</script>
<template>
  <div class="gl-mb-4 gl-display-flex gl-flex-wrap gl-gap-3">
    <gl-button
      v-if="showFileTreeToggle"
      id="file-tree-toggle"
      icon="file-tree"
      data-testid="file-tree-toggle"
      :aria-label="__('File Tree')"
      :loading="isAppLoading"
      @click="onFileTreeBtnClick"
    />
    <file-tree-popover v-if="showFileTreeToggle" />
    <branch-switcher
      :has-unsaved-changes="hasUnsavedChanges"
      :should-load-new-branch="shouldLoadNewBranch"
      v-on="$listeners"
    />
  </div>
</template>