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

Fix Loading and Editing Saved Searches in Discover #8306

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

Conversation

LDrago27
Copy link
Collaborator

@LDrago27 LDrago27 commented Sep 24, 2024

Description

This PR aims at resolving the following issues.

  • Load Saved Search with Non index pattern Datasources
  • Change datasources for a Saved Search
  • Filters not showing up while a saved search is loaded
  • Filters not refreshing across page refresh

The CI group 6 failure for the PR has been addressed as part of this PR opensearch-project/opensearch-dashboards-functional-test#1585.

Issues Resolved

#8339
#8338

Screenshot

Testing the changes

Meeting.Recording.-.Sahoo.Suchit.Instant.Meeting.9.mp4
Meeting.Recording.-.Sahoo.Suchit.Instant.Meeting.10.mp4

Follow the steps mentioned in the video to test out the changes.

Changelog

  • skip

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

@github-actions github-actions bot added all-star-contributor Skip-Changelog PRs that are too trivial to warrant a changelog or release notes entry labels Sep 24, 2024
Copy link

codecov bot commented Sep 24, 2024

Codecov Report

Attention: Patch coverage is 14.28571% with 18 lines in your changes missing coverage. Please review.

Project coverage is 60.85%. Comparing base (e23f332) to head (d69bb15).
Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
...ic/application/view_components/utils/use_search.ts 0.00% 6 Missing ⚠️
...on/index_patterns/index_patterns/index_patterns.ts 0.00% 4 Missing ⚠️
...ommon/search/search_source/create_search_source.ts 0.00% 1 Missing and 2 partials ⚠️
...plication/components/top_nav/get_top_nav_links.tsx 0.00% 2 Missing ⚠️
src/plugins/data/public/search/search_service.ts 0.00% 0 Missing and 1 partial ⚠️
...plication/components/top_nav/open_search_panel.tsx 0.00% 1 Missing ⚠️
...lication/utils/state_management/discover_slice.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8306      +/-   ##
==========================================
- Coverage   60.86%   60.85%   -0.02%     
==========================================
  Files        3793     3793              
  Lines       90367    90381      +14     
  Branches    14182    14189       +7     
==========================================
- Hits        55000    54998       -2     
- Misses      31890    31902      +12     
- Partials     3477     3481       +4     
Flag Coverage Δ
Linux_1 29.09% <0.00%> (-0.01%) ⬇️
Linux_2 56.37% <0.00%> (-0.02%) ⬇️
Linux_3 37.68% <14.28%> (-0.01%) ⬇️
Linux_4 29.82% <0.00%> (-0.01%) ⬇️
Windows_1 29.10% <0.00%> (-0.01%) ⬇️
Windows_2 56.33% <0.00%> (-0.02%) ⬇️
Windows_3 37.68% <14.28%> (-0.01%) ⬇️
Windows_4 29.82% <0.00%> (-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.

@@ -28,6 +28,7 @@
* under the License.
*/

import { QueryStringContract } from 'src/plugins/data/public/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately we should import public into common folder. the compiler might complain about this.

we should consider taking the required function from the query string service (cache dataset) and exporting it in the common folder so that it's reusable by the dataset service and search source service

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would i see it complaining?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am surprised too that CI is not failing.

Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes looks good. Can we add some tests for the logic here. I want to make sure that things like "Filters in URL are higher priority than the filters in saved search" have test that will break if thats ever not true in future

@LDrago27
Copy link
Collaborator Author

LDrago27 commented Oct 7, 2024

The changes looks good. Can we add some tests for the logic here. I want to make sure that things like "Filters in URL are higher priority than the filters in saved search" have test that will break if thats ever not true in future

I have added couple of tests opensearch-project/opensearch-dashboards-functional-test#1585 . One to verify the above scenario and one to ensure we are resetting the existing filters when we are trying to create a new search.

);

useEffect(() => {
const subscription = queryString.getUpdates$(0).subscribe((query: Query) => {
if (query.dataset !== selectedDataset) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recently removed this useEffect() in #8347 to avoid duplicate calls. Does this if condition avoid the duplicate calls? Are we adding this back in so it picks up updates from state sync?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sejli The reasoning behind adding this , is when we are using to load the state from the saved Object it loads it without using the dataset selector component. Therefore although the actual query state has been updated but since the dataset selector is not triggered, the dataset selector content is not updated. The if condition is to avoid multiple updates.

data.query.queryString.setQuery(query);
// Filters in URL are higher priority than the filters in saved search
const urlFilters = (osdUrlStateStorage.get('_q') as QueryState)?.filters ?? [];
if (!urlFilters || urlFilters.length === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is untrusted input; right?

Suggested change
if (!urlFilters || urlFilters.length === 0) {
if (!Array.isArray(urlFilters) || urlFilters.length === 0) {

// Filters in URL are higher priority than the filters in saved search
const urlFilters = (osdUrlStateStorage.get('_q') as QueryState)?.filters ?? [];
if (!urlFilters || urlFilters.length === 0) {
filterManager.setAppFilters(actualFilters);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't we want to make sure to call filterManager.setAppFilters([]); when urlFilters is bad?

@LDrago27
Copy link
Collaborator Author

LDrago27 commented Oct 18, 2024

Will add additional unit tests & concerns in a follow up PR.

Comment on lines +238 to +242
const indexPattern = indexPatternCache.get(id);
if (indexPattern) {
return true;
}
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: return !!indexPatternCache.get(id);

if (
searchSourceDependencies.queryStringService &&
fields.query?.dataset &&
fields.query?.dataset?.type !== 'INDEX_PATTERN' &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: at this point, don't need ? in ?.dataset

) {
await searchSourceDependencies.queryStringService
.getDatasetService()
.cacheDataset(fields.query?.dataset);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this do the right thing if dataset is undefined?

const newQueryString = newQuery.query;
if (this.inputRef.getValue() !== newQueryString) {
const newQueryString = this.props.query.query;
if (this.inputRef.getValue() !== newQueryString && typeof newQueryString === 'string') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is inputRef.getValue() behind prop because its a controlled input (e.g. its value is defined by props)?

Signed-off-by: Ashwin P Chandran <[email protected]>
@@ -9,6 +9,7 @@ import { DatasetSelector as ConnectedDatasetSelector } from './index';
import { DatasetSelector } from './dataset_selector';
import { useOpenSearchDashboards } from '../../../../opensearch_dashboards_react/public';
import { Dataset } from '../../../common';
import { of } from 'rxjs';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { of } from 'rxjs';

@StefanStroebel
Copy link

Can we get an ETA when this will be approved and Merged?

@kavilla kavilla added v2.19.0 and removed v2.18.0 labels Oct 24, 2024
@ohenr
Copy link

ohenr commented Oct 31, 2024

Any news on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
all-star-contributor backport 2.x discover-next Skip-Changelog PRs that are too trivial to warrant a changelog or release notes entry v2.19.0
Projects
None yet
8 participants