-
Notifications
You must be signed in to change notification settings - Fork 898
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 template queries loading and update getSampleQuery interface #8848
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8848 +/- ##
==========================================
- Coverage 60.86% 56.39% -4.48%
==========================================
Files 3800 1239 -2561
Lines 90818 25913 -64905
Branches 14307 4437 -9870
==========================================
- Hits 55276 14613 -40663
+ Misses 32028 10559 -21469
+ Partials 3514 741 -2773
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Joanne Wang <jowg@amazon.com>
eca8670
to
0221592
Compare
Signed-off-by: Joanne Wang <jowg@amazon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only skimmed so far, but posting initial comments
src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx
Show resolved
Hide resolved
src/plugins/data/public/ui/saved_query_flyouts/open_saved_query_flyout.tsx
Outdated
Show resolved
Hide resolved
src/plugins/discover/public/application/components/no_results/no_results.tsx
Show resolved
Hide resolved
@@ -179,7 +197,13 @@ export function OpenSavedQueryFlyout({ | |||
onChange={onChange} | |||
/> | |||
<EuiSpacer /> | |||
{queriesOnCurrentPage.length > 0 ? ( | |||
{isLoading ? ( | |||
<EuiFlexGroup justifyContent="center" alignItems="center" style={{ height: '200px' }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why are we hardcoding height here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
query: selectedQuery.attributes.query.query, | ||
language: selectedQuery.attributes.query.language, | ||
}; | ||
queryStringManager.setQuery(updatedQuery); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious, why does this use setQuery over onQueryOpen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to this line (link), we wanted to preserve the data source info in the URL state when the saved query isn't associated with a data source. onQueryOpen
clears the selected data source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the line that concerns me a little and want to know more about why we need this. What are we trying to do here?
There are 2 states at play here. Query manager state and the local searchbar state. onQueryOpen
updates the search bar state and not the query state because the act of opening a saved query today does not update the query state until the user has decided to fire the query (similar to how you dont want typing the query to update query state until you are ready to fire the query)
Updating the query manager state here for templates changes this behaviour for users when it comes to templates, because now it means that template queries DO change the query state even if the user has not been given the opportunity to confirm that thats the query that they want to run.
This change will not affect datasources that dont run the query by default, but for indices and index patterns, this means that opening a saved query template runs the query automatically while non templates do not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ashwin-pc That's good to know. Given that context, it sounds like the way forward would involve retrieving the dataset from the query state when the saved query doesn't have a dataset (i.e., when the saved query is a template, or when the saved query is not associated with a dataset), and applying it to the saved query before calling onQueryOpen
. Does that sound appropriate?
E.g.,
onClick={() => {
if (selectedQuery) {
if (
// Template queries are not associated with data sources. Apply data source from current query
selectedQuery.attributes.isTemplate ||
// Associating a saved query with a data source is optional. If no data source is present, apply the current source.
!selectedQuery.attributes.query.dataset?.dataSource
) {
selectedQuery.attributes.query.dataset = queryStringManager?.getQuery().dataset;
}
onQueryOpen(selectedQuery);
onClose();
}
}}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR has been merged, I'll adjust this in a follow-up PR.
src/plugins/discover/public/application/components/no_results/no_results.tsx
Show resolved
Hide resolved
if (Array.isArray(sampleQueriesResponse)) { | ||
setSampleQueries([...sampleQueriesResponse, ...newSampleQueries]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, could create a helper function for setting sample queries that gets used in both places to prevent divergence
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 having the savedQueryService take care of this would be ideal. Sample queries and templates are an extension of that
src/plugins/discover/public/application/components/no_results/no_results.tsx
Show resolved
Hide resolved
Signed-off-by: Joanne Wang <jowg@amazon.com>
Signed-off-by: Riya Saxena <riysaxen@amazon.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason codecov is no longer loading, but think the two main things are covered at this point.
I restarted some failed CI that I think is unrelated, but please validate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we sanity test this with the new UI with different datasources and languages?
@@ -179,7 +197,13 @@ export function OpenSavedQueryFlyout({ | |||
onChange={onChange} | |||
/> | |||
<EuiSpacer /> | |||
{queriesOnCurrentPage.length > 0 ? ( | |||
{isLoading ? ( | |||
<EuiFlexGroup justifyContent="center" alignItems="center" style={{ height: '200px' }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
setIsLoading(true); | ||
const query = queryStringManager.getQuery(); | ||
let templateQueries: any[] = []; | ||
|
||
// fetch sample query based on dataset type | ||
if (query?.dataset?.type) { | ||
templateQueries = | ||
(await queryStringManager | ||
.getDatasetService() | ||
?.getType(query.dataset.type) | ||
?.getSampleQueries?.()) || []; | ||
|
||
// Check if any sample query has isTemplate set to true | ||
const hasTemplates = templateQueries.some((q) => q?.attributes?.isTemplate); | ||
setHasTemplateQueries(hasTemplates); | ||
} | ||
|
||
// Set queries based on the current tab | ||
if (currentTabIdRef.current === 'mutable-saved-queries') { | ||
const allQueries = await savedQueryService.getAllSavedQueries(); | ||
const mutableSavedQueries = allQueries.filter((q) => !q.attributes.isTemplate); | ||
if (currentTabIdRef.current === 'mutable-saved-queries') { | ||
setSavedQueries(mutableSavedQueries); | ||
} | ||
} else if (currentTabIdRef.current === 'template-saved-queries') { | ||
setSavedQueries(templateQueries); | ||
} | ||
setIsLoading(false); | ||
}, [savedQueryService, currentTabIdRef, setSavedQueries, queryStringManager]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that now while my sample queries load my saved query flyout is unusable? Also if thats true, whats the user experience when these queries take time to load or fail?
if (currentTabIdRef.current === 'mutable-saved-queries') { | ||
const allQueries = await savedQueryService.getAllSavedQueries(); | ||
const mutableSavedQueries = allQueries.filter((q) => !q.attributes.isTemplate); | ||
if (currentTabIdRef.current === 'mutable-saved-queries') { | ||
setSavedQueries(mutableSavedQueries); | ||
} | ||
} else if (currentTabIdRef.current === 'template-saved-queries') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can we use enums or constants for the tabs and not raw strings?
query: selectedQuery.attributes.query.query, | ||
language: selectedQuery.attributes.query.language, | ||
}; | ||
queryStringManager.setQuery(updatedQuery); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the line that concerns me a little and want to know more about why we need this. What are we trying to do here?
There are 2 states at play here. Query manager state and the local searchbar state. onQueryOpen
updates the search bar state and not the query state because the act of opening a saved query today does not update the query state until the user has decided to fire the query (similar to how you dont want typing the query to update query state until you are ready to fire the query)
Updating the query manager state here for templates changes this behaviour for users when it comes to templates, because now it means that template queries DO change the query state even if the user has not been given the opportunity to confirm that thats the query that they want to run.
This change will not affect datasources that dont run the query by default, but for indices and index patterns, this means that opening a saved query template runs the query automatically while non templates do not.
@@ -256,6 +258,7 @@ export function SavedQueryManagementComponent({ | |||
onClose={() => openSavedQueryFlyout?.close().then()} | |||
onQueryOpen={onLoad} | |||
handleQueryDelete={handleDelete} | |||
queryStringManager={queryStringManager} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Instead of prop drilling queryStringManager
throughout, savedQueryService
should ideally have been responsible for templates too.
if (Array.isArray(sampleQueriesResponse)) { | ||
setSampleQueries([...sampleQueriesResponse, ...newSampleQueries]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 having the savedQueryService take care of this would be ideal. Sample queries and templates are an extension of that
} | ||
}) | ||
.catch((error: any) => { | ||
// noop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets atleast log this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would avoid injecting a new prop to global component. will add more comments to the pr
@@ -467,6 +474,7 @@ class SearchBarUI extends Component<SearchBarProps, State> { | |||
useSaveQueryMenu={useSaveQueryMenu} | |||
isQueryEditorControl={isQueryEditorControl} | |||
saveQuery={this.onSave} | |||
queryStringManager={this.props.queryStringManager} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the query string manager being pass in which will impact the state of the components in search bar which is also utilized by other plugins besides the Discover plugin (like dashboards and visualizations) so i would watch out and generally avoid touching this file.
this already was able to access the query string manager like this:
this should be available in similar locations within this ui
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for calling that out. I'll revert line 205 in create_search_bar.tsx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this PR has been merged, I'll adjust this in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in #8864
}, [savedQueryService, selectedTabId, setSavedQueries]); | ||
setIsLoading(true); | ||
const query = queryStringManager.getQuery(); | ||
let templateQueries: any[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should just be passing around a Query
object.
} | ||
|
||
// Set queries based on the current tab | ||
if (currentTabIdRef.current === 'mutable-saved-queries') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apologies i believe i missed the original design PR for template queries.
Key Issues with Current Approach:
- Saved Query Purpose Change
- Historically, saved queries stored exactly what users typed
- Used for cross-application consistency
- one major use case: Create query in Discover, apply same query in Dashboards against many saved searches and visualizations
- Cross-Plugin Impact
- Potential unexpected behavior in Dashboards when using templated queries
- Need to verify behavior after dataset type selection
- Other plugins may not be aware of template functionality
- Suggested Alternative Structure
- Make saved queries and saved query templates separate entities
- Create new saved object type: "saved query template"
- Keep existing saved query behavior intact
- Share UI components between both types
This maintains backwards compatibility while cleanly separating template functionality from core saved query behavior.
that said might be a little too late. but have we verified existing saved query impact? as of today with this new ui toggled on? do we need to add a saved object migration for saved queries? could we verify the impact to other plugins for example the dashboards plugin?
Overriding due to a parallel conversation where some of the existing issues are an existing bug. This is not the final implimentation and requires changes to incorporate the appropriate fixes. The added property should be fine since it does not modify how the existing properties and saved searches work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditionally approving it to unblock testing the saved query template changes. Saved query as a feature is still broken. That needs to be fixed in a separate PR.
* update sample query impl and fix saved query load Signed-off-by: Joanne Wang <jowg@amazon.com> * Changeset file for PR #8848 created/updated * Changeset file for PR #8848 created/updated * add loading spinner Signed-off-by: Joanne Wang <jowg@amazon.com> * check if tab is shown based on if sample query isTemplate Signed-off-by: Joanne Wang <jowg@amazon.com> * added UTs for svaed queries flyout Signed-off-by: Riya Saxena <riysaxen@amazon.com> --------- Signed-off-by: Joanne Wang <jowg@amazon.com> Signed-off-by: Riya Saxena <riysaxen@amazon.com> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Riya Saxena <riysaxen@amazon.com> (cherry picked from commit 25d3de7) Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
…) (#8859) * update sample query impl and fix saved query load * Changeset file for PR #8848 created/updated * Changeset file for PR #8848 created/updated * add loading spinner * check if tab is shown based on if sample query isTemplate * added UTs for svaed queries flyout --------- (cherry picked from commit 25d3de7) Signed-off-by: Joanne Wang <jowg@amazon.com> Signed-off-by: Riya Saxena <riysaxen@amazon.com> 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> Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com> Co-authored-by: Riya Saxena <riysaxen@amazon.com>
Description
Screen.Recording.2024-11-12.at.9.50.17.AM.mov
Issues Resolved
Screenshot
Testing the changes
Changelog
Check List
yarn test:jest
yarn test:jest_integration