Skip to content

Commit

Permalink
Merge branch 'master' into server-saved-objects-client
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf committed Oct 14, 2019
2 parents 296a0ee + 7e40ced commit ba6b39d
Show file tree
Hide file tree
Showing 98 changed files with 2,756 additions and 10,953 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
/x-pack/legacy/plugins/encrypted_saved_objects/ @elastic/kibana-security
/src/legacy/server/csp/ @elastic/kibana-security
/x-pack/plugins/security/ @elastic/kibana-security
/x-pack/test/api_integration/apis/security/ @elastic/kibana-security

# Kibana Stack Services
/packages/kbn-analytics/ @elastic/kibana-stack-services
Expand Down
2 changes: 1 addition & 1 deletion docs/management/dashboard_only_mode/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[[xpack-dashboard-only-mode]]
== Dashboard-only mode

deprecated[7.4.0, Using the `kibana_dashboard_only_user` role is deprecated. Use <<kibana-feature-privileges,feature privileges>> instead.]
deprecated[7.4.0, "Using the `kibana_dashboard_only_user` role is deprecated. Use <<kibana-feature-privileges,feature privileges>> instead."]

In dashboard-only mode, users have access to only the *Dashboard* app.
Users can view and filter the dashboards, but cannot create, edit, or delete
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"@babel/register": "^7.5.5",
"@elastic/charts": "^13.5.1",
"@elastic/datemath": "5.0.2",
"@elastic/ems-client": "^1.0.2",
"@elastic/eui": "14.4.0",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
Expand Down Expand Up @@ -171,7 +172,7 @@
"hapi": "^17.5.3",
"hapi-auth-cookie": "^9.0.0",
"history": "^4.9.0",
"hjson": "3.1.2",
"hjson": "3.2.0",
"hoek": "^5.0.4",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.2.2",
Expand Down Expand Up @@ -358,7 +359,7 @@
"babel-jest": "^24.9.0",
"babel-plugin-dynamic-import-node": "^2.3.0",
"babel-plugin-istanbul": "^5.2.0",
"backport": "4.7.1",
"backport": "4.7.3",
"chai": "3.5.0",
"chance": "1.0.18",
"cheerio": "0.22.0",
Expand Down Expand Up @@ -446,7 +447,7 @@
"strip-ansi": "^3.0.1",
"supertest": "^3.1.0",
"supertest-as-promised": "^4.0.2",
"tree-kill": "^1.1.0",
"tree-kill": "^1.2.1",
"typescript": "3.5.3",
"typings-tester": "^0.3.2",
"vinyl-fs": "^3.0.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"getopts": "^2.2.5",
"moment": "^2.20.1",
"rxjs": "^6.2.1",
"tree-kill": "^1.2.0",
"tree-kill": "^1.2.1",
"tslib": "^1.9.3"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-dev-utils/src/proc_runner/proc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import chalk from 'chalk';

import treeKill from 'tree-kill';
import { promisify } from 'util';
const treeKillAsync = promisify(treeKill);
const treeKillAsync = promisify((...args: [number, string, any]) => treeKill(...args));

import { ToolingLog } from '../tooling_log';
import { observeLines } from './observe_lines';
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-es/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"node-fetch": "^2.6.0",
"simple-git": "^1.91.0",
"tar-fs": "^1.16.3",
"tree-kill": "^1.1.0",
"tree-kill": "^1.2.1",
"yauzl": "^2.10.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import { SavedQuery } from '../../index';
import { SavedQueryService } from '../../lib/saved_query_service';
import { SavedQueryListItem } from './saved_query_list_item';

const pageCount = 50;

const perPage = 50;
interface Props {
showSaveQuery?: boolean;
loadedSavedQuery?: SavedQuery;
Expand All @@ -61,18 +60,22 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
}) => {
const [isOpen, setIsOpen] = useState(false);
const [savedQueries, setSavedQueries] = useState([] as SavedQuery[]);
const [count, setTotalCount] = useState(0);
const [activePage, setActivePage] = useState(0);

useEffect(() => {
const fetchQueries = async () => {
const allSavedQueries = await savedQueryService.getAllSavedQueries();
const sortedAllSavedQueries = sortBy(allSavedQueries, 'attributes.title');
setSavedQueries(sortedAllSavedQueries);
const fetchCountAndSavedQueries = async () => {
const savedQueryCount = await savedQueryService.getSavedQueryCount();
setTotalCount(savedQueryCount);

const savedQueryItems = await savedQueryService.findSavedQueries('', perPage, activePage + 1);
const sortedSavedQueryItems = sortBy(savedQueryItems, 'attributes.title');
setSavedQueries(sortedSavedQueryItems);
};
if (isOpen) {
fetchQueries();
fetchCountAndSavedQueries();
}
}, [isOpen]);
}, [isOpen, activePage]);

const goToPage = (pageNumber: number) => {
setActivePage(pageNumber);
Expand Down Expand Up @@ -131,7 +134,6 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
);

const savedQueryRows = () => {
// we should be recalculating the savedQueryRows after a delete action
const savedQueriesWithoutCurrent = savedQueries.filter(savedQuery => {
if (!loadedSavedQuery) return true;
return savedQuery.id !== loadedSavedQuery.id;
Expand All @@ -140,11 +142,7 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
loadedSavedQuery && savedQueriesWithoutCurrent.length !== savedQueries.length
? [loadedSavedQuery, ...savedQueriesWithoutCurrent]
: [...savedQueriesWithoutCurrent];
const savedQueriesDisplayRows = savedQueriesReordered.slice(
activePage * pageCount,
activePage * pageCount + pageCount
);
return savedQueriesDisplayRows.map(savedQuery => (
return savedQueriesReordered.map(savedQuery => (
<SavedQueryListItem
key={savedQuery.id}
savedQuery={savedQuery}
Expand Down Expand Up @@ -195,7 +193,7 @@ export const SavedQueryManagementComponent: FunctionComponent<Props> = ({
</div>
<EuiPagination
className="kbnSavedQueryManagement__pagination"
pageCount={Math.ceil(savedQueries.length / pageCount)}
pageCount={Math.ceil(count / perPage)}
activePage={activePage}
onPageClick={goToPage}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ const savedQueryAttributes: SavedQueryAttributes = {
query: 'response:200',
},
};
const savedQueryAttributesBar: SavedQueryAttributes = {
title: 'bar',
description: 'baz',
query: {
language: 'kuery',
query: 'response:200',
},
};

const savedQueryAttributesWithFilters: SavedQueryAttributes = {
...savedQueryAttributes,
Expand Down Expand Up @@ -61,7 +69,14 @@ const mockSavedObjectsClient = {
delete: jest.fn(),
};

const { deleteSavedQuery, getSavedQuery, findSavedQueries, saveQuery } = createSavedQueryService(
const {
deleteSavedQuery,
getSavedQuery,
findSavedQueries,
saveQuery,
getAllSavedQueries,
getSavedQueryCount,
} = createSavedQueryService(
// @ts-ignore
mockSavedObjectsClient
);
Expand Down Expand Up @@ -151,7 +166,7 @@ describe('saved query service', () => {
});
});
describe('findSavedQueries', function() {
it('should find and return saved queries without search text', async () => {
it('should find and return saved queries without search text or pagination parameters', async () => {
mockSavedObjectsClient.find.mockReturnValue({
savedObjects: [{ id: 'foo', attributes: savedQueryAttributes }],
});
Expand All @@ -166,6 +181,8 @@ describe('saved query service', () => {
});
const response = await findSavedQueries('foo');
expect(mockSavedObjectsClient.find).toHaveBeenCalledWith({
page: 1,
perPage: 50,
search: 'foo',
searchFields: ['title^5', 'description'],
sortField: '_score',
Expand Down Expand Up @@ -203,6 +220,43 @@ describe('saved query service', () => {
])
);
});
it('should accept perPage and page properties', async () => {
mockSavedObjectsClient.find.mockReturnValue({
savedObjects: [
{ id: 'foo', attributes: savedQueryAttributes },
{ id: 'bar', attributes: savedQueryAttributesBar },
],
});
const response = await findSavedQueries(undefined, 2, 1);
expect(mockSavedObjectsClient.find).toHaveBeenCalledWith({
page: 1,
perPage: 2,
search: '',
searchFields: ['title^5', 'description'],
sortField: '_score',
type: 'query',
});
expect(response).toEqual(
expect.objectContaining([
{
attributes: {
description: 'bar',
query: { language: 'kuery', query: 'response:200' },
title: 'foo',
},
id: 'foo',
},
{
attributes: {
description: 'baz',
query: { language: 'kuery', query: 'response:200' },
title: 'bar',
},
id: 'bar',
},
])
);
});
});

describe('getSavedQuery', function() {
Expand All @@ -226,4 +280,40 @@ describe('saved query service', () => {
expect(mockSavedObjectsClient.delete).toHaveBeenCalledWith('query', 'foo');
});
});

describe('getAllSavedQueries', function() {
it('should return all the saved queries', async () => {
mockSavedObjectsClient.find.mockReturnValue({
savedObjects: [{ id: 'foo', attributes: savedQueryAttributes }],
});
const response = await getAllSavedQueries();
expect(response).toEqual(
expect.objectContaining([
{
attributes: {
description: 'bar',
query: { language: 'kuery', query: 'response:200' },
title: 'foo',
},
id: 'foo',
},
])
);
expect(mockSavedObjectsClient.find).toHaveBeenCalledWith({
page: 1,
perPage: 0,
type: 'query',
});
});
});

describe('getSavedQueryCount', function() {
it('should return the total number of saved queries', async () => {
mockSavedObjectsClient.find.mockReturnValue({
total: 1,
});
const response = await getSavedQueryCount();
expect(response).toEqual(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ export interface SavedQueryService {
config?: { overwrite: boolean }
) => Promise<SavedQuery>;
getAllSavedQueries: () => Promise<SavedQuery[]>;
findSavedQueries: (searchText?: string) => Promise<SavedQuery[]>;
findSavedQueries: (
searchText?: string,
perPage?: number,
activePage?: number
) => Promise<SavedQuery[]>;
getSavedQuery: (id: string) => Promise<SavedQuery>;
deleteSavedQuery: (id: string) => Promise<{}>;
getSavedQueryCount: () => Promise<number>;
}

export const createSavedQueryService = (
Expand Down Expand Up @@ -89,24 +94,32 @@ export const createSavedQueryService = (

return parseSavedQueryObject(rawQueryResponse);
};

// 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 count = await getSavedQueryCount();
const response = await savedObjectsClient.find<SerializedSavedQueryAttributes>({
type: 'query',
perPage: count,
page: 1,
});

return response.savedObjects.map(
(savedObject: { id: string; attributes: SerializedSavedQueryAttributes }) =>
parseSavedQueryObject(savedObject)
);
};

const findSavedQueries = async (searchText: string = ''): Promise<SavedQuery[]> => {
// findSavedQueries will do a 'match_all' if no search string is passed in
const findSavedQueries = async (
searchText: string = '',
perPage: number = 50,
activePage: number = 1
): Promise<SavedQuery[]> => {
const response = await savedObjectsClient.find<SerializedSavedQueryAttributes>({
type: 'query',
search: searchText,
searchFields: ['title^5', 'description'],
sortField: '_score',
perPage,
page: activePage,
});

return response.savedObjects.map(
Expand Down Expand Up @@ -154,11 +167,21 @@ export const createSavedQueryService = (
};
};

const getSavedQueryCount = async (): Promise<number> => {
const response = await savedObjectsClient.find<SerializedSavedQueryAttributes>({
type: 'query',
perPage: 0,
page: 1,
});
return response.total;
};

return {
saveQuery,
getAllSavedQueries,
findSavedQueries,
getSavedQuery,
deleteSavedQuery,
getSavedQueryCount,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,8 @@ function discoverController(

const updateStateFromSavedQuery = (savedQuery) => {
$state.query = savedQuery.attributes.query;
$state.save();

queryFilter.setFilters(savedQuery.attributes.filters || []);

if (savedQuery.attributes.timefilter) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ba6b39d

Please sign in to comment.