Skip to content

BasicsStep: Extract hooks, add docs, tests, stories#601

Open
skoeva wants to merge 2 commits intoAzure:mainfrom
skoeva:basicsstep
Open

BasicsStep: Extract hooks, add docs, tests, stories#601
skoeva wants to merge 2 commits intoAzure:mainfrom
skoeva:basicsstep

Conversation

@skoeva
Copy link
Copy Markdown
Collaborator

@skoeva skoeva commented Apr 16, 2026

These changes extract all logic from BasicsStep into dedicated useBasicsStep and useRegisterCluster hooks, add comprehensive TSDocs, unit tests, and Storybook stories.

Fixes: #95

Summary

  • Extracts subscription/cluster mapping, auto-selection, focus management, cluster readiness checks, and helper-text derivation into useBasicsStep with a narrow UseBasicsStepInput interface
  • Extracts RegisterCluster async flow into useRegisterCluster, making the component purely presentational
  • Exports pure helpers (getClusterHelperText, isClusterNonReady, getClusterStateMessage) for isolated testing
  • Adds TSDocs to all public interfaces and hooks
  • Adds 37 unit tests across both hooks and 17 Storybook stories covering all visual states

Testing

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

Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
@skoeva skoeva self-assigned this Apr 16, 2026
@skoeva skoeva added the quality label Apr 16, 2026
@skoeva skoeva marked this pull request as ready for review April 16, 2026 18:00
Copilot AI review requested due to automatic review settings April 16, 2026 18:00
@skoeva skoeva changed the title BasicsStep: WIP BasicsStep: Extract hooks, add docs, tests, stories Apr 16, 2026
Copy link
Copy Markdown
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

Note

Copilot was unable to run its full agentic suite in this review.

This PR refactors the BasicsStep wizard step by extracting its stateful logic into dedicated hooks (useBasicsStep, useRegisterCluster), and adds unit tests plus Storybook coverage for the resulting behavior.

Changes:

  • Introduces useBasicsStep to encapsulate focus, auto-selection, option mapping, cluster readiness/missing checks, and helper text derivation (with exported pure helpers for isolated testing).
  • Introduces useRegisterCluster to encapsulate the async “register AKS cluster” flow and related loading/error/success state.
  • Adds Vitest unit tests for both hooks and Storybook stories for BasicsStep.

Reviewed changes

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

Show a summary per file
File Description
plugins/aks-desktop/src/components/CreateAKSProject/hooks/useRegisterCluster.ts New hook encapsulating async AKS cluster registration flow and status state.
plugins/aks-desktop/src/components/CreateAKSProject/hooks/useRegisterCluster.test.ts Unit tests validating register flow behavior and messaging.
plugins/aks-desktop/src/components/CreateAKSProject/hooks/useBasicsStep.ts New hook + pure helpers for Basics-step derived state and callbacks.
plugins/aks-desktop/src/components/CreateAKSProject/hooks/useBasicsStep.test.ts Unit tests for pure helpers and hook-derived behaviors.
plugins/aks-desktop/src/components/CreateAKSProject/components/BasicsStep.tsx Converts BasicsStep and RegisterCluster to presentational components using new hooks.
plugins/aks-desktop/src/components/CreateAKSProject/components/BasicsStep.stories.tsx Adds Storybook stories covering key visual states.

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

Comment thread plugins/aks-desktop/src/components/CreateAKSProject/hooks/useBasicsStep.ts Outdated
Copy link
Copy Markdown
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

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


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

Comment thread plugins/aks-desktop/src/components/CreateAKSProject/hooks/useBasicsStep.ts Outdated
Copy link
Copy Markdown
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 when you have time?

Signed-off-by: Evangelos Skopelitis <eskopelitis@microsoft.com>
Copy link
Copy Markdown
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

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


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

const [success, setSuccess] = useState<string | undefined>(undefined);

const handleRegister = async () => {
if (!cluster || !subscription) {
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

handleRegister currently bails out only when cluster or subscription are empty. registerAKSCluster also requires a non-empty resourceGroup, and calling it with '' will fail (and may produce a confusing error). Consider including resourceGroup in the guard (or surface a clear error when it’s missing).

Suggested change
if (!cluster || !subscription) {
if (!cluster || !resourceGroup || !subscription) {

Copilot uses AI. Check for mistakes.
Comment on lines +226 to +232
subtitle: `Tenant: ${sub.tenantName} - (${sub.tenant}) • Status: ${sub.status}`,
}));

const clusterOptions: SearchableSelectOption[] = clusters.map(cluster => ({
value: cluster.name,
label: cluster.name,
subtitle: `${cluster.location} • ${cluster.version} • ${cluster.nodeCount} nodes • ${cluster.status}`,
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

subscriptionOptions / clusterOptions subtitles include user-visible English strings (Tenant:, Status:, nodes) that bypass i18n. Since this UI already uses useTranslation(), these labels should be wrapped in t(...) (or otherwise localized) so they appear correctly in non-English locales.

Suggested change
subtitle: `Tenant: ${sub.tenantName} - (${sub.tenant}) • Status: ${sub.status}`,
}));
const clusterOptions: SearchableSelectOption[] = clusters.map(cluster => ({
value: cluster.name,
label: cluster.name,
subtitle: `${cluster.location}${cluster.version}${cluster.nodeCount} nodes • ${cluster.status}`,
subtitle: `${t('Tenant')}: ${sub.tenantName} - (${sub.tenant}) • ${t('Status')}: ${sub.status}`,
}));
const clusterOptions: SearchableSelectOption[] = clusters.map(cluster => ({
value: cluster.name,
label: cluster.name,
subtitle: `${cluster.location}${cluster.version}${cluster.nodeCount} ${t('nodes')}${cluster.status}`,

Copilot uses AI. Check for mistakes.
* Initial state: subscriptions loaded, no subscription or cluster selected yet.
*/
export const Default = Template.bind({});
Default.args = BASE_PROPS;
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

The JSDoc for the Default story says “no subscription … selected yet”, but BASE_FORM_DATA already sets subscription: 'sub-123', so the rendered state won’t match the description. Either clear the subscription in Default.args or adjust the story comment to match the actual initial state.

Suggested change
Default.args = BASE_PROPS;
Default.args = {
...BASE_PROPS,
formData: {
...BASE_FORM_DATA,
subscription: '',
},
};

Copilot uses AI. Check for mistakes.
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/CreateAKSProject/components/BasicsStep.tsx BasicsStep

3 participants