blob: 9d853bc73e1375e1f1736c8178304b348b6e5077 [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
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"
SurenNeware6e2cb972020-12-24 20:58:16 +053030 :class="{ 'btn-icon-only': btnIconOnly }"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070031 :disabled="!enabled"
SurenNeware6e2cb972020-12-24 20:58:16 +053032 :title="btnIconOnly ? title : !title"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053033 @click="$emit('click-table-action', value)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070034 >
35 <slot name="icon">
36 {{ title }}
37 </slot>
SurenNeware6e2cb972020-12-24 20:58:16 +053038 <span v-if="btnIconOnly" class="sr-only">{{ title }}</span>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070039 </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 },
SurenNeware6e2cb972020-12-24 20:58:16 +053073 btnIconOnly: {
74 type: Boolean,
75 default: true,
76 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -070077 },
78 computed: {
79 dataForExport() {
80 return JSON.stringify(omit(this.rowData, 'actions'));
81 },
82 download() {
83 return `${this.exportName}.json`;
84 },
85 href() {
86 return `data:text/json;charset=utf-8,${this.dataForExport}`;
Derick Montague602e98a2020-10-21 16:20:00 -050087 },
88 },
Yoshie Muranaka0e893f02020-02-18 13:39:45 -080089};
90</script>