@salesforcedevs/docs-components 1.17.0-hack-alpha8 → 1.17.2-accessfix-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,322 +0,0 @@
1
- # Comment Popup Component
2
-
3
- A Lightning Web Component that allows users to leave comments on documentation sections. The component supports both local storage (for development) and a new API format for production use.
4
-
5
- ## Features
6
-
7
- - ✅ **API Integration**: Now actively tries to fetch from `/get-comments` endpoint
8
- - ✅ **Fallback Support**: Falls back to localStorage if API is unavailable
9
- - ✅ **New API Format**: Supports branch-based comment fetching
10
- - ✅ **Pre-loaded Comments**: Comments are fetched when component is rendered, not when popup opens
11
- - ✅ **Local Storage**: Comments persist across page refreshes during development
12
- - ✅ **Form Validation**: Email format and required field validation
13
- - ✅ **Real-time Display**: Comments appear immediately after posting
14
- - ✅ **Timestamp Formatting**: Shows relative time (e.g., "2 hours ago")
15
- - ✅ **Email Masking**: Protects user privacy in comment display
16
- - ✅ **Comment Count Badge**: Shows total number of comments
17
- - ✅ **Responsive Design**: Works on mobile and desktop
18
- - ✅ **Keyboard Accessibility**: ESC key to close popup
19
- - ✅ **Dark Mode Support**: Adapts to system preferences
20
- - ✅ **Development Tools**: Helper utilities for testing
21
-
22
- ## API Format
23
-
24
- The component now supports a new API format where comments are fetched by branch and then filtered by file path and heading title.
25
-
26
- ### API Endpoints
27
-
28
- - **GET** `/get-comments?branch={branch}` - Fetch all comments for a branch
29
- - **POST** `/post-comment` - Add a new comment
30
-
31
- ### API Response Format
32
-
33
- ```json
34
- {
35
- "request_branch": "feature/documentation-updates",
36
- "paths": [
37
- {
38
- "path": "docs/installation.md",
39
- "titles": [
40
- {
41
- "title": "Installation Guide",
42
- "comments": [
43
- {
44
- "email": "john.doe@example.com",
45
- "comment_text": "This installation guide is very helpful for new users.",
46
- "timestamp": "2024-01-15T10:30:00Z"
47
- }
48
- ]
49
- }
50
- ]
51
- }
52
- ]
53
- }
54
- ```
55
-
56
- ### API Request Format
57
-
58
- ```json
59
- {
60
- "branch": "feature/documentation-updates",
61
- "file_path": "docs/installation.md",
62
- "heading_title": "Installation Guide",
63
- "start_line": "1",
64
- "end_line": "50",
65
- "comment": {
66
- "comment_text": "This is a helpful comment.",
67
- "email": "user@example.com",
68
- "timestamp": "2024-01-15T10:30:00Z"
69
- }
70
- }
71
- ```
72
-
73
- ## Usage
74
-
75
- ### Basic Usage
76
-
77
- ```html
78
- <sb-doc-comment-popup
79
- heading-title="Installation Guide"
80
- file-path="docs/installation.md"
81
- current-branch="feature/documentation-updates"
82
- start-line="1"
83
- end-line="50"
84
- open="false"
85
- icon-symbol="chat"
86
- icon-size="medium"
87
- >
88
- </sb-doc-comment-popup>
89
- ```
90
-
91
- ### Comment Loading Behavior
92
-
93
- The component now fetches comments when it is rendered (connected to the DOM) rather than when the popup is opened. This ensures:
94
-
95
- - **Faster Popup Opening**: Comments are already loaded when the user clicks the icon
96
- - **Immediate Comment Count**: The comment count badge shows the correct number immediately
97
- - **Better User Experience**: No loading delay when opening the popup
98
-
99
- Comments are automatically refetched when any of these properties change:
100
-
101
- - `heading-title`
102
- - `file-path`
103
- - `current-branch`
104
-
105
- ### Required Properties
106
-
107
- - `heading-title`: The title of the section being commented on
108
- - `file-path`: The file path where the comment is located
109
- - `current-branch`: The current git branch
110
-
111
- ### Optional Properties
112
-
113
- - `start-line`: Starting line number (for future line-specific comments)
114
- - `end-line`: Ending line number (for future line-specific comments)
115
- - `open`: Controls the popup visibility (default: false)
116
- - `icon-symbol`: Icon symbol for the comment button (default: "chat")
117
- - `icon-size`: Size of the comment icon (default: "medium")
118
-
119
- ### Available Icon Symbols
120
-
121
- - `chat` - Chat bubble icon
122
- - `comment` - Comment icon
123
- - `message` - Message icon
124
- - `feedback` - Feedback icon
125
-
126
- ### Available Icon Sizes
127
-
128
- - `small` - Small icon
129
- - `medium` - Medium icon (default)
130
- - `large` - Large icon
131
-
132
- ## Local Storage Implementation
133
-
134
- During development, the component uses localStorage to persist comments. Comments are stored with a unique key format:
135
-
136
- ```
137
- {branch}_{file_path}_{heading_title}
138
- ```
139
-
140
- ### Local Storage Structure
141
-
142
- ```json
143
- {
144
- "main_docs/installation.md_Installation Guide": [
145
- {
146
- "email": "user@example.com",
147
- "comment_text": "This is a comment",
148
- "timestamp": "2024-01-15T10:30:00Z"
149
- }
150
- ]
151
- }
152
- ```
153
-
154
- ## Development Tools
155
-
156
- The component includes development tools for testing and managing comments during development.
157
-
158
- ### Console Commands
159
-
160
- ```javascript
161
- // Export all comments to a JSON file
162
- CommentDevHelper.exportCommentsToFile();
163
-
164
- // Add sample comments matching the new API format
165
- CommentDevHelper.addSampleCommentsForNewApi();
166
-
167
- // Get statistics about stored comments
168
- CommentDevHelper.getCommentsStats();
169
-
170
- // Clear all comments from localStorage
171
- CommentDevHelper.clearAllComments();
172
-
173
- // Test the API response format
174
- CommentDevHelper.testApiResponseFormat();
175
-
176
- // Simulate API call for a specific branch
177
- CommentDevHelper.simulateApiCall("main");
178
-
179
- // Show all comments in console
180
- CommentDevHelper.showAllComments();
181
- ```
182
-
183
- ### Development UI
184
-
185
- The component automatically creates a development UI when running on localhost. This UI provides buttons for:
186
-
187
- - Adding sample comments
188
- - Testing API response format
189
- - Exporting comments
190
- - Clearing all comments
191
- - Viewing statistics
192
-
193
- ## API Integration Status
194
-
195
- The component now actively tries to use the backend API with localStorage as a fallback:
196
-
197
- ### Current Behavior
198
-
199
- 1. **Fetch Comments**: First tries `/get-comments?branch={branch}`, falls back to localStorage if API fails
200
- 2. **Post Comments**: First tries `/post-comment`, falls back to localStorage if API fails
201
- 3. **Error Handling**: Graceful degradation with console warnings for debugging
202
- 4. **Backward Compatibility**: localStorage continues to work for development and offline scenarios
203
-
204
- ### API Endpoints
205
-
206
- - **GET** `/get-comments?branch={branch}` - Fetch all comments for a branch
207
- - **POST** `/post-comment` - Add a new comment
208
-
209
- ### Fallback Strategy
210
-
211
- ```typescript
212
- // Fetch comments with fallback
213
- try {
214
- const response = await fetch(`/get-comments?${params.toString()}`);
215
- if (response.ok) {
216
- // Use API response
217
- const data = await response.json();
218
- this.comments = this.extractCommentsFromApiResponse(data);
219
- } else {
220
- // Fallback to localStorage
221
- this.comments = await this.getCommentsFromLocalStorage();
222
- }
223
- } catch (error) {
224
- // Fallback to localStorage on network error
225
- this.comments = await this.getCommentsFromLocalStorage();
226
- }
227
- ```
228
-
229
- ### Testing API Integration
230
-
231
- Use the development tools to test API integration:
232
-
233
- ```javascript
234
- // Test API response format
235
- CommentDevHelper.testApiResponseFormat();
236
-
237
- // Simulate API call for a specific branch
238
- CommentDevHelper.simulateApiCall("main");
239
-
240
- // Check if API is available
241
- CommentDevHelper.checkApiAvailability();
242
- ```
243
-
244
- ## Testing
245
-
246
- ### Storybook Stories
247
-
248
- The component includes comprehensive Storybook stories for testing:
249
-
250
- 1. **Base**: Basic component functionality
251
- 2. **WithNewApiFormatComments**: Testing with new API format
252
- 3. **MultipleBranchesAndFiles**: Testing multiple branches and files
253
- 4. **FormValidation**: Testing form validation features
254
-
255
- ### Jest Tests
256
-
257
- Run the test suite:
258
-
259
- ```bash
260
- npm test commentPopup.test.ts
261
- ```
262
-
263
- The test suite covers:
264
-
265
- - Component initialization
266
- - Form validation
267
- - Local storage operations
268
- - API response format handling
269
- - Comment operations
270
- - UI interactions
271
- - Error handling
272
- - Lifecycle methods
273
-
274
- ## Troubleshooting
275
-
276
- ### Common Issues
277
-
278
- 1. **Comments not appearing**: Check that `heading-title`, `file-path`, and `current-branch` are set correctly
279
- 2. **Form validation errors**: Ensure email format is valid and all required fields are filled
280
- 3. **localStorage errors**: Check browser console for localStorage quota exceeded errors
281
- 4. **API integration issues**: Verify API endpoints and response format match expected structure
282
-
283
- ### Debug Commands
284
-
285
- ```javascript
286
- // Check current comments
287
- console.log(CommentDevHelper.getAllComments());
288
-
289
- // Check component state
290
- console.log(element.comments);
291
- console.log(element.email);
292
- console.log(element.comment);
293
-
294
- // Test API response parsing
295
- CommentDevHelper.testApiResponseFormat();
296
- ```
297
-
298
- ## Browser Support
299
-
300
- - Chrome 60+
301
- - Firefox 55+
302
- - Safari 12+
303
- - Edge 79+
304
-
305
- ## Dependencies
306
-
307
- - Lightning Web Components (LWC)
308
- - TypeScript
309
- - Jest (for testing)
310
-
311
- ## Contributing
312
-
313
- 1. Fork the repository
314
- 2. Create a feature branch
315
- 3. Make your changes
316
- 4. Add tests for new functionality
317
- 5. Update documentation
318
- 6. Submit a pull request
319
-
320
- ## License
321
-
322
- This component is part of the Salesforce Developer Documentation Components package.
@@ -1,380 +0,0 @@
1
- // Development Helper for Comment Management
2
- // This file provides a simple interface to manage comments during development
3
- // You can use this in the browser console or create a simple UI for it
4
-
5
- import {
6
- exportCommentsToFile,
7
- importCommentsFromFile,
8
- getAllComments,
9
- clearAllComments,
10
- getCommentsStats,
11
- convertToApiFormat,
12
- addComment,
13
- getCommentsForBranch,
14
- fetchCommentsForBranch,
15
- extractCommentsFromApiResponse
16
- } from "./commentUtils";
17
-
18
- // Make functions available globally for console access
19
- if (typeof window !== "undefined") {
20
- (window as any).CommentDevHelper = {
21
- exportCommentsToFile,
22
- importCommentsFromFile,
23
- getAllComments,
24
- clearAllComments,
25
- getCommentsStats,
26
- convertToApiFormat,
27
- addComment,
28
- getCommentsForBranch,
29
- fetchCommentsForBranch,
30
- extractCommentsFromApiResponse,
31
- checkApiAvailability
32
- };
33
- }
34
-
35
- /**
36
- * Create a simple UI for managing comments during development
37
- */
38
- export function createDevUI(): void {
39
- if (typeof document === "undefined") {
40
- return;
41
- }
42
-
43
- // Check if UI already exists
44
- if (document.getElementById("comment-dev-ui")) {
45
- return;
46
- }
47
-
48
- const ui = document.createElement("div");
49
- ui.id = "comment-dev-ui";
50
- ui.style.cssText = `
51
- position: fixed;
52
- top: 20px;
53
- right: 20px;
54
- width: 350px;
55
- background: white;
56
- border: 2px solid #007bff;
57
- border-radius: 8px;
58
- padding: 16px;
59
- font-family: Arial, sans-serif;
60
- font-size: 14px;
61
- z-index: 10000;
62
- box-shadow: 0 4px 12px rgba(0,0,0,0.15);
63
- max-height: 80vh;
64
- overflow-y: auto;
65
- `;
66
-
67
- const stats = getCommentsStats();
68
-
69
- ui.innerHTML = `
70
- <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px;">
71
- <h3 style="margin: 0; color: #007bff;">Comment Dev Helper</h3>
72
- <button onclick="document.getElementById('comment-dev-ui').remove()" style="background: none; border: none; font-size: 18px; cursor: pointer;">×</button>
73
- </div>
74
-
75
- <div style="margin-bottom: 12px;">
76
- <strong>Stats:</strong><br>
77
- Branches: ${stats.branches.length}<br>
78
- Locations: ${stats.totalLocations}<br>
79
- Total Comments: ${stats.totalComments}
80
- </div>
81
-
82
- <div style="display: flex; flex-direction: column; gap: 8px;">
83
- <button onclick="CommentDevHelper.exportCommentsToFile()" style="padding: 8px; background: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">
84
- Export Comments
85
- </button>
86
-
87
- <button onclick="CommentDevHelper.clearAllComments()" style="padding: 8px; background: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">
88
- Clear All Comments
89
- </button>
90
-
91
- <button onclick="CommentDevHelper.getCommentsStats()" style="padding: 8px; background: #17a2b8; color: white; border: none; border-radius: 4px; cursor: pointer;">
92
- Show Stats in Console
93
- </button>
94
-
95
- <button onclick="console.log(CommentDevHelper.convertToApiFormat())" style="padding: 8px; background: #6f42c1; color: white; border: none; border-radius: 4px; cursor: pointer;">
96
- Show API Format in Console
97
- </button>
98
-
99
- <button onclick="CommentDevHelper.addSampleCommentsForNewApi()" style="padding: 8px; background: #fd7e14; color: white; border: none; border-radius: 4px; cursor: pointer;">
100
- Add Sample Comments (New API Format)
101
- </button>
102
-
103
- <button onclick="CommentDevHelper.testApiResponseFormat()" style="padding: 8px; background: #20c997; color: white; border: none; border-radius: 4px; cursor: pointer;">
104
- Test API Response Format
105
- </button>
106
- </div>
107
-
108
- <div style="margin-top: 12px; font-size: 12px; color: #666;">
109
- <strong>Console Commands:</strong><br>
110
- CommentDevHelper.exportCommentsToFile()<br>
111
- CommentDevHelper.clearAllComments()<br>
112
- CommentDevHelper.getCommentsStats()<br>
113
- CommentDevHelper.convertToApiFormat()<br>
114
- CommentDevHelper.getCommentsForBranch('main')<br>
115
- CommentDevHelper.testApiResponseFormat()
116
- </div>
117
- `;
118
-
119
- document.body.appendChild(ui);
120
- }
121
-
122
- /**
123
- * Remove the development UI
124
- */
125
- export function removeDevUI(): void {
126
- const ui = document.getElementById("comment-dev-ui");
127
- if (ui) {
128
- ui.remove();
129
- }
130
- }
131
-
132
- /**
133
- * Add sample comments that match the new API format
134
- */
135
- export function addSampleCommentsForNewApi(): void {
136
- const sampleComments = [
137
- {
138
- branch: "feature/documentation-updates",
139
- file_path: "docs/installation.md",
140
- heading_title: "Installation Guide",
141
- start_line: "1",
142
- end_line: "50",
143
- comment: {
144
- comment_text:
145
- "This installation guide is very helpful for new users.",
146
- email: "john.doe@example.com",
147
- timestamp: new Date(Date.now() - 3600000).toISOString() // 1 hour ago
148
- }
149
- },
150
- {
151
- branch: "feature/documentation-updates",
152
- file_path: "docs/installation.md",
153
- heading_title: "Installation Guide",
154
- start_line: "1",
155
- end_line: "50",
156
- comment: {
157
- comment_text:
158
- "Consider adding troubleshooting section for common issues.",
159
- email: "jane.smith@example.com",
160
- timestamp: new Date(Date.now() - 1800000).toISOString() // 30 minutes ago
161
- }
162
- },
163
- {
164
- branch: "feature/documentation-updates",
165
- file_path: "docs/installation.md",
166
- heading_title: "Prerequisites",
167
- start_line: "10",
168
- end_line: "25",
169
- comment: {
170
- comment_text:
171
- "The prerequisites section is clear and well-organized.",
172
- email: "mike.wilson@example.com",
173
- timestamp: new Date(Date.now() - 900000).toISOString() // 15 minutes ago
174
- }
175
- },
176
- {
177
- branch: "feature/documentation-updates",
178
- file_path: "docs/api.md",
179
- heading_title: "API Reference",
180
- start_line: "1",
181
- end_line: "100",
182
- comment: {
183
- comment_text:
184
- "The API documentation needs more examples for authentication.",
185
- email: "sarah.jones@example.com",
186
- timestamp: new Date(Date.now() - 600000).toISOString() // 10 minutes ago
187
- }
188
- },
189
- {
190
- branch: "feature/documentation-updates",
191
- file_path: "docs/api.md",
192
- heading_title: "API Reference",
193
- start_line: "1",
194
- end_line: "100",
195
- comment: {
196
- comment_text: "Great work on the endpoint descriptions!",
197
- email: "david.brown@example.com",
198
- timestamp: new Date().toISOString() // now
199
- }
200
- },
201
- {
202
- branch: "main",
203
- file_path: "docs/getting-started.md",
204
- heading_title: "Quick Start",
205
- start_line: "1",
206
- end_line: "30",
207
- comment: {
208
- comment_text:
209
- "This quick start guide is perfect for beginners.",
210
- email: "alice.johnson@example.com",
211
- timestamp: new Date(Date.now() - 7200000).toISOString() // 2 hours ago
212
- }
213
- }
214
- ];
215
-
216
- sampleComments.forEach((comment) => {
217
- addComment(comment);
218
- });
219
-
220
- console.log("Added sample comments for new API format");
221
- console.log("Sample data includes multiple branches, files, and titles");
222
-
223
- // Refresh the page to show the new comments
224
- setTimeout(() => {
225
- window.location.reload();
226
- }, 1000);
227
- }
228
-
229
- /**
230
- * Test the API response format
231
- */
232
- export function testApiResponseFormat(): void {
233
- console.log("=== Testing API Response Format ===");
234
-
235
- // Test with feature/documentation-updates branch
236
- const featureBranchResponse = getCommentsForBranch(
237
- "feature/documentation-updates"
238
- );
239
- console.log("Feature branch response:", featureBranchResponse);
240
-
241
- // Test with main branch
242
- const mainBranchResponse = getCommentsForBranch("main");
243
- console.log("Main branch response:", mainBranchResponse);
244
-
245
- // Test extracting specific comments
246
- const installationComments = extractCommentsFromApiResponse(
247
- featureBranchResponse,
248
- "docs/installation.md",
249
- "Installation Guide"
250
- );
251
- console.log("Installation Guide comments:", installationComments);
252
-
253
- const apiComments = extractCommentsFromApiResponse(
254
- featureBranchResponse,
255
- "docs/api.md",
256
- "API Reference"
257
- );
258
- console.log("API Reference comments:", apiComments);
259
-
260
- console.log("=== API Response Format Test Complete ===");
261
- }
262
-
263
- /**
264
- * Show all comments in a formatted way in the console
265
- */
266
- export function showAllComments(): void {
267
- const allComments = getAllComments();
268
- console.log("=== ALL COMMENTS ===");
269
- console.table(allComments);
270
-
271
- const stats = getCommentsStats();
272
- console.log("=== STATISTICS ===");
273
- console.table(stats.locations);
274
-
275
- console.log("=== BRANCHES ===");
276
- console.log("Available branches:", stats.branches);
277
- }
278
-
279
- /**
280
- * Simulate API call and show response
281
- */
282
- export async function simulateApiCall(
283
- branch: string = "feature/documentation-updates"
284
- ): Promise<void> {
285
- console.log(`=== Simulating API Call for branch: ${branch} ===`);
286
-
287
- try {
288
- const response = await fetchCommentsForBranch(branch);
289
- console.log("API Response:", response);
290
-
291
- // Show all paths and titles
292
- response.paths.forEach((path) => {
293
- console.log(`File: ${path.path}`);
294
- path.titles.forEach((title) => {
295
- console.log(
296
- ` Title: ${title.title} (${title.comments.length} comments)`
297
- );
298
- });
299
- });
300
- } catch (error) {
301
- console.error("API call simulation failed:", error);
302
- }
303
- }
304
-
305
- /**
306
- * Check if the API endpoints are available
307
- */
308
- export async function checkApiAvailability(): Promise<void> {
309
- console.log("=== Checking API Availability ===");
310
-
311
- try {
312
- // Test GET endpoint
313
- const getResponse = await fetch("/get-comments?branch=test");
314
- console.log(
315
- `GET /get-comments status: ${getResponse.status} ${getResponse.statusText}`
316
- );
317
-
318
- if (getResponse.ok) {
319
- console.log("✅ GET /get-comments is available");
320
- } else {
321
- console.log("❌ GET /get-comments is not available");
322
- }
323
-
324
- // Test POST endpoint (with a test payload)
325
- const testPayload = {
326
- branch: "test",
327
- file_path: "test.md",
328
- heading_title: "Test",
329
- start_line: "1",
330
- end_line: "10",
331
- comment: {
332
- comment_text: "Test comment",
333
- email: "test@example.com",
334
- timestamp: new Date().toISOString()
335
- }
336
- };
337
-
338
- const postResponse = await fetch("/post-comment", {
339
- method: "POST",
340
- headers: {
341
- "Content-Type": "application/json"
342
- },
343
- body: JSON.stringify(testPayload)
344
- });
345
-
346
- console.log(
347
- `POST /post-comment status: ${postResponse.status} ${postResponse.statusText}`
348
- );
349
-
350
- if (postResponse.ok) {
351
- console.log("✅ POST /post-comment is available");
352
- } else {
353
- console.log("❌ POST /post-comment is not available");
354
- }
355
-
356
- console.log("=== API Availability Check Complete ===");
357
- } catch (error) {
358
- console.error("❌ API availability check failed:", error);
359
- console.log("This is expected if the backend is not running");
360
- }
361
- }
362
-
363
- // Add the helper functions to the global CommentDevHelper
364
- if (typeof window !== "undefined") {
365
- (window as any).CommentDevHelper = {
366
- ...(window as any).CommentDevHelper,
367
- addSampleCommentsForNewApi,
368
- testApiResponseFormat,
369
- showAllComments,
370
- simulateApiCall
371
- };
372
- }
373
-
374
- // Auto-create UI when this module is imported (in development)
375
- if (typeof window !== "undefined" && window.location.hostname === "localhost") {
376
- // Only auto-create in development environment
377
- setTimeout(() => {
378
- createDevUI();
379
- }, 1000);
380
- }