diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClient.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClient.ts index af997016a4a..febafdc7f32 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClient.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClient.ts @@ -5,6 +5,8 @@ import { FeedbackCreateRes, FeedbackPurgeReq, FeedbackPurgeRes, + FeedbackReplaceReq, + FeedbackReplaceRes, TraceCallsDeleteReq, TraceCallUpdateReq, TraceRefsReadBatchReq, @@ -23,7 +25,11 @@ export class TraceServerClient extends DirectTraceServerClient { }> = []; private onDeleteListeners: Array<() => void>; private onRenameListeners: Array<() => void>; - private onFeedbackListeners: Record void>>; + // weave_ref -> feedback_type -> callback + private onFeedbackListeners: Record< + string, + Record void>> + >; constructor(baseUrl: string) { super(baseUrl); @@ -34,6 +40,8 @@ export class TraceServerClient extends DirectTraceServerClient { this.onFeedbackListeners = {}; } + private FEEDBACK_TYPE_DEFAULT = ''; + /** * Registers a callback to be called when a delete operation occurs. * This method is purely for local notification within the client @@ -60,20 +68,25 @@ export class TraceServerClient extends DirectTraceServerClient { } public registerOnFeedbackListener( weaveRef: string, - callback: () => void + callback: () => void, + feedbackType?: string ): () => void { + const feedbackTypeResolved = feedbackType ?? this.FEEDBACK_TYPE_DEFAULT; if (!(weaveRef in this.onFeedbackListeners)) { - this.onFeedbackListeners[weaveRef] = []; + this.onFeedbackListeners[weaveRef] = {}; + } + if (!(feedbackTypeResolved in this.onFeedbackListeners[weaveRef])) { + this.onFeedbackListeners[weaveRef][feedbackTypeResolved] = []; } - this.onFeedbackListeners[weaveRef].push(callback); + this.onFeedbackListeners[weaveRef][feedbackTypeResolved].push(callback); return () => { - const newListeners = this.onFeedbackListeners[weaveRef].filter( - listener => listener !== callback - ); + const newListeners = this.onFeedbackListeners[weaveRef][ + feedbackTypeResolved + ].filter(listener => listener !== callback); if (newListeners.length) { - this.onFeedbackListeners[weaveRef] = newListeners; + this.onFeedbackListeners[weaveRef][feedbackTypeResolved] = newListeners; } else { - delete this.onFeedbackListeners[weaveRef]; + delete this.onFeedbackListeners[weaveRef][feedbackTypeResolved]; } }; } @@ -94,7 +107,13 @@ export class TraceServerClient extends DirectTraceServerClient { public feedbackCreate(req: FeedbackCreateReq): Promise { const res = super.feedbackCreate(req).then(createRes => { - const listeners = this.onFeedbackListeners[req.weave_ref] ?? []; + const listeners = + this.onFeedbackListeners[req.weave_ref]?.[req.feedback_type] ?? []; + listeners.push( + ...(this.onFeedbackListeners?.[req.weave_ref]?.[ + this.FEEDBACK_TYPE_DEFAULT + ] ?? []) + ); listeners.forEach(listener => listener()); return createRes; }); @@ -106,13 +125,31 @@ export class TraceServerClient extends DirectTraceServerClient { // information about the refs that were modified. // For now, just call all registered feedback listeners. for (const listeners of Object.values(this.onFeedbackListeners)) { - listeners.forEach(listener => listener()); + for (const listenersForWeaveRef of Object.values(listeners)) { + listenersForWeaveRef.forEach(listener => listener()); + } } return purgeRes; }); return res; } + public feedbackReplace(req: FeedbackReplaceReq): Promise { + const res = super.feedbackReplace(req).then(replaceRes => { + const listeners = + this.onFeedbackListeners[req.weave_ref]?.[req.feedback_type] ?? []; + // also fire the default feedback type listeners + listeners.push( + ...(this.onFeedbackListeners?.[req.weave_ref]?.[ + this.FEEDBACK_TYPE_DEFAULT + ] ?? []) + ); + listeners.forEach(listener => listener()); + return replaceRes; + }); + return res; + } + public readBatch(req: TraceRefsReadBatchReq): Promise { return this.requestReadBatch(req); } diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts index d7219af5834..8147857a5fb 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerClientTypes.ts @@ -144,6 +144,10 @@ export type FeedbackCreateReq = { weave_ref: string; feedback_type: string; payload: Record; + annotation_ref?: string; + runnable_ref?: string; + call_ref?: string; + trigger_ref?: string; }; export type FeedbackCreateSuccess = { @@ -190,6 +194,16 @@ export type FeedbackPurgeError = { detail: string; }; export type FeedbackPurgeRes = FeedbackPurgeSuccess | FeedbackPurgeError; + +export type FeedbackReplaceReq = FeedbackCreateReq & { + feedback_id: string; +}; +export type FeedbackReplaceSuccess = {}; +export type FeedbackReplaceError = { + detail: string; +}; +export type FeedbackReplaceRes = FeedbackCreateRes; + interface TraceObjectsFilter { base_object_classes?: string[]; object_ids?: string[]; diff --git a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerDirectClient.ts b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerDirectClient.ts index 25f11624740..c2e9c11d9d7 100644 --- a/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerDirectClient.ts +++ b/weave-js/src/components/PagePanelComponents/Home/Browse3/pages/wfReactInterface/traceServerDirectClient.ts @@ -23,6 +23,8 @@ import { FeedbackPurgeRes, FeedbackQueryReq, FeedbackQueryRes, + FeedbackReplaceReq, + FeedbackReplaceRes, TraceCallReadReq, TraceCallReadRes, TraceCallSchema, @@ -286,6 +288,13 @@ export class DirectTraceServerClient { ); } + public feedbackReplace(req: FeedbackReplaceReq): Promise { + return this.makeRequest( + '/feedback/replace', + req + ); + } + public fileContent( req: TraceFileContentReadReq ): Promise {