Skip to content

fix: reset to general step when dialog opens#4241

Merged
MichaelUnkey merged 2 commits intomainfrom
eng-2180-ui-key-create-modal-keeps-some-state-after-creating
Nov 5, 2025
Merged

fix: reset to general step when dialog opens#4241
MichaelUnkey merged 2 commits intomainfrom
eng-2180-ui-key-create-modal-keeps-some-state-after-creating

Conversation

@MichaelUnkey
Copy link
Collaborator

What does this PR do?

Fixes # (issue)
Eng-2108

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How should this be tested?

  • key creation dialog still works without errors
  • After creating a key and re opening dialog it should be reset to general step

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

@linear
Copy link

linear bot commented Nov 5, 2025

@changeset-bot
Copy link

changeset-bot bot commented Nov 5, 2025

⚠️ No Changeset found

Latest commit: 0ac714d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Nov 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
dashboard Ignored Ignored Preview Nov 5, 2025 6:05pm
engineering Ignored Ignored Preview Nov 5, 2025 6:05pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

📝 Walkthrough

Walkthrough

The CreateKeyDialog component is refactored to implement a dialog reset mechanism using a dialogKey state. The dialogKey increments on dialog open, close, and key creation completion, forcing NavigableDialogRoot remounting to ensure consistent state initialization with "general" as the default section.

Changes

Cohort / File(s) Change Summary
Dialog state reset mechanism
apps/dashboard/app/(app)/[workspaceSlug]/apis/[apiId]/_components/create-key/index.tsx
Added dialogKey state to force remounting of NavigableDialogRoot; incremented on dialog open/close and key creation completion; passed as key prop to NavigableDialogRoot; set initialSelectedId to "general" in navigable dialog header.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Single file modified with straightforward state management changes
  • All modifications relate to a cohesive dialog lifecycle pattern (dialogKey increments)
  • No complex logic; changes consist of state hooks, prop updates, and callback handlers

Possibly related PRs

  • chore: Dialog container into UI step 1 #3294: Refactored and re-exported NavigableDialog components with updated imports to @unkey/ui, directly affecting the component dependencies used in this file.
  • fix: remaining issue #3278: Centralizes close action handling in KeyCreatedSuccessDialog within the same create-key dialog flow, complementing this PR's dialog state reset mechanism.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: resetting the dialog to the general step when it opens, which directly relates to the code changes shown in the summary.
Description check ✅ Passed The description includes all required sections: issue reference (Eng-2108), type of change (bug fix), testing instructions, and most required checklist items completed. The testing section clearly explains the expected behavior.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch eng-2180-ui-key-create-modal-keeps-some-state-after-creating

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e6fbc8 and 0ac714d.

