blob: f86bce229c3c4ed2905e676a4d623763cfb89134 [file] [log] [blame]
Yoshie Muranaka0e893f02020-02-18 13:39:45 -08001<template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -07002 <span>
3 <b-link
4 v-if="value === 'export'"
5 class="align-bottom btn-link py-0"
6 :download="download"
7 :href="href"
8 :title="title"
9 :aria-label="title"
10 >
11 <slot name="icon">
12 {{ $t('global.action.export') }}
13 </slot>
14 </b-link>
15 <b-button
16 v-else
17 variant="link"
18 class="py-0"
19 :aria-label="title"
20 :title="title"
21 :disabled="!enabled"
22 @click="$emit('click:tableAction', value)"
23 >
24 <slot name="icon">
25 {{ title }}
26 </slot>
27 </b-button>
28 </span>
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080029</template>
30
31<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070032import { omit } from 'lodash';
33
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080034export default {
35 name: 'TableRowAction',
36 props: {
37 value: {
38 type: String,
39 required: true
40 },
41 enabled: {
42 type: Boolean,
43 default: true
44 },
45 title: {
46 type: String,
47 default: null
Yoshie Muranakabe3af332020-05-11 08:23:04 -070048 },
49 rowData: {
50 type: Object,
51 default: () => {}
52 },
53 exportName: {
54 type: String,
55 default: 'export'
56 }
57 },
58 computed: {
59 dataForExport() {
60 return JSON.stringify(omit(this.rowData, 'actions'));
61 },
62 download() {
63 return `${this.exportName}.json`;
64 },
65 href() {
66 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080067 }
68 }
69};
70</script>