Skip to content

Commit d0e5c68

Browse files
updated multiple Kmodals into one and used dialog config to maintain state
1 parent c3a3a58 commit d0e5c68

File tree

1 file changed

+62
-74
lines changed

1 file changed

+62
-74
lines changed

contentcuration/contentcuration/frontend/administration/pages/Channels/ChannelActionsDropdown.vue

Lines changed: 62 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,15 @@
22

33
<div>
44
<KModal
5-
v-if="restoreDialog"
6-
:title="$tr('restoreChannelTitle')"
7-
:submitText="$tr('restoreAction')"
5+
v-if="activeDialog"
6+
:title="dialogConfig.title"
7+
:submitText="dialogConfig.submitText"
88
:cancelText="$tr('cancelAction')"
9-
data-test="confirm-restore"
10-
@submit="restoreHandler"
11-
@cancel="restoreDialog = false"
9+
:data-test="dialogConfig.testId"
10+
@submit="handleSubmit"
11+
@cancel="activeDialog = null"
1212
>
13-
<p>
14-
{{ $tr('restoreChannelMessage', { name: name }) }}
15-
</p>
16-
</KModal>
17-
18-
<KModal
19-
v-if="makePublicDialog"
20-
:title="$tr('makePublicTitle')"
21-
:submitText="$tr('makePublicAction')"
22-
:cancelText="$tr('cancelAction')"
23-
data-test="confirm-public"
24-
@submit="makePublicHandler"
25-
@cancel="makePublicDialog = false"
26-
>
27-
<p>{{ $tr('makePublicMessage', { name: name }) }}</p>
28-
</KModal>
29-
30-
<KModal
31-
v-if="makePrivateDialog"
32-
:title="$tr('makePrivateTitle')"
33-
:submitText="$tr('makePrivateAction')"
34-
:cancelText="$tr('cancelAction')"
35-
data-test="confirm-private"
36-
@submit="makePrivateHandler"
37-
@cancel="makePrivateDialog = false"
38-
>
39-
<p>{{ $tr('makePrivateMessage', { name: name }) }}</p>
40-
</KModal>
41-
42-
<KModal
43-
v-if="deleteDialog"
44-
:title="$tr('permanentDeleteTitle')"
45-
:submitText="$tr('permanentDeleteAction')"
46-
:cancelText="$tr('cancelAction')"
47-
data-test="confirm-delete"
48-
@submit="deleteHandler"
49-
@cancel="deleteDialog = false"
50-
>
51-
<p>
52-
{{ $tr('permanentDeleteMessage', { name: name }) }}
53-
</p>
54-
</KModal>
55-
56-
<KModal
57-
v-if="softDeleteDialog"
58-
:title="$tr('softDeleteTitle')"
59-
:submitText="$tr('softDeleteAction')"
60-
:cancelText="$tr('cancelAction')"
61-
data-test="confirm-softdelete"
62-
@submit="softDeleteHandler"
63-
@cancel="softDeleteDialog = false"
64-
>
65-
<p>{{ $tr('softDeleteMessage', { name: name }) }}</p>
13+
<p>{{ dialogConfig.message }}</p>
6614
</KModal>
6715

