1<template>
2  <span>
3    <b-link
4      v-if="value === 'export'"
5      class="align-bottom btn-icon-only py-0 btn-link"
6      :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>
15    <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>
27    <b-button
28      v-else
29      variant="link"
30      class="btn-icon-only"
31      :aria-label="title"
32      :title="title"
33      :disabled="!enabled"
34      @click="$emit('click-table-action', value)"
35    >
36      <slot name="icon">
37        {{ title }}
38      </slot>
39    </b-button>
40  </span>
41</template>
42
43<script>
44import { omit } from 'lodash';
45
46export default {
47  name: 'TableRowAction',
48  props: {
49    value: {
50      type: String,
51      required: true,
52    },
53    enabled: {
54      type: Boolean,
55      default: true,
56    },
57    title: {
58      type: String,
59      default: null,
60    },
61    rowData: {
62      type: Object,
63      default: () => {},
64    },
65    exportName: {
66      type: String,
67      default: 'export',
68    },
69    downloadLocation: {
70      type: String,
71      default: '',
72    },
73  },
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}`;
83    },
84  },
85};
86</script>
87