-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(ui): add feedback_replace to ui, update listeners w/ feedback_type
#2804
Closed
Closed
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f76e316
chore(ui): add feedback_replace to ui, update listeners w/ feedback_ref
gtarpenning 81331b7
Merge branch 'master' into griffin/feedback-replace-ts
gtarpenning cbcdd33
typ
gtarpenning 91ea1fb
wip
gtarpenning 026b28e
Merge branch 'master' into griffin/feedback-replace-ts
gtarpenning 005a165
fix
gtarpenning fd0d7b7
Merge branch 'master' into griffin/feedback-replace-ts
gtarpenning File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import { | |
FeedbackCreateRes, | ||
FeedbackPurgeReq, | ||
FeedbackPurgeRes, | ||
FeedbackReplaceReq, | ||
FeedbackReplaceRes, | ||
TraceCallsDeleteReq, | ||
TraceCallUpdateReq, | ||
TraceRefsReadBatchReq, | ||
|
@@ -23,7 +25,13 @@ export class TraceServerClient extends DirectTraceServerClient { | |
}> = []; | ||
private onDeleteListeners: Array<() => void>; | ||
private onRenameListeners: Array<() => void>; | ||
private onFeedbackListeners: Record<string, Array<() => void>>; | ||
// weave_ref -> feedback_ref -> callback | ||
// For feedback without a feedback_ref, (the default case) | ||
// the key is the empty string (this.FEEDBACK_REF_DEFAULT). | ||
private onFeedbackListeners: Record< | ||
string, | ||
Record<string, Array<() => void>> | ||
>; | ||
|
||
constructor(baseUrl: string) { | ||
super(baseUrl); | ||
|
@@ -34,6 +42,8 @@ export class TraceServerClient extends DirectTraceServerClient { | |
this.onFeedbackListeners = {}; | ||
} | ||
|
||
private FEEDBACK_REF_DEFAULT = ''; | ||
|
||
/** | ||
* Registers a callback to be called when a delete operation occurs. | ||
* This method is purely for local notification within the client | ||
|
@@ -60,20 +70,25 @@ export class TraceServerClient extends DirectTraceServerClient { | |
} | ||
public registerOnFeedbackListener( | ||
weaveRef: string, | ||
callback: () => void | ||
callback: () => void, | ||
feedbackRef?: string | ||
): () => void { | ||
if (!(weaveRef in this.onFeedbackListeners)) { | ||
this.onFeedbackListeners[weaveRef] = []; | ||
const feedbackRefResolved = feedbackRef ?? this.FEEDBACK_REF_DEFAULT; | ||
if (!(feedbackRefResolved in this.onFeedbackListeners)) { | ||
this.onFeedbackListeners[feedbackRefResolved] = {}; | ||
} | ||
if (!(weaveRef in this.onFeedbackListeners[feedbackRefResolved])) { | ||
this.onFeedbackListeners[feedbackRefResolved][weaveRef] = []; | ||
} | ||
this.onFeedbackListeners[weaveRef].push(callback); | ||
this.onFeedbackListeners[feedbackRefResolved][weaveRef].push(callback); | ||
return () => { | ||
const newListeners = this.onFeedbackListeners[weaveRef].filter( | ||
listener => listener !== callback | ||
); | ||
const newListeners = this.onFeedbackListeners[feedbackRefResolved][ | ||
weaveRef | ||
].filter(listener => listener !== callback); | ||
if (newListeners.length) { | ||
this.onFeedbackListeners[weaveRef] = newListeners; | ||
this.onFeedbackListeners[feedbackRefResolved][weaveRef] = newListeners; | ||
} else { | ||
delete this.onFeedbackListeners[weaveRef]; | ||
delete this.onFeedbackListeners[feedbackRefResolved][weaveRef]; | ||
} | ||
}; | ||
} | ||
|
@@ -94,7 +109,10 @@ export class TraceServerClient extends DirectTraceServerClient { | |
|
||
public feedbackCreate(req: FeedbackCreateReq): Promise<FeedbackCreateRes> { | ||
const res = super.feedbackCreate(req).then(createRes => { | ||
const listeners = this.onFeedbackListeners[req.weave_ref] ?? []; | ||
const feedbackRefResolved = | ||
req.payload?.feedback_ref ?? this.FEEDBACK_REF_DEFAULT; | ||
const listeners = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for here and in replace, i think what you want to hit all the listeners for weave_ref + feedback_type AND weave_ref + ''. |
||
this.onFeedbackListeners[feedbackRefResolved][req.weave_ref] ?? []; | ||
listeners.forEach(listener => listener()); | ||
return createRes; | ||
}); | ||
|
@@ -106,13 +124,27 @@ 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<FeedbackReplaceRes> { | ||
const res = super.feedbackReplace(req).then(replaceRes => { | ||
const feedbackRefResolved = | ||
req.payload?.feedback_ref ?? this.FEEDBACK_REF_DEFAULT; | ||
gtarpenning marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const listeners = | ||
this.onFeedbackListeners[feedbackRefResolved][req.weave_ref] ?? []; | ||
listeners.forEach(listener => listener()); | ||
return replaceRes; | ||
}); | ||
return res; | ||
} | ||
|
||
public readBatch(req: TraceRefsReadBatchReq): Promise<TraceRefsReadBatchRes> { | ||
return this.requestReadBatch(req); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure what this means
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, you are talking about the keys of the nested structure