Skip to content

feat(dexie-cloud): Add copy-to-clipboard button for whitelist command#2261

Merged
dfahlander merged 2 commits intomasterfrom
liz/whitelist-copy-button
Mar 17, 2026
Merged

feat(dexie-cloud): Add copy-to-clipboard button for whitelist command#2261
dfahlander merged 2 commits intomasterfrom
liz/whitelist-copy-button

Conversation

@liz709
Copy link
Copy Markdown
Contributor

@liz709 liz709 commented Mar 16, 2026

What

When authentication fails because the origin isn't whitelisted, the error dialog now shows a copy-to-clipboard button with the full CLI command:

npx dexie-cloud whitelist http://localhost:8080

One click copies the complete command — no need to manually type it.

Changes

  • DXCAlert: Added optional copyText field to all alert types (extensible for future use)
  • authenticate.ts: Passes the full whitelist command as copyText
  • LoginDialog.tsx: New CopyButton component with Clipboard API + execCommand fallback
  • Styles.ts: Button styling with visual ✓ feedback on copy

QoL improvement

Requested by @jesperforss 🙏

Summary by CodeRabbit

  • New Features
    • Authentication alerts now include a one-click copy button for actionable text (e.g., whitelist commands), with optimistic "Copied!" feedback and a reliable fallback when clipboard APIs are unavailable.
  • Style
    • Added visual states for the copy button (default and copied) to clearly indicate success.

… in auth error dialog

When authentication fails due to an unwhitelisted origin, the error dialog
now shows a clickable copy button with the full CLI command:
  npx dexie-cloud whitelist <origin>

This saves developers from having to manually type or construct the command.

Changes:
- DXCAlert: Added optional 'copyText' field to all alert types
- authenticate.ts: Passes the full whitelist command as copyText
- LoginDialog.tsx: CopyButton component with clipboard API + fallback
- Styles.ts: Copy button styling with visual feedback on copy

Requested by: Jesper
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0b75a134-6251-44af-ba8b-be519ad43dda

📥 Commits

Reviewing files that changed from the base of the PR and between 3abf657 and d22456e.

📒 Files selected for processing (2)
  • addons/dexie-cloud/src/authentication/authenticate.ts
  • addons/dexie-cloud/src/default-ui/LoginDialog.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • addons/dexie-cloud/src/authentication/authenticate.ts
  • addons/dexie-cloud/src/default-ui/LoginDialog.tsx

📝 Walkthrough

Walkthrough

Adds clipboard copy support for authentication alerts: alert types gain an optional copyText, the login UI renders a CopyButton with fallback clipboard behavior and transient "Copied!" feedback, styles for the button added, and authentication error handling populates a ready-to-copy whitelist command in dev/localhost scenarios.

Changes

Cohort / File(s) Summary
Alert Type Extensions
addons/dexie-cloud/src/types/DXCAlert.ts
Added optional copyText?: string to DXCErrorAlert, DXCWarningAlert, and DXCInfoAlert.
UI Component & Styling
addons/dexie-cloud/src/default-ui/LoginDialog.tsx, addons/dexie-cloud/src/default-ui/Styles.ts
Added an internal CopyButton component (uses navigator.clipboard with a hidden-textarea fallback), optimistic "Copied!" UI for 2s, cleanup on unmount, and two styles: CopyButton and CopyButtonCopied.
Authentication Flow
addons/dexie-cloud/src/authentication/authenticate.ts
On TypeError during authentication in dev/localhost (Dexie.debug or hostname localhost/127.0.0.1), constructs a whitelistCommand and includes it as copyText in the authentication failure alert so the UI can offer a one-click copy.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A tiny paw taps, the clipboard sings,
A whitelist command on nimble wings.
Click once, it’s copied—no frantic despair,
Dev localhost ready, tidy and fair.
Hooray for crumbs of convenience in air!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main feature added: a copy-to-clipboard button for the whitelist command in the authentication error dialog.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch liz/whitelist-copy-button
📝 Coding Plan
  • Generate coding plan for human review comments

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.

Tip

CodeRabbit can use your project's `biome` configuration to improve the quality of JS/TS/CSS/JSON code reviews.

Add a configuration file to your project to customize how CodeRabbit runs biome.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
addons/dexie-cloud/src/default-ui/Styles.ts (1)

211-241: Reduce duplication between CopyButton style variants.

CopyButton and CopyButtonCopied repeat many identical declarations; extracting a shared base style will reduce drift risk.

