1313 :row-id =" row.id"
1414 :value =" getCellValue(col)" />
1515 </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 >
2242 </td >
2343 </tr >
2444</template >
2545
2646<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'
2851import 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'
2954import TableCellHtml from ' ./TableCellHtml.vue'
3055import TableCellProgress from ' ./TableCellProgress.vue'
3156import TableCellLink from ' ./TableCellLink.vue'
@@ -55,13 +80,17 @@ export default {
5580 TableCellHtml,
5681 NcButton,
5782 Pencil,
83+ ContentCopy,
84+ Delete,
5885 NcCheckboxRadioSwitch,
5986 TableCellDateTime,
6087 TableCellTextLine,
6188 TableCellSelection,
6289 TableCellMultiSelection,
6390 TableCellTextRich,
6491 TableCellUsergroup,
92+ NcActions,
93+ NcActionButton,
6594 },
6695
6796 props: {
@@ -85,6 +114,14 @@ export default {
85114 type: Object ,
86115 default: null ,
87116 },
117+ elementId: {
118+ type: Number ,
119+ default: null ,
120+ },
121+ isView: {
122+ type: Boolean ,
123+ default: false ,
124+ },
88125 },
89126 computed: {
90127 getSelection: {
@@ -165,6 +202,42 @@ export default {
165202 return text
166203 }
167204 },
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+ },
168241 },
169242}
170243< / script>
@@ -185,4 +258,11 @@ tr.selected {
185258 margin: 0 ;
186259}
187260
261+ .row - actions- container {
262+ display: flex;
263+ align- items: center;
264+ justify- content: center;
265+ gap: var (-- default- grid- baseline);
266+ }
267+
188268< / style>
0 commit comments