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

[Discover] Allow save query to load correctly in Discover #5951

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

ananzh
Copy link
Member

@ananzh ananzh commented Feb 26, 2024

Description

  • add save query logic in Discover
  • add save query logic in VisBuilder

Issues Resolved

#5942

Changelog

  • fix: Load saved queries into Discover correctly

Screenshot

  • discover save query
discover-save-query.mov
  • visbuilder save query
visbuilder-save-query.mov

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

Copy link

codecov bot commented Feb 26, 2024

Codecov Report

Attention: Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.

Project coverage is 67.48%. Comparing base (7f0e9d0) to head (cd55d1a).

Files Patch % Lines
..._builder/public/application/components/top_nav.tsx 0.00% 4 Missing ⚠️
src/plugins/discover/public/url_generator.ts 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5951      +/-   ##
==========================================
+ Coverage   67.45%   67.48%   +0.02%     
==========================================
  Files        3448     3448              
  Lines       67916    67928      +12     
  Branches    11042    11045       +3     
==========================================
+ Hits        45812    45840      +28     
+ Misses      19435    19416      -19     
- Partials     2669     2672       +3     
Flag Coverage Δ
Linux_1 33.12% <30.76%> (+0.04%) ⬆️
Linux_2 55.11% <ø> (ø)
Linux_3 45.28% <80.00%> (+<0.01%) ⬆️
Linux_4 34.86% <ø> (ø)
Windows_1 33.14% <30.76%> (+0.04%) ⬆️
Windows_2 55.06% <ø> (ø)
Windows_3 45.29% <80.00%> (+<0.01%) ⬆️
Windows_4 34.86% <ø> (ø)

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.

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 change looks foo to me. Did not pull it down to validate it yet but i agree with most of the logic except on how to intiialize the undefined columns and sort. Also can you add a test to make sure we dont regress here. Not sure if functional tests her are preferred, but we can definitely atleast have unit/integ tests that ensure that the saved query is loaded when the page loads and that changing it changes the redux state.

Comment on lines 84 to 91
if (newSavedQueryId) {
dispatch(setSavedQuery(newSavedQueryId));
} else {
// remove savedQueryId from state
const newState = rootState;
delete newState.visualization.savedQuery;
dispatch(setState(newState.visualization));
}
Copy link
Member

Choose a reason for hiding this comment

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

Delete the saved query prop in the redux action if SavedQueryId is undefined

Suggested change
if (newSavedQueryId) {
dispatch(setSavedQuery(newSavedQueryId));
} else {
// remove savedQueryId from state
const newState = rootState;
delete newState.visualization.savedQuery;
dispatch(setState(newState.visualization));
}
dispatch(setSavedQuery(newSavedQueryId));

Copy link
Member Author

Choose a reason for hiding this comment

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

good point. Will clean it.

Comment on lines +45 to +56
const { columns } = useSelector((state) => {
const stateColumns = state.discover.columns;
// check if state columns is not undefined, otherwise use buildColumns
return {
columns: stateColumns !== undefined ? stateColumns : buildColumns([]),
};
});
const { sort } = useSelector((state) => {
const stateSort = state.discover.sort;
// check if state sort is not undefined, otherwise assign an empty array
return {
sort: stateSort !== undefined ? stateSort : [],
};
});
Copy link
Member

Choose a reason for hiding this comment

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

Why do we have this here? Cant we initialize the redux store with these values directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

load saved query is like load a saved object in discover. since discover is registered as a view in ui

ui: {
        defaults: async () => {
          this.initializeServices?.();
          const services = getServices();
          return await getPreloadedState(services);
        },
        slice: discoverSlice,
      },

it will not call getPreloadedState again. this is fine for saved object since we save sort and columns. but for saved query object, we only save an id. therefore for a tmp fix, we need to make the initiazation in panel and canvas to make it robust.

Comment on lines 30 to 42
const { columns } = useSelector(state => {
const stateColumns = state.discover.columns;

// check if stateColumns is not undefined, otherwise use buildColumns
return {
columns: stateColumns !== undefined ? stateColumns : buildColumns([])
};
});
Copy link
Member

Choose a reason for hiding this comment

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

Same goes here. Initializing them in the redux store means that you can always expect these to be not undefined and avoid this check alltogether.

Copy link
Member Author

@ananzh ananzh Feb 26, 2024

Choose a reason for hiding this comment

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

same explain here. we could create an issue and re-visit the routing logic.

ashwin-pc
ashwin-pc previously approved these changes Feb 27, 2024
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.

Can you provide a link to the issue or PR for the corresponding functional test?

abbyhu2000
abbyhu2000 previously approved these changes Feb 27, 2024
@ananzh
Copy link
Member Author

ananzh commented Feb 27, 2024

@ashwin-pc this is the tracking issue for complete ftr tests for discover #5713

I believe Function Test Suite 10: Saved query is the one for this bug. We will assign resources to add these tests.

@ananzh ananzh marked this pull request as draft March 14, 2024 18:43
@ananzh ananzh removed the v2.13.0 label Mar 14, 2024
* add save query logic in Discover
* add save query logic in VisBuilder
* remove double render

Issue Resolve
opensearch-project#5942

Signed-off-by: Anan Zhuang <[email protected]>
opensearch-changeset-bot bot added a commit to ananzh/OpenSearch-Dashboards that referenced this pull request Jun 24, 2024
@ananzh ananzh marked this pull request as ready for review June 24, 2024 19:38
Comment on lines +56 to 59
columns &&
timeFieldname &&
!prevColumns.current.includes(timeFieldname) &&
columns.includes(timeFieldname)
Copy link
Collaborator

@AMoo-Miki AMoo-Miki Jun 25, 2024

Choose a reason for hiding this comment

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

tiny bit of hardening:

Suggested change
columns &&
timeFieldname &&
!prevColumns.current.includes(timeFieldname) &&
columns.includes(timeFieldname)
timeFieldname &&
!prevColumns.current.includes(timeFieldname) &&
columns?.includes?.(timeFieldname)

} as VisualizationState;
});

it('should handle setIndexPattern', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: not the best test titles

AMoo-Miki
AMoo-Miki previously approved these changes Jun 25, 2024
Signed-off-by: Anan Zhuang <[email protected]>
@ananzh ananzh merged commit 170ac61 into opensearch-project:main Jun 26, 2024
66 of 67 checks passed
@ananzh ananzh deleted the fix-5942 branch June 26, 2024 23:43
opensearch-trigger-bot bot pushed a commit that referenced this pull request Jun 26, 2024
* [Discover] Allow save query to load correctly in Discover

* add save query logic in Discover
* add save query logic in VisBuilder
* remove double render

Issue Resolve
#5942

---------

Signed-off-by: Anan Zhuang <[email protected]>
(cherry picked from commit 170ac61)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@ananzh
Copy link
Member Author

ananzh commented Jun 26, 2024

Changeset dismissed after commit a fix. Add a failed changeset tag to mark this.

ananzh pushed a commit that referenced this pull request Jun 27, 2024
)

* [Discover] Allow save query to load correctly in Discover

* add save query logic in Discover
* add save query logic in VisBuilder
* remove double render

---------


(cherry picked from commit 170ac61)

Signed-off-by: Anan Zhuang <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants