@salesforcedevs/docs-components 1.17.0-hack-alpha4 → 1.17.0-hack-alpha6

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