UI fix api in project view (#11191)

* Add project id for post requests as well in the params

* Replace leftover api calls to getAPI calls

* ui: don't remove values from request if the value is null or empty string

* Address comments

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>

* fixup

* Return null if guiTheme requests fails

---------

Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
This commit is contained in:
Vishesh 2025-07-15 18:19:46 +05:30 committed by GitHub
parent e8ab0ae70a
commit f52e05863e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 47 additions and 16 deletions

View File

@ -47,7 +47,7 @@ export function postAPI (command, data = {}) {
params.append('response', 'json')
if (data) {
Object.entries(data).forEach(([key, value]) => {
if (value !== undefined && value !== null && value !== '') {
if (value !== undefined && value !== null) {
params.append(key, value)
}
})

View File

@ -41,7 +41,7 @@
</template>
<script>
import { api } from '@/api'
import { getAPI } from '@/api'
import ResourceIcon from '@/components/view/ResourceIcon'
export default {
@ -100,7 +100,7 @@ export default {
this.itemCount = 0
this.fetchLoading = true
this.zones = []
api(this.imageApi, params).then(json => {
getAPI(this.imageApi, params).then(json => {
const imageResponse = json?.[this.imageApi.toLowerCase() + 'response']?.[this.$route.meta.name] || []
this.zones = imageResponse.map(i => ({
id: i.zoneid,
@ -122,7 +122,7 @@ export default {
}
const zoneids = this.zones.map(z => z.id)
this.loading = true
api('listZones', { showicon: true, ids: zoneids.join(',') }).then(json => {
getAPI('listZones', { showicon: true, ids: zoneids.join(',') }).then(json => {
this.zones = json.listzonesresponse.zone || []
}).finally(() => {
this.loading = false

View File

@ -44,7 +44,7 @@ import {
import { VueAxios } from './utils/request'
import directives from './utils/directives'
import Cookies from 'js-cookie'
import { api } from '@/api'
import { getAPI } from '@/api'
import { applyCustomGuiTheme } from './utils/guiTheme'
vueApp.use(VueAxios, router)
@ -106,7 +106,7 @@ fetch('config.json?ts=' + Date.now())
let domainid = null
if (userid !== undefined && Cookies.get('sessionkey')) {
await api('listUsers', { userid: userid }).then(response => {
await getAPI('listUsers', { userid: userid }).then(response => {
accountid = response.listusersresponse.user[0].accountid
domainid = response.listusersresponse.user[0].domainid
})

View File

@ -16,7 +16,7 @@
// under the License.
import { vueProps } from '@/vue-app'
import { api } from '@/api'
import { getAPI } from '@/api'
export async function applyCustomGuiTheme (accountid, domainid) {
await fetch('config.json').then(response => response.json()).then(config => {
@ -45,10 +45,13 @@ export async function applyCustomGuiTheme (accountid, domainid) {
}
async function fetchGuiTheme (params) {
return await api('listGuiThemes', params).then(response => {
return await getAPI('listGuiThemes', params).then(response => {
if (response.listguithemesresponse.guiThemes) {
return response.listguithemesresponse.guiThemes[0]
}
}).catch(error => {
console.error('Error fetching GUI theme:', error)
return null
})
}

View File

@ -149,6 +149,15 @@ const err = (error) => {
service.interceptors.request.use(config => {
source = sourceToken.getSource()
config.cancelToken = source.token
handleGetRequestParams(config)
handlePostRequestParams(config)
return config
}, err)
function handleGetRequestParams (config) {
if (config && config.params) {
config.params.response = 'json'
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
@ -160,11 +169,30 @@ service.interceptors.request.use(config => {
}
}
if (config.params.ignoreproject !== undefined) {
config.params.ignoreproject = null
delete config.params.ignoreproject
}
}
return config
}, err)
}
function handlePostRequestParams (config) {
if (config && config.data && config.data instanceof URLSearchParams) {
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
const command = config.data.get('command')
const hasProjectId = config.data.has('projectid')
const ignoreProject = config.data.has('ignoreproject')
if (!hasProjectId && !ignoreProject && project && project.id) {
if (command === 'listTags') {
config.data.append('projectid', '-1')
} else if (command !== 'assignVirtualMachine') {
config.data.append('projectid', project.id)
}
}
if (config.data.has('ignoreproject')) {
config.data.delete('ignoreproject')
}
}
}
// response interceptor
service.interceptors.response.use((response) => {

View File

@ -66,7 +66,7 @@
<script>
import { ref, reactive, toRaw } from 'vue'
import { api } from '@/api'
import { getAPI, postAPI } from '@/api'
import TooltipLabel from '@/components/widgets/TooltipLabel'
export default {
@ -112,7 +112,7 @@ export default {
callListVms (accountId, domainId) {
return new Promise((resolve) => {
this.volumes = []
api('listVirtualMachines', {
getAPI('listVirtualMachines', {
accountId: accountId,
domainId: domainId,
details: 'min',
@ -172,7 +172,7 @@ export default {
},
addNodesToKubernetesCluster (params) {
return new Promise((resolve, reject) => {
api('addNodesToKubernetesCluster', params).then(json => {
postAPI('addNodesToKubernetesCluster', params).then(json => {
const jobId = json.addnodestokubernetesclusterresponse.jobid
return resolve(jobId)
}).catch(error => {

View File

@ -54,7 +54,7 @@
<script>
import { ref, reactive, toRaw } from 'vue'
import { api } from '@/api'
import { postAPI } from '@/api'
import TooltipLabel from '@/components/widgets/TooltipLabel'
export default {
@ -137,7 +137,7 @@ export default {
},
removeNodesFromKubernetesCluster (params) {
return new Promise((resolve, reject) => {
api('removeNodesFromKubernetesCluster', params).then(json => {
postAPI('removeNodesFromKubernetesCluster', params).then(json => {
const jobId = json.removenodesfromkubernetesclusterresponse.jobid
return resolve(jobId)
}).catch(error => {