From f1bce69b5dd3a59d22ee54483092b4866a1e5d46 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Wed, 6 Jul 2022 09:26:31 +0530 Subject: [PATCH] ui: allow instances to be filtered by group (#6495) Fixes #6428 Signed-off-by: Abhishek Kumar --- ui/src/components/view/SearchView.vue | 50 +++++++++++++++++++++++++-- ui/src/config/section/compute.js | 2 +- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/ui/src/components/view/SearchView.vue b/ui/src/components/view/SearchView.vue index 48345218693..2c350de816d 100644 --- a/ui/src/components/view/SearchView.vue +++ b/ui/src/components/view/SearchView.vue @@ -54,8 +54,7 @@ :ref="field.name" :name="field.name" :key="index" - :label="field.name==='keyword' ? - ('listAnnotations' in $store.getters.apis ? $t('label.annotation') : $t('label.name')) : $t('label.' + field.name)"> + :label="retrieveFieldLabel(field.name)"> item.name === 'groupid') + this.fields[groupIndex].loading = true + promises.push(await this.fetchInstanceGroups()) + } + if (arrayField.includes('entitytype')) { const entityTypeIndex = this.fields.findIndex(item => item.name === 'entitytype') this.fields[entityTypeIndex].loading = true @@ -378,6 +400,12 @@ export default { this.fields[clusterIndex].opts = this.sortArray(cluster[0].data) } } + if (groupIndex > -1) { + const groups = response.filter(item => item.type === 'groupid') + if (groups && groups.length > 0) { + this.fields[groupIndex].opts = this.sortArray(groups[0].data) + } + } }).finally(() => { if (zoneIndex > -1) { this.fields[zoneIndex].loading = false @@ -391,6 +419,9 @@ export default { if (clusterIndex > -1) { this.fields[clusterIndex].loading = false } + if (groupIndex > -1) { + this.fields[groupIndex].loading = false + } this.fillFormFieldValues() }) }, @@ -468,6 +499,19 @@ export default { }) }) }, + fetchInstanceGroups () { + return new Promise((resolve, reject) => { + api('listInstanceGroups', { listAll: true }).then(json => { + const instancegroups = json.listinstancegroupsresponse.instancegroup + resolve({ + type: 'groupid', + data: instancegroups + }) + }).catch(error => { + reject(error.response.headers['x-description']) + }) + }) + }, fetchGuestNetworkTypes () { const types = [] if (this.apiName.indexOf('listNetworks') > -1) { diff --git a/ui/src/config/section/compute.js b/ui/src/config/section/compute.js index 447bcf3243b..5249185651d 100644 --- a/ui/src/config/section/compute.js +++ b/ui/src/config/section/compute.js @@ -75,7 +75,7 @@ export default { } return fields }, - searchFilters: ['name', 'zoneid', 'domainid', 'account', 'tags'], + searchFilters: ['name', 'zoneid', 'domainid', 'account', 'groupid', 'tags'], details: () => { var fields = ['displayname', 'name', 'id', 'state', 'ipaddress', 'ip6address', 'templatename', 'ostypename', 'serviceofferingname', 'isdynamicallyscalable', 'haenable', 'hypervisor', 'boottype', 'bootmode', 'account', 'domain', 'zonename'] const listZoneHaveSGEnabled = store.getters.zones.filter(zone => zone.securitygroupsenabled === true)