@salesforcedevs/docs-components 1.17.0-hack-alpha5 → 1.17.0-hack-alpha7

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-alpha5",
3
+ "version": "1.17.0-hack-alpha7",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -1,71 +1,180 @@
1
- # Comment Popup Component - Local Storage Implementation
1
+ # Comment Popup Component
2
2
 
3
- This component provides a commenting system that uses browser localStorage for data persistence while the backend API is being developed.
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
4
 
5
5
  ## Features
6
6
 
7
- - ✅ **Local Storage**: Comments are stored in browser localStorage
8
- - ✅ **API-Ready**: Code structure prepared for backend integration
9
- - ✅ **Development Tools**: Helper utilities for managing comments
10
- - ✅ **Export/Import**: Ability to export comments to JSON files
11
- - ✅ **Migration Ready**: Tools to convert data for backend migration
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
12
21
 
13
- ## How It Works
22
+ ## API Format
14
23
 
15
- ### Storage Structure
24
+ The component now supports a new API format where comments are fetched by branch and then filtered by file path and heading title.
16
25
 
17
- Comments are stored in localStorage under the key `dsc_comments` with the following structure:
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
18
32
 
19
33
  ```json
20
34
  {
21
- "branch_filepath_headingtitle": [
35
+ "request_branch": "feature/documentation-updates",
36
+ "paths": [
22
37
  {
23
- "email": "user@example.com",
24
- "comment_text": "This is a comment",
25
- "timestamp": "2024-01-15T10:30:00Z"
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
+ ]
26
51
  }
27
52
  ]
28
53
  }
29
54
  ```
30
55
 
31
- ### API Payload Format
32
-
33
- When posting comments, the component uses this exact format (ready for backend):
56
+ ### API Request Format
34
57
 
35
58
  ```json
36
59
  {
37
60
  "branch": "feature/documentation-updates",
38
61
  "file_path": "docs/installation.md",
39
62
  "heading_title": "Installation Guide",
63
+ "start_line": "1",
64
+ "end_line": "50",
40
65
  "comment": {
41
- "comment_text": "This installation guide is very helpful for new users.",
42
- "email": "john.doe@example.com",
66
+ "comment_text": "This is a helpful comment.",
67
+ "email": "user@example.com",
43
68
  "timestamp": "2024-01-15T10:30:00Z"
44
69
  }
45
70
  }
46
71
  ```
47
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
+
48
154
  ## Development Tools
49
155
 
50
- ### Console Commands
156
+ The component includes development tools for testing and managing comments during development.
51
157
 
52
- When the component is loaded, you can access these functions in the browser console:
158
+ ### Console Commands
53
159
 
54
160
  ```javascript
55
161
  // Export all comments to a JSON file
56
162
  CommentDevHelper.exportCommentsToFile();
57
163
 
58
- // Clear all comments from localStorage
59
- CommentDevHelper.clearAllComments();
164
+ // Add sample comments matching the new API format
165
+ CommentDevHelper.addSampleCommentsForNewApi();
60
166
 
61
167
  // Get statistics about stored comments
62
168
  CommentDevHelper.getCommentsStats();
63
169
 
64
- // Convert comments to API format (for backend migration)
65
- CommentDevHelper.convertToApiFormat();
170
+ // Clear all comments from localStorage
171
+ CommentDevHelper.clearAllComments();
172
+
173
+ // Test the API response format
174
+ CommentDevHelper.testApiResponseFormat();
66
175
 
67
- // Add a sample comment for testing
68
- CommentDevHelper.addSampleComment();
176
+ // Simulate API call for a specific branch
177
+ CommentDevHelper.simulateApiCall("main");
69
178
 
70
179
  // Show all comments in console
71
180
  CommentDevHelper.showAllComments();
@@ -73,140 +182,141 @@ CommentDevHelper.showAllComments();
73
182
 
74
183
  ### Development UI
75
184
 
76
- In development mode (localhost), a floating UI will appear in the top-right corner with buttons to:
185
+ The component automatically creates a development UI when running on localhost. This UI provides buttons for:
77
186
 
78
- - Export comments
79
- - Clear all comments
80
- - View statistics
81
- - Show API format
187
+ - Adding sample comments
188
+ - Testing API response format
189
+ - Exporting comments
190
+ - Clearing all comments
191
+ - Viewing statistics
82
192
 
83
- ## Migration to Backend
193
+ ## API Integration Status
84
194
 
85
- When the backend is ready, follow these steps:
195
+ The component now actively tries to use the backend API with localStorage as a fallback:
86
196
 
87
- ### 1. Export Current Comments
197
+ ### Current Behavior
88
198
 
89
- ```javascript
90
- // Export all comments to JSON file
91
- CommentDevHelper.exportCommentsToFile();
92
- ```
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
93
203
 
94
- ### 2. Convert to API Format
204
+ ### API Endpoints
95
205
 
96
- ```javascript
97
- // Get comments in API format
98
- const apiFormat = CommentDevHelper.convertToApiFormat();
99
- console.log(apiFormat);
100
- ```
101
-
102
- ### 3. Uncomment API Code
206
+ - **GET** `/get-comments?branch={branch}` - Fetch all comments for a branch
207
+ - **POST** `/post-comment` - Add a new comment
103
208
 
104
- In `commentPopup.ts`, uncomment the API implementation sections:
209
+ ### Fallback Strategy
105
210
 
106
211
  ```typescript