♻️ Proposed refactor
+const CopyButtonBase = {
+  display: "inline-flex",
+  alignItems: "center",
+  gap: "4px",
+  padding: "4px 10px",
+  marginTop: "8px",
+  borderRadius: "4px",
+  fontSize: "12px",
+  fontWeight: "500",
+  fontFamily: "monospace"
+};
+
 export const Styles: { [styleAlias: string]: Partial<CSSStyleDeclaration> | any} = {
   ...
   CopyButton: {
-    display: "inline-flex",
-    alignItems: "center",
-    gap: "4px",
-    padding: "4px 10px",
-    marginTop: "8px",
+    ...CopyButtonBase,
     border: "1px solid `#d1d5db`",
-    borderRadius: "4px",
     backgroundColor: "#f9fafb",
     cursor: "pointer",
-    fontSize: "12px",
-    fontWeight: "500",
     color: "#374151",
-    transition: "all 0.15s ease",
-    fontFamily: "monospace"
+    transition: "all 0.15s ease"
   },
   CopyButtonCopied: {
-    display: "inline-flex",
-    alignItems: "center",
-    gap: "4px",
-    padding: "4px 10px",
-    marginTop: "8px",
+    ...CopyButtonBase,
     border: "1px solid `#22c55e`",
-    borderRadius: "4px",
     backgroundColor: "#f0fdf4",
     cursor: "default",
-    fontSize: "12px",
-    fontWeight: "500",
-    color: "#16a34a",
-    fontFamily: "monospace"
+    color: "#16a34a"
   },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@addons/dexie-cloud/src/default-ui/Styles.ts` around lines 211 - 241, Extract
the duplicated declarations between CopyButton and CopyButtonCopied into a
shared base style object (e.g., CopyButtonBase or CopyButtonCommon) and have
CopyButton and CopyButtonCopied spread/extend that base, keeping only the
differing properties (border, backgroundColor, cursor, color, transition if
different) in each variant; update references to CopyButton and CopyButtonCopied
to preserve behavior while reducing duplication and drift risk.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@addons/dexie-cloud/src/authentication/authenticate.ts`:
- Around line 254-264: Guard use of location.origin in the Dexie.debug branch:
before building whitelistCommand and message (the code that sets
whitelistCommand, message and calls alertUser), check typeof location !==
'undefined' (and optionally location.origin) and only reference location.origin
when present; otherwise use a safe fallback string (e.g. '<origin unavailable>')
or omit copyText. Update the logic around whitelistCommand, message and the
alertUser call (the block that constructs whitelistCommand and calls alertUser)
to avoid direct access to location.origin when running in environments without
window/location.

In `@addons/dexie-cloud/src/default-ui/LoginDialog.tsx`:
- Around line 208-220: The handleClick handler currently assumes
navigator.clipboard exists and always calls scheduleCopiedReset after the DOM
fallback; update handleClick to first guard clipboard access (check
navigator.clipboard and navigator.clipboard.writeText) and call it inside a
try/catch, and for the fallback create-and-copy path check the boolean result of
document.execCommand('copy') (and also guard document before DOM ops); only call
scheduleCopiedReset when either navigator.clipboard.writeText resolves
successfully or document.execCommand('copy') returns true, otherwise handle the
failure (e.g., show/error state or no-op) so the "Copied!" indicator is not
shown on failure.

---

Nitpick comments:
In `@addons/dexie-cloud/src/default-ui/Styles.ts`:
- Around line 211-241: Extract the duplicated declarations between CopyButton
and CopyButtonCopied into a shared base style object (e.g., CopyButtonBase or
CopyButtonCommon) and have CopyButton and CopyButtonCopied spread/extend that
base, keeping only the differing properties (border, backgroundColor, cursor,
color, transition if different) in each variant; update references to CopyButton
and CopyButtonCopied to preserve behavior while reducing duplication and drift
risk.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 92330fe6-9b36-4a51-8040-bd92d51a2908

📥 Commits

Reviewing files that changed from the base of the PR and between c421bb6 and 3abf657.

📒 Files selected for processing (4)
  • addons/dexie-cloud/src/authentication/authenticate.ts
  • addons/dexie-cloud/src/default-ui/LoginDialog.tsx
  • addons/dexie-cloud/src/default-ui/Styles.ts
  • addons/dexie-cloud/src/types/DXCAlert.ts

- Move typeof location check before Dexie.debug to prevent ReferenceError
  in non-browser environments (Node/SSR)
- Guard navigator.clipboard access with existence check
- Check execCommand('copy') return value - only show 'Copied!' on success
- Extract fallback copy logic into separate function
@dfahlander dfahlander merged commit fbac535 into master Mar 17, 2026
7 checks passed
@dfahlander dfahlander deleted the liz/whitelist-copy-button branch March 17, 2026 14:13
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.

2 participants