-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Saved Queries] Improve saved query management #170599
Merged
davismcphee
merged 79 commits into
elastic:main
from
davismcphee:saved-query-impovements
Feb 12, 2024
Merged
Changes from 34 commits
Commits
Show all changes
79 commits
Select commit
Hold shift + click to select a range
744a72e
Optimize saved queries exist check
davismcphee ef1a293
Check for saved query title conflicts at save instead of preloading a…
davismcphee 88026dd
Add pagination to saved query list
davismcphee ab567ca
Get rid of saved query _all endpoint
davismcphee 4e37a21
Improve saved query filtering and pagination
davismcphee f215a1d
Move delete button out of list to improve UX and improve a11y
davismcphee 5d7082f
Add support for titleKeyword field and sorting on title
davismcphee f67c59a
Add active badge
davismcphee 4e61c8a
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 72ef1e7
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine b18ce80
UI cleanup -- remove and replace it with EUI prop, change props to…
davismcphee 1dc1b0d
Remove unused useEuiTheme
davismcphee 4a38b0a
Fix issue where load and delete query buttons are still enabled after…
davismcphee 14a0d90
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine 03c2d38
Update saved query popover design to match new mockups
davismcphee 9ea296a
Add query count display
davismcphee 9fa2fff
Clear selected query after search if it no longer exists on the page
davismcphee 8a99931
Improve the logic that pulls the loaded query to the first page
davismcphee cf0b432
Fix Jest tests
davismcphee 5b85dbf
Fix issue deleting saved queries, and fix failing FTR tests
davismcphee 27df4a4
Fix broken tests
davismcphee e8598a2
Attempting to fix failing test
davismcphee 17c60c3
Drop saved query management list style override
davismcphee 1b0408b
Small type cleanup and removing modified translation entries.
davismcphee c7ea202
Added comment about Axe failure
davismcphee 81676a1
Fix bug in Lens where loading the same saved query which is already l…
davismcphee 543d44a
Add Jest tests for saved_query_management_list.test.tsx
davismcphee fcb45ea
Finish adding Jest tests
davismcphee 6663eee
Cleanup in saved_query_mangement_list
davismcphee 008b853
Jest test cleanup
davismcphee 18dd2b3
Update route_handler_context Jest tests
davismcphee 30e66ec
Add model version tests
davismcphee 35f83cf
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 24f2911
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine 61e509a
Merge branch 'main' into saved-query-impovements
davismcphee c629b8c
Fix update button underline on hover and the focus outline being cut off
davismcphee 88989da
Clean up query menu panels
davismcphee cafc480
Simplify query name help text
davismcphee 9beba60
Improve query save and delete messages
davismcphee e48acf9
Remove /_all endpoint
davismcphee e99675a
Implement server side duplicate title check, and improve error handling
davismcphee e3938b5
Make saved query update button aware of time filter
davismcphee 70c3c4d
Refine saved query search functionality
davismcphee daabd0b
Drop saved query switchToModelVersionAt
davismcphee 7e87c5f
Merge branch 'main' into saved-query-impovements
davismcphee fda58ed
Fix duplicate query check
davismcphee 303e1b8
Remove saved query title help text
davismcphee 7d677de
Reset currentPanelId on popover open, fixes minor styling bug
davismcphee acf4cf0
Remove selectable list item background override
davismcphee 02d7d60
No longer clear selected saved query on page change
davismcphee 6da59d9
Add disabled button text
davismcphee 711d620
Migrate saved_query endpoint error handling to Boom
davismcphee 70fbfd1
Update Jest route_handler_context Jest tests
davismcphee 572c7a0
Add saved query duplicate title check
davismcphee 99ba526
Update saved query search functionality
davismcphee 367d4f5
Merge branch 'main' into saved-query-impovements
davismcphee 8287ae3
Clean up saved query search logic
davismcphee 8f1385f
Fix failing tests by waiting for saved query form to close after saving
davismcphee c765fed
Fix broken saved query Cypress tests
davismcphee 257dffb
Convert saved query API tests to TypeScript, and add tests for search…
davismcphee fd0e331
Add utilities to saved query API integration tests to simplify tests
davismcphee f62e5ce
Reorganize saved query API integration tests
davismcphee fea1606
Ensure all saved query filter changes are detected
davismcphee 1da5917
Fix issue where saved query 'Include filters' and 'Include time filte…
davismcphee 5ea22f5
Add loading indicator to query list
davismcphee 0d06849
Fix issue where query count could show a negative value in some situa…
davismcphee eee8645
Allow searching for queries with titles containing special characters
davismcphee c6cff43
Merge branch 'main' into saved-query-impovements
davismcphee a505553
Merge branch 'main' into saved-query-impovements
kibanamachine 94e9361
Fix React errors caused by calling usePrettyDuration within itemTitle…
davismcphee 032a918
Switch from lodash max to Math.max
davismcphee 8736091
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 9a09649
Merge branch 'main' into saved-query-impovements
stratoula d98d2c2
Merge branch 'main' into saved-query-impovements
davismcphee 6dd865a
Fix current_mappings.json
davismcphee 9888240
Merge branch 'main' into saved-query-impovements
davismcphee 5eff403
Merge branch 'main' into saved-query-impovements
davismcphee 62281ff
Merge branch 'main' into saved-query-impovements
davismcphee 41605ec
Merge branch 'main' into saved-query-impovements
davismcphee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,24 @@ | |
|
||
import { CustomRequestHandlerContext, RequestHandlerContext, SavedObject } from '@kbn/core/server'; | ||
import { isFilters, isOfQueryType } from '@kbn/es-query'; | ||
import { omit } from 'lodash'; | ||
import { isQuery, SavedQueryAttributes } from '../../common'; | ||
import { extract, inject } from '../../common/query/filters/persistable_state'; | ||
|
||
export interface InternalSavedQueryAttributes extends SavedQueryAttributes { | ||
titleKeyword: string; | ||
} | ||
|
||
function injectReferences({ | ||
id, | ||
attributes, | ||
attributes: internalAttributes, | ||
namespaces, | ||
references, | ||
}: Pick<SavedObject<SavedQueryAttributes>, 'id' | 'attributes' | 'namespaces' | 'references'>) { | ||
}: Pick< | ||
SavedObject<InternalSavedQueryAttributes>, | ||
'id' | 'attributes' | 'namespaces' | 'references' | ||
>) { | ||
const attributes: SavedQueryAttributes = omit(internalAttributes, 'titleKeyword'); | ||
const { query } = attributes; | ||
if (isOfQueryType(query) && typeof query.query === 'string') { | ||
try { | ||
|
@@ -48,8 +57,9 @@ function extractReferences({ | |
} | ||
} | ||
|
||
const attributes: SavedQueryAttributes = { | ||
const attributes: InternalSavedQueryAttributes = { | ||
title: title.trim(), | ||
titleKeyword: title.trim(), | ||
description: description.trim(), | ||
query: { | ||
...query, | ||
|
@@ -83,7 +93,7 @@ export async function registerSavedQueryRouteHandlerContext(context: RequestHand | |
verifySavedQuery(attrs); | ||
const { attributes, references } = extractReferences(attrs); | ||
|
||
const savedObject = await soClient.create<SavedQueryAttributes>('query', attributes, { | ||
const savedObject = await soClient.create<InternalSavedQueryAttributes>('query', attributes, { | ||
references, | ||
}); | ||
|
||
|
@@ -97,9 +107,14 @@ export async function registerSavedQueryRouteHandlerContext(context: RequestHand | |
verifySavedQuery(attrs); | ||
const { attributes, references } = extractReferences(attrs); | ||
|
||
const savedObject = await soClient.update<SavedQueryAttributes>('query', id, attributes, { | ||
references, | ||
}); | ||
const savedObject = await soClient.update<InternalSavedQueryAttributes>( | ||
'query', | ||
id, | ||
attributes, | ||
{ | ||
references, | ||
} | ||
); | ||
|
||
// TODO: Handle properly | ||
if (savedObject.error) throw new Error(savedObject.error.message); | ||
|
@@ -108,10 +123,8 @@ export async function registerSavedQueryRouteHandlerContext(context: RequestHand | |
}; | ||
|
||
const getSavedQuery = async (id: string) => { | ||
const { saved_object: savedObject, outcome } = await soClient.resolve<SavedQueryAttributes>( | ||
'query', | ||
id | ||
); | ||
const { saved_object: savedObject, outcome } = | ||
await soClient.resolve<InternalSavedQueryAttributes>('query', id); | ||
if (outcome === 'conflict') { | ||
throw new Error(`Multiple saved queries found with ID: ${id} (legacy URL alias conflict)`); | ||
} else if (savedObject.error) { | ||
|
@@ -121,41 +134,30 @@ export async function registerSavedQueryRouteHandlerContext(context: RequestHand | |
}; | ||
|
||
const getSavedQueriesCount = async () => { | ||
const { total } = await soClient.find<SavedQueryAttributes>({ | ||
const { total } = await soClient.find<InternalSavedQueryAttributes>({ | ||
type: 'query', | ||
page: 0, | ||
perPage: 0, | ||
}); | ||
return total; | ||
}; | ||
|
||
const findSavedQueries = async ({ page = 1, perPage = 50, search = '' } = {}) => { | ||
const { total, saved_objects: savedObjects } = await soClient.find<SavedQueryAttributes>({ | ||
type: 'query', | ||
page, | ||
perPage, | ||
search, | ||
}); | ||
const { total, saved_objects: savedObjects } = | ||
await soClient.find<InternalSavedQueryAttributes>({ | ||
type: 'query', | ||
page, | ||
perPage, | ||
search, | ||
sortField: search ? undefined : 'titleKeyword', | ||
sortOrder: search ? undefined : 'asc', | ||
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. ℹ️ If no search term is passed, we sort by title alphabetically. If a search term is passed, we use the default score based sorting. |
||
}); | ||
|
||
const savedQueries = savedObjects.map(injectReferences); | ||
|
||
return { total, savedQueries }; | ||
}; | ||
|
||
const getAllSavedQueries = async () => { | ||
const finder = soClient.createPointInTimeFinder<SavedQueryAttributes>({ | ||
type: 'query', | ||
perPage: 100, | ||
}); | ||
|
||
const savedObjects: Array<SavedObject<SavedQueryAttributes>> = []; | ||
for await (const response of finder.find()) { | ||
savedObjects.push(...(response.saved_objects ?? [])); | ||
} | ||
await finder.close(); | ||
|
||
const savedQueries = savedObjects.map(injectReferences); | ||
return { total: savedQueries.length, savedQueries }; | ||
}; | ||
|
||
const deleteSavedQuery = async (id: string) => { | ||
return await soClient.delete('query', id, { force: true }); | ||
}; | ||
|
@@ -166,7 +168,6 @@ export async function registerSavedQueryRouteHandlerContext(context: RequestHand | |
get: getSavedQuery, | ||
count: getSavedQueriesCount, | ||
find: findSavedQueries, | ||
getAll: getAllSavedQueries, | ||
delete: deleteSavedQuery, | ||
}; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ℹ️ Minor performance optimization to no longer request documents when we only need the
total
.