blob: 99fa58b35f14e41558d8b8f17d84d64578279e53 [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 Singh06d53862021-05-24 13:51:09 +053016 v-else-if="value === 'download' && downloadInNewTab"
17 class="align-bottom btn-icon-only py-0 btn-link"
18 target="_blank"
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>
27 <b-link
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080028 v-else-if="value === 'download'"
29 class="align-bottom btn-icon-only py-0 btn-link"
30 :download="exportName"
31 :href="downloadLocation"
32 :title="title"
33 >
34 <slot name="icon" />
35 <span class="sr-only">
36 {{ $t('global.action.download') }}
37 </span>
38 </b-link>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070039 <b-button
40 v-else
41 variant="link"
SurenNeware6e2cb972020-12-24 20:58:16 +053042 :class="{ 'btn-icon-only': btnIconOnly }"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070043 :disabled="!enabled"
SurenNeware6e2cb972020-12-24 20:58:16 +053044 :title="btnIconOnly ? title : !title"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053045 @click="$emit('click-table-action', value)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070046 >
47 <slot name="icon">
48 {{ title }}
49 </slot>
SurenNeware6e2cb972020-12-24 20:58:16 +053050 <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070051 </b-button>
52 </span>
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080053</template>
54
55<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070056import { omit } from 'lodash';
57
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080058export default {
59 name: 'TableRowAction',
60 props: {
61 value: {
62 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050063 required: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080064 },
65 enabled: {
66 type: Boolean,
Derick Montague602e98a2020-10-21 16:20:00 -050067 default: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080068 },
69 title: {
70 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050071 default: null,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070072 },
73 rowData: {
74 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -050075 default: () => {},
Yoshie Muranakabe3af332020-05-11 08:23:04 -070076 },
77 exportName: {
78 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050079 default: 'export',
80 },
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080081 downloadLocation: {
82 type: String,
83 default: '',
84 },
SurenNeware6e2cb972020-12-24 20:58:16 +053085 btnIconOnly: {
86 type: Boolean,
87 default: true,
88 },
Sandeepa Singh06d53862021-05-24 13:51:09 +053089 downloadInNewTab: {
90 type: Boolean,
91 default: false,
92 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070093 },
94 computed: {
95 dataForExport() {
96 return JSON.stringify(omit(this.rowData, 'actions'));
97 },
98 download() {
99 return `${this.exportName}.json`;
100 },
101 href() {
102 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Derick Montague602e98a2020-10-21 16:20:00 -0500103 },
104 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800105};
106</script>