@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,71 +1,180 @@
|
|
|
1
|
-
# Comment Popup Component
|
|
1
|
+
# Comment Popup Component
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
- ✅ **
|
|
8
|
-
- ✅ **
|
|
9
|
-
- ✅ **
|
|
10
|
-
- ✅ **
|
|
11
|
-
- ✅ **
|
|
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
|
-
##
|
|
22
|
+
## API Format
|
|
14
23
|
|
|
15
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
35
|
+
"request_branch": "feature/documentation-updates",
|
|
36
|
+
"paths": [
|
|
22
37
|
{
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
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
|
|
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
|
|
42
|
-
"email": "
|
|
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
|
-
|
|
156
|
+
The component includes development tools for testing and managing comments during development.
|
|
51
157
|
|
|
52
|
-
|
|
158
|
+
### Console Commands
|
|
53
159
|
|
|
54
160
|
```javascript
|
|
55
161
|
// Export all comments to a JSON file
|
|
56
162
|
CommentDevHelper.exportCommentsToFile();
|
|
57
163
|
|
|
58
|
-
//
|
|
59
|
-
CommentDevHelper.
|
|
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
|
-
//
|
|
65
|
-
CommentDevHelper.
|
|
170
|
+
// Clear all comments from localStorage
|
|
171
|
+
CommentDevHelper.clearAllComments();
|
|
172
|
+
|
|
173
|
+
// Test the API response format
|
|
174
|
+
CommentDevHelper.testApiResponseFormat();
|
|
66
175
|
|
|
67
|
-
//
|
|
68
|
-
CommentDevHelper.
|
|
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
|
-
|
|
185
|
+
The component automatically creates a development UI when running on localhost. This UI provides buttons for:
|
|
77
186
|
|
|
78
|
-
-
|
|
79
|
-
-
|
|
80
|
-
-
|
|
81
|
-
-
|
|
187
|
+
- Adding sample comments
|
|
188
|
+
- Testing API response format
|
|
189
|
+
- Exporting comments
|
|
190
|
+
- Clearing all comments
|
|
191
|
+
- Viewing statistics
|
|
82
192
|
|
|
83
|
-
##
|
|
193
|
+
## API Integration Status
|
|
84
194
|
|
|
85
|
-
|
|
195
|
+
The component now actively tries to use the backend API with localStorage as a fallback:
|
|
86
196
|
|
|
87
|
-
###
|
|
197
|
+
### Current Behavior
|
|
88
198
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
###
|
|
204
|
+
### API Endpoints
|
|
95
205
|
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
209
|
+
### Fallback Strategy
|
|
105
210
|
|
|
106
211
|
```typescript
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
const response = await fetch(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
###
|
|
229
|
+
### Testing API Integration
|
|
120
230
|
|
|
121
|
-
|
|
231
|
+
Use the development tools to test API integration:
|
|
122
232
|
|
|
123
|
-
|
|
124
|
-
|
|
233
|
+
```javascript
|
|
234
|
+
// Test API response format
|
|
235
|
+
CommentDevHelper.testApiResponseFormat();
|
|
125
236
|
|
|
126
|
-
|
|
237
|
+
// Simulate API call for a specific branch
|
|
238
|
+
CommentDevHelper.simulateApiCall("main");
|
|
127
239
|
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
##
|
|
244
|
+
## Testing
|
|
139
245
|
|
|
140
|
-
###
|
|
246
|
+
### Storybook Stories
|
|
141
247
|
|
|
142
|
-
|
|
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
|
-
|
|
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
|
-
|
|
154
|
-
- `file-path`: The file path where the comment is located
|
|
155
|
-
- `current-branch`: The current git branch
|
|
255
|
+
### Jest Tests
|
|
156
256
|
|
|
157
|
-
|
|
257
|
+
Run the test suite:
|
|
158
258
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
259
|
+
```bash
|
|
260
|
+
npm test commentPopup.test.ts
|
|
261
|
+
```
|
|
162
262
|
|
|
163
|
-
|
|
263
|
+
The test suite covers:
|
|
164
264
|
|
|
165
|
-
|
|
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
|
-
|
|
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
|
-
|
|
276
|
+
### Common Issues
|
|
175
277
|
|
|
176
|
-
-
|
|
177
|
-
|
|
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
|
-
|
|
283
|
+
### Debug Commands
|
|
180
284
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
285
|
+
```javascript
|
|
286
|
+
// Check current comments
|
|
287
|
+
console.log(CommentDevHelper.getAllComments());
|
|
184
288
|
|
|
185
|
-
|
|
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
|
-
|
|
298
|
+
## Browser Support
|
|
188
299
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
300
|
+
- Chrome 60+
|
|
301
|
+
- Firefox 55+
|
|
302
|
+
- Safari 12+
|
|
303
|
+
- Edge 79+
|
|
192
304
|
|
|
193
|
-
|
|
305
|
+
## Dependencies
|
|
194
306
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
307
|
+
- Lightning Web Components (LWC)
|
|
308
|
+
- TypeScript
|
|
309
|
+
- Jest (for testing)
|
|
198
310
|
|
|
199
|
-
|
|
311
|
+
## Contributing
|
|
200
312
|
|
|
201
|
-
1.
|
|
202
|
-
2.
|
|
203
|
-
3.
|
|
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
|
-
##
|
|
320
|
+
## License
|
|
206
321
|
|
|
207
|
-
|
|
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.
|