-
Notifications
You must be signed in to change notification settings - Fork 894
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
Adjusted source of QueryStringManager functions for flyout. #8864
base: main
Are you sure you want to change the base?
Changes from all commits
da36888
9867fe8
b0a31bc
654fa32
7864ebd
b4e32f7
3013ed8
c6e6441
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,16 +24,16 @@ | |
} from '@elastic/eui'; | ||
import React, { useCallback, useEffect, useRef, useState } from 'react'; | ||
import { i18n } from '@osd/i18n'; | ||
import { QueryStringManager, SavedQuery, SavedQueryService } from '../../query'; | ||
import { SavedQuery, SavedQueryService } from '../../query'; | ||
import { SavedQueryCard } from './saved_query_card'; | ||
import { Query } from '../../../common'; | ||
import { getQueryService } from '../../services'; | ||
|
||
export interface OpenSavedQueryFlyoutProps { | ||
savedQueryService: SavedQueryService; | ||
onClose: () => void; | ||
onQueryOpen: (query: SavedQuery) => void; | ||
handleQueryDelete: (query: SavedQuery) => Promise<void>; | ||
queryStringManager: QueryStringManager; | ||
} | ||
|
||
interface SavedQuerySearchableItem { | ||
|
@@ -50,7 +50,6 @@ | |
onClose, | ||
onQueryOpen, | ||
handleQueryDelete, | ||
queryStringManager, | ||
}: OpenSavedQueryFlyoutProps) { | ||
const [selectedTabId, setSelectedTabId] = useState<string>('mutable-saved-queries'); | ||
const [savedQueries, setSavedQueries] = useState<SavedQuery[]>([]); | ||
|
@@ -65,36 +64,43 @@ | |
const [searchQuery, setSearchQuery] = useState(EuiSearchBar.Query.MATCH_ALL); | ||
const [isLoading, setIsLoading] = useState(false); | ||
const currentTabIdRef = useRef(selectedTabId); | ||
const queryStringManager = getQueryService().queryString; | ||
|
||
const fetchAllSavedQueriesForSelectedTab = useCallback(async () => { | ||
setIsLoading(true); | ||
const query = queryStringManager.getQuery(); | ||
let templateQueries: any[] = []; | ||
try { | ||
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?.()) || []; | ||
// 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); | ||
} | ||
// 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); | ||
// Set queries based on the current tab | ||
if (currentTabIdRef.current === 'mutable-saved-queries') { | ||
setSavedQueries(mutableSavedQueries); | ||
const allQueries = await savedQueryService.getAllSavedQueries(); | ||
const mutableSavedQueries = allQueries.filter((q) => !q.attributes.isTemplate); | ||
if (currentTabIdRef.current === 'mutable-saved-queries') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this required? line 89 should be covering it right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jowg-amazon could you clarify? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We were noticing that the getAllSavedQueries call can take a little while to return. If a user switches tabs before this call is finished, we were seeing that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of just have a state variable that sets a boolean if it Or even more so just set saved queries to all queries and then in the component if the selected tab is template-saved-queries you filter out all the saved queries not matching template-saved-queries etc. |
||
setSavedQueries(mutableSavedQueries); | ||
} | ||
} else if (currentTabIdRef.current === 'template-saved-queries') { | ||
setSavedQueries(templateQueries); | ||
} | ||
} else if (currentTabIdRef.current === 'template-saved-queries') { | ||
setSavedQueries(templateQueries); | ||
} catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error('Error occurred while retrieving saved queries.', e); | ||
} finally { | ||
setIsLoading(false); | ||
} | ||
setIsLoading(false); | ||
}, [savedQueryService, currentTabIdRef, setSavedQueries, queryStringManager]); | ||
|
||
const updatePageIndex = useCallback((index: number) => { | ||
|
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 refactor this component. we shouldn't need to fire a request to get all saved queries if the user opened saved queries and then switched to template queries and then switch back to saved queries and fire a request. we already have their 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.
Yes i think we already noticed the queries taking way longer to show up than they should