blob: 549f1b529fc81c49490b25fe6911bebbf579df7a [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"
Yoshie Muranakabe3af332020-05-11 08:23:04 -07009 >
10 <slot name="icon">
11 {{ $t('global.action.export') }}
12 </slot>
SurenNeware6e2cb972020-12-24 20:58:16 +053013 <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070014 </b-link>
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080015 <b-link
Sandeepa Singh450bdb02021-08-05 15:51:56 +053016 v-else-if="
17 value === 'download' && downloadInNewTab && downloadLocation !== ''
18 "
Sandeepa Singh06d53862021-05-24 13:51:09 +053019 class="align-bottom btn-icon-only py-0 btn-link"
20 target="_blank"
21 :href="downloadLocation"
22 :title="title"
23 >
24 <slot name="icon" />
25 <span class="sr-only">
26 {{ $t('global.action.download') }}
27 </span>
28 </b-link>
29 <b-link
Sandeepa Singh450bdb02021-08-05 15:51:56 +053030 v-else-if="value === 'download' && downloadLocation !== ''"
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080031 class="align-bottom btn-icon-only py-0 btn-link"
32 :download="exportName"
33 :href="downloadLocation"
34 :title="title"
35 >
36 <slot name="icon" />
37 <span class="sr-only">
38 {{ $t('global.action.download') }}
39 </span>
40 </b-link>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070041 <b-button
Sandeepa Singh450bdb02021-08-05 15:51:56 +053042 v-else-if="showButton"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070043 variant="link"
SurenNeware6e2cb972020-12-24 20:58:16 +053044 :class="{ 'btn-icon-only': btnIconOnly }"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070045 :disabled="!enabled"
SurenNeware6e2cb972020-12-24 20:58:16 +053046 :title="btnIconOnly ? title : !title"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053047 @click="$emit('click-table-action', value)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070048 >
49 <slot name="icon">
50 {{ title }}
51 </slot>
SurenNeware6e2cb972020-12-24 20:58:16 +053052 <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070053 </b-button>
54 </span>
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080055</template>
56
57<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070058import { omit } from 'lodash';
59
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080060export default {
61 name: 'TableRowAction',
62 props: {
63 value: {
64 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050065 required: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080066 },
67 enabled: {
68 type: Boolean,
Derick Montague602e98a2020-10-21 16:20:00 -050069 default: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080070 },
71 title: {
72 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050073 default: null,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070074 },
75 rowData: {
76 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -050077 default: () => {},
Yoshie Muranakabe3af332020-05-11 08:23:04 -070078 },
79 exportName: {
80 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050081 default: 'export',
82 },
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080083 downloadLocation: {
84 type: String,
85 default: '',
86 },
SurenNeware6e2cb972020-12-24 20:58:16 +053087 btnIconOnly: {
88 type: Boolean,
89 default: true,
90 },
Sandeepa Singh06d53862021-05-24 13:51:09 +053091 downloadInNewTab: {
92 type: Boolean,
93 default: false,
94 },
Sandeepa Singh450bdb02021-08-05 15:51:56 +053095 showButton: {
96 type: Boolean,
97 default: true,
98 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070099 },
100 computed: {
101 dataForExport() {
102 return JSON.stringify(omit(this.rowData, 'actions'));
103 },
104 download() {
105 return `${this.exportName}.json`;
106 },
107 href() {
108 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Derick Montague602e98a2020-10-21 16:20:00 -0500109 },
110 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800111};
112</script>