mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Pierre Gayvallet <pierre.gayvallet@elastic.co>
This commit is contained in:
parent
2d6c10a1e9
commit
06d9ffb4a3
3 changed files with 60 additions and 21 deletions
|
@ -7,30 +7,29 @@
|
|||
*/
|
||||
|
||||
import { Query } from '@elastic/eui';
|
||||
import type { SavedObjectManagementTypeInfo } from '../../common';
|
||||
import { parseQuery } from './parse_query';
|
||||
|
||||
const createType = (name: string, displayName?: string): SavedObjectManagementTypeInfo => ({
|
||||
name,
|
||||
displayName: displayName ?? name,
|
||||
hidden: false,
|
||||
namespaceType: 'multiple',
|
||||
});
|
||||
|
||||
describe('getQueryText', () => {
|
||||
it('parses the query text', () => {
|
||||
const query = Query.parse('some search');
|
||||
|
||||
expect(parseQuery(query)).toEqual({
|
||||
expect(parseQuery(query, [])).toEqual({
|
||||
queryText: 'some search',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses the types', () => {
|
||||
const query = Query.parse('type:(index-pattern or dashboard) kibana');
|
||||
|
||||
expect(parseQuery(query)).toEqual({
|
||||
queryText: 'kibana',
|
||||
visibleTypes: ['index-pattern', 'dashboard'],
|
||||
});
|
||||
});
|
||||
|
||||
it('parses the tags', () => {
|
||||
const query = Query.parse('tag:(tag-1 or tag-2) kibana');
|
||||
|
||||
expect(parseQuery(query)).toEqual({
|
||||
expect(parseQuery(query, [])).toEqual({
|
||||
queryText: 'kibana',
|
||||
selectedTags: ['tag-1', 'tag-2'],
|
||||
});
|
||||
|
@ -39,7 +38,7 @@ describe('getQueryText', () => {
|
|||
it('parses all the fields', () => {
|
||||
const query = Query.parse('tag:(tag-1 or tag-2) type:(index-pattern) kibana');
|
||||
|
||||
expect(parseQuery(query)).toEqual({
|
||||
expect(parseQuery(query, [])).toEqual({
|
||||
queryText: 'kibana',
|
||||
visibleTypes: ['index-pattern'],
|
||||
selectedTags: ['tag-1', 'tag-2'],
|
||||
|
@ -49,8 +48,37 @@ describe('getQueryText', () => {
|
|||
it('does not fail on unknown fields', () => {
|
||||
const query = Query.parse('unknown:(hello or dolly) some search');
|
||||
|
||||
expect(parseQuery(query)).toEqual({
|
||||
expect(parseQuery(query, [])).toEqual({
|
||||
queryText: 'some search',
|
||||
});
|
||||
});
|
||||
|
||||
it('parses the types when provided types are empty', () => {
|
||||
const query = Query.parse('type:(index-pattern or dashboard) kibana');
|
||||
|
||||
expect(parseQuery(query, [])).toEqual({
|
||||
queryText: 'kibana',
|
||||
visibleTypes: ['index-pattern', 'dashboard'],
|
||||
});
|
||||
});
|
||||
|
||||
it('maps displayName to name when parsing the types', () => {
|
||||
const query = Query.parse('type:(i-p or dash) kibana');
|
||||
const types = [createType('index-pattern', 'i-p'), createType('dashboard', 'dash')];
|
||||
|
||||
expect(parseQuery(query, types)).toEqual({
|
||||
queryText: 'kibana',
|
||||
visibleTypes: ['index-pattern', 'dashboard'],
|
||||
});
|
||||
});
|
||||
|
||||
it('maps displayName to name even when some types are missing', () => {
|
||||
const query = Query.parse('type:(i-p or dashboard) kibana');
|
||||
const types = [createType('index-pattern', 'i-p')];
|
||||
|
||||
expect(parseQuery(query, types)).toEqual({
|
||||
queryText: 'kibana',
|
||||
visibleTypes: ['index-pattern', 'dashboard'],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
|
||||
import { Query } from '@elastic/eui';
|
||||
import type { SavedObjectManagementTypeInfo } from '../../common';
|
||||
|
||||
interface ParsedQuery {
|
||||
queryText?: string;
|
||||
|
@ -14,7 +15,7 @@ interface ParsedQuery {
|
|||
selectedTags?: string[];
|
||||
}
|
||||
|
||||
export function parseQuery(query: Query): ParsedQuery {
|
||||
export function parseQuery(query: Query, types: SavedObjectManagementTypeInfo[]): ParsedQuery {
|
||||
let queryText: string | undefined;
|
||||
let visibleTypes: string[] | undefined;
|
||||
let selectedTags: string[] | undefined;
|
||||
|
@ -27,7 +28,14 @@ export function parseQuery(query: Query): ParsedQuery {
|
|||
.join(' ');
|
||||
}
|
||||
if (query.ast.getFieldClauses('type')) {
|
||||
visibleTypes = query.ast.getFieldClauses('type')[0].value as string[];
|
||||
const displayedTypes = query.ast.getFieldClauses('type')[0].value as string[];
|
||||
const displayNameToNameMap = types.reduce((map, type) => {
|
||||
map.set(type.displayName, type.name);
|
||||
return map;
|
||||
}, new Map<string, string>());
|
||||
visibleTypes = displayedTypes.map((type) => {
|
||||
return displayNameToNameMap.get(type) ?? type;
|
||||
});
|
||||
}
|
||||
if (query.ast.getFieldClauses('tag')) {
|
||||
selectedTags = query.ast.getFieldClauses('tag')[0].value as string[];
|
||||
|
|
|
@ -149,7 +149,10 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
|
|||
|
||||
fetchCounts = async () => {
|
||||
const { taggingApi } = this.props;
|
||||
const { queryText, visibleTypes, selectedTags } = parseQuery(this.state.activeQuery);
|
||||
const { queryText, visibleTypes, selectedTags } = parseQuery(
|
||||
this.state.activeQuery,
|
||||
this.props.allowedTypes
|
||||
);
|
||||
|
||||
const allowedTypes = this.props.allowedTypes.map((type) => type.name);
|
||||
|
||||
|
@ -210,7 +213,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
|
|||
debouncedFindObjects = debounce(async () => {
|
||||
const { activeQuery: query, page, perPage } = this.state;
|
||||
const { notifications, http, allowedTypes, taggingApi } = this.props;
|
||||
const { queryText, visibleTypes, selectedTags } = parseQuery(query);
|
||||
const { queryText, visibleTypes, selectedTags } = parseQuery(query, allowedTypes);
|
||||
|
||||
const searchTypes = allowedTypes
|
||||
.map((type) => type.name)
|
||||
|
@ -404,8 +407,8 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
|
|||
|
||||
onExportAll = async () => {
|
||||
const { exportAllSelectedOptions, isIncludeReferencesDeepChecked, activeQuery } = this.state;
|
||||
const { notifications, http, taggingApi } = this.props;
|
||||
const { queryText, selectedTags } = parseQuery(activeQuery);
|
||||
const { notifications, http, taggingApi, allowedTypes } = this.props;
|
||||
const { queryText, selectedTags } = parseQuery(activeQuery, allowedTypes);
|
||||
const exportTypes = Object.entries(exportAllSelectedOptions).reduce((accum, [id, selected]) => {
|
||||
if (selected) {
|
||||
accum.push(id);
|
||||
|
@ -658,8 +661,8 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
|
|||
};
|
||||
|
||||
const filterOptions = allowedTypes.map((type) => ({
|
||||
value: type.name,
|
||||
name: type.name,
|
||||
value: type.displayName,
|
||||
name: type.displayName,
|
||||
view: `${type.displayName} (${savedObjectCounts[type.name] || 0})`,
|
||||
}));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue