Skip to content

Conversation

@vishesh92
Copy link
Member

@vishesh92 vishesh92 commented Jul 14, 2025

Description

This PR fixes the project views for different resources. This bug was introduced in #10899

Generated Summary

This pull request introduces several changes aimed at improving API request handling and refactoring the codebase for better readability and maintainability. The most significant updates include adjustments to how parameters are handled in API requests, the introduction of helper functions for GET and POST request parameters, and the replacement of the api function with getAPI across multiple components.

Improvements to API request handling:

  • ui/src/api/index.js: Simplified the parameter-checking logic in the postAPI function by removing checks for null and empty strings, ensuring only undefined values are excluded.
  • ui/src/utils/request.js: Added helper functions handleGetRequestParams and handlePostRequestParams to streamline the processing of GET and POST request parameters. These functions ensure proper handling of project-related parameters and clean up unnecessary fields like ignoreproject. [1] [2]

Codebase refactoring:

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • build/CI
  • test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

How did you try to break this feature and the system with this change?

@vishesh92
Copy link
Member Author

@blueorangutan ui

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Jul 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 16.58%. Comparing base (fb6adac) to head (37d9db4).
Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main   #11191      +/-   ##
============================================
+ Coverage     16.56%   16.58%   +0.01%     
- Complexity    14010    14038      +28     
============================================
  Files          5758     5758              
  Lines        511578   511733     +155     
  Branches      62192    62216      +24     
============================================
+ Hits          84756    84869     +113     
- Misses       417350   417390      +40     
- Partials       9472     9474       +2     
Flag Coverage Δ
uitests 3.90% <ø> (-0.01%) ⬇️
unittests 17.48% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This comment was marked as outdated.

@vishesh92
Copy link
Member Author

@blueorangutan ui

@blueorangutan
Copy link

@vishesh92 a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

@blueorangutan
Copy link

UI build: ✔️
Live QA URL: https://qa.cloudstack.cloud/simulator/pr/11191 (QA-JID-663)

Copy link
Contributor

@DaanHoogland DaanHoogland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good and reviewed the deploy instance from image dropdown. To be clear @vishesh92 this is a regression on 4.21-HEAD only right? none of the functionality existed in 4.20?

@vishesh92
Copy link
Member Author

@blueorangutan package

@blueorangutan
Copy link

@vishesh92 a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 14168

@vishesh92
Copy link
Member Author

@blueorangutan ui

@blueorangutan
Copy link

@vishesh92 a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

@blueorangutan
Copy link

UI build: ✔️
Live QA URL: https://qa.cloudstack.cloud/simulator/pr/11191 (QA-JID-665)

@sureshanaparti sureshanaparti requested a review from Copilot July 15, 2025 08:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR corrects API usage in several project-related views and centralizes request parameter handling.

  • Replaces generic api calls with getAPI for GET requests and postAPI for POST requests in multiple Vue components.
  • Introduces handleGetRequestParams and handlePostRequestParams in the request interceptor to automatically manage project and ignoreproject parameters.
  • Simplifies postAPI to only exclude undefined values when appending parameters.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
ui/src/views/compute/KubernetesRemoveNodes.vue Swapped api import/usage for postAPI in the remove-nodes API
ui/src/views/compute/KubernetesAddNodes.vue Updated imports and replaced api calls with getAPI/postAPI
ui/src/utils/request.js Added handleGetRequestParams and handlePostRequestParams
ui/src/components/view/ImageDeployInstanceButton.vue Replaced api calls with getAPI
ui/src/api/index.js Adjusted postAPI to filter out only undefined values
Comments suppressed due to low confidence (1)

ui/src/utils/request.js:153

  • Consider adding unit tests for handleGetRequestParams and handlePostRequestParams to verify that project IDs and ignoreproject flags are correctly added or removed under different scenarios.
  handleGetRequestParams(config)

removeNodesFromKubernetesCluster (params) {
return new Promise((resolve, reject) => {
api('removeNodesFromKubernetesCluster', params).then(json => {
postAPI('removeNodesFromKubernetesCluster', params).then(json => {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid wrapping postAPI in a new Promise. Instead, return the promise directly and chain .then() to extract the job ID, which simplifies the code and ensures errors propagate correctly.

Copilot uses AI. Check for mistakes.
addNodesToKubernetesCluster (params) {
return new Promise((resolve, reject) => {
api('addNodesToKubernetesCluster', params).then(json => {
postAPI('addNodesToKubernetesCluster', params).then(json => {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simplify this method by returning postAPI(...).then(json => json.addnodestokubernetesclusterresponse.jobid) directly, removing the explicit new Promise wrapper and reducing boilerplate.

Copilot uses AI. Check for mistakes.
Comment on lines +185 to +187
if (command === 'listTags') {
config.data.append('projectid', '-1')
} else if (command !== 'assignVirtualMachine') {
Copy link

Copilot AI Jul 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Hardcoding command names like 'listTags' and 'assignVirtualMachine' can be brittle. Consider centralizing these exceptions into a configuration constant or lookup table to improve maintainability.

Suggested change
if (command === 'listTags') {
config.data.append('projectid', '-1')
} else if (command !== 'assignVirtualMachine') {
if (command === COMMANDS.LIST_TAGS) {
config.data.append('projectid', '-1')
} else if (command !== COMMANDS.ASSIGN_VM) {

Copilot uses AI. Check for mistakes.
@vishesh92
Copy link
Member Author

@blueorangutan ui

@blueorangutan
Copy link

@vishesh92 a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

@blueorangutan
Copy link

UI build: ✔️
Live QA URL: https://qa.cloudstack.cloud/simulator/pr/11191 (QA-JID-666)

@vishesh92 vishesh92 force-pushed the ui-fix-api-in-project-view branch from e3abc5d to 3908815 Compare July 15, 2025 10:56
@vishesh92
Copy link
Member Author

@blueorangutan ui

@blueorangutan
Copy link

@vishesh92 a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

@blueorangutan
Copy link

UI build: ✔️
Live QA URL: https://qa.cloudstack.cloud/simulator/pr/11191 (QA-JID-667)

@vishesh92
Copy link
Member Author

@blueorangutan ui

@blueorangutan
Copy link

@vishesh92 a Jenkins job has been kicked to build UI QA env. I'll keep you posted as I make progress.

@blueorangutan
Copy link

UI build: ✔️
Live QA URL: https://qa.cloudstack.cloud/simulator/pr/11191 (QA-JID-669)

@vishesh92
Copy link
Member Author

code looks good and reviewed the deploy instance from image dropdown. To be clear @vishesh92 this is a regression on 4.21-HEAD only right? none of the functionality existed in 4.20?

Yes. This is in main branch only as of now and didn't exist in 4.20.
Also, we will need to fix the api calls after forward merging UI related changes from previous versions.

Some of the bugs @rosi-shapeblue shared with me were:

  • Cannot Remove Host Tag from UI Once Set
  • Instances are not visible when deployed in project

@sureshanaparti
Copy link
Contributor

verified the ui build, and some calls from ui in simulator env.

@sureshanaparti sureshanaparti merged commit f52e058 into apache:main Jul 15, 2025
24 of 26 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Apache CloudStack 4.21.0 Jul 15, 2025
@vishesh92 vishesh92 deleted the ui-fix-api-in-project-view branch July 15, 2025 12:51
@DaanHoogland DaanHoogland mentioned this pull request Jul 15, 2025
12 tasks
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Aug 1, 2025
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants