Skip to content

Commit b1798c2

Browse files
fixed an issue that the initial result summary generated with the wrong data (#9611)
* fixed an issue that the initial discover summary generated with stale data Signed-off-by: Yulong Ruan <[email protected]> * Changeset file for PR #9611 created/updated --------- Signed-off-by: Yulong Ruan <[email protected]> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
1 parent 07eb676 commit b1798c2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

changelogs/fragments/9611.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix:
2+
- Initial result summary generated with the wrong data ([#9611](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9611))

src/plugins/query_enhancements/public/query_assist/components/query_assist_summary.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ export const QueryAssistSummary: React.FC<QueryAssistSummaryProps> = (props) =>
6868
const [feedback, setFeedback] = useState(FeedbackStatus.NONE);
6969
const [isEnabledByCapability, setIsEnabledByCapability] = useState(false);
7070
const selectedDataset = useRef(query.queryString.getQuery()?.dataset);
71-
const { queryState, isQuerySummaryCollapsed, isSummaryAgentAvailable } = useQueryAssist();
71+
const {
72+
queryState,
73+
isQuerySummaryCollapsed,
74+
isSummaryAgentAvailable,
75+
updateQueryState,
76+
} = useQueryAssist();
7277

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

152+
useEffect(() => {
153+
return () => {
154+
// reset the state when unmount, so when navigating away and
155+
// back to discover, it won't use stale state
156+
updateQueryState({ question: '', generatedQuery: '' });
157+
};
158+
}, [updateQueryState]);
159+
147160
useEffect(() => {
148161
const subscription = search.df.df$
149162
.pipe(
150163
distinctUntilChanged(),
151164
filter((value) => !isEmpty(value) && !isEmpty(value?.fields))
152165
)
153166
.subscribe((df) => {
154-
if (df) {
167+
if (df && currentQueryStateRef.current.question) {
155168
setResults(convertResult(df));
156169
}
157170
});

0 commit comments

Comments
 (0)