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
|
<script>
import { isEmpty } from 'lodash';
import getToolbarItemsQuery from '~/editor/graphql/get_items.query.graphql';
import { EDITOR_TOOLBAR_BUTTON_GROUPS } from '~/editor/constants';
import SourceEditorToolbarButton from './source_editor_toolbar_button.vue';
export default {
name: 'SourceEditorToolbar',
components: {
SourceEditorToolbarButton,
},
data() {
return {
items: [],
};
},
apollo: {
items: {
query: getToolbarItemsQuery,
update(data) {
return this.setDefaultGroup(data?.items?.nodes);
},
},
},
computed: {
isVisible() {
return this.items.length;
},
},
methods: {
setDefaultGroup(nodes = []) {
return nodes.map((item) => {
return {
...item,
group: EDITOR_TOOLBAR_BUTTON_GROUPS[item.group] || EDITOR_TOOLBAR_BUTTON_GROUPS.settings,
};
});
},
getGroupItems(group) {
return this.items.filter((item) => item.group === group);
},
hasGroupItems(group) {
return !isEmpty(this.getGroupItems(group));
},
},
groups: EDITOR_TOOLBAR_BUTTON_GROUPS,
};
</script>
<template>
<section
v-if="isVisible"
id="se-toolbar"
class="file-buttons gl-display-flex gl-align-items-center gl-justify-content-end"
>
<div v-if="hasGroupItems($options.groups.file)">
<source-editor-toolbar-button
v-for="item in getGroupItems($options.groups.file)"
:key="item.id"
:button="item"
@click="$emit('click', item)"
/>
</div>
<div
v-if="hasGroupItems($options.groups.edit)"
class="md-header-toolbar gl-display-flex gl-flex-wrap gl-gap-3 gl-ml-auto"
>
<source-editor-toolbar-button
v-for="item in getGroupItems($options.groups.edit)"
:key="item.id"
:button="item"
@click="$emit('click', item)"
/>
</div>
<div v-if="hasGroupItems($options.groups.settings)" class="gl-align-self-start">
<source-editor-toolbar-button
v-for="item in getGroupItems($options.groups.settings)"
:key="item.id"
:button="item"
@click="$emit('click', item)"
/>
</div>
</section>
</template>
|