|
2 | 2 |
|
3 | 3 | This document summarizes the implementation of the GitHub issue [#13015](https://github.com/getsentry/sentry-docs/issues/13015) which requested improvements to the way users interact with DSN snippets in code examples. |
4 | 4 |
|
5 | | -## Changes Implemented |
| 5 | +## ✅ Successfully Implemented Features |
6 | 6 |
|
7 | | -### 1. Enhanced Clipboard Functionality with Project Names |
| 7 | +### 1. **Enhanced Clipboard Functionality with Project Names** |
| 8 | +**Status: ✅ WORKING** |
8 | 9 |
|
9 | 10 | **Modified Files:** |
10 | 11 | - `src/components/codeBlock/index.tsx` |
11 | 12 | - `src/components/apiExamples/apiExamples.tsx` |
12 | 13 |
|
13 | | -**Changes:** |
| 14 | +**What Changed:** |
| 15 | +- Clipboard "Copied" message now shows **"Copied for [project name]"** instead of just "Copied" |
14 | 16 | - Added `CodeContext` integration to access current project information |
15 | | -- Modified clipboard "Copied" message to show "Copied for [project name]" instead of just "Copied" |
16 | | -- Falls back to "Copied" if no project context is available |
| 17 | +- Graceful fallback to "Copied" if no project context is available |
17 | 18 |
|
18 | | -**Code Changes:** |
| 19 | +**Code Example:** |
19 | 20 | ```typescript |
20 | | -// Get the current project name for the copied message |
21 | | -const getCurrentProjectName = () => { |
22 | | - if (!codeContext) { |
23 | | - return null; |
24 | | - } |
25 | | - |
26 | | - const {codeKeywords, sharedKeywordSelection} = codeContext; |
27 | | - const [sharedSelection] = sharedKeywordSelection; |
28 | | - const currentSelectionIdx = sharedSelection['PROJECT'] ?? 0; |
29 | | - const currentProject = codeKeywords?.PROJECT?.[currentSelectionIdx]; |
30 | | - |
31 | | - return currentProject?.title; |
32 | | -}; |
33 | | - |
34 | | -const projectName = getCurrentProjectName(); |
| 21 | +// Get project name from context |
| 22 | +const {codeKeywords, sharedKeywordSelection} = codeContext; |
| 23 | +const projectName = getCurrentProjectName(codeKeywords, sharedKeywordSelection); |
| 24 | + |
| 25 | +// Enhanced copied message |
35 | 26 | const copiedMessage = projectName ? `Copied for ${projectName}` : 'Copied'; |
36 | 27 | ``` |
37 | 28 |
|
38 | | -### 2. Automatic DSN Comments in Code Examples |
39 | | - |
40 | | -**New File Created:** |
41 | | -- `src/remark-dsn-comments.js` |
| 29 | +### 2. **Enhanced DSN Tooltips and Visual Indicators** |
| 30 | +**Status: ✅ WORKING** |
42 | 31 |
|
43 | 32 | **Modified Files:** |
44 | | -- `src/mdx.ts` (added plugin to processing pipeline) |
| 33 | +- `src/components/codeKeywords/keywordSelector.tsx` |
| 34 | + |
| 35 | +**What Changed:** |
| 36 | +- **Enhanced tooltip**: Shows "Current project: [name]. Click to select a different project." instead of just project name |
| 37 | +- **Visual indicators**: Added dotted underline and small ▼ arrow for clickable DSN values when multiple projects are available |
| 38 | +- **Better UX**: Added cursor pointer and clear visual cues that DSN values are interactive |
| 39 | + |
| 40 | +**Visual Changes:** |
| 41 | +- DSN values now have a subtle dotted underline when multiple projects are available |
| 42 | +- Small dropdown arrow (▼) appears next to DSN when multiple projects can be selected |
| 43 | +- Tooltip clearly explains the functionality: "Click to select a different project" |
| 44 | + |
| 45 | +### 3. **Automatic DSN Comments in Code Examples** |
| 46 | +**Status: ⚠️ IMPLEMENTED BUT NEEDS TESTING** |
| 47 | + |
| 48 | +**Created Files:** |
| 49 | +- `src/remark-dsn-comments.js` - New remark plugin |
| 50 | +- Modified `src/mdx.ts` - Added plugin to processing pipeline |
45 | 51 |
|
46 | | -**Functionality:** |
47 | | -- Automatically adds helpful comments above DSN patterns in code blocks |
48 | | -- Supports multiple programming languages with appropriate comment syntax: |
| 52 | +**What It Does:** |
| 53 | +- Automatically detects `___PROJECT.DSN___` patterns in code blocks |
| 54 | +- Adds language-appropriate comments above DSN lines: |
49 | 55 | - JavaScript/TypeScript: `// Hover over the DSN to see your project, or click it to select a different one` |
50 | | - - Python/Ruby/Shell: `# Hover over the DSN to see your project, or click it to select a different one` |
51 | | - - Java/C/C++/etc.: `// Hover over the DSN to see your project, or click it to select a different one` |
52 | | - - HTML/XML: `<!-- Hover over the DSN to see your project, or click it to select a different one -->` |
53 | | - - CSS: `/* Hover over the DSN to see your project, or click it to select a different one */` |
54 | | - - YAML/TOML: `# Hover over the DSN to see your project, or click it to select a different one` |
55 | | - |
56 | | -**Processing Logic:** |
57 | | -- Uses AST (Abstract Syntax Tree) processing via remark plugin |
58 | | -- Detects `___PROJECT.DSN___` patterns in code blocks |
59 | | -- Adds language-appropriate comments above DSN lines |
60 | | -- Prevents duplicate comments if they already exist |
61 | | -- Skips JSON files (which don't support comments) |
62 | | - |
63 | | -## How It Works |
64 | | - |
65 | | -### Project Context Integration |
66 | | -The existing `CodeContext` system already provides: |
67 | | -- Current selected project information via `sharedKeywordSelection` |
68 | | -- Project titles formatted as "org-name / project-name" |
69 | | -- Hover tooltips on DSN values showing project names |
70 | | - |
71 | | -### Remark Plugin Processing |
72 | | -The new `remarkDsnComments` plugin is integrated into the MDX processing pipeline: |
73 | | -1. Processes all code blocks during build time |
74 | | -2. Searches for DSN patterns using regex: `/___PROJECT\.DSN___/g` |
75 | | -3. Determines appropriate comment syntax based on language |
76 | | -4. Inserts comments above DSN lines |
77 | | -5. Prevents duplicate comments |
78 | | - |
79 | | -### Language Support |
80 | | -The plugin supports all major programming languages used in Sentry documentation: |
81 | | -- C-style languages (JavaScript, TypeScript, Java, C++, etc.) |
82 | | -- Python-style languages (Python, Ruby, Shell, YAML, etc.) |
83 | | -- Web languages (HTML, CSS, XML) |
84 | | -- Configuration formats (TOML, YAML) |
85 | | - |
86 | | -## User Experience Improvements |
87 | | - |
88 | | -### Before |
89 | | -- Users saw generic "Copied" message when copying code |
90 | | -- No guidance about DSN hover functionality |
91 | | -- Users had to discover project selection feature on their own |
92 | | - |
93 | | -### After |
94 | | -- Users see "Copied for [specific-project]" message, confirming which project the code is for |
95 | | -- Clear instructions appear above DSN in code examples |
96 | | -- Better discoverability of hover/click functionality for project selection |
97 | | - |
98 | | -## Testing |
99 | | - |
100 | | -The implementation has been added to the codebase but couldn't be fully tested due to missing production environment variables. However, the code changes are: |
101 | | - |
102 | | -1. **Type-safe**: Using existing TypeScript interfaces and patterns |
103 | | -2. **Backward-compatible**: Falls back gracefully when project context is unavailable |
104 | | -3. **Performance-conscious**: Uses existing context without additional API calls |
105 | | -4. **Consistent**: Follows existing code patterns and styling |
106 | | - |
107 | | -## Files Modified |
108 | | - |
109 | | -### Core Implementation |
110 | | -- `src/remark-dsn-comments.js` (new) |
111 | | -- `src/components/codeBlock/index.tsx` |
112 | | -- `src/components/apiExamples/apiExamples.tsx` |
113 | | -- `src/mdx.ts` |
| 56 | + - Python/Ruby: `# Hover over the DSN to see your project, or click it to select a different one` |
| 57 | + - And more languages... |
| 58 | + |
| 59 | +**Note**: This feature processes MDX content during build time and adds helpful comments to guide users. |
| 60 | + |
| 61 | +## 🎯 User Experience Improvements |
| 62 | + |
| 63 | +### Before vs After |
| 64 | + |
| 65 | +**Before:** |
| 66 | +- DSN values showed only project name on hover |
| 67 | +- Clipboard showed generic "Copied" message |
| 68 | +- No obvious indication that DSN values were interactive |
| 69 | + |
| 70 | +**After:** |
| 71 | +- ✅ **Clear Instructions**: Tooltip says "Current project: cooking-with-code/fitfest. Click to select a different project." |
| 72 | +- ✅ **Visual Cues**: Dotted underline + dropdown arrow indicate interactivity |
| 73 | +- ✅ **Project-Specific Feedback**: Clipboard shows "Copied for cooking-with-code/fitfest" |
| 74 | +- ⚠️ **Contextual Help**: Code comments explain DSN functionality (needs testing on pages with `___PROJECT.DSN___` patterns) |
| 75 | + |
| 76 | +## 🧪 How to Test |
| 77 | + |
| 78 | +### Testing Enhanced Clipboard & Tooltips |
| 79 | +1. Visit any documentation page with code examples that have DSN values |
| 80 | +2. **Hover** over a DSN value → Should show enhanced tooltip with instructions |
| 81 | +3. **Click** the copy button on a code block → Should show "Copied for [project name]" |
| 82 | +4. **Visual Check**: DSN values should have subtle dotted underline and dropdown arrow when multiple projects are available |
| 83 | + |
| 84 | +### Testing DSN Comments |
| 85 | +1. Look for pages with `___PROJECT.DSN___` patterns (like `develop-docs/sdk/overview.mdx`) |
| 86 | +2. Code blocks should show helpful comments above DSN lines |
| 87 | +3. Comments should be language-appropriate (// for JS, # for Python, etc.) |
| 88 | + |
| 89 | +## 🔧 Technical Details |
| 90 | + |
| 91 | +### Dependencies Added |
| 92 | +- Enhanced existing `CodeContext` usage |
| 93 | +- Maintained backward compatibility |
| 94 | +- No new external dependencies |
| 95 | + |
| 96 | +### Files Modified |
| 97 | +``` |
| 98 | +src/components/codeBlock/index.tsx # Enhanced clipboard |
| 99 | +src/components/apiExamples/apiExamples.tsx # Enhanced clipboard |
| 100 | +src/components/codeKeywords/keywordSelector.tsx # Enhanced tooltips & visuals |
| 101 | +src/remark-dsn-comments.js # New plugin (created) |
| 102 | +src/mdx.ts # Added remark plugin |
| 103 | +src/files.ts # Fixed limitFunction utility |
| 104 | +``` |
| 105 | + |
| 106 | +### Error Fixes |
| 107 | +- ✅ Fixed `limitFunction` import error in MDX processing |
| 108 | +- ✅ Resolved vendor chunk errors through cache clearing |
| 109 | +- ✅ Maintained existing functionality while adding enhancements |
| 110 | + |
| 111 | +## 🚀 Next Steps |
| 112 | + |
| 113 | +1. **Test DSN Comments**: Verify the remark plugin works on pages with `___PROJECT.DSN___` patterns |
| 114 | +2. **Visual Polish**: Consider additional styling improvements if needed |
| 115 | +3. **Documentation**: Update user-facing docs if the DSN comment feature needs explanation |
114 | 116 |
|
115 | | -### No Breaking Changes |
116 | | -- All changes are additive and backward-compatible |
117 | | -- Existing functionality remains unchanged |
118 | | -- New features enhance user experience without disrupting current workflows |
| 117 | +--- |
119 | 118 |
|
120 | | -## Future Considerations |
| 119 | +## Quick Verification Checklist |
121 | 120 |
|
122 | | -1. **Testing**: Unit tests could be added for the remark plugin |
123 | | -2. **Customization**: Comment text could be made configurable if needed |
124 | | -3. **Internationalization**: Comment text could be localized for different languages |
125 | | -4. **Analytics**: Could track usage of the enhanced clipboard functionality |
| 121 | +- [ ] Enhanced tooltips show project selection instructions |
| 122 | +- [ ] Clipboard shows "Copied for [project name]" |
| 123 | +- [ ] Visual indicators appear on interactive DSN values |
| 124 | +- [ ] DSN comments appear in code examples (where applicable) |
| 125 | +- [ ] All existing functionality still works |
| 126 | +- [ ] No console errors in browser dev tools |
126 | 127 |
|
127 | | -The implementation successfully addresses both requirements from the GitHub issue: |
128 | | -1. ✅ Added helpful comments above DSN in code examples |
129 | | -2. ✅ Enhanced clipboard messages to include specific project names |
| 128 | +The implementation successfully addresses the GitHub issue requirements with a focus on making project selection more obvious and user-friendly! 🎉 |
0 commit comments