blob: 79162bcc7d908840ff515c6f6585612f520b535d [file] [log] [blame]
Yoshie Muranaka0e893f02020-02-18 13:39:45 -08001<template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -07002 <span>
jason westoverd36ac8a2025-11-03 20:58:59 -06003 <b-button
Yoshie Muranakabe3af332020-05-11 08:23:04 -07004 v-if="value === 'export'"
jason westoverd36ac8a2025-11-03 20:58:59 -06005 variant="link"
6 class="align-bottom btn-icon-only py-0"
Yoshie Muranakabe3af332020-05-11 08:23:04 -07007 :download="download"
8 :href="href"
9 :title="title"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070010 >
11 <slot name="icon">
12 {{ $t('global.action.export') }}
13 </slot>
jason westoverd36ac8a2025-11-03 20:58:59 -060014 <span v-if="btnIconOnly" class="visually-hidden">{{ title }}</span>
15 </b-button>
16 <b-button
Sandeepa Singh450bdb02021-08-05 15:51:56 +053017 v-else-if="
18 value === 'download' && downloadInNewTab && downloadLocation !== ''
19 "
jason westoverd36ac8a2025-11-03 20:58:59 -060020 variant="link"
21 class="align-bottom btn-icon-only py-0"
Sandeepa Singh06d53862021-05-24 13:51:09 +053022 target="_blank"
23 :href="downloadLocation"
24 :title="title"
25 >
26 <slot name="icon" />
jason westoverd36ac8a2025-11-03 20:58:59 -060027 <span class="visually-hidden">
Sandeepa Singh06d53862021-05-24 13:51:09 +053028 {{ $t('global.action.download') }}
29 </span>
jason westoverd36ac8a2025-11-03 20:58:59 -060030 </b-button>
31 <b-button
Sandeepa Singh450bdb02021-08-05 15:51:56 +053032 v-else-if="value === 'download' && downloadLocation !== ''"
jason westoverd36ac8a2025-11-03 20:58:59 -060033 variant="link"
34 class="align-bottom btn-icon-only py-0"
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080035 :download="exportName"
36 :href="downloadLocation"
37 :title="title"
38 >
39 <slot name="icon" />
jason westoverd36ac8a2025-11-03 20:58:59 -060040 <span class="visually-hidden">
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080041 {{ $t('global.action.download') }}
42 </span>
jason westoverd36ac8a2025-11-03 20:58:59 -060043 </b-button>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070044 <b-button
Sandeepa Singh450bdb02021-08-05 15:51:56 +053045 v-else-if="showButton"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070046 variant="link"
SurenNeware6e2cb972020-12-24 20:58:16 +053047 :class="{ 'btn-icon-only': btnIconOnly }"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070048 :disabled="!enabled"
jason westoverd36ac8a2025-11-03 20:58:59 -060049 :title="title"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053050 @click="$emit('click-table-action', value)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070051 >
52 <slot name="icon">
53 {{ title }}
54 </slot>
jason westoverd36ac8a2025-11-03 20:58:59 -060055 <span v-if="btnIconOnly" class="visually-hidden">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070056 </b-button>
57 </span>
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080058</template>
59
60<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070061import { omit } from 'lodash';
Ed Tanous883a0d52024-03-23 14:56:34 -070062import { useI18n } from 'vue-i18n';
Yoshie Muranakabe3af332020-05-11 08:23:04 -070063
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080064export default {
65 name: 'TableRowAction',
66 props: {
67 value: {
68 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050069 required: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080070 },
71 enabled: {
72 type: Boolean,
Derick Montague602e98a2020-10-21 16:20:00 -050073 default: true,
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080074 },
75 title: {
76 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050077 default: null,
Yoshie Muranakabe3af332020-05-11 08:23:04 -070078 },
79 rowData: {
80 type: Object,
Derick Montague602e98a2020-10-21 16:20:00 -050081 default: () => {},
Yoshie Muranakabe3af332020-05-11 08:23:04 -070082 },
83 exportName: {
84 type: String,
Derick Montague602e98a2020-10-21 16:20:00 -050085 default: 'export',
86 },
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080087 downloadLocation: {
88 type: String,
89 default: '',
90 },
SurenNeware6e2cb972020-12-24 20:58:16 +053091 btnIconOnly: {
92 type: Boolean,
93 default: true,
94 },
Sandeepa Singh06d53862021-05-24 13:51:09 +053095 downloadInNewTab: {
96 type: Boolean,
97 default: false,
98 },
Sandeepa Singh450bdb02021-08-05 15:51:56 +053099 showButton: {
100 type: Boolean,
101 default: true,
102 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700103 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +0530104 emits: ['click-table-action'],
Ed Tanous883a0d52024-03-23 14:56:34 -0700105 data() {
106 return {
107 $t: useI18n().t,
108 };
109 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700110 computed: {
111 dataForExport() {
112 return JSON.stringify(omit(this.rowData, 'actions'));
113 },
114 download() {
115 return `${this.exportName}.json`;
116 },
117 href() {
118 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Derick Montague602e98a2020-10-21 16:20:00 -0500119 },
120 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -0800121};
122</script>