Skip to content

ImportAKSProjects: Extract hook, add tests, refactor UI#397

Draft
skoeva wants to merge 1 commit intoAzure:mainfrom
skoeva:refactor-import
Draft

ImportAKSProjects: Extract hook, add tests, refactor UI#397
skoeva wants to merge 1 commit intoAzure:mainfrom
skoeva:refactor-import

Conversation

@skoeva
Copy link
Collaborator

@skoeva skoeva commented Mar 10, 2026

These changes extract all logic from ImportAKSProjects into a dedicated useImportAKSProjects hook and replace the custom selection UI with the built-in MRT row selection.

Fixes: #118

Summary

  • Extracts namespace discovery, import orchestration, and navigation into useImportAKSProjects
  • Replaces custom checkbox column and Select All/Deselect All buttons with enableRowSelection
  • Registers clusters sequentially (per-cluster) to avoid localStorage race conditions when multiple clusters share the same name
  • Keeps table visible on all-failure so the user can retry without navigating away
  • Removes aksLabels.ts — superseded by utils/constants/projectLabels.ts introduced in project: Add ability to import and convert namespaces into projects  #314
  • Adds 20 unit tests for the hook + 17 component rendering tests

Testing

  • Run cd plugins/aks-desktop && npm test and ensure the tests pass

Screenshot

image

@skoeva skoeva self-assigned this Mar 10, 2026
Copilot AI review requested due to automatic review settings March 10, 2026 16:16
@skoeva skoeva added the quality label Mar 10, 2026
Copy link

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 refactors the AKS Desktop “Import AKS Projects” flow by extracting the orchestration logic into a reusable hook, switching the UI to use built-in table row selection, and centralizing AKS project label constants for reuse across create/import/delete flows.

Changes:

  • Introduces useImportAKSProjects to handle namespace discovery (az graph), cluster registration, localStorage updates, and navigation.
  • Updates the Import UI to use MRT row selection and a simplified action toolbar.
  • Adds shared AKS label constants and updates multiple components to consume them; adds unit tests for the new hook.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
plugins/aks-desktop/src/utils/shared/isAksProject.tsx Uses centralized AKS label constants when identifying AKS-managed projects.
plugins/aks-desktop/src/utils/shared/aksLabels.ts New shared constants for AKS project label keys/values.
plugins/aks-desktop/src/components/ImportAKSProjects/hooks/useImportAKSProjects.ts New hook encapsulating import discovery + orchestration, including parallel cluster registration.
plugins/aks-desktop/src/components/ImportAKSProjects/hooks/useImportAKSProjects.test.ts New unit tests covering discovery, import grouping, storage updates, and navigation.
plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx Refactored UI to use hook + built-in row selection with a simplified layout.
plugins/aks-desktop/src/components/DeleteAKSProject/AKSProjectDeleteButton.tsx Replaces hardcoded label strings with shared constants.
plugins/aks-desktop/src/components/CreateAKSProject/CreateAKSProject.tsx Replaces hardcoded label strings with shared constants when creating projects.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sniok
Copy link
Collaborator

sniok commented Mar 10, 2026

I think this PR is going to have a lot of conflicts with this one #314, can we hold this one until 314 is merged?

Copy link

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

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@skoeva skoeva marked this pull request as draft March 11, 2026 14:12
@skoeva skoeva force-pushed the refactor-import branch 2 times, most recently from ca480ad to 0a6e850 Compare March 11, 2026 15:28
@skoeva skoeva marked this pull request as ready for review March 11, 2026 19:15
Copilot AI review requested due to automatic review settings March 11, 2026 19:15
Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

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

Thanks for this. Can you please address the open review comments?

@illume illume marked this pull request as draft March 12, 2026 11:28
Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@skoeva skoeva marked this pull request as ready for review March 12, 2026 20:59
Copilot AI review requested due to automatic review settings March 12, 2026 20:59
Copy link

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

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


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Collaborator

@illume illume left a comment

Choose a reason for hiding this comment

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

There's some conflicts. Can you please have a look?

@illume illume marked this pull request as draft March 13, 2026 18:25
Copy link

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

Copilot reviewed 23 out of 23 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +178 to +201
// Register the cluster if it's not already registered in Headlamp.
// Re-registering overwrites the kubeconfig with namespace-scoped credentials,
// which would break access to previously imported namespaces on this cluster.
if (!registeredClusters.has(clusterName)) {
if (!subscriptionId || !resourceGroup) {
for (const ns of namespacesInCluster) {
results.push({
namespace: `${ns.name} (${clusterName})`,
clusterName,
success: false,
message: t(
'Cluster {{clusterName}} must be registered before importing regular namespaces. Import a managed namespace from this cluster first.',
{ clusterName }
),
});
}
continue;
}

const registerResult = await registerAKSCluster(
subscriptionId,
resourceGroup,
clusterName
);
"Waiting for namespace to be created": "Waiting for namespace to be created",
"Namespace status verification failed: {{message}}": "Namespace status verification failed: {{message}}",
"Namespace creation API succeeded, proceeding with user assignments": "Namespace creation API succeeded, proceeding with user assignments",
"Namespace creation completed successfully! Adding user access": "Namespace creation completed successfully! Adding user access",
Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugins/aks-desktop: Separate presentation from logic plugins/aks-desktop/src/components/ImportAKSProjects/ImportAKSProjects.tsx ImportAKSProjects

4 participants