Skip to content

Commit

Permalink
[BUG][Discover] Ensure save query loaded properly from asset (opensea…
Browse files Browse the repository at this point in the history
…rch-project#8707)

* [BUG][Discover] Ensure save query loaded properly from asset

Signed-off-by: Anan Zhuang <ananzh@amazon.com>

* Changeset file for PR opensearch-project#8707 created/updated

---------

Signed-off-by: Anan Zhuang <ananzh@amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and Qxisylolo committed Oct 30, 2024
1 parent a1b0780 commit aad1de1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8707.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Ensure save query loaded properly from asset ([#8707](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8707))
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ export const useSearch = (services: DiscoverViewServices) => {
const { pathname } = useLocation();
const initalSearchComplete = useRef(false);
const [savedSearch, setSavedSearch] = useState<SavedSearch | undefined>(undefined);
const { savedSearch: savedSearchId, sort, interval } = useSelector((state) => state.discover);
const { savedSearch: savedSearchId, sort, interval, savedQuery } = useSelector(
(state) => state.discover
);
const indexPattern = useIndexPattern(services);
const skipInitialFetch = useRef(false);
const {
Expand Down Expand Up @@ -387,17 +389,20 @@ export const useSearch = (services: DiscoverViewServices) => {

// sync initial app filters from savedObject to filterManager
const filters = cloneDeep(savedSearchInstance.searchSource.getOwnField('filter'));
const actualFilters = [];

if (filters !== undefined) {
let actualFilters: any[] = [];

if (savedQuery) {
actualFilters = data.query.filterManager.getFilters();
} else if (filters !== undefined) {
const result = typeof filters === 'function' ? filters() : filters;
if (result !== undefined) {
actualFilters.push(...(Array.isArray(result) ? result : [result]));
}
}

filterManager.setAppFilters(actualFilters);
data.query.queryString.setQuery(query);
data.query.queryString.setQuery(savedQuery ? data.query.queryString.getQuery() : query);
setSavedSearch(savedSearchInstance);

if (savedSearchInstance?.id) {
Expand Down

0 comments on commit aad1de1

Please sign in to comment.