Skip to content
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

[BUG][Discover] Ensure save query loaded properly from asset #8707

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Oct 25, 2024

Description

Saved query workflow

useSavedQuery → populateStateFromSavedQuery with new saved query → queryString.setQuery(new saved query)
useSavedQuery → populateStateFromSavedQuery with new saved query → filterManager.setFilters(new saved query)

Then they are clean out in use_search

useEffect(() => {
    (async () => {
      const savedSearchInstance = await getSavedSearchById(savedSearchId);

      const query =
        savedSearchInstance.searchSource.getField('query') ||
        data.query.queryString.getDefaultQuery();

      const isEnhancementsEnabled = await uiSettings.get('query:enhancements:enabled');
      if (isEnhancementsEnabled && query.dataset) {
        let pattern = await data.indexPatterns.get(
          query.dataset.id,
          query.dataset.type !== 'INDEX_PATTERN'
        );
        if (!pattern) {
          await data.query.queryString.getDatasetService().cacheDataset(query.dataset, {
            uiSettings: services.uiSettings,
            savedObjects: services.savedObjects,
            notifications: services.notifications,
            http: services.http,
            data: services.data,
          });
          pattern = await data.indexPatterns.get(
            query.dataset.id,
            query.dataset.type !== 'INDEX_PATTERN'
          );
          savedSearchInstance.searchSource.setField('index', pattern);
        }
      }

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

      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);
      setSavedSearch(savedSearchInstance);

      if (savedSearchInstance?.id) {
        chrome.recentlyAccessed.add(
          savedSearchInstance.getFullPath(),
          savedSearchInstance.title,
          savedSearchInstance.id,
          {
            type: savedSearchInstance.getOpenSearchType(),
          }
        );
      }
    })();
    // This effect will only run when getSavedSearchById is called, which is
    // only called when the component is first mounted.
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [getSavedSearchById, savedSearchId]);

After change:

  • legacy
2024-10-25_15-53-55.mp4
  • with enhancement
2024-10-25_15-57-36.mp4

Issues Resolved

NA

Screenshot

NA

Testing the changes

Changelog

  • fix: Ensure save query loaded properly from asset

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

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

codecov bot commented Oct 25, 2024

Codecov Report

Attention: Patch coverage is 0% with 7 lines in your changes missing coverage. Please review.

Project coverage is 60.75%. Comparing base (463a6c0) to head (6f9ad4a).

Files with missing lines Patch % Lines
...ic/application/view_components/utils/use_search.ts 0.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8707      +/-   ##
==========================================
- Coverage   60.75%   60.75%   -0.01%     
==========================================
  Files        3798     3798              
  Lines       90650    90653       +3     
  Branches    14254    14256       +2     
==========================================
- Hits        55076    55072       -4     
- Misses      32079    32085       +6     
- Partials     3495     3496       +1     
Flag Coverage Δ
Linux_1 29.06% <0.00%> (-0.01%) ⬇️
Linux_2 56.39% <ø> (ø)
Linux_3 37.57% <0.00%> (-0.01%) ⬇️
Linux_4 29.83% <ø> (ø)
Windows_1 29.10% <0.00%> (-0.01%) ⬇️
Windows_2 56.35% <ø> (ø)
Windows_3 37.57% <0.00%> (-0.01%) ⬇️
Windows_4 29.83% <ø> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discover for discover reinvent distinguished-contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant