Skip to content

Commit bddc0a7

Browse files
Hoang Nguyenrp-
authored andcommitted
ui: update treeview when clicking the refresh button (#4999)
Fixes #4975 When a domain is generated by another client, the treeview is modified when clicking the refresh button.
1 parent ab9b418 commit bddc0a7

3 files changed

Lines changed: 34 additions & 105 deletions

File tree

ui/src/components/view/TreeView.vue

Lines changed: 32 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ export default {
117117
type: Boolean,
118118
default: false
119119
},
120-
actionData: {
121-
type: Array,
122-
default () {
123-
return []
124-
}
125-
},
126120
treeStore: {
127121
type: Object,
128122
default () {
@@ -163,22 +157,15 @@ export default {
163157
watch: {
164158
loading () {
165159
this.detailLoading = this.loading
166-
},
167-
treeData () {
168-
if (this.oldTreeViewData.length === 0) {
160+
this.treeViewData = []
161+
this.arrExpand = []
162+
if (!this.loading) {
169163
this.treeViewData = this.treeData
170164
this.treeVerticalData = this.treeData
171-
}
172-
173-
if (this.treeViewData.length > 0) {
174-
this.oldTreeViewData = this.treeViewData
175-
this.rootKey = this.treeViewData[0].key
176-
}
177165
178-
if (Object.keys(this.resource).length > 0) {
179-
const resourceIndex = this.treeVerticalData.findIndex(item => item.id === this.resource.id)
180-
if (resourceIndex === -1) {
181-
this.$el.querySelector(`[title=${this.resource.parentdomainname}]`).click()
166+
if (this.treeViewData.length > 0) {
167+
this.oldTreeViewData = this.treeViewData
168+
this.rootKey = this.treeViewData[0].key
182169
}
183170
}
184171
},
@@ -213,13 +200,6 @@ export default {
213200
this.defaultSelected.push(arrSelected[0])
214201
}
215202
},
216-
actionData (newData, oldData) {
217-
if (!newData || newData.length === 0) {
218-
return
219-
}
220-
221-
this.reloadTreeData(newData)
222-
},
223203
treeVerticalData () {
224204
if (!this.treeStore.isExpand) {
225205
return
@@ -233,25 +213,6 @@ export default {
233213
if (keyVisible > -1) this.arrExpand.push(expandKey)
234214
}
235215
}
236-
237-
if (this.treeStore.selected) {
238-
this.selectedTreeKey = this.treeStore.selected
239-
this.defaultSelected = [this.selectedTreeKey]
240-
241-
const resource = this.treeVerticalData.filter(item => item.id === this.selectedTreeKey)
242-
if (resource.length > 0) {
243-
this.resource = resource[0]
244-
this.$emit('change-resource', this.resource)
245-
} else {
246-
const rootResource = this.treeVerticalData[0]
247-
if (rootResource) {
248-
this.resource = rootResource
249-
this.selectedTreeKey = this.resource.key
250-
this.defaultSelected = [this.selectedTreeKey]
251-
this.$emit('change-resource', this.resource)
252-
}
253-
}
254-
}
255216
}
256217
},
257218
methods: {
@@ -297,10 +258,36 @@ export default {
297258
}
298259
}
299260
261+
this.onSelectResource()
300262
resolve()
301263
})
302264
})
303265
},
266+
onSelectResource () {
267+
if (this.treeStore.selected) {
268+
this.selectedTreeKey = this.treeStore.selected
269+
this.defaultSelected = [this.selectedTreeKey]
270+
271+
const resource = this.treeVerticalData.filter(item => item.id === this.selectedTreeKey)
272+
if (resource.length > 0) {
273+
this.resource = resource[0]
274+
this.$emit('change-resource', this.resource)
275+
} else {
276+
const resourceIdx = this.treeVerticalData.findIndex(item => item.id === this.resource.id)
277+
const parentIndex = this.treeVerticalData.findIndex(item => item.id === this.resource.parentdomainid)
278+
if (resourceIdx !== -1) {
279+
this.resource = this.treeVerticalData[resourceIdx]
280+
} else if (parentIndex !== 1) {
281+
this.resource = this.treeVerticalData[parentIndex]
282+
} else {
283+
this.resource = this.treeVerticalData[0]
284+
}
285+
this.selectedTreeKey = this.resource.key
286+
this.defaultSelected = [this.selectedTreeKey]
287+
this.$emit('change-resource', this.resource)
288+
}
289+
}
290+
},
304291
onSelect (selectedKeys, event) {
305292
if (!event.selected) {
306293
setTimeout(() => { event.node.$refs.selectHandle.click() })
@@ -398,53 +385,6 @@ export default {
398385
onTabChange (key) {
399386
this.tabActive = key
400387
},
401-
reloadTreeData (objData) {
402-
if (objData && objData[0].isDel) {
403-
this.treeVerticalData = this.treeVerticalData.filter(item => item.id !== objData[0].id)
404-
this.treeVerticalData = this.treeVerticalData.filter(item => item.parentdomainid !== objData[0].id)
405-
} else {
406-
// data response from action
407-
let jsonResponse = this.getResponseJsonData(objData[0])
408-
jsonResponse = this.createResourceData(jsonResponse)
409-
410-
// resource for check create or edit
411-
const resource = this.treeVerticalData.filter(item => item.id === jsonResponse.id)
412-
413-
// when edit
414-
if (resource && resource[0]) {
415-
this.treeVerticalData.filter((item, index) => {
416-
if (item.id === jsonResponse.id) {
417-
// replace all value of tree data
418-
Object.keys(jsonResponse).forEach((value, idx) => {
419-
this.$set(this.treeVerticalData[index], value, jsonResponse[value])
420-
})
421-
}
422-
})
423-
} else {
424-
// when create
425-
let resourceExists = true
426-
427-
// check is searching data
428-
if (this.searchQuery !== '') {
429-
resourceExists = jsonResponse.title.indexOf(this.searchQuery) > -1
430-
}
431-
432-
// push new resource to tree data
433-
if (this.resource.haschild && resourceExists) {
434-
this.treeVerticalData.push(jsonResponse)
435-
}
436-
437-
// set resource is currently active as a parent
438-
this.treeVerticalData.filter((item, index) => {
439-
if (item.id === this.resource.id) {
440-
this.$set(this.treeVerticalData[index], 'isLeaf', false)
441-
this.$set(this.treeVerticalData[index], 'haschild', true)
442-
}
443-
})
444-
}
445-
}
446-
this.recursiveTreeData(this.treeVerticalData)
447-
},
448388
getDetailResource (selectedKey) {
449389
// set api name and parameter
450390
const apiName = this.$route.meta.permission[0]

ui/src/views/iam/DomainActionForm.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,12 @@ export default {
169169
this.fillEditFormFieldValues()
170170
}
171171
},
172-
inject: ['parentCloseAction', 'parentFetchData', 'parentUpdActionData'],
172+
inject: ['parentCloseAction', 'parentFetchData'],
173173
methods: {
174174
pollActionCompletion (jobId, action) {
175175
this.$pollJob({
176176
jobId,
177177
successMethod: result => {
178-
if (this.action.api === 'deleteDomain') {
179-
this.$set(this.resource, 'isDel', true)
180-
this.parentUpdActionData(this.resource)
181-
}
182178
this.parentFetchData()
183179
if (action.response) {
184180
const description = action.response(result.jobresult)
@@ -283,7 +279,6 @@ export default {
283279
key: this.action.label + resourceName,
284280
duration: duration
285281
})
286-
this.parentUpdActionData(json)
287282
this.parentFetchData()
288283
}
289284
this.parentCloseAction()

ui/src/views/iam/DomainView.vue

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
:loading="loading"
6767
:tabs="$route.meta.tabs"
6868
@change-resource="changeResource"
69-
@change-tree-store="changeDomainStore"
70-
:actionData="actionData"/>
69+
@change-tree-store="changeDomainStore"/>
7170
</div>
7271

7372
<div v-if="showAction">
@@ -106,7 +105,6 @@ export default {
106105
loading: false,
107106
selectedRowKeys: [],
108107
treeData: [],
109-
actionData: [],
110108
treeSelected: {},
111109
showAction: false,
112110
action: {},
@@ -154,7 +152,6 @@ export default {
154152
provide () {
155153
return {
156154
parentCloseAction: this.closeAction,
157-
parentUpdActionData: this.updateActionData,
158155
parentFetchData: this.fetchData
159156
}
160157
},
@@ -317,9 +314,6 @@ export default {
317314
},
318315
closeAction () {
319316
this.showAction = false
320-
},
321-
updateActionData (data) {
322-
this.actionData.push(data)
323317
}
324318
}
325319
}

0 commit comments

Comments
 (0)