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

[data views] Implement content management api #153733

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
afa704e
initial changes, mostly working...why doesn't find work?
mattkime Mar 27, 2023
f9a6231
Merge branch 'main' into data_views_content_mgmt
mattkime Mar 27, 2023
90a3672
fix find request
mattkime Mar 27, 2023
0e2a92d
fix get data view
mattkime Mar 27, 2023
c6b79f2
type improvement
mattkime Mar 27, 2023
61f01c7
type fixes
mattkime Mar 27, 2023
3547bfd
fix data view creation
mattkime Mar 27, 2023
76c479d
fix tests
mattkime Mar 28, 2023
931fa7f
Merge branch 'main' into data_views_content_mgmt
mattkime Mar 28, 2023
4019be6
fix saved search expression
mattkime Mar 28, 2023
d5c3885
fix mock
mattkime Mar 28, 2023
d1833f5
add version update support
mattkime Mar 28, 2023
0d6e1e5
fix data view find functionality
mattkime Mar 28, 2023
036b377
Merge branch 'main' into data_views_content_mgmt
mattkime Mar 28, 2023
07620ad
allow creating with specific id
mattkime Mar 28, 2023
2285966
Merge branch 'data_views_content_mgmt' of github.com:mattkime/kibana …
mattkime Mar 29, 2023
e1c6f9e
Merge branch 'main' into data_views_content_mgmt
mattkime Mar 29, 2023
497f042
fix jest, try to fix not found error type
mattkime Mar 29, 2023
1ca4968
attempt at fixing how errors are thrown
mattkime Mar 29, 2023
0cda290
revert error chan
mattkime Mar 29, 2023
6390394
another try at a front end specific get error
mattkime Mar 29, 2023
e0a252c
yet another attempt at getting the desired error on missing data view
mattkime Mar 29, 2023
4cac392
Merge branch 'main' into data_views_content_mgmt
mattkime Apr 13, 2023
003f508
Merge branch 'main' into data_views_content_mgmt
mattkime Apr 14, 2023
7d3bf15
fix circular dependency
mattkime Apr 14, 2023
d601dbd
abstract types
mattkime Apr 15, 2023
9e06b50
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 15, 2023
83b1ff5
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Apr 15, 2023
86e3a85
fix types
mattkime Apr 15, 2023
8daec60
Merge branch 'content_management_api_so_type_abstraction' of github.c…
mattkime Apr 15, 2023
aea2173
remove comment
mattkime Apr 15, 2023
28548f7
fix partial types
mattkime Apr 15, 2023
44ca8ee
add readme content
mattkime Apr 15, 2023
e1de41a
Merge branch 'content_management_api_so_type_abstraction' into data_v…
mattkime Apr 15, 2023
70799e3
use shared types
mattkime Apr 15, 2023
42e1d38
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 15, 2023
13077c3
integrate abstract types and data view storage
mattkime Apr 15, 2023
6d95210
Merge branch 'data_views_content_mgmt' of github.com:mattkime/kibana …
mattkime Apr 15, 2023
97490b3
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 15, 2023
8d9d753
fix jest test
mattkime Apr 16, 2023
aa9f5b4
fix saved search and version handling
mattkime Apr 16, 2023
caa7ffa
Merge branch 'data_views_content_mgmt' of github.com:mattkime/kibana …
mattkime Apr 16, 2023
cf972da
fix saved search
mattkime Apr 16, 2023
12b19bc
fix tabify test
mattkime Apr 16, 2023
a1f0c60
fix test
mattkime Apr 16, 2023
333a8bb
correctly specify which fields to query
mattkime Apr 16, 2023
10830bf
correctly specify which fields to query
mattkime Apr 16, 2023
6469d33
cleanup
mattkime Apr 16, 2023
e658855
cleanup
mattkime Apr 16, 2023
fc0fe17
cleanup
mattkime Apr 16, 2023
b0c3849
remove noisy test changes for fields attr
mattkime Apr 16, 2023
3b55776
restore test
mattkime Apr 16, 2023
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
14 changes: 14 additions & 0 deletions src/plugins/data_views/common/content_management/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

/**
* Data view saved object version.
*/
export const LATEST_VERSION = 1;

export const DataViewContentType = 'index-pattern';
28 changes: 28 additions & 0 deletions src/plugins/data_views/common/content_management/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { LATEST_VERSION } from './constants';

export type {
DataViewSavedObject,
DataViewGetIn,
DataViewGetOut,
DataViewCreateIn,
DataViewCreateOut,
CreateOptions,
DataViewUpdateIn,
DataViewUpdateOut,
UpdateOptions,
DataViewDeleteIn,
DataViewDeleteOut,
DataViewSearchIn,
DataViewSearchOut,
DataViewSearchQuery,
} from './types';

export { DataViewContentType } from './constants';
115 changes: 115 additions & 0 deletions src/plugins/data_views/common/content_management/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type {
SavedObject,
SavedObjectReference,
SavedObjectsResolveResponse,
SavedObjectsUpdateResponse,
} from '@kbn/core-saved-objects-api-server';
import type { SavedObjectsMigrationVersion } from '@kbn/core-saved-objects-common';

import type {
GetIn,
CreateIn,
SearchIn,
UpdateIn,
DeleteIn,
} from '@kbn/content-management-plugin/common';

import { DataViewAttributes } from '../types';
import { DataViewContentType } from './constants';

interface Reference {
type: string;
id: string;
}

export type DataViewSavedObject = SavedObject<DataViewAttributes>;

// ----------- GET --------------

export type DataViewGetIn = GetIn<typeof DataViewContentType>;

export interface DataViewGetOut {
savedObject: SavedObjectsResolveResponse<DataViewAttributes>['saved_object'];
outcome: SavedObjectsResolveResponse['outcome'];
aliasTargetId: SavedObjectsResolveResponse['alias_target_id'];
aliasPurpose: SavedObjectsResolveResponse['alias_purpose'];
}

// ----------- CREATE --------------

export interface CreateOptions {
/** If a document with the given `id` already exists, overwrite it's contents (default=false). */
overwrite?: boolean;
migrationVersion?: SavedObjectsMigrationVersion;
/** A semver value that is used when upgrading objects between Kibana versions. */
coreMigrationVersion?: string;
/** Array of referenced saved objects. */
references?: SavedObjectReference[];
}

export type DataViewCreateIn = CreateIn<
typeof DataViewContentType,
DataViewAttributes,
CreateOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are explicitely declaring that DataViewCreateIn takes CreateOptions. You now have to pass it in saved_objects_client_wrapper.ts L91

>;

export type DataViewCreateOut = DataViewSavedObject;

// ----------- UPDATE --------------

export interface UpdateOptions {
/** Array of referenced saved objects. */
references?: SavedObjectReference[];
}

export type DataViewUpdateIn = UpdateIn<
typeof DataViewContentType,
DataViewAttributes,
UpdateOptions
>;

export type DataViewUpdateOut = SavedObjectsUpdateResponse<DataViewAttributes>;

// ----------- DELETE --------------

export type DataViewDeleteIn = DeleteIn<typeof DataViewContentType>;

export interface DataViewDeleteOut {
status: 'success';
}

// ----------- SEARCH --------------

export interface MapSearchQuery {
search?: string;
fields?: string[];
searchFields?: string[];
perPage?: number;
page?: number;
defaultSearchOperator?: 'AND' | 'OR';
hasReference?: Reference | Reference[];
hasNoReference?: Reference | Reference[];
}

export type MapSearchIn = SearchIn<typeof DataViewContentType, MapSearchQuery>;