107
- // Remove the localStorage implementation and uncomment:
108
- /*
109
- const response = await fetch('/post-comment', {
110
- method: 'POST',
111
- headers: {
112
- 'Content-Type': 'application/json'
113
- },
114
- body: JSON.stringify(payload)
115
- });
116
- */
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
+ }
117
227
  ```
118
228
 
119
- ### 4. Update Endpoints
229
+ ### Testing API Integration
120
230
 
121
- Update the API endpoints in the component:
231
+ Use the development tools to test API integration:
122
232
 
123
- - POST: `/post-comment` (for adding comments)
124
- - GET: `/api/comments` (for fetching comments)
233
+ ```javascript
234
+ // Test API response format
235
+ CommentDevHelper.testApiResponseFormat();
125
236
 
126
- ## File Structure
237
+ // Simulate API call for a specific branch
238
+ CommentDevHelper.simulateApiCall("main");
127
239
 
128
- ```
129
- commentPopup/
130
- ├── commentPopup.ts # Main component
131
- ├── commentPopup.html # Template
132
- ├── commentPopup.css # Styles
133
- ├── commentUtils.ts # Utility functions
134
- ├── commentDevHelper.ts # Development tools
135
- └── README.md # This file
240
+ // Check if API is available
241
+ CommentDevHelper.checkApiAvailability();
136
242
  ```
137
243
 
138
- ## Usage
244
+ ## Testing
139
245
 
140
- ### Basic Usage
246
+ ### Storybook Stories
141
247
 
142
- ```html
143
- <c-comment-popup
144
- heading-title="Installation Guide"
145
- file-path="docs/installation.md"
146
- current-branch="main"
147
- >
148
- </c-comment-popup>
149
- ```
248
+ The component includes comprehensive Storybook stories for testing:
150
249
 
151
- ### Required Properties
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
152
254
 
153
- - `heading-title`: The title of the section being commented on
154
- - `file-path`: The file path where the comment is located
155
- - `current-branch`: The current git branch
255
+ ### Jest Tests
156
256
 
157
- ### Optional Properties
257
+ Run the test suite:
158
258
 
159
- - `start-line`: Starting line number (for future line-specific comments)
160
- - `end-line`: Ending line number (for future line-specific comments)
161
- - `open`: Boolean to control popup visibility
259
+ ```bash
260
+ npm test commentPopup.test.ts
261
+ ```
162
262
 
163
- ## Events
263
+ The test suite covers:
164
264
 
165
- The component dispatches these events:
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
166
273
 
167
- ```javascript
168
- // When a comment is added
169
- element.addEventListener("commentadded", (event) => {
170
- console.log("New comment:", event.detail);
171
- });
172
- ```
274
+ ## Troubleshooting
173
275
 
174
- ## Browser Compatibility
276
+ ### Common Issues
175
277
 
176
- - Modern browsers with localStorage support
177
- - IE10+ (with polyfills if needed)
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
178
282
 
179
- ## Storage Limits
283
+ ### Debug Commands
180
284
 
181
- - localStorage typically has a 5-10MB limit
182
- - Comments are stored as JSON strings
183
- - Monitor storage usage with `CommentDevHelper.getCommentsStats()`
285
+ ```javascript
286
+ // Check current comments
287
+ console.log(CommentDevHelper.getAllComments());
184
288
 
185
- ## Troubleshooting
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
+ ```
186
297
 
187
- ### Comments Not Appearing
298
+ ## Browser Support
188
299
 
189
- 1. Check browser console for errors
190
- 2. Verify localStorage is enabled
191
- 3. Check if the comment key matches: `branch_filepath_headingtitle`
300
+ - Chrome 60+
301
+ - Firefox 55+
302
+ - Safari 12+
303
+ - Edge 79+
192
304
 
193
- ### Storage Issues
305
+ ## Dependencies
194
306
 
195
- 1. Clear localStorage: `CommentDevHelper.clearAllComments()`
196
- 2. Export existing comments before clearing
197
- 3. Check browser storage limits
307
+ - Lightning Web Components (LWC)
308
+ - TypeScript
309
+ - Jest (for testing)
198
310
 
199
- ### Development UI Not Showing
311
+ ## Contributing
200
312
 
201
- 1. Ensure you're on localhost
202
- 2. Check if the UI was manually closed
203
- 3. Refresh the page to recreate the UI
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
204
319
 
205
- ## Future Enhancements
320
+ ## License
206
321
 
207
- - [ ] Line-specific comments
208
- - [ ] Comment threading/replies
209
- - [ ] Comment moderation
210
- - [ ] User authentication integration
211
- - [ ] Real-time comment updates
212
- - [ ] Comment search and filtering
322
+ This component is part of the Salesforce Developer Documentation Components package.