forked from owncloud/web
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathActionMenuItem.vue
More file actions
100 lines (96 loc) · 2.2 KB
/
ActionMenuItem.vue
File metadata and controls
100 lines (96 loc) · 2.2 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<template>
<li>
<component
:is="action.componentType"
v-bind="getComponentProps(action, items)"
:class="['oc-text-bold', action.class]"
data-testid="action-handler"
v-on="getComponentListeners(action, items)"
>
<oc-img
v-if="action.img"
data-testid="action-img"
:src="action.img"
alt=""
class="oc-icon oc-icon-m"
/>
<oc-icon
v-else-if="action.icon"
data-testid="action-icon"
:name="action.icon"
size="medium"
/>
<span class="oc-files-context-action-label" data-testid="action-label">{{
action.label(filterParams)
}}</span>
<span
v-if="action.opensInNewWindow"
data-testid="action-sr-hint"
class="oc-invisible-sr"
v-text="$gettext('(Opens in new window)')"
/>
</component>
</li>
</template>
<script>
export default {
name: 'ActionMenuItem',
props: {
action: {
type: Object,
required: true
},
items: {
type: Array,
required: true
},
appearance: {
type: String,
default: 'raw'
}
},
computed: {
filterParams() {
return {
resources: this.items
}
}
},
methods: {
getComponentProps(action, resources) {
if (action.componentType === 'router-link' && action.route) {
return {
to: {
name: action.route,
params: {
item: resources.map((resource) => resource.path)
}
}
}
}
return {
appearance: this.appearance,
...(action.isDisabled && { disabled: action.isDisabled() }),
...(action.variation && { variation: action.variation })
}
},
getComponentListeners(action, resources) {
if (typeof action.handler !== 'function' || action.componentType !== 'oc-button') {
return {}
}
const callback = () => action.handler({ resources, ...action.handlerData })
if (action.keepOpen) {
return {
click: (event) => {
event.stopPropagation()
callback()
}
}
}
return {
click: callback
}
}
}
}
</script>