@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.
@@ -9,7 +9,10 @@ import {
9
9
  clearAllComments,
10
10
  getCommentsStats,
11
11
  convertToApiFormat,
12
- addComment
12
+ addComment,
13
+ getCommentsForBranch,
14
+ fetchCommentsForBranch,
15
+ extractCommentsFromApiResponse
13
16
  } from "./commentUtils";
14
17
 
15
18
  // Make functions available globally for console access
@@ -21,7 +24,11 @@ if (typeof window !== "undefined") {
21
24
  clearAllComments,
22
25
  getCommentsStats,
23
26
  convertToApiFormat,
24
- addComment
27
+ addComment,
28
+ getCommentsForBranch,
29
+ fetchCommentsForBranch,
30
+ extractCommentsFromApiResponse,
31
+ checkApiAvailability
25
32
  };
26
33
  }
27
34
 
@@ -44,7 +51,7 @@ export function createDevUI(): void {
44
51
  position: fixed;
45
52
  top: 20px;
46
53
  right: 20px;
47
- width: 300px;
54
+ width: 350px;
48
55
  background: white;
49
56
  border: 2px solid #007bff;
50
57
  border-radius: 8px;
@@ -53,6 +60,8 @@ export function createDevUI(): void {
53
60
  font-size: 14px;
54
61
  z-index: 10000;
55
62
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
63
+ max-height: 80vh;
64
+ overflow-y: auto;
56
65
  `;
57
66
 
58
67
  const stats = getCommentsStats();
@@ -65,6 +74,7 @@ export function createDevUI(): void {
65
74
 
66
75
  <div style="margin-bottom: 12px;">
67
76
  <strong>Stats:</strong><br>
77
+ Branches: ${stats.branches.length}<br>
68
78
  Locations: ${stats.totalLocations}<br>
69
79
  Total Comments: ${stats.totalComments}
70
80
  </div>
@@ -85,6 +95,14 @@ export function createDevUI(): void {
85
95
  <button onclick="console.log(CommentDevHelper.convertToApiFormat())" style="padding: 8px; background: #6f42c1; color: white; border: none; border-radius: 4px; cursor: pointer;">
86
96
  Show API Format in Console
87
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>
88
106
  </div>
89
107
 
90
108
  <div style="margin-top: 12px; font-size: 12px; color: #666;">
@@ -92,7 +110,9 @@ export function createDevUI(): void {
92
110
  CommentDevHelper.exportCommentsToFile()<br>
93
111
  CommentDevHelper.clearAllComments()<br>
94
112
  CommentDevHelper.getCommentsStats()<br>
95
- CommentDevHelper.convertToApiFormat()
113
+ CommentDevHelper.convertToApiFormat()<br>
114
+ CommentDevHelper.getCommentsForBranch('main')<br>
115
+ CommentDevHelper.testApiResponseFormat()
96
116
  </div>
97
117
  `;
98
118
 
@@ -110,24 +130,134 @@ export function removeDevUI(): void {
110
130
  }
111
131
 
112
132
  /**
113
- * Add a sample comment for testing
133
+ * Add sample comments that match the new API format
114
134
  */
115
- export function addSampleComment(): void {
116
- const samplePayload = {
117
- branch: "feature/documentation-updates",
118
- file_path: "docs/installation.md",
119
- heading_title: "Installation Guide",
120
- start_line: "10",
121
- end_line: "25",
122
- comment: {
123
- comment_text: "This is a sample comment for testing purposes.",
124
- email: "test@example.com",
125
- timestamp: new Date().toISOString()
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
+ }
126
213
  }
127
- };
214
+ ];
215
+
216
+ sampleComments.forEach((comment) => {
217
+ addComment(comment);
218
+ });
128
219
 
129
- addComment(samplePayload);
130
- console.log("Sample comment added:", samplePayload);
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 ===");
131
261
  }
132
262
 
133
263
  /**
@@ -141,6 +271,104 @@ export function showAllComments(): void {
141
271
  const stats = getCommentsStats();
142
272
  console.log("=== STATISTICS ===");
143
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
+ };
144
372
  }
145
373
 
146
374
  // Auto-create UI when this module is imported (in development)