6816
<BaseMenu>
@@ -82,13 +30,13 @@
8230
<template v-if="channel.deleted">
8331
<VListTile
8432
data-test="restore"
85-
@click="restoreDialog = true"
33+
@click="openDialog('restore')"
8634
>
8735
<VListTileTitle>Restore</VListTileTitle>
8836
</VListTile>
8937
<VListTile
9038
data-test="delete"
91-
@click="deleteDialog = true"
39+
@click="openDialog('permanentDelete')"
9240
>
9341
<VListTileTitle>Delete permanently</VListTileTitle>
9442
</VListTile>
@@ -115,21 +63,21 @@
11563
<VListTile
11664
v-if="channel.public"
11765
data-test="private"
118-
@click="makePrivateDialog = true"
66+
@click="openDialog('makePrivate')"
11967
>
12068
<VListTileTitle>Make private</VListTileTitle>
12169
</VListTile>
12270
<VListTile
12371
v-else
12472
data-test="public"
125-
@click="makePublicDialog = true"
73+
@click="openDialog('makePublic')"
12674
>
12775
<VListTileTitle>Make public</VListTileTitle>
12876
</VListTile>
12977
<VListTile
13078
v-if="!channel.public"
13179
data-test="softdelete"
132-
@click="softDeleteDialog = true"
80+
@click="openDialog('softDelete')"
13381
>
13482
<VListTileTitle>Delete channel</VListTileTitle>
13583
</VListTile>
@@ -157,11 +105,7 @@
157105
},
158106
},
159107
data: () => ({
160-
deleteDialog: false,
161-
makePublicDialog: false,
162-
makePrivateDialog: false,
163-
restoreDialog: false,
164-
softDeleteDialog: false,
108+
activeDialog: null,
165109
}),
166110
computed: {
167111
...mapGetters('channel', ['getChannel']),
@@ -179,13 +123,62 @@
179123
},
180124
};
181125
},
126+
dialogConfig() {
127+
const configs = {
128+
restore: {
129+
title: this.$tr('restoreChannelTitle'),
130+
submitText: this.$tr('restoreAction'),
131+
message: this.$tr('restoreChannelMessage', { name: this.name }),
132+
testId: 'confirm-restore',
133+
handler: this.restoreHandler,
134+
},
135+
makePublic: {
136+
title: this.$tr('makePublicTitle'),
137+
submitText: this.$tr('makePublicAction'),
138+
message: this.$tr('makePublicMessage', { name: this.name }),
139+
testId: 'confirm-public',
140+
handler: this.makePublicHandler,
141+
},
142+
makePrivate: {
143+
title: this.$tr('makePrivateTitle'),
144+
submitText: this.$tr('makePrivateAction'),
145+
message: this.$tr('makePrivateMessage', { name: this.name }),
146+
testId: 'confirm-private',
147+
handler: this.makePrivateHandler,
148+
},
149+
permanentDelete: {
150+
title: this.$tr('permanentDeleteTitle'),
151+
submitText: this.$tr('permanentDeleteAction'),
152+
message: this.$tr('permanentDeleteMessage', { name: this.name }),
153+
testId: 'confirm-delete',
154+
handler: this.deleteHandler,
155+
},
156+
softDelete: {
157+
title: this.$tr('softDeleteTitle'),
158+
submitText: this.$tr('softDeleteAction'),
159+
message: this.$tr('softDeleteMessage', { name: this.name }),
160+
testId: 'confirm-softdelete',
161+
handler: this.softDeleteHandler,
162+
},
163+
};
164+
return configs[this.activeDialog] || {};
165+
},
182166
},
183167
methods: {
184168
...mapActions('channelAdmin', [
185169
'getAdminChannelListDetails',
186170
'deleteChannel',
187171
'updateChannel',
188172
]),
173+
openDialog(type) {
174+
this.activeDialog = type;
175+
},
176+
handleSubmit() {
177+
if (this.dialogConfig.handler) {
178+
this.dialogConfig.handler();
179+
}
180+
this.activeDialog = null;
181+
},
189182
async downloadPDF() {
190183
this.$store.dispatch('showSnackbarSimple', 'Generating PDF...');
191184
const channelList = await this.getAdminChannelListDetails([this.channel.id]);
@@ -197,7 +190,6 @@
197190
return this.generateChannelsCSV(channelList);
198191
},
199192
restoreHandler() {
200-
this.restoreDialog = false;
201193
this.updateChannel({
202194
id: this.channelId,
203195
deleted: false,
@@ -206,7 +198,6 @@
206198
});
207199
},
208200
softDeleteHandler() {
209-
this.softDeleteDialog = false;
210201
this.updateChannel({
211202
id: this.channelId,
212203
deleted: true,
@@ -215,14 +206,12 @@
215206
});
216207
},
217208
deleteHandler() {
218-
this.deleteDialog = false;
219209
this.$emit('deleted');
220210
return this.deleteChannel(this.channelId).then(() => {
221211
this.$store.dispatch('showSnackbarSimple', 'Channel deleted permanently');
222212
});
223213
},
224214
makePublicHandler() {
225-
this.makePublicDialog = false;
226215
this.updateChannel({
227216
id: this.channelId,
228217
isPublic: true,
@@ -231,7 +220,6 @@
231220
});
232221
},
233222
makePrivateHandler() {
234-
this.makePrivateDialog = false;
235223
this.updateChannel({
236224
id: this.channelId,
237225
isPublic: false,

0 commit comments

Comments
 (0)