🐛 [scanner] fix: auto-select first cluster in CreateNamespaceModal and CanIChecker#21363
Conversation
…d CanIChecker Both components initialised their cluster state to '' while their tests (updated by PRs #21344 and #21354) assert auto-selection of the first available cluster. This mismatch caused the nightly unit-test suite to fail on every run since the revert in PR #21323. CreateNamespaceModal: change useState('') → useState(clusters[0] ?? '') so the first cluster prop is selected on mount, matching the assertion in 'auto-selects first cluster on initialization'. CanIChecker: memoize the clusters array with useMemo to stabilise the dependency reference, then add a useEffect that dispatches SET_FIELD for 'cluster' when clusters become available and no cluster is selected yet, matching 'auto-selects the first cluster'. Fixes #21083 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Scanner Agent <scanner@agents.github.com>
✅ Deploy Preview for kubestellarconsole ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
👋 Hey @clubanderson — thanks for opening this PR!
This is an automated message. |
|
🐝 Hi @clubanderson! I'm Trusted users — org members and contributors with write access — can mention Automation may take a moment to start, and follow-up happens through workflow activity rather than chat replies. |
✅ Test Coverage CheckAll new source files in this PR have corresponding test files. Checked |
♿ Accessibility Audit (WCAG 2.1 AA)✅ No WCAG 2.1 AA violations detected in audited routes. Powered by axe-core. Target: WCAG 2.1 AA compliance. |
There was a problem hiding this comment.
Pull request overview
Restores “auto-select first cluster” behavior in two RBAC/namespace UI components to match the unit test expectations (fixing the nightly unit-test regression tracked in #21083).
Changes:
CreateNamespaceModal: initialize theclusterstate toclusters[0] ?? ''so the first cluster is preselected on mount.CanIChecker: memoize the derived cluster-name array and auto-select the first cluster via an effect when clusters become available.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| web/src/components/rbac/CanIChecker.tsx | Memoizes cluster-name list and reintroduces first-cluster auto-select to match tests. |
| web/src/components/namespaces/CreateNamespaceModal.tsx | Initializes modal cluster selection to the first provided cluster. |
Comments suppressed due to low confidence (1)
web/src/components/namespaces/CreateNamespaceModal.tsx:22
useState(clusters[0] ?? '')only runs on the initial mount. If the modal is opened before clusters have loaded (prop is[]initially) and then theclustersprop updates,clusterwill stay''and the first cluster won’t actually auto-select (and Create remains disabled until the user manually selects). Consider syncingclusterwhenclusterschanges and no cluster is selected yet (and optionally when the selected cluster disappears).
export function CreateNamespaceModal({ clusters, onClose, onCreated }: CreateNamespaceModalProps) {
const { t } = useTranslation()
const [name, setName] = useState('')
const [cluster, setCluster] = useState(clusters[0] ?? '')
const [teamLabel, setTeamLabel] = useState('')
const [creating, setCreating] = useState(false)
const [error, setError] = useState<string | null>(null)
const [showDiscardConfirm, setShowDiscardConfirm] = useState(false)
| useEffect(() => { | ||
| if (!cluster && clusters.length > 0) { | ||
| dispatch({ type: 'SET_FIELD', field: 'cluster', value: clusters[0] }) | ||
| } | ||
| }, [cluster, clusters]) |
|
Thank you for your contribution! Your PR has been merged. Check out what's new:
Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey |
✅ Post-Merge Verification: passedCommit: |
|
Post-merge build verification passed ✅ Both Go and frontend builds compiled successfully against merge commit |
Fixes #21083
Root cause
Issue #21083 tracks the nightly
unit-testsuite regression. The original 3-file failures (helm-core, helm-branches, useStackDiscovery) were fixed in prior PRs. However the nightly kept failing because the component–test mismatch introduced by the revert in PR #21323 was never resolved.What happened:
CreateNamespaceModalandCanIChecker''initial state)'cluster-a'/'cluster-1'), not knowing the component was already revertedFix
CreateNamespaceModal.tsx: changeuseState('')→useState(clusters[0] ?? '')so the first cluster prop is pre-selected on mount, matching the test assertion inauto-selects first cluster on initialization.CanIChecker.tsx: memoize the derivedclustersarray (prevents spurious effect re-runs), then add auseEffectthat dispatchesSET_FIELDfor'cluster'when clusters are available and none is selected yet, matching theauto-selects the first clusterassertion. Pattern mirrors the approach from PR #21318.Test impact
CreateNamespaceModal.test.tsx > auto-selects first cluster on initialization— now passesCanIChecker.test.tsx > auto-selects the first cluster— now passesselectCluster()explicitly or don't depend on initial cluster valueSigned-off-by: clubanderson 407614+clubanderson@users.noreply.github.com