[UI] Use GET request method for list API calls (#11354)

* [UI] Use GET request method for list API calls

* Updated UI unit tests
This commit is contained in:
Suresh Kumar Anaparti 2025-07-31 15:09:12 +05:30 committed by GitHub
parent 1f1e38f3a8
commit f58372e97b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 70 additions and 51 deletions

View File

@ -23,6 +23,19 @@ import {
ACCESS_TOKEN ACCESS_TOKEN
} from '@/store/mutation-types' } from '@/store/mutation-types'
const getAPICommandsRegex = /^(get|list|query|find)\w+$/i
const additionalGetAPICommandsList = [
'isaccountallowedtocreateofferingswithtags',
'readyforshutdown',
'cloudianisenabled',
'quotabalance',
'quotasummary',
'quotatarifflist',
'quotaisenabled',
'quotastatement',
'verifyoauthcodeandgetuser'
]
export function getAPI (command, args = {}) { export function getAPI (command, args = {}) {
args.command = command args.command = command
args.response = 'json' args.response = 'json'
@ -64,6 +77,12 @@ export function postAPI (command, data = {}) {
}) })
} }
export function callAPI (command, args = {}) {
const isGetAPICommand = getAPICommandsRegex.test(command) || additionalGetAPICommandsList.includes(command.toLowerCase())
const call = isGetAPICommand ? getAPI : postAPI
return call(command, args)
}
export function login (arg) { export function login (arg) {
if (!sourceToken.checkExistSource()) { if (!sourceToken.checkExistSource()) {
sourceToken.init() sourceToken.init()

View File

@ -1230,45 +1230,45 @@ export default {
this.editableValue = record.value this.editableValue = record.value
}, },
getUpdateApi () { getUpdateApi () {
let apiString = '' let apiCommand = ''
switch (this.$route.name) { switch (this.$route.name) {
case 'template': case 'template':
apiString = 'updateTemplate' apiCommand = 'updateTemplate'
break break
case 'iso': case 'iso':
apiString = 'updateIso' apiCommand = 'updateIso'
break break
case 'zone': case 'zone':
apiString = 'updateZone' apiCommand = 'updateZone'
break break
case 'computeoffering': case 'computeoffering':
case 'systemoffering': case 'systemoffering':
apiString = 'updateServiceOffering' apiCommand = 'updateServiceOffering'
break break
case 'diskoffering': case 'diskoffering':
apiString = 'updateDiskOffering' apiCommand = 'updateDiskOffering'
break break
case 'networkoffering': case 'networkoffering':
apiString = 'updateNetworkOffering' apiCommand = 'updateNetworkOffering'
break break
case 'vpcoffering': case 'vpcoffering':
apiString = 'updateVPCOffering' apiCommand = 'updateVPCOffering'
break break
case 'guestoscategory': case 'guestoscategory':
apiString = 'updateOsCategory' apiCommand = 'updateOsCategory'
break break
} }
return apiString return apiCommand
}, },
isOrderUpdatable () { isOrderUpdatable () {
return this.getUpdateApi() in this.$store.getters.apis return this.getUpdateApi() in this.$store.getters.apis
}, },
handleUpdateOrder (id, index) { handleUpdateOrder (id, index) {
this.parentToggleLoading() this.parentToggleLoading()
const apiString = this.getUpdateApi() const apiCommand = this.getUpdateApi()
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
postAPI(apiString, { postAPI(apiCommand, {
id, id,
sortKey: index sortKey: index
}).then((response) => { }).then((response) => {

View File

@ -92,7 +92,7 @@
<script> <script>
import store from '@/store' import store from '@/store'
import { postAPI } from '@/api' import { callAPI } from '@/api'
import DetailsTab from '@/components/view/DetailsTab' import DetailsTab from '@/components/view/DetailsTab'
import ResourceView from '@/components/view/ResourceView' import ResourceView from '@/components/view/ResourceView'
import ResourceLayout from '@/layouts/ResourceLayout' import ResourceLayout from '@/layouts/ResourceLayout'
@ -268,7 +268,7 @@ export default {
} }
return new Promise(resolve => { return new Promise(resolve => {
postAPI(this.apiChildren, params).then(json => { callAPI(this.apiChildren, params).then(json => {
const dataResponse = this.getResponseJsonData(json) const dataResponse = this.getResponseJsonData(json)
const dataGenerate = this.generateTreeData(dataResponse) const dataGenerate = this.generateTreeData(dataResponse)
treeNode.dataRef.children = dataGenerate treeNode.dataRef.children = dataGenerate
@ -390,7 +390,7 @@ export default {
this.treeViewData = [] this.treeViewData = []
this.loadingSearch = true this.loadingSearch = true
this.$emit('change-tree-store', {}) this.$emit('change-tree-store', {})
postAPI(this.apiList, params).then(json => { callAPI(this.apiList, params).then(json => {
const listDomains = this.getResponseJsonData(json) const listDomains = this.getResponseJsonData(json)
this.treeVerticalData = this.treeVerticalData.concat(listDomains) this.treeVerticalData = this.treeVerticalData.concat(listDomains)
@ -454,7 +454,7 @@ export default {
params.pageSize = 1 params.pageSize = 1
this.detailLoading = true this.detailLoading = true
postAPI(apiName, params).then(json => { callAPI(apiName, params).then(json => {
const jsonResponse = this.getResponseJsonData(json) const jsonResponse = this.getResponseJsonData(json)
resolve(jsonResponse[0]) resolve(jsonResponse[0])
}).catch(() => { }).catch(() => {

View File

@ -88,7 +88,7 @@
</template> </template>
<script> <script>
import { postAPI } from '@/api' import { getAPI } from '@/api'
import ResourceIcon from '@/components/view/ResourceIcon' import ResourceIcon from '@/components/view/ResourceIcon'
export default { export default {
@ -191,7 +191,7 @@ export default {
if (this.showIcon) { if (this.showIcon) {
params.showicon = true params.showicon = true
} }
postAPI(this.api, params).then(json => { getAPI(this.api, params).then(json => {
const response = json[this.api.toLowerCase() + 'response'] || {} const response = json[this.api.toLowerCase() + 'response'] || {}
if (this.totalCount === null) { if (this.totalCount === null) {
this.totalCount = response.count || 0 this.totalCount = response.count || 0

View File

@ -587,7 +587,7 @@
<script> <script>
import { ref, reactive, toRaw, h } from 'vue' import { ref, reactive, toRaw, h } from 'vue'
import { Button } from 'ant-design-vue' import { Button } from 'ant-design-vue'
import { getAPI, postAPI } from '@/api' import { getAPI, postAPI, callAPI } from '@/api'
import { mixinDevice } from '@/utils/mixin.js' import { mixinDevice } from '@/utils/mixin.js'
import { genericCompare } from '@/utils/sort.js' import { genericCompare } from '@/utils/sort.js'
import { sourceToken } from '@/utils/request' import { sourceToken } from '@/utils/request'
@ -1119,7 +1119,7 @@ export default {
delete params.listall delete params.listall
} }
postAPI(this.apiName, params).then(json => { callAPI(this.apiName, params).then(json => {
var responseName var responseName
var objectName var objectName
for (const key in json) { for (const key in json) {
@ -1449,7 +1449,7 @@ export default {
if (showIcon) { if (showIcon) {
params.showicon = true params.showicon = true
} }
postAPI(possibleApi, params).then(json => { callAPI(possibleApi, params).then(json => {
param.loading = false param.loading = false
for (const obj in json) { for (const obj in json) {
if (obj.includes('response')) { if (obj.includes('response')) {

View File

@ -2897,7 +2897,7 @@ export default {
const param = this.params.zones const param = this.params.zones
const args = { showicon: true } const args = { showicon: true }
if (zoneId) args.id = zoneId if (zoneId) args.id = zoneId
postAPI(param.list, args).then(json => { getAPI(param.list, args).then(json => {
const zoneResponse = (json.listzonesresponse.zone || []).filter(item => item.securitygroupsenabled === false) const zoneResponse = (json.listzonesresponse.zone || []).filter(item => item.securitygroupsenabled === false)
if (listZoneAllow && listZoneAllow.length > 0) { if (listZoneAllow && listZoneAllow.length > 0) {
zoneResponse.map(zone => { zoneResponse.map(zone => {
@ -2929,7 +2929,7 @@ export default {
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'dynamicScalingVmConfig', 'hypervisors'].includes(name)) { if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'dynamicScalingVmConfig', 'hypervisors'].includes(name)) {
options.listall = true options.listall = true
} }
postAPI(param.list, options).then((response) => { getAPI(param.list, options).then((response) => {
param.loading = false param.loading = false
_.map(response, (responseItem, responseKey) => { _.map(response, (responseItem, responseKey) => {
if (Object.keys(responseItem).length === 0) { if (Object.keys(responseItem).length === 0) {

View File

@ -1813,7 +1813,7 @@ export default {
} }
if (!apiName) return resolve(zones) if (!apiName) return resolve(zones)
postAPI(apiName, params).then(json => { getAPI(apiName, params).then(json => {
let objectName let objectName
const responseName = [apiName.toLowerCase(), 'response'].join('') const responseName = [apiName.toLowerCase(), 'response'].join('')
for (const key in json[responseName]) { for (const key in json[responseName]) {
@ -2505,7 +2505,7 @@ export default {
const param = this.params.zones const param = this.params.zones
const args = { showicon: true } const args = { showicon: true }
if (zoneId) args.id = zoneId if (zoneId) args.id = zoneId
postAPI(param.list, args).then(json => { getAPI(param.list, args).then(json => {
const zoneResponse = json.listzonesresponse.zone || [] const zoneResponse = json.listzonesresponse.zone || []
if (listZoneAllow && listZoneAllow.length > 0) { if (listZoneAllow && listZoneAllow.length > 0) {
zoneResponse.map(zone => { zoneResponse.map(zone => {
@ -2537,7 +2537,7 @@ export default {
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'hypervisors'].includes(name)) { if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'hypervisors'].includes(name)) {
options.listall = true options.listall = true
} }
postAPI(param.list, options).then((response) => { getAPI(param.list, options).then((response) => {
param.loading = false param.loading = false
_.map(response, (responseItem, responseKey) => { _.map(response, (responseItem, responseKey) => {
if (Object.keys(responseItem).length === 0) { if (Object.keys(responseItem).length === 0) {

View File

@ -1721,7 +1721,7 @@ export default {
} }
if (!apiName) return resolve(zones) if (!apiName) return resolve(zones)
postAPI(apiName, params).then(json => { getAPI(apiName, params).then(json => {
let objectName let objectName
const responseName = [apiName.toLowerCase(), 'response'].join('') const responseName = [apiName.toLowerCase(), 'response'].join('')
for (const key in json[responseName]) { for (const key in json[responseName]) {
@ -2447,7 +2447,7 @@ export default {
const param = this.params.zones const param = this.params.zones
const args = { showicon: true } const args = { showicon: true }
if (zoneId) args.id = zoneId if (zoneId) args.id = zoneId
postAPI(param.list, args).then(json => { getAPI(param.list, args).then(json => {
const zoneResponse = json.listzonesresponse.zone || [] const zoneResponse = json.listzonesresponse.zone || []
if (listZoneAllow && listZoneAllow.length > 0) { if (listZoneAllow && listZoneAllow.length > 0) {
zoneResponse.map(zone => { zoneResponse.map(zone => {
@ -2479,7 +2479,7 @@ export default {
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'hypervisors'].includes(name)) { if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'hypervisors'].includes(name)) {
options.listall = true options.listall = true
} }
postAPI(param.list, options).then((response) => { getAPI(param.list, options).then((response) => {
param.loading = false param.loading = false
_.map(response, (responseItem, responseKey) => { _.map(response, (responseItem, responseKey) => {
if (Object.keys(responseItem).length === 0) { if (Object.keys(responseItem).length === 0) {

View File

@ -78,7 +78,7 @@
</template> </template>
<script> <script>
import { getAPI, postAPI } from '@/api' import { getAPI, callAPI } from '@/api'
import store from '@/store' import store from '@/store'
import { mixinDevice } from '@/utils/mixin.js' import { mixinDevice } from '@/utils/mixin.js'
@ -274,7 +274,7 @@ export default {
} }
param.loading = true param.loading = true
param.opts = [] param.opts = []
postAPI(possibleApi, params) callAPI(possibleApi, params)
.then(json => { .then(json => {
param.loading = false param.loading = false
const responseObj = Object.values(json).find(obj => obj.includes('response')) const responseObj = Object.values(json).find(obj => obj.includes('response'))

View File

@ -51,7 +51,7 @@
</template> </template>
<script> <script>
import { postAPI } from '@/api' import { getAPI } from '@/api'
import ActionButton from '@/components/view/ActionButton' import ActionButton from '@/components/view/ActionButton'
import ProviderDetail from '@/views/infra/network/providers/ProviderDetail' import ProviderDetail from '@/views/infra/network/providers/ProviderDetail'
import ProviderListView from '@/views/infra/network/providers/ProviderListView' import ProviderListView from '@/views/infra/network/providers/ProviderListView'
@ -199,7 +199,7 @@ export default {
}, },
executeApi (apiName, params) { executeApi (apiName, params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
postAPI(apiName, params).then(json => { getAPI(apiName, params).then(json => {
let responseName let responseName
let objectName let objectName
let itemCount = 0 let itemCount = 0

View File

@ -122,7 +122,7 @@
<script> <script>
import { ref, reactive, toRaw } from 'vue' import { ref, reactive, toRaw } from 'vue'
import { postAPI } from '@/api' import { getAPI, postAPI } from '@/api'
import TungstenNetworkAction from '@/views/network/tungsten/TungstenNetworkAction' import TungstenNetworkAction from '@/views/network/tungsten/TungstenNetworkAction'
import TungstenNetworkTable from '@/views/network/tungsten/TungstenNetworkTable' import TungstenNetworkTable from '@/views/network/tungsten/TungstenNetworkTable'
import TooltipLabel from '@/components/widgets/TooltipLabel' import TooltipLabel from '@/components/widgets/TooltipLabel'
@ -233,7 +233,7 @@ export default {
this.dataSource = [] this.dataSource = []
this.fetchLoading = true this.fetchLoading = true
postAPI(this.apiName, params).then(json => { getAPI(this.apiName, params).then(json => {
let responseName let responseName
let objectName let objectName
for (const key in json) { for (const key in json) {
@ -274,7 +274,7 @@ export default {
const fieldIndex = this.currentAction.fields.findIndex(item => item.name === field.name) const fieldIndex = this.currentAction.fields.findIndex(item => item.name === field.name)
this.currentAction.fields[fieldIndex].loading = true this.currentAction.fields[fieldIndex].loading = true
postAPI(field.api, params).then(json => { getAPI(field.api, params).then(json => {
let responseName let responseName
let objectName let objectName
for (const key in json) { for (const key in json) {

View File

@ -1001,7 +1001,7 @@ export default {
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'pools'].includes(name)) { if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'pools'].includes(name)) {
options.listall = true options.listall = true
} }
postAPI(param.list, options).then((response) => { getAPI(param.list, options).then((response) => {
param.loading = false param.loading = false
_.map(response, (responseItem, responseKey) => { _.map(response, (responseItem, responseKey) => {
if (Object.keys(responseItem).length === 0) { if (Object.keys(responseItem).length === 0) {
@ -1200,7 +1200,7 @@ export default {
} }
} }
postAPI(apiName, params).then(json => { getAPI(apiName, params).then(json => {
const response = this.isMigrateFromVmware ? json.listvmwaredcvmsresponse : json.listunmanagedinstancesresponse const response = this.isMigrateFromVmware ? json.listvmwaredcvmsresponse : json.listunmanagedinstancesresponse
const listUnmanagedInstances = response.unmanagedinstance const listUnmanagedInstances = response.unmanagedinstance
if (this.arrayHasItems(listUnmanagedInstances)) { if (this.arrayHasItems(listUnmanagedInstances)) {

View File

@ -818,7 +818,7 @@ export default {
if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'pools'].includes(name)) { if (!('listall' in options) && !['zones', 'pods', 'clusters', 'hosts', 'pools'].includes(name)) {
options.listall = true options.listall = true
} }
postAPI(param.list, options).then((response) => { getAPI(param.list, options).then((response) => {
param.loading = false param.loading = false
_.map(response, (responseItem, responseKey) => { _.map(response, (responseItem, responseKey) => {
if (Object.keys(responseItem).length === 0) { if (Object.keys(responseItem).length === 0) {

View File

@ -1293,12 +1293,12 @@ describe('Views > AutogenView.vue', () => {
expect(mockAxios).toHaveBeenCalled() expect(mockAxios).toHaveBeenCalled()
expect(mockAxios).toHaveBeenLastCalledWith({ expect(mockAxios).toHaveBeenLastCalledWith({
url: '/', url: '/',
method: 'POST', method: 'GET',
data: common.createDataParams({ params: {
command: 'listTestApiNames', command: 'listTestApiNames',
response: 'json', response: 'json',
listall: true listall: true
}) }
}) })
expect(param).toEqual({ expect(param).toEqual({
name: 'testapiname', name: 'testapiname',
@ -1390,13 +1390,13 @@ describe('Views > AutogenView.vue', () => {
expect(mockAxios).toHaveBeenCalled() expect(mockAxios).toHaveBeenCalled()
expect(mockAxios).toHaveBeenLastCalledWith({ expect(mockAxios).toHaveBeenLastCalledWith({
url: '/', url: '/',
method: 'POST', method: 'GET',
data: common.createDataParams({ params: {
command: 'listTemplates', command: 'listTemplates',
response: 'json', response: 'json',
listall: true, listall: true,
templatefilter: 'executable' templatefilter: 'executable'
}) }
}) })
expect(param).toEqual({ expect(param).toEqual({
name: 'id', name: 'id',
@ -1429,13 +1429,13 @@ describe('Views > AutogenView.vue', () => {
expect(mockAxios).toHaveBeenCalled() expect(mockAxios).toHaveBeenCalled()
expect(mockAxios).toHaveBeenLastCalledWith({ expect(mockAxios).toHaveBeenLastCalledWith({
url: '/', url: '/',
method: 'POST', method: 'GET',
data: common.createDataParams({ params: {
command: 'listIsos', command: 'listIsos',
response: 'json', response: 'json',
listall: true, listall: true,
isofilter: 'executable' isofilter: 'executable'
}) }
}) })
expect(param).toEqual({ expect(param).toEqual({
name: 'id', name: 'id',
@ -1468,13 +1468,13 @@ describe('Views > AutogenView.vue', () => {
expect(mockAxios).toHaveBeenCalled() expect(mockAxios).toHaveBeenCalled()
expect(mockAxios).toHaveBeenLastCalledWith({ expect(mockAxios).toHaveBeenLastCalledWith({
url: '/', url: '/',
method: 'POST', method: 'GET',
data: common.createDataParams({ params: {
command: 'listHosts', command: 'listHosts',
response: 'json', response: 'json',
listall: true, listall: true,
type: 'routing' type: 'routing'
}) }
}) })
expect(param).toEqual({ expect(param).toEqual({
name: 'id', name: 'id',