13
13
:row-id =" row.id"
14
14
:value =" getCellValue(col)" />
15
15
</td >
16
- <td v-if =" config.showActions" :class =" {sticky: config.showActions}" >
17
- <NcButton v-if =" config.canEditRows || config.canDeleteRows" type =" primary" :aria-label =" t('tables', 'Edit row')" data-cy =" editRowBtn" @click =" $emit('edit-row', row.id)" >
18
- <template #icon >
19
- <Pencil :size =" 20" />
20
- </template >
21
- </NcButton >
16
+ <td v-if =" config.showActions" :class =" {sticky: config.showActions}" class =" row-actions" >
17
+ <div class =" row-actions-container" >
18
+ <NcButton v-if =" config.canEditRows || config.canDeleteRows" type =" secondary" :aria-label =" t('tables', 'Edit row')" data-cy =" editRowBtn" @click =" $emit('edit-row', row.id)" >
19
+ <template #icon >
20
+ <Pencil :size =" 20" />
21
+ </template >
22
+ </NcButton >
23
+ <NcActions v-if =" config.canDeleteRows || config.canCreateRows" >
24
+ <NcActionButton v-if =" config.canCreateRows"
25
+ :close-after-click =" true"
26
+ @click =" handleCloneRow" >
27
+ <template #icon >
28
+ <ContentCopy :size =" 20" />
29
+ </template >
30
+ {{ t('tables', 'Duplicate row') }}
31
+ </NcActionButton >
32
+ <NcActionButton v-if =" config.canDeleteRows"
33
+ :close-after-click =" true"
34
+ @click =" handleDeleteRow" >
35
+ <template #icon >
36
+ <Delete :size =" 20" />
37
+ </template >
38
+ {{ t('tables', 'Delete row') }}
39
+ </NcActionButton >
40
+ </NcActions >
41
+ </div >
22
42
</td >
23
43
</tr >
24
44
</template >
25
45
26
46
<script >
27
- import { NcCheckboxRadioSwitch , NcButton } from ' @nextcloud/vue'
47
+ import { mapActions } from ' pinia'
48
+ import { useDataStore } from ' ../../../../store/data.js'
49
+ import { NcCheckboxRadioSwitch , NcButton , NcActions , NcActionButton } from ' @nextcloud/vue'
50
+ import { getDialogBuilder , showError , DialogSeverity } from ' @nextcloud/dialogs'
28
51
import Pencil from ' vue-material-design-icons/Pencil.vue'
52
+ import ContentCopy from ' vue-material-design-icons/ContentCopy.vue'
53
+ import Delete from ' vue-material-design-icons/Delete.vue'
29
54
import TableCellHtml from ' ./TableCellHtml.vue'
30
55
import TableCellProgress from ' ./TableCellProgress.vue'
31
56
import TableCellLink from ' ./TableCellLink.vue'
@@ -55,13 +80,17 @@ export default {
55
80
TableCellHtml,
56
81
NcButton,
57
82
Pencil,
83
+ ContentCopy,
84
+ Delete,
58
85
NcCheckboxRadioSwitch,
59
86
TableCellDateTime,
60
87
TableCellTextLine,
61
88
TableCellSelection,
62
89
TableCellMultiSelection,
63
90
TableCellTextRich,
64
91
TableCellUsergroup,
92
+ NcActions,
93
+ NcActionButton,
65
94
},
66
95
67
96
props: {
@@ -85,6 +114,14 @@ export default {
85
114
type: Object ,
86
115
default: null ,
87
116
},
117
+ elementId: {
118
+ type: Number ,
119
+ default: null ,
120
+ },
121
+ isView: {
122
+ type: Boolean ,
123
+ default: false ,
124
+ },
88
125
},
89
126
computed: {
90
127
getSelection: {
@@ -165,6 +202,42 @@ export default {
165
202
return text
166
203
}
167
204
},
205
+ ... mapActions (useDataStore, [' removeRow' , ' insertNewRow' ]),
206
+ async handleDeleteRow () {
207
+ await getDialogBuilder (t (' tables' , ' Delete row' ))
208
+ .setText (t (' tables' , ' Are you sure you want to delete this row?' ))
209
+ .setSeverity (DialogSeverity .Warning )
210
+ .addButton ({
211
+ label: t (' tables' , ' Delete' ),
212
+ type: ' error' ,
213
+ callback: async () => {
214
+ const res = await this .removeRow ({
215
+ rowId: this .row .id ,
216
+ isView: this .isView ,
217
+ elementId: this .elementId ,
218
+ })
219
+ if (! res) {
220
+ showError (t (' tables' , ' Could not delete row.' ))
221
+ }
222
+ },
223
+ })
224
+ .build ()
225
+ .show ()
226
+ },
227
+ async handleCloneRow () {
228
+ const data = this .row .data .reduce ((acc , curr ) => {
229
+ acc[curr .columnId ] = curr .value
230
+ return acc
231
+ }, {})
232
+ const res = await this .insertNewRow ({
233
+ viewId: this .isView ? this .elementId : null ,
234
+ tableId: this .isView ? null : this .elementId ,
235
+ data,
236
+ })
237
+ if (! res) {
238
+ showError (t (' tables' , ' Could not clone row.' ))
239
+ }
240
+ },
168
241
},
169
242
}
170
243
< / script>
@@ -185,4 +258,11 @@ tr.selected {
185
258
margin: 0 ;
186
259
}
187
260
261
+ .row - actions- container {
262
+ display: flex;
263
+ align- items: center;
264
+ justify- content: center;
265
+ gap: var (-- default- grid- baseline);
266
+ }
267
+
188
268
< / style>
0 commit comments