Skip to content

Commit 76b0f38

Browse files
committed
feat: Add row actions to delete or duplicate a row
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent d075d13 commit 76b0f38

3 files changed

Lines changed: 64 additions & 3 deletions

File tree

‎src/modules/modals/EditRow.vue‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ export default {
178178
},
179179
reset() {
180180
this.localRow = {}
181-
this.dataLoaded = false
182181
this.prepareDeleteRow = false
183182
},
184183
actionDeleteRow() {

‎src/shared/components/ncTable/partials/TableRow.vue‎

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,40 @@
1414
:value="getCellValue(col)" />
1515
</td>
1616
<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)">
17+
<NcButton v-if="config.canEditRows || config.canDeleteRows" type="secondary" :aria-label="t('tables', 'Edit row')" data-cy="editRowBtn" @click="$emit('edit-row', row.id)">
1818
<template #icon>
1919
<Pencil :size="20" />
2020
</template>
2121
</NcButton>
22+
<NcActions v-if="config.canDeleteRows || config.canCreateRows">
23+
<NcActionButton v-if="config.canDeleteRows"
24+
:close-after-click="true"
25+
@click="handleDeleteRow">
26+
<template #icon>
27+
<Delete :size="20" />
28+
</template>
29+
{{ t('tables', 'Delete row') }}
30+
</NcActionButton>
31+
<NcActionButton v-if="config.canCreateRows"
32+
:close-after-click="true"
33+
@click="handleCloneRow">
34+
<template #icon>
35+
<ContentCopy :size="20" />
36+
</template>
37+
{{ t('tables', 'Duplicate row') }}
38+
</NcActionButton>
39+
</NcActions>
2240
</td>
2341
</tr>
2442
</template>
2543

2644
<script>
27-
import { NcCheckboxRadioSwitch, NcButton } from '@nextcloud/vue'
45+
import { mapActions } from 'pinia'
46+
import { useDataStore } from '../../../../store/data.js'
47+
import { NcCheckboxRadioSwitch, NcButton, NcActions, NcActionButton } from '@nextcloud/vue'
2848
import Pencil from 'vue-material-design-icons/Pencil.vue'
49+
import ContentCopy from 'vue-material-design-icons/ContentCopy.vue'
50+
import Delete from 'vue-material-design-icons/Delete.vue'
2951
import TableCellHtml from './TableCellHtml.vue'
3052
import TableCellProgress from './TableCellProgress.vue'
3153
import TableCellLink from './TableCellLink.vue'
@@ -40,6 +62,7 @@ import TableCellTextRich from './TableCellEditor.vue'
4062
import TableCellUsergroup from './TableCellUsergroup.vue'
4163
import { ColumnTypes } from './../mixins/columnHandler.js'
4264
import { translate as t } from '@nextcloud/l10n'
65+
import { showError } from '@nextcloud/dialogs'
4366
import {
4467
TYPE_META_ID, TYPE_META_CREATED_BY, TYPE_META_CREATED_AT, TYPE_META_UPDATED_BY, TYPE_META_UPDATED_AT,
4568
} from '../../../../shared/constants.js'
@@ -55,13 +78,17 @@ export default {
5578
TableCellHtml,
5679
NcButton,
5780
Pencil,
81+
ContentCopy,
82+
Delete,
5883
NcCheckboxRadioSwitch,
5984
TableCellDateTime,
6085
TableCellTextLine,
6186
TableCellSelection,
6287
TableCellMultiSelection,
6388
TableCellTextRich,
6489
TableCellUsergroup,
90+
NcActions,
91+
NcActionButton,
6592
},
6693
6794
props: {
@@ -85,6 +112,14 @@ export default {
85112
type: Object,
86113
default: null,
87114
},
115+
elementId: {
116+
type: Number,
117+
default: null,
118+
},
119+
isView: {
120+
type: Boolean,
121+
default: false,
122+
},
88123
},
89124
computed: {
90125
getSelection: {
@@ -165,6 +200,31 @@ export default {
165200
return text
166201
}
167202
},
203+
...mapActions(useDataStore, ['removeRow', 'insertNewRow']),
204+
async handleDeleteRow() {
205+
const res = await this.removeRow({
206+
rowId: this.row.id,
207+
isView: this.isView,
208+
elementId: this.elementId,
209+
})
210+
if (!res) {
211+
showError(t('tables', 'Could not delete row.'))
212+
}
213+
},
214+
async handleCloneRow() {
215+
const data = this.row.data.reduce((acc, curr) => {
216+
acc[curr.columnId] = curr.value
217+
return acc
218+
}, {})
219+
const res = await this.insertNewRow({
220+
viewId: this.isView ? this.elementId : null,
221+
tableId: this.isView ? null : this.elementId,
222+
data,
223+
})
224+
if (!res) {
225+
showError(t('tables', 'Could not clone row.'))
226+
}
227+
},
168228
},
169229
}
170230
</script>

‎src/shared/components/ncTable/sections/CustomTable.vue‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
<tbody>
2626
<TableRow v-for="(row, index) in currentPageRows"
2727
:key="index"
28+
:element-id="elementId"
29+
:is-view="isView"
2830
data-cy="customTableRow"
2931
:row="row"
3032
:columns="columns"

0 commit comments

Comments
 (0)