context_drop 0.3.0 → 0.3.2
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.
- checksums.yaml +4 -4
- data/app/assets/javascripts/context_drop/context_drop.js +488 -11
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +87 -6
- data/app/controllers/context_drop/feedbacks_controller.rb +172 -19
- data/app/helpers/context_drop/dashboard_helper.rb +23 -0
- data/app/javascript/context_drop/api-client.ts +37 -0
- data/app/javascript/context_drop/icons.ts +2 -0
- data/app/javascript/context_drop/styles.ts +130 -0
- data/app/javascript/context_drop/types.ts +48 -3
- data/app/javascript/context_drop/widget.ts +325 -11
- data/app/models/context_drop/attachment.rb +5 -0
- data/app/models/context_drop/comment.rb +50 -0
- data/app/models/context_drop/feedback.rb +19 -6
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +115 -89
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +176 -18
- data/app/views/layouts/context_drop/application.html.erb +431 -118
- data/config/routes.rb +5 -1
- data/db/migrate/20261116000001_create_context_drop_comments_and_update_statuses.rb +44 -0
- data/lib/context_drop/agent/orchestrator.rb +1 -1
- data/lib/context_drop/mcp/dispatcher.rb +2 -1
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +2 -2
- data/lib/context_drop/mcp/server.rb +1 -0
- data/lib/context_drop/mcp/tools/add_feedback_comment.rb +139 -0
- data/lib/context_drop/mcp/tools/get_feedback.rb +29 -1
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +1 -1
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +2 -2
- data/lib/context_drop/version.rb +1 -1
- metadata +5 -2
|
@@ -79,6 +79,16 @@ export interface SessionFeedbackAttachmentItem {
|
|
|
79
79
|
metadata?: Record<string, unknown>;
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
+
export interface SessionFeedbackCommentItem {
|
|
83
|
+
id: number | string;
|
|
84
|
+
author_label: string;
|
|
85
|
+
author_type?: string | null;
|
|
86
|
+
body: string | null;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
rawCreatedAt?: string;
|
|
89
|
+
attachments: SessionFeedbackAttachmentItem[];
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
export interface SessionFeedbackEntry {
|
|
83
93
|
id: number | string;
|
|
84
94
|
message: string;
|
|
@@ -91,6 +101,7 @@ export interface SessionFeedbackEntry {
|
|
|
91
101
|
ownershipToken?: string;
|
|
92
102
|
elements: ElementReferenceSnapshot[];
|
|
93
103
|
attachments: SessionFeedbackAttachmentItem[];
|
|
104
|
+
comments?: SessionFeedbackCommentItem[];
|
|
94
105
|
}
|
|
95
106
|
|
|
96
107
|
export interface ContextDropApiClientOptions {
|
|
@@ -153,6 +164,17 @@ export interface OwnFeedbackAttachment {
|
|
|
153
164
|
created_at?: string;
|
|
154
165
|
}
|
|
155
166
|
|
|
167
|
+
export interface FeedbackCommentRecord {
|
|
168
|
+
id: number | string;
|
|
169
|
+
feedback_id?: number | string;
|
|
170
|
+
author_label: string;
|
|
171
|
+
author_type?: string | null;
|
|
172
|
+
body: string | null;
|
|
173
|
+
attachments: OwnFeedbackAttachment[];
|
|
174
|
+
created_at: string;
|
|
175
|
+
updated_at?: string;
|
|
176
|
+
}
|
|
177
|
+
|
|
156
178
|
export interface OwnFeedbackRecord {
|
|
157
179
|
id: number;
|
|
158
180
|
environment?: string;
|
|
@@ -164,6 +186,8 @@ export interface OwnFeedbackRecord {
|
|
|
164
186
|
element_references_count: number;
|
|
165
187
|
element_references: ElementReferenceSnapshot[];
|
|
166
188
|
attachments: OwnFeedbackAttachment[];
|
|
189
|
+
comments_count?: number;
|
|
190
|
+
comments?: FeedbackCommentRecord[];
|
|
167
191
|
created_at: string;
|
|
168
192
|
updated_at: string;
|
|
169
193
|
ownership_token?: string;
|
|
@@ -185,10 +209,31 @@ export interface FeedbackAttachmentUpdateInput {
|
|
|
185
209
|
}
|
|
186
210
|
|
|
187
211
|
export interface FeedbackUpdatePayload {
|
|
188
|
-
message
|
|
212
|
+
message?: string;
|
|
213
|
+
status?: string;
|
|
189
214
|
metadata?: Record<string, unknown>;
|
|
190
|
-
element_references
|
|
191
|
-
attachments
|
|
215
|
+
element_references?: ElementReferenceSnapshot[];
|
|
216
|
+
attachments?: FeedbackAttachmentUpdateInput[];
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface CreateCommentPayload {
|
|
220
|
+
body: string;
|
|
221
|
+
attachments: Array<{
|
|
222
|
+
attachment_type: "image" | "screenshot";
|
|
223
|
+
filename: string;
|
|
224
|
+
signed_blob_id?: string;
|
|
225
|
+
data_url?: string;
|
|
226
|
+
metadata: Record<string, unknown>;
|
|
227
|
+
}>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface CreateCommentResponse {
|
|
231
|
+
id: number | string;
|
|
232
|
+
feedback_id: number | string;
|
|
233
|
+
status: string;
|
|
234
|
+
comment: FeedbackCommentRecord;
|
|
235
|
+
feedback?: OwnFeedbackRecord;
|
|
236
|
+
created_at: string;
|
|
192
237
|
}
|
|
193
238
|
|
|
194
239
|
export interface FeedbackUpdateResponse {
|
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
AgentProviderInfo,
|
|
4
4
|
AgentStatusResponse,
|
|
5
5
|
ContextDropApiClientOptions,
|
|
6
|
+
CreateCommentPayload,
|
|
6
7
|
CrossEnvFeedbackItem,
|
|
7
8
|
ElementReferenceSnapshot,
|
|
8
9
|
FeedbackSubmissionPayload,
|
|
@@ -12,6 +13,7 @@ import type {
|
|
|
12
13
|
ProposedFileEdit,
|
|
13
14
|
SelectionMode,
|
|
14
15
|
SessionFeedbackAttachmentItem,
|
|
16
|
+
SessionFeedbackCommentItem,
|
|
15
17
|
SessionFeedbackEntry,
|
|
16
18
|
WidgetConfig,
|
|
17
19
|
WidgetPosition,
|
|
@@ -26,6 +28,7 @@ import {
|
|
|
26
28
|
ICON_CHEVRON_UP,
|
|
27
29
|
ICON_CLOSE,
|
|
28
30
|
ICON_CODE_PROMPT,
|
|
31
|
+
ICON_COMMENT,
|
|
29
32
|
ICON_EDIT,
|
|
30
33
|
ICON_EXPAND,
|
|
31
34
|
ICON_FILE_CODE,
|
|
@@ -195,6 +198,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
195
198
|
private ownFeedbacksLoaded: boolean = false;
|
|
196
199
|
private inFlightOwnFeedbacksPromise: Promise<SessionFeedbackEntry[]> | null = null;
|
|
197
200
|
private editingFeedbackId: string | null = null;
|
|
201
|
+
private commentingFeedbackId: string | null = null;
|
|
202
|
+
private reviewingFeedbackId: string | null = null;
|
|
198
203
|
private confirmingDeleteId: string | null = null;
|
|
199
204
|
private deletingFeedbackId: string | null = null;
|
|
200
205
|
private stashedDraftBeforeEdit: {
|
|
@@ -693,6 +698,30 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
693
698
|
? structuredClone(existingEntry.elements)
|
|
694
699
|
: [];
|
|
695
700
|
|
|
701
|
+
const mappedComments: SessionFeedbackCommentItem[] = Array.isArray(record.comments)
|
|
702
|
+
? record.comments.map((c) => ({
|
|
703
|
+
id: c.id,
|
|
704
|
+
author_label: c.author_label || "You",
|
|
705
|
+
author_type: c.author_type ?? null,
|
|
706
|
+
body: c.body ?? null,
|
|
707
|
+
createdAt: this.formatTimestampLabel(c.created_at),
|
|
708
|
+
rawCreatedAt: c.created_at,
|
|
709
|
+
attachments: Array.isArray(c.attachments)
|
|
710
|
+
? c.attachments.map((att) => ({
|
|
711
|
+
id: `srv-catt-${att.id}`,
|
|
712
|
+
server_id: att.id,
|
|
713
|
+
label: att.filename || "image.png",
|
|
714
|
+
preview_url: this.apiClient.buildAttachmentPreviewUrl(record.id, att.id, token),
|
|
715
|
+
attachment_type: att.attachment_type || "image",
|
|
716
|
+
filename: att.filename,
|
|
717
|
+
metadata: att.metadata || {}
|
|
718
|
+
}))
|
|
719
|
+
: []
|
|
720
|
+
}))
|
|
721
|
+
: existingEntry?.comments
|
|
722
|
+
? structuredClone(existingEntry.comments)
|
|
723
|
+
: [];
|
|
724
|
+
|
|
696
725
|
return {
|
|
697
726
|
id: record.id,
|
|
698
727
|
message: displayMessage,
|
|
@@ -704,7 +733,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
704
733
|
status: record.status,
|
|
705
734
|
ownershipToken: token,
|
|
706
735
|
elements,
|
|
707
|
-
attachments: mappedAttachments
|
|
736
|
+
attachments: mappedAttachments,
|
|
737
|
+
comments: mappedComments
|
|
708
738
|
};
|
|
709
739
|
}
|
|
710
740
|
|
|
@@ -771,10 +801,13 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
771
801
|
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
772
802
|
if (!entry) return false;
|
|
773
803
|
|
|
804
|
+
if (this.commentingFeedbackId !== null) {
|
|
805
|
+
this.cancelCommentingFeedback();
|
|
806
|
+
}
|
|
774
807
|
this.confirmingDeleteId = null;
|
|
775
808
|
this.hideStatus();
|
|
776
809
|
|
|
777
|
-
if (this.editingFeedbackId === null) {
|
|
810
|
+
if (this.editingFeedbackId === null && this.commentingFeedbackId === null) {
|
|
778
811
|
this.stashedDraftBeforeEdit = {
|
|
779
812
|
message: this.textareaEl?.value || "",
|
|
780
813
|
elementReferences: [...this.elementReferences],
|
|
@@ -854,6 +887,100 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
854
887
|
this.syncUiStates();
|
|
855
888
|
}
|
|
856
889
|
|
|
890
|
+
public startCommentingFeedback(feedbackId: number | string): boolean {
|
|
891
|
+
const targetKey = String(feedbackId);
|
|
892
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
893
|
+
if (!entry) return false;
|
|
894
|
+
|
|
895
|
+
if (this.editingFeedbackId !== null) {
|
|
896
|
+
this.cancelEditingFeedback();
|
|
897
|
+
}
|
|
898
|
+
this.confirmingDeleteId = null;
|
|
899
|
+
this.hideStatus();
|
|
900
|
+
|
|
901
|
+
if (this.commentingFeedbackId === null && this.editingFeedbackId === null) {
|
|
902
|
+
this.stashedDraftBeforeEdit = {
|
|
903
|
+
message: this.textareaEl?.value || "",
|
|
904
|
+
elementReferences: [...this.elementReferences],
|
|
905
|
+
elementDomNodes: new Map(this.elementDomNodes),
|
|
906
|
+
attachments: [...this.attachments]
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
this.commentingFeedbackId = targetKey;
|
|
911
|
+
if (this.textareaEl) {
|
|
912
|
+
this.textareaEl.value = "";
|
|
913
|
+
}
|
|
914
|
+
this.elementReferences = [];
|
|
915
|
+
this.elementDomNodes.clear();
|
|
916
|
+
this.attachments = [];
|
|
917
|
+
|
|
918
|
+
this.picker?.hideExternalPreview();
|
|
919
|
+
this.picker?.refreshPinnedMarkers();
|
|
920
|
+
this.renderTray();
|
|
921
|
+
this.renderChatThread();
|
|
922
|
+
this.syncUiStates();
|
|
923
|
+
this.textareaEl?.focus();
|
|
924
|
+
return true;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
public cancelCommentingFeedback(): void {
|
|
928
|
+
if (this.commentingFeedbackId === null) return;
|
|
929
|
+
this.commentingFeedbackId = null;
|
|
930
|
+
|
|
931
|
+
if (this.stashedDraftBeforeEdit) {
|
|
932
|
+
if (this.textareaEl) {
|
|
933
|
+
this.textareaEl.value = this.stashedDraftBeforeEdit.message;
|
|
934
|
+
}
|
|
935
|
+
this.elementReferences = this.stashedDraftBeforeEdit.elementReferences;
|
|
936
|
+
this.elementDomNodes = this.stashedDraftBeforeEdit.elementDomNodes;
|
|
937
|
+
this.attachments = this.stashedDraftBeforeEdit.attachments;
|
|
938
|
+
this.stashedDraftBeforeEdit = null;
|
|
939
|
+
} else {
|
|
940
|
+
if (this.textareaEl) {
|
|
941
|
+
this.textareaEl.value = "";
|
|
942
|
+
}
|
|
943
|
+
this.elementReferences = [];
|
|
944
|
+
this.elementDomNodes.clear();
|
|
945
|
+
this.attachments = [];
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
this.renderTray();
|
|
949
|
+
this.renderChatThread();
|
|
950
|
+
this.syncUiStates();
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
public async markFeedbackReviewed(feedbackId: number | string): Promise<void> {
|
|
954
|
+
if (this.reviewingFeedbackId !== null || this.isSubmitting) return;
|
|
955
|
+
const targetKey = String(feedbackId);
|
|
956
|
+
const entry = this.sessionHistory.find((item) => String(item.id) === targetKey);
|
|
957
|
+
if (!entry) return;
|
|
958
|
+
|
|
959
|
+
this.reviewingFeedbackId = targetKey;
|
|
960
|
+
this.renderChatThread();
|
|
961
|
+
|
|
962
|
+
try {
|
|
963
|
+
const res = await this.apiClient.updateFeedback(
|
|
964
|
+
entry.id,
|
|
965
|
+
{ status: "reviewed" },
|
|
966
|
+
entry.ownershipToken
|
|
967
|
+
);
|
|
968
|
+
entry.status = res?.status || "reviewed";
|
|
969
|
+
if (res?.ownership_token) {
|
|
970
|
+
entry.ownershipToken = res.ownership_token;
|
|
971
|
+
}
|
|
972
|
+
this.reviewingFeedbackId = null;
|
|
973
|
+
this.renderChatThread();
|
|
974
|
+
this.showStatus("Fix marked as reviewed.", "success");
|
|
975
|
+
this.emitWidgetEvent("context-drop:update", { response: res, id: entry.id });
|
|
976
|
+
} catch (err) {
|
|
977
|
+
this.reviewingFeedbackId = null;
|
|
978
|
+
this.renderChatThread();
|
|
979
|
+
const msg = err instanceof Error ? err.message : "Failed to mark feedback as reviewed.";
|
|
980
|
+
this.showStatus(msg, "error");
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
|
|
857
984
|
public requestDeleteFeedback(feedbackId: number | string): void {
|
|
858
985
|
const targetKey = String(feedbackId);
|
|
859
986
|
if (!this.sessionHistory.some((item) => String(item.id) === targetKey)) return;
|
|
@@ -1976,7 +2103,11 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1976
2103
|
cancelEditBtn.setAttribute("aria-label", "Cancel editing feedback");
|
|
1977
2104
|
cancelEditBtn.textContent = "Cancel";
|
|
1978
2105
|
cancelEditBtn.addEventListener("click", () => {
|
|
1979
|
-
this.
|
|
2106
|
+
if (this.commentingFeedbackId !== null) {
|
|
2107
|
+
this.cancelCommentingFeedback();
|
|
2108
|
+
} else {
|
|
2109
|
+
this.cancelEditingFeedback();
|
|
2110
|
+
}
|
|
1980
2111
|
});
|
|
1981
2112
|
editBanner.appendChild(cancelEditBtn);
|
|
1982
2113
|
this.editBannerEl = editBanner;
|
|
@@ -1995,6 +2126,8 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
1995
2126
|
ev.preventDefault();
|
|
1996
2127
|
if (this.confirmingDeleteId !== null) {
|
|
1997
2128
|
this.cancelDeleteFeedback();
|
|
2129
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
2130
|
+
this.cancelCommentingFeedback();
|
|
1998
2131
|
} else if (this.editingFeedbackId !== null) {
|
|
1999
2132
|
this.cancelEditingFeedback();
|
|
2000
2133
|
} else {
|
|
@@ -3254,12 +3387,21 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3254
3387
|
if (this.composerModeSwitchWrap) {
|
|
3255
3388
|
this.composerModeSwitchWrap.hidden = !this.config.agent?.enabled;
|
|
3256
3389
|
}
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3390
|
+
const isCommenting = this.commentingFeedbackId !== null;
|
|
3391
|
+
if (this.textareaEl) {
|
|
3392
|
+
if (isCommenting) {
|
|
3393
|
+
this.textareaEl.placeholder = "Write a comment... (attach or paste images below)";
|
|
3394
|
+
} else if (!this.customPlaceholderSet) {
|
|
3395
|
+
this.textareaEl.placeholder = smartMode
|
|
3396
|
+
? DEFAULT_SMART_PLACEHOLDER
|
|
3397
|
+
: DEFAULT_VERBOSE_PLACEHOLDER;
|
|
3398
|
+
}
|
|
3399
|
+
}
|
|
3400
|
+
if (this.cornerPinBtn) {
|
|
3401
|
+
this.cornerPinBtn.hidden = isCommenting;
|
|
3261
3402
|
}
|
|
3262
3403
|
if (this.composerToolbarPickBtn) {
|
|
3404
|
+
this.composerToolbarPickBtn.hidden = isCommenting;
|
|
3263
3405
|
if (smartMode) {
|
|
3264
3406
|
this.composerToolbarPickBtn.title = "Highlight an area on the page";
|
|
3265
3407
|
this.composerToolbarPickBtn.setAttribute("aria-label", "Highlight an area on the page");
|
|
@@ -3274,7 +3416,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3274
3416
|
}
|
|
3275
3417
|
}
|
|
3276
3418
|
if (this.composerToolbarScreenshotBtn) {
|
|
3277
|
-
this.composerToolbarScreenshotBtn.hidden = smartMode;
|
|
3419
|
+
this.composerToolbarScreenshotBtn.hidden = smartMode && !isCommenting;
|
|
3278
3420
|
}
|
|
3279
3421
|
if (this.composerToolbarUploadBtn) {
|
|
3280
3422
|
this.composerToolbarUploadBtn.innerHTML = smartMode
|
|
@@ -3297,6 +3439,21 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3297
3439
|
idSpan.textContent = `#${this.editingFeedbackId}`;
|
|
3298
3440
|
this.editBannerInfoEl.appendChild(idSpan);
|
|
3299
3441
|
}
|
|
3442
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
3443
|
+
this.editBannerEl.hidden = false;
|
|
3444
|
+
this.editBannerInfoEl.innerHTML = "";
|
|
3445
|
+
const iconSpan = document.createElement("span");
|
|
3446
|
+
iconSpan.innerHTML = ICON_COMMENT;
|
|
3447
|
+
const labelSpan = document.createElement("span");
|
|
3448
|
+
labelSpan.textContent = smartMode ? "Commenting on feedback" : "Commenting on";
|
|
3449
|
+
this.editBannerInfoEl.appendChild(iconSpan);
|
|
3450
|
+
this.editBannerInfoEl.appendChild(labelSpan);
|
|
3451
|
+
if (!smartMode) {
|
|
3452
|
+
const idSpan = document.createElement("span");
|
|
3453
|
+
idSpan.className = "cd-edit-banner-id";
|
|
3454
|
+
idSpan.textContent = `#${this.commentingFeedbackId}`;
|
|
3455
|
+
this.editBannerInfoEl.appendChild(idSpan);
|
|
3456
|
+
}
|
|
3300
3457
|
} else {
|
|
3301
3458
|
this.editBannerEl.hidden = true;
|
|
3302
3459
|
}
|
|
@@ -3305,6 +3462,9 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3305
3462
|
if (this.editingFeedbackId !== null) {
|
|
3306
3463
|
this.submitBtn.setAttribute("aria-label", "Save feedback changes");
|
|
3307
3464
|
this.submitBtn.innerHTML = `${ICON_CHECK}<span>Save</span>`;
|
|
3465
|
+
} else if (this.commentingFeedbackId !== null) {
|
|
3466
|
+
this.submitBtn.setAttribute("aria-label", "Submit comment");
|
|
3467
|
+
this.submitBtn.innerHTML = `${ICON_SEND}<span>Comment</span>`;
|
|
3308
3468
|
} else {
|
|
3309
3469
|
this.submitBtn.setAttribute("aria-label", "Submit feedback");
|
|
3310
3470
|
this.submitBtn.innerHTML = `${ICON_SEND}<span>Send</span>`;
|
|
@@ -3547,11 +3707,18 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3547
3707
|
for (const entry of this.sessionHistory) {
|
|
3548
3708
|
const entryIdStr = String(entry.id);
|
|
3549
3709
|
const isEditingThis = this.editingFeedbackId === entryIdStr;
|
|
3710
|
+
const isCommentingThis = this.commentingFeedbackId === entryIdStr;
|
|
3711
|
+
const isReviewingThis = this.reviewingFeedbackId === entryIdStr;
|
|
3550
3712
|
const isConfirmingDelete = this.confirmingDeleteId === entryIdStr;
|
|
3551
3713
|
const isDeletingThis = this.deletingFeedbackId === entryIdStr;
|
|
3714
|
+
const statusName = entry.status || "new";
|
|
3552
3715
|
|
|
3553
3716
|
const msgCard = document.createElement("div");
|
|
3554
|
-
msgCard.className = isEditingThis
|
|
3717
|
+
msgCard.className = isEditingThis
|
|
3718
|
+
? "cd-chat-msg is-editing"
|
|
3719
|
+
: isCommentingThis
|
|
3720
|
+
? "cd-chat-msg is-commenting"
|
|
3721
|
+
: "cd-chat-msg";
|
|
3555
3722
|
msgCard.setAttribute("data-feedback-id", entryIdStr);
|
|
3556
3723
|
|
|
3557
3724
|
if (entry.elements.length > 0 || entry.attachments.length > 0) {
|
|
@@ -3585,12 +3752,68 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3585
3752
|
msgCard.appendChild(textP);
|
|
3586
3753
|
}
|
|
3587
3754
|
|
|
3755
|
+
if (entry.comments && entry.comments.length > 0) {
|
|
3756
|
+
const commentsList = document.createElement("div");
|
|
3757
|
+
commentsList.className = "cd-comments-list";
|
|
3758
|
+
for (const comment of entry.comments) {
|
|
3759
|
+
const cItem = document.createElement("div");
|
|
3760
|
+
cItem.className = "cd-comment-item";
|
|
3761
|
+
|
|
3762
|
+
const cHeader = document.createElement("div");
|
|
3763
|
+
cHeader.className = "cd-comment-header";
|
|
3764
|
+
const cAuthor = document.createElement("span");
|
|
3765
|
+
cAuthor.className = "cd-comment-author";
|
|
3766
|
+
cAuthor.textContent = comment.author_label || "You";
|
|
3767
|
+
const cTime = document.createElement("span");
|
|
3768
|
+
cTime.textContent = comment.createdAt;
|
|
3769
|
+
cHeader.appendChild(cAuthor);
|
|
3770
|
+
cHeader.appendChild(cTime);
|
|
3771
|
+
cItem.appendChild(cHeader);
|
|
3772
|
+
|
|
3773
|
+
if (comment.body) {
|
|
3774
|
+
const cBody = document.createElement("p");
|
|
3775
|
+
cBody.className = "cd-comment-body";
|
|
3776
|
+
cBody.textContent = comment.body;
|
|
3777
|
+
cItem.appendChild(cBody);
|
|
3778
|
+
}
|
|
3779
|
+
|
|
3780
|
+
if (comment.attachments && comment.attachments.length > 0) {
|
|
3781
|
+
const cImgs = document.createElement("div");
|
|
3782
|
+
cImgs.className = "cd-comment-images";
|
|
3783
|
+
for (const att of comment.attachments) {
|
|
3784
|
+
if (att.preview_url) {
|
|
3785
|
+
const imgLink = document.createElement("a");
|
|
3786
|
+
imgLink.href = att.preview_url;
|
|
3787
|
+
imgLink.target = "_blank";
|
|
3788
|
+
imgLink.rel = "noopener noreferrer";
|
|
3789
|
+
const img = document.createElement("img");
|
|
3790
|
+
img.src = att.preview_url;
|
|
3791
|
+
img.alt = att.label || "Comment image";
|
|
3792
|
+
img.className = "cd-comment-thumb";
|
|
3793
|
+
imgLink.appendChild(img);
|
|
3794
|
+
cImgs.appendChild(imgLink);
|
|
3795
|
+
}
|
|
3796
|
+
}
|
|
3797
|
+
if (cImgs.childNodes.length > 0) {
|
|
3798
|
+
cItem.appendChild(cImgs);
|
|
3799
|
+
}
|
|
3800
|
+
}
|
|
3801
|
+
|
|
3802
|
+
commentsList.appendChild(cItem);
|
|
3803
|
+
}
|
|
3804
|
+
msgCard.appendChild(commentsList);
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3588
3807
|
const meta = document.createElement("div");
|
|
3589
3808
|
meta.className = "cd-chat-msg-meta";
|
|
3590
3809
|
|
|
3591
3810
|
const metaInfo = document.createElement("div");
|
|
3592
3811
|
metaInfo.className = "cd-chat-msg-meta-info";
|
|
3593
3812
|
|
|
3813
|
+
const statusBadge = document.createElement("span");
|
|
3814
|
+
statusBadge.className = `cd-msg-status-badge is-${statusName}`;
|
|
3815
|
+
statusBadge.textContent = statusName;
|
|
3816
|
+
|
|
3594
3817
|
const idSpan = document.createElement("span");
|
|
3595
3818
|
const baseLabel = smartMode ? "Feedback sent" : `Dropped #${entry.id}`;
|
|
3596
3819
|
idSpan.textContent = entry.isEdited ? `${baseLabel} · edited` : baseLabel;
|
|
@@ -3602,6 +3825,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3602
3825
|
const timeSpan = document.createElement("span");
|
|
3603
3826
|
timeSpan.textContent = entry.createdAt;
|
|
3604
3827
|
|
|
3828
|
+
metaInfo.appendChild(statusBadge);
|
|
3605
3829
|
metaInfo.appendChild(idSpan);
|
|
3606
3830
|
metaInfo.appendChild(sepSpan);
|
|
3607
3831
|
metaInfo.appendChild(timeSpan);
|
|
@@ -3609,6 +3833,36 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3609
3833
|
const actions = document.createElement("div");
|
|
3610
3834
|
actions.className = "cd-chat-msg-actions";
|
|
3611
3835
|
|
|
3836
|
+
if (statusName === "fixed") {
|
|
3837
|
+
const reviewBtn = document.createElement("button");
|
|
3838
|
+
reviewBtn.type = "button";
|
|
3839
|
+
reviewBtn.className = "cd-review-btn";
|
|
3840
|
+
reviewBtn.title = "Confirm fix was tested and reviewed";
|
|
3841
|
+
reviewBtn.setAttribute("aria-label", "Mark fix as reviewed");
|
|
3842
|
+
reviewBtn.disabled = isReviewingThis || this.isSubmitting || this.deletingFeedbackId !== null;
|
|
3843
|
+
reviewBtn.innerHTML = `${ICON_CHECK}<span>${isReviewingThis ? "Saving..." : "Mark Reviewed"}</span>`;
|
|
3844
|
+
reviewBtn.addEventListener("click", () => {
|
|
3845
|
+
void this.markFeedbackReviewed(entry.id);
|
|
3846
|
+
});
|
|
3847
|
+
actions.appendChild(reviewBtn);
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3850
|
+
const commentBtn = document.createElement("button");
|
|
3851
|
+
commentBtn.type = "button";
|
|
3852
|
+
commentBtn.className = `cd-msg-action-btn${isCommentingThis ? " is-active" : ""}`;
|
|
3853
|
+
commentBtn.title = isCommentingThis ? "Cancel comment" : "Add comment";
|
|
3854
|
+
commentBtn.setAttribute("aria-label", "Add comment");
|
|
3855
|
+
commentBtn.setAttribute("aria-pressed", String(isCommentingThis));
|
|
3856
|
+
commentBtn.disabled = this.isSubmitting || this.deletingFeedbackId !== null;
|
|
3857
|
+
commentBtn.innerHTML = ICON_COMMENT;
|
|
3858
|
+
commentBtn.addEventListener("click", () => {
|
|
3859
|
+
if (this.commentingFeedbackId === entryIdStr) {
|
|
3860
|
+
this.cancelCommentingFeedback();
|
|
3861
|
+
} else {
|
|
3862
|
+
this.startCommentingFeedback(entry.id);
|
|
3863
|
+
}
|
|
3864
|
+
});
|
|
3865
|
+
|
|
3612
3866
|
const editBtn = document.createElement("button");
|
|
3613
3867
|
editBtn.type = "button";
|
|
3614
3868
|
editBtn.className = `cd-msg-action-btn${isEditingThis ? " is-active" : ""}`;
|
|
@@ -3636,6 +3890,7 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
3636
3890
|
this.requestDeleteFeedback(entry.id);
|
|
3637
3891
|
});
|
|
3638
3892
|
|
|
3893
|
+
actions.appendChild(commentBtn);
|
|
3639
3894
|
actions.appendChild(editBtn);
|
|
3640
3895
|
actions.appendChild(deleteBtn);
|
|
3641
3896
|
|
|
@@ -4072,13 +4327,19 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
4072
4327
|
if (this.isSubmitting) return;
|
|
4073
4328
|
const smartMode = this.isSmartSelectionMode();
|
|
4074
4329
|
const editingId = this.editingFeedbackId;
|
|
4330
|
+
const commentingId = this.commentingFeedbackId;
|
|
4075
4331
|
|
|
4076
4332
|
if (this.pendingSmartCaptures.size > 0) {
|
|
4077
4333
|
await Promise.allSettled(Array.from(this.pendingSmartCaptures));
|
|
4078
4334
|
}
|
|
4079
4335
|
|
|
4080
4336
|
const message = (this.textareaEl?.value || "").trim();
|
|
4081
|
-
if (
|
|
4337
|
+
if (commentingId !== null) {
|
|
4338
|
+
if (message.length === 0 && this.attachments.length === 0) {
|
|
4339
|
+
this.showStatus("Write a comment or attach an image first.", "error");
|
|
4340
|
+
return;
|
|
4341
|
+
}
|
|
4342
|
+
} else if (
|
|
4082
4343
|
message.length === 0 &&
|
|
4083
4344
|
this.attachments.length === 0 &&
|
|
4084
4345
|
this.elementReferences.length === 0
|
|
@@ -4096,7 +4357,11 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
4096
4357
|
if (this.submitBtn) {
|
|
4097
4358
|
this.submitBtn.disabled = true;
|
|
4098
4359
|
this.submitBtn.innerHTML =
|
|
4099
|
-
editingId !== null
|
|
4360
|
+
editingId !== null
|
|
4361
|
+
? `<span>Saving...</span>`
|
|
4362
|
+
: commentingId !== null
|
|
4363
|
+
? `<span>Posting...</span>`
|
|
4364
|
+
: `<span>Sending...</span>`;
|
|
4100
4365
|
}
|
|
4101
4366
|
|
|
4102
4367
|
try {
|
|
@@ -4125,6 +4390,55 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
|
|
|
4125
4390
|
locale: typeof navigator !== "undefined" ? navigator.language : "en"
|
|
4126
4391
|
};
|
|
4127
4392
|
|
|
4393
|
+
if (commentingId !== null) {
|
|
4394
|
+
const existingIdx = this.sessionHistory.findIndex(
|
|
4395
|
+
(item) => String(item.id) === commentingId
|
|
4396
|
+
);
|
|
4397
|
+
const existingEntry = existingIdx >= 0 ? this.sessionHistory[existingIdx] : undefined;
|
|
4398
|
+
|
|
4399
|
+
const commentPayload: CreateCommentPayload = {
|
|
4400
|
+
body: message,
|
|
4401
|
+
attachments: this.attachments.map((att) => ({
|
|
4402
|
+
attachment_type: att.attachment_type,
|
|
4403
|
+
filename: att.filename,
|
|
4404
|
+
signed_blob_id: att.signed_blob_id,
|
|
4405
|
+
data_url: att.signed_blob_id ? undefined : att.data_url,
|
|
4406
|
+
metadata: att.metadata
|
|
4407
|
+
}))
|
|
4408
|
+
};
|
|
4409
|
+
|
|
4410
|
+
const commentRes = await this.apiClient.createComment(
|
|
4411
|
+
existingEntry?.id ?? commentingId,
|
|
4412
|
+
commentPayload,
|
|
4413
|
+
existingEntry?.ownershipToken
|
|
4414
|
+
);
|
|
4415
|
+
|
|
4416
|
+
if (commentRes?.feedback) {
|
|
4417
|
+
const updatedEntry = this.mapOwnRecordToSessionEntry(commentRes.feedback, existingEntry);
|
|
4418
|
+
if (existingIdx >= 0) {
|
|
4419
|
+
this.sessionHistory[existingIdx] = updatedEntry;
|
|
4420
|
+
}
|
|
4421
|
+
} else if (existingEntry) {
|
|
4422
|
+
existingEntry.status = commentRes?.status || "updated";
|
|
4423
|
+
if (!existingEntry.comments) existingEntry.comments = [];
|
|
4424
|
+
existingEntry.comments.push({
|
|
4425
|
+
id: commentRes?.id ?? Date.now(),
|
|
4426
|
+
author_label: commentRes?.comment?.author_label || "You",
|
|
4427
|
+
body: message || null,
|
|
4428
|
+
createdAt: this.formatTimestampLabel(commentRes?.created_at),
|
|
4429
|
+
attachments: submittedAttachments
|
|
4430
|
+
});
|
|
4431
|
+
}
|
|
4432
|
+
|
|
4433
|
+
this.cancelCommentingFeedback();
|
|
4434
|
+
this.showStatus("Comment added.", "success");
|
|
4435
|
+
this.emitWidgetEvent("context-drop:comment", {
|
|
4436
|
+
response: commentRes,
|
|
4437
|
+
payload: commentPayload
|
|
4438
|
+
});
|
|
4439
|
+
return;
|
|
4440
|
+
}
|
|
4441
|
+
|
|
4128
4442
|
if (editingId !== null) {
|
|
4129
4443
|
const existingIdx = this.sessionHistory.findIndex(
|
|
4130
4444
|
(item) => String(item.id) === editingId
|
|
@@ -10,6 +10,11 @@ module ContextDrop
|
|
|
10
10
|
class_name: "ContextDrop::Feedback",
|
|
11
11
|
inverse_of: :attachments
|
|
12
12
|
|
|
13
|
+
belongs_to :comment,
|
|
14
|
+
class_name: "ContextDrop::Comment",
|
|
15
|
+
optional: true,
|
|
16
|
+
inverse_of: :attachments
|
|
17
|
+
|
|
13
18
|
belongs_to :element_reference,
|
|
14
19
|
class_name: "ContextDrop::ElementReference",
|
|
15
20
|
optional: true,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ContextDrop
|
|
4
|
+
class Comment < ApplicationRecord
|
|
5
|
+
self.table_name = "context_drop_comments"
|
|
6
|
+
|
|
7
|
+
belongs_to :feedback,
|
|
8
|
+
class_name: "ContextDrop::Feedback",
|
|
9
|
+
inverse_of: :comments
|
|
10
|
+
|
|
11
|
+
has_many :attachments,
|
|
12
|
+
class_name: "ContextDrop::Attachment",
|
|
13
|
+
foreign_key: :comment_id,
|
|
14
|
+
inverse_of: :comment,
|
|
15
|
+
dependent: :destroy
|
|
16
|
+
|
|
17
|
+
validate :ensure_body_or_attachments_present
|
|
18
|
+
validate :ensure_attachments_limit
|
|
19
|
+
|
|
20
|
+
before_validation :normalize_metadata
|
|
21
|
+
|
|
22
|
+
def display_author_label
|
|
23
|
+
return author_label.to_s if author_label.present?
|
|
24
|
+
return "#{author_type}##{author_id}" if author_type.present? && author_id.present?
|
|
25
|
+
|
|
26
|
+
"Submitter"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def normalize_metadata
|
|
32
|
+
self.metadata = {} unless metadata.is_a?(Hash)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def ensure_body_or_attachments_present
|
|
36
|
+
has_body = body.to_s.strip != ""
|
|
37
|
+
has_attachments = attachments.reject(&:marked_for_destruction?).any?
|
|
38
|
+
return if has_body || has_attachments
|
|
39
|
+
|
|
40
|
+
errors.add(:base, "Comment must include text or an image attachment")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def ensure_attachments_limit
|
|
44
|
+
max_att = ContextDrop.config.max_attachments.to_i
|
|
45
|
+
return unless attachments.reject(&:marked_for_destruction?).size > max_att
|
|
46
|
+
|
|
47
|
+
errors.add(:attachments, "exceeds maximum allowed (#{max_att})")
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|