-
Notifications
You must be signed in to change notification settings - Fork 23
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
reset chat or reload history after data source change #194
reset chat or reload history after data source change #194
Conversation
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
}, [props.shouldRefresh, services.conversations]); | ||
|
||
useEffect(() => { | ||
services.conversations.load(bulkGetOptions); | ||
const subscription = services.dataSource | ||
.getDataSourceId$() |
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.
Would it be possible that dataSourceId$
emit the same value one after another? In such case, I think we don't want to reload.
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.
In current implementation, the same value will be emit after default data source change. Do you have any suggestions about that? How about add a distinctUntilChanged
?
}, [props.shouldRefresh, services.conversations]); | ||
|
||
useEffect(() => { | ||
services.conversations.load(bulkGetOptions); | ||
const subscription = services.dataSource | ||
.getDataSourceId$() | ||
.pipe(skip(1)) |
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.
Could you leave a comment to describe why it should skip the first value?
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.
Sure, since the the conversations load will be called after mount. We skip the first value here to avoid duplicate load API request.
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.
Can we say that we are skipping the case that dataSource$ emits the same value? In that case we'd use distinctUntilChanged
instead of skip the first value right?
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 the same value. Since dataSourceId$
and defaultDataSourceId$
are BehaviorSubject
. The observer will be executed once first subscribed. The observer will reload conversations history. Since we already call conversations.load
after mount, skip first value here to avoid duplicate API call.
@@ -106,6 +106,15 @@ export const useChatActions = (): AssistantActions => { | |||
} | |||
}; | |||
|
|||
const resetChat = () => { |
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.
Can you simply call loadChat
without any parameter instead of creating a new method? we can call loadChat()
to start a new conversation
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.
The loadChat
only work when current tab is chat tab. The loadChat will set current tab to CHAT in this line. I think we can't change tab to CHAT if user is in history tab. So add a new resetChat
here.
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
public/chat_header_button.tsx
Outdated
@@ -54,6 +56,9 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => { | |||
const flyoutFullScreen = sidecarDockedMode === SIDECAR_DOCKED_MODE.TAKEOVER; | |||
const flyoutMountPoint = useRef(null); | |||
|
|||
const resetChatRef = useRef(props.assistantActions.resetChat); | |||
resetChatRef.current = props.assistantActions.resetChat; |
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.
Can we just use the props.assistantActions.resetChat
without a ref?
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.
I've tested in my local machine, the props.assistantActions.resetChat
will be changed after chat button render. The getDataSourceId$
will be executed multi times. It's OK to change to use props.assistantActions.resetChat
directly.
if (this.dataSourceId$.getValue() === newDataSourceId) { | ||
return; | ||
} |
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.
Could you elaborate more on why we remove duplicate check in set function?
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.
Since we already add distinctUntilChanged
in getDataSourceId$
, the next value won't be the same. Then we can remove the duplicate check here.
Signed-off-by: Lin Wang <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #194 +/- ##
==========================================
+ Coverage 90.02% 90.50% +0.48%
==========================================
Files 54 57 +3
Lines 1433 1527 +94
Branches 347 361 +14
==========================================
+ Hits 1290 1382 +92
- Misses 141 143 +2
Partials 2 2 ☔ View full report in Codecov by Sentry. |
how about |
Do you mean refresh how was it generated page when data source changed? I think it's a little bit confused. Because user won't get the trace info in another data source. |
right, show existing trace data maybe confusing. how about reset to chat window? |
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
…ot-after-data-source-change Signed-off-by: Lin Wang <[email protected]>
Thanks for suggestions, I've already updated this part. |
Signed-off-by: Lin Wang <[email protected]>
const bulkGetOptionsRef = useRef(bulkGetOptions); | ||
bulkGetOptionsRef.current = bulkGetOptions; |
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 needed anymore I think?
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.
Sure, can be removed.
Signed-off-by: Lin Wang <[email protected]>
Signed-off-by: Lin Wang <[email protected]>
* reset chat or reload history when data source change Signed-off-by: Lin Wang <[email protected]> * Add change log Signed-off-by: Lin Wang <[email protected]> * Address PR comments Signed-off-by: Lin Wang <[email protected]> * Set search and page after data source change Signed-off-by: Lin Wang <[email protected]> * Remove skip first value when subscribe dataSourceId$ Signed-off-by: Lin Wang <[email protected]> * Add dataSourceIdUdpates$ and finalDataSourceId Signed-off-by: Lin Wang <[email protected]> * Remove data source service mock in chat header button Signed-off-by: Lin Wang <[email protected]> * Remove no need useRef Signed-off-by: Lin Wang <[email protected]> * Refactor load history after data source change Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]> (cherry picked from commit a2a98f6) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md
* reset chat or reload history when data source change Signed-off-by: Lin Wang <[email protected]> * Add change log Signed-off-by: Lin Wang <[email protected]> * Address PR comments Signed-off-by: Lin Wang <[email protected]> * Set search and page after data source change Signed-off-by: Lin Wang <[email protected]> * Remove skip first value when subscribe dataSourceId$ Signed-off-by: Lin Wang <[email protected]> * Add dataSourceIdUdpates$ and finalDataSourceId Signed-off-by: Lin Wang <[email protected]> * Remove data source service mock in chat header button Signed-off-by: Lin Wang <[email protected]> * Remove no need useRef Signed-off-by: Lin Wang <[email protected]> * Refactor load history after data source change Signed-off-by: Lin Wang <[email protected]> --------- Signed-off-by: Lin Wang <[email protected]> (cherry picked from commit a2a98f6) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> # Conflicts: # CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Description
Issues Resolved
#192
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.