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

[Saved Queries] Improve saved query management #170599

Merged
merged 79 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 73 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
744a72e
Optimize saved queries exist check
davismcphee Nov 4, 2023
ef1a293
Check for saved query title conflicts at save instead of preloading a…
davismcphee Nov 4, 2023
88026dd
Add pagination to saved query list
davismcphee Nov 4, 2023
ab567ca
Get rid of saved query _all endpoint
davismcphee Nov 4, 2023
4e37a21
Improve saved query filtering and pagination
davismcphee Nov 4, 2023
f215a1d
Move delete button out of list to improve UX and improve a11y
davismcphee Nov 4, 2023
5d7082f
Add support for titleKeyword field and sorting on title
davismcphee Nov 4, 2023
f67c59a
Add active badge
davismcphee Nov 6, 2023
4e61c8a
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Nov 6, 2023
72ef1e7
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Nov 6, 2023
b18ce80
UI cleanup -- remove and replace it with EUI prop, change props to…
davismcphee Nov 7, 2023
1dc1b0d
Remove unused useEuiTheme
davismcphee Nov 8, 2023
4a38b0a
Fix issue where load and delete query buttons are still enabled after…
davismcphee Nov 8, 2023
14a0d90
[CI] Auto-commit changed files from 'node scripts/check_mappings_upda…
kibanamachine Dec 6, 2023
03c2d38
Update saved query popover design to match new mockups
davismcphee Dec 7, 2023
9ea296a
Add query count display
davismcphee Dec 7, 2023
9fa2fff
Clear selected query after search if it no longer exists on the page
davismcphee Dec 7, 2023
8a99931
Improve the logic that pulls the loaded query to the first page
davismcphee Dec 7, 2023
cf0b432
Fix Jest tests
davismcphee Dec 8, 2023
5b85dbf
Fix issue deleting saved queries, and fix failing FTR tests
davismcphee Dec 8, 2023
27df4a4
Fix broken tests
davismcphee Dec 8, 2023
e8598a2
Attempting to fix failing test
davismcphee Dec 8, 2023
17c60c3
Drop saved query management list style override
davismcphee Jan 16, 2024
1b0408b
Small type cleanup and removing modified translation entries.
davismcphee Jan 16, 2024
c7ea202
Added comment about Axe failure
davismcphee Jan 16, 2024
81676a1
Fix bug in Lens where loading the same saved query which is already l…
davismcphee Jan 17, 2024
543d44a
Add Jest tests for saved_query_management_list.test.tsx
davismcphee Jan 17, 2024
fcb45ea
Finish adding Jest tests
davismcphee Jan 17, 2024
6663eee
Cleanup in saved_query_mangement_list
davismcphee Jan 17, 2024
008b853
Jest test cleanup
davismcphee Jan 17, 2024
18dd2b3
Update route_handler_context Jest tests
davismcphee Jan 17, 2024
30e66ec
Add model version tests
davismcphee Jan 18, 2024
35f83cf
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jan 18, 2024
24f2911
[CI] Auto-commit changed files from 'node scripts/jest_integration -u…
kibanamachine Jan 18, 2024
61e509a
Merge branch 'main' into saved-query-impovements
davismcphee Jan 26, 2024
c629b8c
Fix update button underline on hover and the focus outline being cut off
davismcphee Jan 27, 2024
88989da
Clean up query menu panels
davismcphee Jan 27, 2024
cafc480
Simplify query name help text
davismcphee Jan 27, 2024
9beba60
Improve query save and delete messages
davismcphee Jan 27, 2024
e48acf9
Remove /_all endpoint
davismcphee Jan 27, 2024
e99675a
Implement server side duplicate title check, and improve error handling
davismcphee Jan 27, 2024
e3938b5
Make saved query update button aware of time filter
davismcphee Jan 27, 2024
70c3c4d
Refine saved query search functionality
davismcphee Jan 29, 2024
daabd0b
Drop saved query switchToModelVersionAt
davismcphee Jan 29, 2024
7e87c5f
Merge branch 'main' into saved-query-impovements
davismcphee Jan 29, 2024
fda58ed
Fix duplicate query check
davismcphee Jan 29, 2024
303e1b8
Remove saved query title help text
davismcphee Jan 29, 2024
7d677de
Reset currentPanelId on popover open, fixes minor styling bug
davismcphee Jan 29, 2024
acf4cf0
Remove selectable list item background override
davismcphee Jan 29, 2024
02d7d60
No longer clear selected saved query on page change
davismcphee Jan 29, 2024
6da59d9
Add disabled button text
davismcphee Feb 1, 2024
711d620
Migrate saved_query endpoint error handling to Boom
davismcphee Feb 1, 2024
70fbfd1
Update Jest route_handler_context Jest tests
davismcphee Feb 1, 2024
572c7a0
Add saved query duplicate title check
davismcphee Feb 1, 2024
99ba526
Update saved query search functionality
davismcphee Feb 2, 2024
367d4f5
Merge branch 'main' into saved-query-impovements
davismcphee Feb 2, 2024
8287ae3
Clean up saved query search logic
davismcphee Feb 2, 2024
8f1385f
Fix failing tests by waiting for saved query form to close after saving
davismcphee Feb 3, 2024
c765fed
Fix broken saved query Cypress tests
davismcphee Feb 3, 2024
257dffb
Convert saved query API tests to TypeScript, and add tests for search…
davismcphee Feb 6, 2024
fd0e331
Add utilities to saved query API integration tests to simplify tests
davismcphee Feb 6, 2024
f62e5ce
Reorganize saved query API integration tests
davismcphee Feb 6, 2024
fea1606
Ensure all saved query filter changes are detected
davismcphee Feb 7, 2024
1da5917
Fix issue where saved query 'Include filters' and 'Include time filte…
davismcphee Feb 7, 2024
5ea22f5
Add loading indicator to query list
davismcphee Feb 7, 2024
0d06849
Fix issue where query count could show a negative value in some situa…
davismcphee Feb 7, 2024
eee8645
Allow searching for queries with titles containing special characters
davismcphee Feb 7, 2024
c6cff43
Merge branch 'main' into saved-query-impovements
davismcphee Feb 7, 2024
a505553
Merge branch 'main' into saved-query-impovements
kibanamachine Feb 7, 2024
94e9361
Fix React errors caused by calling usePrettyDuration within itemTitle…
davismcphee Feb 8, 2024
032a918
Switch from lodash max to Math.max
davismcphee Feb 8, 2024
8736091
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Feb 8, 2024
9a09649
Merge branch 'main' into saved-query-impovements
stratoula Feb 8, 2024
d98d2c2
Merge branch 'main' into saved-query-impovements
davismcphee Feb 9, 2024
6dd865a
Fix current_mappings.json
davismcphee Feb 9, 2024
9888240
Merge branch 'main' into saved-query-impovements
davismcphee Feb 9, 2024
5eff403
Merge branch 'main' into saved-query-impovements
davismcphee Feb 9, 2024
62281ff
Merge branch 'main' into saved-query-impovements
davismcphee Feb 9, 2024
41605ec
Merge branch 'main' into saved-query-impovements
davismcphee Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
],
"query": [
"description",
"title"
"title",
"titleKeyword"
],
"kql-telemetry": [],
"search-session": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@
"title": {
"type": "text"
},
"titleKeyword": {
"type": "keyword"
},
"description": {
"type": "text"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"osquery-pack-asset": "cd140bc2e4b092e93692b587bf6e38051ef94c75",
"osquery-saved-query": "6095e288750aa3164dfe186c74bc5195c2bf2bd4",
"policy-settings-protection-updates-note": "33924bb246f9e5bcb876109cc83e3c7a28308352",
"query": "21cbbaa09abb679078145ce90087b1e88b7eae95",
"query": "501bece68f26fe561286a488eabb1a8ab12f1137",
"risk-engine-configuration": "b105d4a3c6adce40708d729d12e5ef3c8fbd9508",
"rules-settings": "892a2918ebaeba809a612b8d97cec0b07c800b5f",
"sample-data-telemetry": "37441b12f5b0159c2d6d5138a494c9f440e950b5",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/query/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const createStartContractMock = () => {
addToQueryLog: jest.fn(),
filterManager: createFilterManagerMock(),
queryString: queryStringManagerMock.createStartContract(),
savedQueries: { getSavedQuery: jest.fn() } as any,
savedQueries: { getSavedQuery: jest.fn(), getSavedQueryCount: jest.fn() } as any,
state$: new Observable(),
getState: jest.fn(),
timefilter: timefilterServiceMock.createStartContract(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import { SAVED_QUERY_BASE_URL } from '../../../common/constants';
const http = httpServiceMock.createStartContract();

const {
isDuplicateTitle,
deleteSavedQuery,
getSavedQuery,
findSavedQueries,
createQuery,
updateQuery,
getAllSavedQueries,
getSavedQueryCount,
} = createSavedQueryService(http);

Expand All @@ -42,6 +42,18 @@ describe('saved query service', () => {
http.delete.mockReset();
});

describe('isDuplicateTitle', function () {
it('should post the title and ID', async () => {
http.post.mockResolvedValue({ isDuplicate: true });
await isDuplicateTitle('foo', 'bar');
expect(http.post).toBeCalled();
expect(http.post).toHaveBeenCalledWith(`${SAVED_QUERY_BASE_URL}/_is_duplicate_title`, {
body: '{"title":"foo","id":"bar"}',
version,
});
});
});

describe('createQuery', function () {
it('should post the stringified given attributes', async () => {
await createQuery(savedQueryAttributes);
Expand All @@ -64,19 +76,6 @@ describe('saved query service', () => {
});
});

describe('getAllSavedQueries', function () {
it('should post and extract the saved queries from the response', async () => {
http.post.mockResolvedValue({
total: 0,
savedQueries: [{ attributes: savedQueryAttributes }],
});
const result = await getAllSavedQueries();
expect(http.post).toBeCalled();
expect(http.post).toHaveBeenCalledWith(`${SAVED_QUERY_BASE_URL}/_all`, { version });
expect(result).toEqual([{ attributes: savedQueryAttributes }]);
});
});

describe('findSavedQueries', function () {
it('should post and return the total & saved queries', async () => {
http.post.mockResolvedValue({
Expand Down
22 changes: 12 additions & 10 deletions src/plugins/data/public/query/saved_query/saved_query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ import { SAVED_QUERY_BASE_URL } from '../../../common/constants';
const version = '1';

export const createSavedQueryService = (http: HttpStart) => {
const isDuplicateTitle = async (title: string, id?: string) => {
const response = await http.post<{ isDuplicate: boolean }>(
`${SAVED_QUERY_BASE_URL}/_is_duplicate_title`,
{
body: JSON.stringify({ title, id }),
version,
}
);
return response.isDuplicate;
};

const createQuery = async (attributes: SavedQueryAttributes, { overwrite = false } = {}) => {
const savedQuery = await http.post<SavedQuery>(`${SAVED_QUERY_BASE_URL}/_create`, {
body: JSON.stringify(attributes),
Expand All @@ -30,15 +41,6 @@ export const createSavedQueryService = (http: HttpStart) => {
return savedQuery;
};

// we have to tell the saved objects client how many to fetch, otherwise it defaults to fetching 20 per page
const getAllSavedQueries = async (): Promise<SavedQuery[]> => {
const { savedQueries } = await http.post<{ savedQueries: SavedQuery[] }>(
`${SAVED_QUERY_BASE_URL}/_all`,
{ version }
);
return savedQueries;
};

// findSavedQueries will do a 'match_all' if no search string is passed in
const findSavedQueries = async (
search: string = '',
Expand Down Expand Up @@ -69,9 +71,9 @@ export const createSavedQueryService = (http: HttpStart) => {
};

return {
isDuplicateTitle,
createQuery,
updateQuery,
getAllSavedQueries,
findSavedQueries,
getSavedQuery,
deleteSavedQuery,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/query/saved_query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ export type SavedQueryTimeFilter = TimeRange & {
export type { SavedQuery, SavedQueryAttributes };

export interface SavedQueryService {
isDuplicateTitle: (title: string, id?: string) => Promise<boolean>;
createQuery: (attributes: SavedQueryAttributes) => Promise<SavedQuery>;
updateQuery: (id: string, attributes: SavedQueryAttributes) => Promise<SavedQuery>;
getAllSavedQueries: () => Promise<SavedQuery[]>;
findSavedQueries: (
searchText?: string,
perPage?: number,
Expand Down
Loading