Skip to content

fixed an issue that the initial result summary generated with the wrong data #9611

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9611.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Initial result summary generated with the wrong data ([#9611](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9611))
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ export const QueryAssistSummary: React.FC<QueryAssistSummaryProps> = (props) =>
const [feedback, setFeedback] = useState(FeedbackStatus.NONE);
const [isEnabledByCapability, setIsEnabledByCapability] = useState(false);
const selectedDataset = useRef(query.queryString.getQuery()?.dataset);
const { queryState, isQuerySummaryCollapsed, isSummaryAgentAvailable } = useQueryAssist();
const {
queryState,
isQuerySummaryCollapsed,
isSummaryAgentAvailable,
updateQueryState,
} = useQueryAssist();

const [results, setResults] = useState<any[]>([]);
// the question and answer used last time to generate summary
Expand Down Expand Up @@ -144,14 +149,22 @@ export const QueryAssistSummary: React.FC<QueryAssistSummaryProps> = (props) =>
return () => subscription.unsubscribe();
}, [query.queryString]);

useEffect(() => {
return () => {
// reset the state when unmount, so when navigating away and
// back to discover, it won't use stale state
updateQueryState({ question: '', generatedQuery: '' });
};
}, [updateQueryState]);

useEffect(() => {
const subscription = search.df.df$
.pipe(
distinctUntilChanged(),
filter((value) => !isEmpty(value) && !isEmpty(value?.fields))
)
.subscribe((df) => {
if (df) {
if (df && currentQueryStateRef.current.question) {
setResults(convertResult(df));
}
});
Expand Down
Loading