Skip to content

Commit e0c4dd0

Browse files
CopilotrobertsLando
andcommitted
refactor(frontend): replace DialogGroupEdit with app.confirm pattern
- Remove DialogGroupEdit.vue component - Replace dialog with app.confirm inputs pattern following SmartStart.vue example - Use list input type with multiple selection for nodes - Combine create and edit operations in single editItem method - Maintain same validation rules and user experience - Addresses code review feedback for consistency Addresses review comment 2359484174. Co-authored-by: robertsLando <11502495+robertsLando@users.noreply.github.com>
1 parent b1025e8 commit e0c4dd0

File tree

2 files changed

+83
-229
lines changed

2 files changed

+83
-229
lines changed

src/components/dialogs/DialogGroupEdit.vue

Lines changed: 0 additions & 147 deletions
This file was deleted.

src/views/Groups.vue

Lines changed: 83 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,14 @@
1919
<v-btn
2020
color="primary"
2121
variant="text"
22-
@click="openCreateDialog"
22+
@click="editItem()"
2323
:disabled="!newGroupName"
2424
>
2525
Create Group
2626
</v-btn>
2727
</v-col>
2828
</v-row>
2929

30-
<DialogGroupEdit
31-
@save="saveGroup"
32-
@close="closeDialog"
33-
v-model="dialogGroup"
34-
:title="dialogTitle"
35-
:editedGroup="editedGroup"
36-
:nodes="physicalNodes"
37-
/>
38-
3930
<v-data-table
4031
:headers="headers_groups"
4132
:items="groups"
@@ -79,38 +70,22 @@
7970
import { mapState, mapActions } from 'pinia'
8071
import useBaseStore from '../stores/base.js'
8172
import InstancesMixin from '../mixins/InstancesMixin.js'
82-
import { defineAsyncComponent } from 'vue'
8373
8474
export default {
8575
name: 'Groups',
8676
mixins: [InstancesMixin],
87-
components: {
88-
DialogGroupEdit: defineAsyncComponent(
89-
() => import('@/components/dialogs/DialogGroupEdit.vue'),
90-
),
91-
},
92-
watch: {
93-
dialogGroup(val) {
94-
val || this.closeDialog()
95-
},
96-
},
77+
components: {},
9778
computed: {
9879
...mapState(useBaseStore, ['nodes']),
9980
physicalNodes() {
10081
// Only return physical nodes (not virtual ones)
10182
return this.nodes.filter((node) => !node.virtual)
10283
},
103-
dialogTitle() {
104-
return this.editedIndex === -1 ? 'New Group' : 'Edit Group'
105-
},
10684
},
10785
data() {
10886
return {
109-
dialogGroup: false,
11087
groups: [],
11188
newGroupName: '',
112-
editedGroup: {},
113-
editedIndex: -1,
11489
headers_groups: [
11590
{ title: 'ID', key: 'id' },
11691
{ title: 'Name', key: 'name' },
@@ -140,52 +115,57 @@ export default {
140115
this.groups = response.result || []
141116
}
142117
},
143-
openCreateDialog() {
144-
this.editedIndex = -1
145-
this.editedGroup = {
146-
name: this.newGroupName,
147-
nodeIds: [],
148-
}
149-
this.dialogGroup = true
150-
},
151-
editItem(item) {
152-
this.editedIndex = this.groups.indexOf(item)
153-
this.editedGroup = {
154-
...item,
155-
nodeIds: [...item.nodeIds], // Create a copy of the array
156-
}
157-
this.dialogGroup = true
158-
},
159-
async deleteItem(group) {
160-
if (
161-
await this.app.confirm(
162-
'Attention',
163-
`Are you sure you want to delete group "${group.name}"? This will also remove the virtual node.`,
164-
'alert',
165-
)
166-
) {
167-
const response = await this.app.apiRequest('_deleteGroup', [
168-
group.id,
169-
])
118+
async editItem(existingGroup) {
119+
const isEdit = !!existingGroup
120+
121+
let inputs = [
122+
{
123+
type: 'text',
124+
label: 'Group Name',
125+
required: true,
126+
key: 'name',
127+
hint: 'Enter a descriptive name for this multicast group',
128+
default: isEdit ? existingGroup.name : this.newGroupName,
129+
},
130+
{
131+
type: 'list',
132+
label: 'Nodes',
133+
required: true,
134+
key: 'nodeIds',
135+
multiple: true,
136+
items: this.physicalNodes.map(node => ({
137+
title: node.name || `Node ${node.id}`,
138+
value: node.id
139+
})),
140+
hint: 'Select at least 1 node for the multicast group',
141+
default: isEdit ? existingGroup.nodeIds : [],
142+
rules: [(value) => {
143+
if (!value || value.length === 0) {
144+
return 'Please select at least one node'
145+
}
146+
return true
147+
}],
148+
},
149+
]
170150
171-
if (response.success) {
172-
this.showSnackbar('Group deleted', 'success')
173-
this.refreshGroups()
174-
}
151+
let result = await this.app.confirm(
152+
isEdit ? 'Edit Group' : 'New Group',
153+
'',
154+
'info',
155+
{
156+
confirmText: isEdit ? 'Update' : 'Create',
157+
width: 500,
158+
inputs,
159+
},
160+
)
161+
162+
// cancelled
163+
if (!result || Object.keys(result).length === 0) {
164+
return
175165
}
176-
},
177-
closeDialog() {
178-
this.dialogGroup = false
179-
setTimeout(() => {
180-
this.editedGroup = {}
181-
this.editedIndex = -1
182-
this.newGroupName = ''
183-
}, 300)
184-
},
185-
async saveGroup() {
186-
const group = this.editedGroup
187166
188-
if (!group.name || !group.nodeIds || group.nodeIds.length === 0) {
167+
// Validate inputs
168+
if (!result.name || !result.nodeIds || result.nodeIds.length === 0) {
189169
this.showSnackbar(
190170
'Please provide a name and select at least one node',
191171
'error',
@@ -194,26 +174,47 @@ export default {
194174
}
195175
196176
let response
197-
if (this.editedIndex === -1) {
198-
// Create new group
199-
response = await this.app.apiRequest('_createGroup', [
200-
group.name,
201-
group.nodeIds,
202-
])
203-
} else {
177+
if (isEdit) {
204178
// Update existing group
205179
response = await this.app.apiRequest('_updateGroup', [
206-
group.id,
207-
group.name,
208-
group.nodeIds,
180+
existingGroup.id,
181+
result.name,
182+
result.nodeIds,
183+
])
184+
} else {
185+
// Create new group
186+
response = await this.app.apiRequest('_createGroup', [
187+
result.name,
188+
result.nodeIds,
209189
])
210190
}
211191
212192
if (response.success) {
213-
const action = this.editedIndex === -1 ? 'created' : 'updated'
193+
const action = isEdit ? 'updated' : 'created'
214194
this.showSnackbar(`Group ${action}`, 'success')
215195
this.refreshGroups()
216-
this.closeDialog()
196+
// Clear the input field after successful creation
197+
if (!isEdit) {
198+
this.newGroupName = ''
199+
}
200+
}
201+
},
202+
async deleteItem(group) {
203+
if (
204+
await this.app.confirm(
205+
'Attention',
206+
`Are you sure you want to delete group "${group.name}"? This will also remove the virtual node.`,
207+
'alert',
208+
)
209+
) {
210+
const response = await this.app.apiRequest('_deleteGroup', [
211+
group.id,
212+
])
213+
214+
if (response.success) {
215+
this.showSnackbar('Group deleted', 'success')
216+
this.refreshGroups()
217+
}
217218
}
218219
},
219220
},

0 commit comments

Comments
 (0)