blob: 5b2c4a99ee4c93f5a25f9c7170d93b2e473a25c0 [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'"
Dixsie Wolmers30f11f82020-11-10 16:07:56 -06005 class="align-bottom btn-icon-only py-0 btn-link"
Yoshie Muranakabe3af332020-05-11 08:23:04 -07006 :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>
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080015 <b-link
16 v-else-if="value === 'download'"
17 class="align-bottom btn-icon-only py-0 btn-link"
18 :download="exportName"
19 :href="downloadLocation"
20 :title="title"
21 >
22 <slot name="icon" />
23 <span class="sr-only">
24 {{ $t('global.action.download') }}
25 </span>
26 </b-link>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070027 <b-button
28 v-else
29 variant="link"
Dixsie Wolmers30f11f82020-11-10 16:07:56 -060030 class="btn-icon-only"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070031 :aria-label="title"
32 :title="title"
33 :disabled="!enabled"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053034 @click="$emit('click-table-action', value)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070035 >
36 <slot name="icon">
37 {{ title }}
38 </slot>
39 </b-button>
40 </span>
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080041</template>
42
43<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070044import { omit } from 'lodash';
45
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080046export default {
47 name: 'TableRowAction',
48 props: {
49 value: {
50 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050051 required: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080052 },
53 enabled: {
54 type: Boolean,
Derick Montague602e98a2020-10-21 16:20:00 -050055 default: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080056 },
57 title: {
58 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050059 default: null,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070060 },
61 rowData: {
62 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -050063 default: () => {},
Yoshie Muranakabe3af332020-05-11 08:23:04 -070064 },
65 exportName: {
66 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050067 default: 'export',
68 },
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080069 downloadLocation: {
70 type: String,
71 default: '',
72 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070073 },
74 computed: {
75 dataForExport() {
76 return JSON.stringify(omit(this.rowData, 'actions'));
77 },
78 download() {
79 return `${this.exportName}.json`;
80 },
81 href() {
82 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Derick Montague602e98a2020-10-21 16:20:00 -050083 },
84 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080085};
86</script>