Skip to content

fix(pm-wizard): support stored credentials in edit mode#1153

Merged
zbigniewsobiecki merged 3 commits intodevfrom
fix/pm-wizard-edit-mode
Apr 18, 2026
Merged

fix(pm-wizard): support stored credentials in edit mode#1153
zbigniewsobiecki merged 3 commits intodevfrom
fix/pm-wizard-edit-mode

Conversation

@zbigniewsobiecki
Copy link
Copy Markdown
Member

Summary

Two related bugs surface when a user re-opens an existing Linear/Trello/JIRA PM integration to tweak settings:

  1. "Failed to create label: Missing credentials or team selection" — clicking "Create label" in the Labels mapping step throws a client-side error even though the integration is fully configured.
  2. No "Verify Connection" button on the credentials step — the button was hidden entirely in edit-mode with stored credentials and no re-typed API key.

Root cause: buildEditState intentionally leaves raw API credentials blank when re-opening an integration (security — hasStoredCredentials is flipped true instead). The discovery hooks (useTrelloBoards, useLinearStates, etc.) already had an edit-mode fallback: when stored creds exist and the API-key field is empty, pass projectId and let the backend resolve credentials via resolvePMCredentials. But the mutation hooks (useVerification, useTrelloLabelCreation, useLinearLabelCreation, useTrelloCustomFieldCreation, useJiraCustomFieldCreation) required form-state credentials and threw synchronously.

This PR plumbs the same projectId fallback into every mutation hook. Zero backend change — pm.discovery.createLabel, createCustomField, and discover all already accept an optional projectId.

What changed

  • New shouldUseStoredCredentials(state) helper in pm-wizard-state.ts. Single source of truth: "is this a stored-creds-path mutation". 8 unit tests.
  • 5 mutation hooks in pm-wizard-hooks.ts updated to consult the helper and branch between { projectId } and { credentials: ... }. Team / board / project-key checks stay (those come from config state, not creds).
  • pm-wizard.tsx: drop the visibility gate on the Verify Connection button. Always render on the credentials step. Enable when credsReady || (editing && stored). Show a muted "Using stored credentials" hint when taking the stored-creds path.
  • Refactored the two createMissingLabelsMutation bodies to extract a runPerLabelCreations helper (keeps them under the biome cognitive-complexity threshold).

Test plan

  • npm test — 8210 / 8210 (8 new tests in pm-wizard-state.test.ts, the rest unchanged)
  • npm run lint — clean
  • npm run typecheck — clean
  • cd web && npm run build — clean
  • Post-merge browser smoke — re-open an existing Linear/Trello/JIRA integration:
    • Credentials step shows a Verify Connection button with "Using stored credentials" hint; clicking verifies without re-typing the key
    • Labels step Create label succeeds in edit mode
    • Custom-field creation (Trello/JIRA) succeeds in edit mode
    • Fresh-setup flow still requires typed credentials (no regression)

🤖 Generated with Claude Code

zbigniewsobiecki and others added 3 commits April 18, 2026 19:47
buildEditState intentionally leaves raw API credentials blank when
re-opening an existing integration (security), but the verify,
create-label, and create-custom-field hooks required form-state
credentials and threw "Missing credentials or team selection"
client-side before reaching the backend. The discovery hooks already
had the projectId fallback — now the mutation hooks do too.

Introduces shouldUseStoredCredentials(state) in pm-wizard-state.ts
as the single source of truth for "send projectId vs send credentials".
Each hook (useVerification, useTrello/LinearLabelCreation,
useTrello/JiraCustomFieldCreation) now picks the correct path.

Team / board / project-key checks stay — those come from config
state, not credentials, so their error messages are split out.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
The gate `(!state.isEditing || !state.hasStoredCredentials || credsReady)`
hid the button precisely when it was most useful — editing an existing
integration with stored credentials but an empty API-key field. User
had no way to test that the stored key still works.

Drop the gate. Enable the button whenever credentials are ready OR the
user is editing with stored credentials (backend resolves them via
projectId path). Add a muted "Using stored credentials" hint when
taking the stored-creds path so it's obvious what's happening.

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
Eight new tests, one per (provider × scenario) combo. Fresh setup →
false; edit with stored creds + empty API-key → true; edit with
re-typed API-key → false; edit without stored creds → false. Locks in
the #1152-follow-up contract that stored-creds-aware mutations route
through projectId instead of throwing "Missing credentials".

Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
@zbigniewsobiecki zbigniewsobiecki merged commit fddda84 into dev Apr 18, 2026
7 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant