Skip to content

Commit

Permalink
Finish initial implementation of saved searches by value
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Jun 16, 2023
1 parent 8e87da5 commit dacae99
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 243 deletions.
4 changes: 3 additions & 1 deletion src/plugins/discover/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* Side Public License, v 1.
*/

import { SEARCH_EMBEDDABLE_TYPE as EMBEDDABLE_TYPE } from '@kbn/saved-search-plugin/common';

export const PLUGIN_ID = 'discover';
export const APP_ICON = 'discoverApp';
export const DEFAULT_COLUMNS_SETTING = 'defaultColumns';
Expand All @@ -26,7 +28,7 @@ export const SHOW_FIELD_STATISTICS = 'discover:showFieldStatistics';
export const SHOW_MULTIFIELDS = 'discover:showMultiFields';
export const TRUNCATE_MAX_HEIGHT = 'truncate:maxHeight';
export const ROW_HEIGHT_OPTION = 'discover:rowHeightOption';
export const SEARCH_EMBEDDABLE_TYPE = 'search';
export const SEARCH_EMBEDDABLE_TYPE = EMBEDDABLE_TYPE;
export const HIDE_ANNOUNCEMENTS = 'hideAnnouncements';
export const ENABLE_SQL = 'discover:enableSql';

Expand Down

This file was deleted.

45 changes: 15 additions & 30 deletions src/plugins/discover/public/embeddable/saved_search_embeddable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import {
ReferenceOrValueEmbeddable,
} from '@kbn/embeddable-plugin/public';
import { Adapters, RequestAdapter } from '@kbn/inspector-plugin/common';
import type { SortOrder } from '@kbn/saved-search-plugin/public';
import type {
SavedSearchAttributeService,
SearchByReferenceInput,
SearchByValueInput,
SortOrder,
} from '@kbn/saved-search-plugin/public';
import {
APPLY_FILTER_TRIGGER,
FilterManager,
Expand All @@ -45,13 +50,7 @@ import { getSavedSearchUrl } from '@kbn/saved-search-plugin/public';
import { getSortForEmbeddable, SortPair } from '../utils/sorting';
import { buildDataTableRecord } from '../utils/build_data_record';
import { DataTableRecord, EsHitRecord } from '../types';
import {
ISearchEmbeddable,
SearchByReferenceInput,
SearchByValueInput,
SearchInput,
SearchOutput,
} from './types';
import { ISearchEmbeddable, SearchInput, SearchOutput } from './types';
import { SEARCH_EMBEDDABLE_TYPE } from './constants';
import { DiscoverServices } from '../build_services';
import { SavedSearchEmbeddableComponent } from './saved_search_embeddable_component';
Expand All @@ -74,11 +73,6 @@ import { isTextBasedQuery } from '../application/main/utils/is_text_based_query'
import { getValidViewMode } from '../application/main/utils/get_valid_view_mode';
import { fetchSql } from '../application/main/utils/fetch_sql';
import { ADHOC_DATA_VIEW_RENDER_EVENT } from '../constants';
import {
SavedSearchAttributeService,
SavedSearchUnwrapResult,
} from './saved_search_attribute_service';
import { fromSavedSearchAttributes } from '@kbn/saved-search-plugin/public/services/saved_searches/saved_searches_utils';

export type SearchProps = Partial<DiscoverGridProps> &
Partial<DocTableProps> & {
Expand All @@ -101,7 +95,6 @@ export interface SearchEmbeddableConfig {
editable: boolean;
filterManager: FilterManager;
services: DiscoverServices;
attributeService: SavedSearchAttributeService;
}

export class SavedSearchEmbeddable
Expand Down Expand Up @@ -135,15 +128,15 @@ export class SavedSearchEmbeddable
private node?: HTMLElement;

constructor(
{ editable, filterManager, services, attributeService }: SearchEmbeddableConfig,
{ editable, filterManager, services }: SearchEmbeddableConfig,
initialInput: SearchInput,
private readonly executeTriggerActions: UiActionsStart['executeTriggerActions'],
parent?: Container
) {
super(initialInput, { editApp: 'discover', editable }, parent);

this.services = services;
this.attributeService = attributeService;
this.attributeService = services.savedSearch.embeddable.attributesService;
this.filterManager = filterManager;
this.inspectorAdapters = {
requests: new RequestAdapter(),
Expand All @@ -170,26 +163,18 @@ export class SavedSearchEmbeddable
}

private async initializeSavedSearch(input: SearchInput) {
const unwrapResult: SavedSearchUnwrapResult | false = await this.attributeService
.unwrapAttributes(input)
.catch((e: Error) => {
this.onFatalError(e);
return false;
});
const unwrapResult = await this.attributeService.unwrapAttributes(input).catch((e: Error) => {
this.onFatalError(e);
return undefined;
});

if (!unwrapResult || this.isDestroyed) {
return;
}

const { metaInfo, attributes } = unwrapResult;

this.savedSearch = fromSavedSearchAttributes(
this.savedSearch = await this.services.savedSearch.embeddable.toSavedSearch(
(input as SearchByReferenceInput)?.savedObjectId,
attributes,
metaInfo?.tags,
metaInfo?.references,
metaInfo?.searchSource!,
metaInfo?.sharingSavedObjectProps
unwrapResult
);

this.panelTitle = this.savedSearch.title ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import {
Container,
ErrorEmbeddable,
} from '@kbn/embeddable-plugin/public';
import { SearchByReferenceInput, SearchInput, SearchOutput } from './types';
import type { SearchInput, SearchOutput } from './types';
import { SEARCH_EMBEDDABLE_TYPE } from './constants';
import { SavedSearchEmbeddable } from './saved_search_embeddable';
import { DiscoverServices } from '../build_services';
import { getSavedSearchAttributeService } from './saved_search_attribute_service';
import type { SearchByReferenceInput } from '@kbn/saved-search-plugin/public';

export interface StartServices {
executeTriggerActions: UiActionsStart['executeTriggerActions'];
Expand Down Expand Up @@ -68,7 +68,6 @@ export class SearchEmbeddableFactory

public async create(input: SearchInput, parent?: Container) {
const services = await this.getDiscoverServices();
const attributeService = getSavedSearchAttributeService(services);
const filterManager = services.filterManager;

try {
Expand All @@ -81,7 +80,6 @@ export class SearchEmbeddableFactory
filterManager,
editable: services.capabilities.discover.save as boolean,
services,
attributeService,
},
input,
executeTriggerActions,
Expand Down
37 changes: 7 additions & 30 deletions src/plugins/discover/public/embeddable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,13 @@
* Side Public License, v 1.
*/

import {
Embeddable,
EmbeddableInput,
EmbeddableOutput,
IEmbeddable,
SavedObjectEmbeddableInput,
} from '@kbn/embeddable-plugin/public';
import type { Filter, TimeRange, Query } from '@kbn/es-query';
import { DataView } from '@kbn/data-views-plugin/public';
import { SavedSearch } from '@kbn/saved-search-plugin/public';
import type { SortOrder } from '@kbn/saved-search-plugin/public';
import { SavedSearchAttributes } from '@kbn/saved-search-plugin/common';

interface SearchBaseInput extends EmbeddableInput {
timeRange: TimeRange;
timeslice?: [number, number];
query?: Query;
filters?: Filter[];
hidePanelTitles?: boolean;
columns?: string[];
sort?: SortOrder[];
rowHeight?: number;
rowsPerPage?: number;
}

export type SearchByValueInput = {
attributes: SavedSearchAttributes;
} & SearchBaseInput;

export type SearchByReferenceInput = SavedObjectEmbeddableInput & SearchBaseInput;
import type { Embeddable, EmbeddableOutput, IEmbeddable } from '@kbn/embeddable-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import type {
SavedSearch,
SearchByReferenceInput,
SearchByValueInput,
} from '@kbn/saved-search-plugin/public';

export type SearchInput = SearchByValueInput | SearchByReferenceInput;

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/saved_search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export const SavedSearchType = 'search';
export const LATEST_VERSION = 1;

export type SavedSearchContentType = typeof SavedSearchType;

export const SEARCH_EMBEDDABLE_TYPE = 'search';
3 changes: 1 addition & 2 deletions src/plugins/saved_search/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ export enum VIEW_MODE {
AGGREGATED_LEVEL = 'aggregated',
}

export { SavedSearchType } from './constants';
export { LATEST_VERSION } from './constants';
export { SavedSearchType, LATEST_VERSION, SEARCH_EMBEDDABLE_TYPE } from './constants';
17 changes: 4 additions & 13 deletions src/plugins/saved_search/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@
"id": "savedSearch",
"server": true,
"browser": true,
"requiredPlugins": [
"data",
"contentManagement"
],
"optionalPlugins": [
"spaces",
"savedObjectsTaggingOss"
],
"requiredBundles": [
],
"extraPublicDirs": [
"common"
]
"requiredPlugins": ["data", "contentManagement", "embeddable"],
"optionalPlugins": ["spaces", "savedObjectsTaggingOss"],
"requiredBundles": [],
"extraPublicDirs": ["common"]
}
}
8 changes: 7 additions & 1 deletion src/plugins/saved_search/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
*/

export type { SortOrder } from '../common/types';
export type { SavedSearch, SaveSavedSearchOptions } from './services/saved_searches';
export type {
SavedSearch,
SaveSavedSearchOptions,
SearchByReferenceInput,
SearchByValueInput,
SavedSearchAttributeService,
} from './services/saved_searches';

export { getSavedSearchFullPathUrl, getSavedSearchUrl } from './services/saved_searches';

Expand Down
Loading

0 comments on commit dacae99

Please sign in to comment.