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
|
<script>
import { GlDropdown, GlDropdownItem, GlDropdownSectionHeader, GlIcon } from '@gitlab/ui';
import { historyPushState } from '~/lib/utils/common_utils';
import { setUrlParams } from '~/lib/utils/url_utility';
import { s__ } from '~/locale';
import { DEFAULT_FAILURE } from '~/pipeline_editor/constants';
import getAvailableBranches from '~/pipeline_editor/graphql/queries/available_branches.graphql';
import getCurrentBranch from '~/pipeline_editor/graphql/queries/client/current_branch.graphql';
export default {
i18n: {
title: s__('Branches'),
fetchError: s__('Unable to fetch branch list for this project.'),
},
components: {
GlDropdown,
GlDropdownItem,
GlDropdownSectionHeader,
GlIcon,
},
inject: ['projectFullPath'],
apollo: {
branches: {
query: getAvailableBranches,
variables() {
return {
projectFullPath: this.projectFullPath,
};
},
update(data) {
return data.project?.repository?.branches || [];
},
error() {
this.$emit('showError', {
type: DEFAULT_FAILURE,
reasons: [this.$options.i18n.fetchError],
});
},
},
currentBranch: {
query: getCurrentBranch,
},
},
computed: {
hasBranchList() {
return this.branches?.length > 0;
},
},
methods: {
async selectBranch(newBranch) {
if (newBranch === this.currentBranch) {
return;
}
await this.$apollo.getClient().writeQuery({
query: getCurrentBranch,
data: { currentBranch: newBranch },
});
const updatedPath = setUrlParams({ branch_name: newBranch });
historyPushState(updatedPath);
this.$emit('refetchContent');
},
},
};
</script>
<template>
<gl-dropdown v-if="hasBranchList" class="gl-ml-2" :text="currentBranch" icon="branch">
<gl-dropdown-section-header>
{{ this.$options.i18n.title }}
</gl-dropdown-section-header>
<gl-dropdown-item
v-for="branch in branches"
:key="branch.name"
:is-checked="currentBranch === branch.name"
:is-check-item="true"
@click="selectBranch(branch.name)"
>
<gl-icon name="check" class="gl-visibility-hidden" />
{{ branch.name }}
</gl-dropdown-item>
</gl-dropdown>
</template>
|