This is an automated email from the ASF dual-hosted git repository.

sureshanaparti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack.git


The following commit(s) were added to refs/heads/main by this push:
     new f52e05863e6 UI fix api in project view (#11191)
f52e05863e6 is described below

commit f52e05863e608f53f9e97e93fe47577b8dfe189b
Author: Vishesh <[email protected]>
AuthorDate: Tue Jul 15 18:19:46 2025 +0530

    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 <[email protected]>
    
    * fixup
    
    * Return null if guiTheme requests fails
    
    ---------
    
    Co-authored-by: Suresh Kumar Anaparti <[email protected]>
---
 ui/src/api/index.js                                |  2 +-
 .../components/view/ImageDeployInstanceButton.vue  |  6 ++--
 ui/src/main.js                                     |  4 +--
 ui/src/utils/guiTheme.js                           |  7 +++--
 ui/src/utils/request.js                            | 34 ++++++++++++++++++++--
 ui/src/views/compute/KubernetesAddNodes.vue        |  6 ++--
 ui/src/views/compute/KubernetesRemoveNodes.vue     |  4 +--
 7 files changed, 47 insertions(+), 16 deletions(-)

diff --git a/ui/src/api/index.js b/ui/src/api/index.js
index 45938df6cab..1f532c36336 100644
--- a/ui/src/api/index.js
+++ b/ui/src/api/index.js
@@ -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)
       }
     })
diff --git a/ui/src/components/view/ImageDeployInstanceButton.vue 
b/ui/src/components/view/ImageDeployInstanceButton.vue
index 4f632cc0383..b2d4b55bc6a 100644
--- a/ui/src/components/view/ImageDeployInstanceButton.vue
+++ b/ui/src/components/view/ImageDeployInstanceButton.vue
@@ -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
diff --git a/ui/src/main.js b/ui/src/main.js
index c25ab1066d4..2bd9d945e9a 100644
--- a/ui/src/main.js
+++ b/ui/src/main.js
@@ -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
       })
diff --git a/ui/src/utils/guiTheme.js b/ui/src/utils/guiTheme.js
index 7cc3dc0cc03..b1a7209fd27 100644
--- a/ui/src/utils/guiTheme.js
+++ b/ui/src/utils/guiTheme.js
@@ -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
   })
 }
 
diff --git a/ui/src/utils/request.js b/ui/src/utils/request.js
index 7c757691f2b..42b26c9785b 100644
--- a/ui/src/utils/request.js
+++ b/ui/src/utils/request.js
@@ -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) => {
diff --git a/ui/src/views/compute/KubernetesAddNodes.vue 
b/ui/src/views/compute/KubernetesAddNodes.vue
index dddcc90be25..2ee0b5ed528 100644
--- a/ui/src/views/compute/KubernetesAddNodes.vue
+++ b/ui/src/views/compute/KubernetesAddNodes.vue
@@ -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 => {
diff --git a/ui/src/views/compute/KubernetesRemoveNodes.vue 
b/ui/src/views/compute/KubernetesRemoveNodes.vue
index 57d6409b784..803ec2bd1b1 100644
--- a/ui/src/views/compute/KubernetesRemoveNodes.vue
+++ b/ui/src/views/compute/KubernetesRemoveNodes.vue
@@ -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 => {

Reply via email to