xref: /openbmc/webui-vue/src/components/Global/TableRowAction.vue (revision f2cec7529040013ae50bc7768463aac280df491f)
1 <template>
2   <span>
3     <b-link
4       v-if="value === 'export'"
5       class="align-bottom btn-link py-0"
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-button
16       v-else
17       variant="link"
18       class="py-0"
19       :aria-label="title"
20       :title="title"
21       :disabled="!enabled"
22       @click="$emit('click:tableAction', value)"
23     >
24       <slot name="icon">
25         {{ title }}
26       </slot>
27     </b-button>
28   </span>
29 </template>
30 
31 <script>
32 import { omit } from 'lodash';
33 
34 export default {
35   name: 'TableRowAction',
36   props: {
37     value: {
38       type: String,
39       required: true
40     },
41     enabled: {
42       type: Boolean,
43       default: true
44     },
45     title: {
46       type: String,
47       default: null
48     },
49     rowData: {
50       type: Object,
51       default: () => {}
52     },
53     exportName: {
54       type: String,
55       default: 'export'
56     }
57   },
58   computed: {
59     dataForExport() {
60       return JSON.stringify(omit(this.rowData, 'actions'));
61     },
62     download() {
63       return `${this.exportName}.json`;
64     },
65     href() {
66       return `data:text/json;charset=utf-8,${this.dataForExport}`;
67     }
68   }
69 };
70 </script>
71