export interface MapSearchOut {
/** current page in results*/
page: number;
/** number of results per page */
perPage: number;
/** total number of results */
total: number;
/** Array of simple saved objects */
savedObjects: DataViewSavedObject[];
/** aggregations from the search query */
aggregations?: unknown; // TODO: Check if used in Maps
}
11 changes: 4 additions & 7 deletions src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export interface DataViewsServicePublicMethods {
* Delete data view
* @param indexPatternId - Id of the data view to delete.
*/
delete: (indexPatternId: string) => Promise<{}>;
delete: (indexPatternId: string) => Promise<unknown>; // todo
/**
* Takes field array and field attributes and returns field map by name.
* @param fields - Array of fieldspecs
Expand Down Expand Up @@ -349,7 +349,7 @@ export class DataViewsService {
* Refresh cache of index pattern ids and titles.
*/
private async refreshSavedObjectsCache() {
const so = await this.savedObjectsClient.find<DataViewSavedObjectAttrs>({
const so = await this.savedObjectsClient.find({
type: DATA_VIEW_SAVED_OBJECT_TYPE,
fields: ['title', 'type', 'typeMeta', 'name'],
perPage: 10000,
Expand Down Expand Up @@ -392,7 +392,7 @@ export class DataViewsService {
* @returns DataView[]
*/
find = async (search: string, size: number = 10): Promise<DataView[]> => {
const savedObjects = await this.savedObjectsClient.find<DataViewSavedObjectAttrs>({
const savedObjects = await this.savedObjectsClient.find({
type: DATA_VIEW_SAVED_OBJECT_TYPE,
fields: ['title'],
search,
Expand Down Expand Up @@ -726,10 +726,7 @@ export class DataViewsService {
id: string,
displayErrors: boolean = true
): Promise<DataView> => {
const savedObject = await this.savedObjectsClient.get<DataViewAttributes>(
DATA_VIEW_SAVED_OBJECT_TYPE,
id
);
const savedObject = await this.savedObjectsClient.get(DATA_VIEW_SAVED_OBJECT_TYPE, id);

if (!savedObject.version) {
throw new SavedObjectNotFound('data view', id, 'management/kibana/dataViews');
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data_views/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export {
DATA_VIEW_SAVED_OBJECT_TYPE,
} from './constants';

export { LATEST_VERSION } from './content_management';

export type { ToSpecConfig } from './fields';
export type { IIndexPatternFieldList } from './fields';
export {
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,13 +267,15 @@ export interface SavedObjectsClientCommon {
* Search for saved objects
* @param options - options for search
*/
find: <T = unknown>(options: SavedObjectsClientCommonFindArgs) => Promise<Array<SavedObject<T>>>;
find: (
options: SavedObjectsClientCommonFindArgs
) => Promise<Array<SavedObject<DataViewAttributes>>>;
/**
* Get a single saved object by id
* @param type - type of saved object
* @param id - id of saved object
*/
get: <T = unknown>(type: string, id: string) => Promise<SavedObject<T>>;
get: (type: string, id: string) => Promise<SavedObject<DataViewAttributes>>;
/**
* Update a saved object by id
* @param type - type of saved object
Expand Down Expand Up @@ -303,7 +305,7 @@ export interface SavedObjectsClientCommon {
* @param type - type of saved object
* @param id - id of saved object
*/
delete: (type: string, id: string) => Promise<{}>;
delete: (type: string, id: string) => Promise<unknown>; // todo remove unknown
}

export interface GetFieldsOptions {
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/data_views/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"browser": true,
"requiredPlugins": [
"fieldFormats",
"expressions"
"expressions",
"contentManagement"
],
"optionalPlugins": [
"usageCollection"
Expand Down
18 changes: 14 additions & 4 deletions src/plugins/data_views/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { getIndices, HasData } from './services';

import { debounceByKey } from './debounce_by_key';

import { DATA_VIEW_SAVED_OBJECT_TYPE, LATEST_VERSION } from '../common';

export class DataViewsPublicPlugin
implements
Plugin<
Expand All @@ -38,18 +40,26 @@ export class DataViewsPublicPlugin

public setup(
core: CoreSetup<DataViewsPublicStartDependencies, DataViewsPublicPluginStart>,
{ expressions }: DataViewsPublicSetupDependencies
{ expressions, contentManagement }: DataViewsPublicSetupDependencies
): DataViewsPublicPluginSetup {
expressions.registerFunction(getIndexPatternLoad({ getStartServices: core.getStartServices }));

contentManagement.registry.register({
id: DATA_VIEW_SAVED_OBJECT_TYPE,
version: {
latest: LATEST_VERSION,
},
name: 'data view',
});

return {};
}

public start(
core: CoreStart,
{ fieldFormats }: DataViewsPublicStartDependencies
{ fieldFormats, contentManagement }: DataViewsPublicStartDependencies
): DataViewsPublicPluginStart {
const { uiSettings, http, notifications, savedObjects, application } = core;
const { uiSettings, http, notifications, application } = core;

const onNotifDebounced = debounceByKey(
notifications.toasts.add.bind(notifications.toasts),
Expand All @@ -63,7 +73,7 @@ export class DataViewsPublicPlugin
return new DataViewsServicePublic({
hasData: this.hasData.start(core),
uiSettings: new UiSettingsPublicToCommon(uiSettings),
savedObjectsClient: new SavedObjectsClientPublicToCommon(savedObjects.client),
savedObjectsClient: new SavedObjectsClientPublicToCommon(contentManagement.client),
apiClient: new DataViewsApiClient(http),
fieldFormats,
onNotification: (toastInputFields, key) => {
Expand Down
Loading