Skip to content

Commit

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

Signed-off-by: Anan Zhuang <[email protected]>

* Changeset file for PR #8707 created/updated

---------

Signed-off-by: Anan Zhuang <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
(cherry picked from commit c66b698)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent a02cda9 commit 8a1e8e8
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

Check warning on line 90 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L89-L90

Added lines #L89 - L90 were not covered by tests
);
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[] = [];

Check warning on line 393 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L393

Added line #L393 was not covered by tests

if (savedQuery) {
actualFilters = data.query.filterManager.getFilters();

Check warning on line 396 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L396

Added line #L396 was not covered by tests
} 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 8a1e8e8

Please sign in to comment.