📒 Files selected for processing (1)
  • apps/dashboard/app/(app)/[workspaceSlug]/apis/[apiId]/_components/create-key/index.tsx (4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: imeyer
Repo: unkeyed/unkey PR: 3755
File: .github/workflows/runbook-freshness-check.yaml:157-173
Timestamp: 2025-08-08T14:59:52.283Z
Learning: Repo unkeyed/unkey: When a CI/workflow fix is deferred, imeyer prefers a thorough GitHub issue be opened with sections (Summary, Impact, Where, Repro, Observed vs Expected, Acceptance Criteria, Validation Plan, Out of Scope, References) and assigned to imeyer, including backlinks to the originating PR and comment.
Learnt from: imeyer
Repo: unkeyed/unkey PR: 3755
File: .github/actions/setup-node/action.yaml:0-0
Timestamp: 2025-08-08T15:10:46.436Z
Learning: Repo: unkeyed/unkey — Preference: If imeyer comments “issue” on a PR thread, automatically open a thorough GitHub issue (Summary, Impact, Where, Observed vs Expected, Acceptance Criteria, Validation Plan, Out of Scope, References), include backlinks to the PR and comment, and assign to imeyer.
Learnt from: imeyer
Repo: unkeyed/unkey PR: 3755
File: .github/workflows/job_detect_changes.yaml:111-114
Timestamp: 2025-08-08T16:10:00.224Z
Learning: Repo: unkeyed/unkey — When imeyer writes “make me an issue” on a PR thread, automatically open a thorough GitHub issue (Summary, Impact, Where, Repro, Observed vs Expected, Acceptance Criteria, Validation Plan, Out of Scope, References), include backlinks to the PR and comment, and assign to imeyer.
Learnt from: ogzhanolguncu
Repo: unkeyed/unkey PR: 3156
File: apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/index.tsx:112-0
Timestamp: 2025-04-22T11:49:06.167Z
Learning: In the CreateKeyDialog component of Unkey, section navigation is designed to always allow progression even if validation fails, as visual indicators display the validation state of each section.
📚 Learning: 2025-04-22T11:49:06.167Z
Learnt from: ogzhanolguncu
Repo: unkeyed/unkey PR: 3156
File: apps/dashboard/app/(app)/apis/[apiId]/_components/create-key/index.tsx:112-0
Timestamp: 2025-04-22T11:49:06.167Z
Learning: In the CreateKeyDialog component of Unkey, section navigation is designed to always allow progression even if validation fails, as visual indicators display the validation state of each section.

Applied to files:

  • apps/dashboard/app/(app)/[workspaceSlug]/apis/[apiId]/_components/create-key/index.tsx
📚 Learning: 2024-10-04T17:27:09.821Z
Learnt from: chronark
Repo: unkeyed/unkey PR: 2146
File: apps/dashboard/app/(app)/apis/[apiId]/settings/default-prefix.tsx:74-75
Timestamp: 2024-10-04T17:27:09.821Z
Learning: In `apps/dashboard/app/(app)/apis/[apiId]/settings/default-prefix.tsx`, the hidden `<input>` elements for `workspaceId` and `keyAuthId` work correctly without being registered with React Hook Form.

Applied to files:

  • apps/dashboard/app/(app)/[workspaceSlug]/apis/[apiId]/_components/create-key/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Test Dashboard / Test Dashboard
🔇 Additional comments (5)
apps/dashboard/app/(app)/[workspaceSlug]/apis/[apiId]/_components/create-key/index.tsx (5)

54-54: LGTM! Clean remounting pattern.

The dialogKey state is correctly initialized for forcing component remounts when navigation needs to be reset.


108-109: LGTM! Proper sequencing of reset operations.

The dialogKey increment correctly occurs after closing the dialog, ensuring a clean remount before the next open. The comment clearly explains the intent.


112-119: LGTM! Correct reset behavior with form persistence.

The sequence of operations is correct:

  1. Form values are saved to memory (line 114)
  2. Dialog is remounted via dialogKey increment (line 116)
  3. Dialog closes (line 118)

React's batching ensures these updates happen together without visual glitches. The form values persist across remounts (via usePersistedForm), while navigation state resets to "general" on next open—this appears to be the intended UX.


169-169: LGTM! Standard React remount pattern.

Using dialogKey as the key prop correctly forces NavigableDialogRoot to remount when the key changes, resetting all internal navigation state.


186-186: LGTM! Essential for ensuring consistent initial state.

Explicitly setting initialSelectedId="general" ensures the dialog consistently starts at the general section on each remount, which is critical for the reset behavior to work correctly.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Collaborator

@mcstepp mcstepp left a comment

Choose a reason for hiding this comment

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

tested in vercel preview, it works

@MichaelUnkey MichaelUnkey added this pull request to the merge queue Nov 5, 2025
@graphite-app
Copy link

graphite-app bot commented Nov 5, 2025

Video gif. An elderly man in suspenders smiles as he holds up two thumbs as if saying good luck.  (Added via Giphy)

Merged via the queue into main with commit 46769f4 Nov 5, 2025
19 checks passed
@MichaelUnkey MichaelUnkey deleted the eng-2180-ui-key-create-modal-keeps-some-state-after-creating branch November 5, 2025 18:47
@graphite-app
Copy link

graphite-app bot commented Nov 5, 2025

Graphite Automations

"Post a GIF when PR approved" took an action on this PR • (11/05/25)

1 gif was posted to this PR based on Andreas Thomas's automation.

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.

3 participants