diff --git a/docs/development/core/public/kibana-plugin-public.savedobject.md b/docs/development/core/public/kibana-plugin-public.savedobject.md index b1bb3e267bf0ea7..542d7d3a063ecc5 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobject.md +++ b/docs/development/core/public/kibana-plugin-public.savedobject.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObject +export interface SavedObject ``` ## Properties diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md index 5a08b3f97f4299e..97772112ff0066a 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbatchresponse.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsBatchResponse +export interface SavedObjectsBatchResponse ``` ## Properties diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md index c479e9f9f3e3f1e..ef83acb8fd73d19 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkcreateobject.md @@ -7,7 +7,7 @@ Signature: ```typescript -export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions +export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions ``` ## Properties diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkupdateobject.md b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkupdateobject.md index ca0eabb26590179..a57702c305f506e 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsbulkupdateobject.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsbulkupdateobject.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsBulkUpdateObject +export interface SavedObjectsBulkUpdateObject ``` ## Properties diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md index 391b2f57205d5c9..c5072bea5b50e47 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkcreate.md @@ -9,5 +9,5 @@ Creates multiple documents at once Signature: ```typescript -bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; +bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md index a54dfe72167a793..37b9f6d6c951df7 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkget.md @@ -12,7 +12,7 @@ Returns an array of objects by id bulkGet: (objects?: { id: string; type: string; - }[]) => Promise>; + }[]) => Promise>; ``` ## Example diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkupdate.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkupdate.md index 94ae9bb70ccdae2..2f8565def3d40d2 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkupdate.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.bulkupdate.md @@ -9,7 +9,7 @@ Update multiple documents at once Signature: ```typescript -bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; +bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; ``` ## Parameters @@ -20,7 +20,7 @@ bulkUpdate(objects?: SavedObjectsBulkUpdateObje Returns: -`Promise>` +`Promise>` The result of the update operation containing both failed and updated saved objects. diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md index 5a7666084ea0f44..ea3fbe31ca8a5ef 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.create.md @@ -9,5 +9,5 @@ Persists an object Signature: ```typescript -create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; +create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md index d3494045952ad37..3d8005c9390b7fc 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.find.md @@ -9,5 +9,5 @@ Search for objects Signature: ```typescript -find: (options: Pick) => Promise>; +find: (options: Pick) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md index bddbadd3e136188..37a91f7211da5c2 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.get.md @@ -9,5 +9,5 @@ Fetches a single object Signature: ```typescript -get: (type: string, id: string) => Promise>; +get: (type: string, id: string) => Promise>; ``` diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md index 7aa17eae2da87cb..5c22a2a0bdd916c 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.md @@ -20,12 +20,12 @@ The constructor for this class is marked as internal. Third-party code should no | Property | Modifiers | Type | Description | | --- | --- | --- | --- | -| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: SavedObjectsBulkCreateObject<SavedObjectAttributes>[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Creates multiple documents at once | -| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<SavedObjectsBatchResponse<SavedObjectAttributes>> | Returns an array of objects by id | -| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T extends SavedObjectAttributes>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | +| [bulkCreate](./kibana-plugin-public.savedobjectsclient.bulkcreate.md) | | (objects?: SavedObjectsBulkCreateObject<unknown>[], options?: SavedObjectsBulkCreateOptions) => Promise<SavedObjectsBatchResponse<unknown>> | Creates multiple documents at once | +| [bulkGet](./kibana-plugin-public.savedobjectsclient.bulkget.md) | | (objects?: {
id: string;
type: string;
}[]) => Promise<SavedObjectsBatchResponse<unknown>> | Returns an array of objects by id | +| [create](./kibana-plugin-public.savedobjectsclient.create.md) | | <T = unknown>(type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise<SimpleSavedObject<T>> | Persists an object | | [delete](./kibana-plugin-public.savedobjectsclient.delete.md) | | (type: string, id: string) => Promise<{}> | Deletes an object | -| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T extends SavedObjectAttributes>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "perPage" | "sortField" | "fields" | "searchFields" | "hasReference" | "defaultSearchOperator">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | -| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <T extends SavedObjectAttributes>(type: string, id: string) => Promise<SimpleSavedObject<T>> | Fetches a single object | +| [find](./kibana-plugin-public.savedobjectsclient.find.md) | | <T = unknown>(options: Pick<SavedObjectFindOptionsServer, "search" | "filter" | "type" | "page" | "perPage" | "sortField" | "fields" | "searchFields" | "hasReference" | "defaultSearchOperator">) => Promise<SavedObjectsFindResponsePublic<T>> | Search for objects | +| [get](./kibana-plugin-public.savedobjectsclient.get.md) | | <T = unknown>(type: string, id: string) => Promise<SimpleSavedObject<T>> | Fetches a single object | ## Methods diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md index 9f7e46943bbd5d1..d1049a75edf1fc7 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsclient.update.md @@ -9,7 +9,7 @@ Updates an object Signature: ```typescript -update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; +update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md index f60e7305fba3475..31ab73464dfd9cd 100644 --- a/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md +++ b/docs/development/core/public/kibana-plugin-public.savedobjectsfindresponsepublic.md @@ -11,7 +11,7 @@ Return type of the Saved Objects `find()` method. Signature: ```typescript -export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse ``` ## Properties diff --git a/docs/development/core/public/kibana-plugin-public.simplesavedobject.md b/docs/development/core/public/kibana-plugin-public.simplesavedobject.md index 1f6de163ec17d58..4906d5967f7dfa4 100644 --- a/docs/development/core/public/kibana-plugin-public.simplesavedobject.md +++ b/docs/development/core/public/kibana-plugin-public.simplesavedobject.md @@ -11,7 +11,7 @@ It provides basic functionality for creating/saving/deleting saved objects, but Signature: ```typescript -export declare class SimpleSavedObject +export declare class SimpleSavedObject ``` ## Constructors diff --git a/docs/development/core/server/kibana-plugin-server.savedobject.md b/docs/development/core/server/kibana-plugin-server.savedobject.md index b3184fd38ad93cb..5ab08f4eadf2e13 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobject.md +++ b/docs/development/core/server/kibana-plugin-server.savedobject.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObject +export interface SavedObject ``` ## Properties diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md index 87386b986009da1..7b765055de6c131 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkcreateobject.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsBulkCreateObject +export interface SavedObjectsBulkCreateObject ``` ## Properties diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkresponse.md b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkresponse.md index 20a1194c87eda42..2ced4f4c8e1a010 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkresponse.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkresponse.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsBulkResponse +export interface SavedObjectsBulkResponse ``` ## Properties diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateobject.md b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateobject.md index 8e4e3d761148e95..67013290a629da8 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateobject.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateobject.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsBulkUpdateObject extends Pick +export interface SavedObjectsBulkUpdateObject extends Pick ``` ## Properties diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateresponse.md b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateresponse.md index 065b9df0823cd71..346899161160825 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateresponse.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsbulkupdateresponse.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsBulkUpdateResponse +export interface SavedObjectsBulkUpdateResponse ``` ## Properties diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkcreate.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkcreate.md index 40f947188de545a..47da795631a3a56 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkcreate.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkcreate.md @@ -9,7 +9,7 @@ Persists multiple documents batched together as a single request Signature: ```typescript -bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; +bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkget.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkget.md index c86c30d14db3b81..71006e2afa3ee47 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkget.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkget.md @@ -9,7 +9,7 @@ Returns an array of objects by id Signature: ```typescript -bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; +bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkupdate.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkupdate.md index 33958837ebca399..cceeb9c1ca320ec 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkupdate.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.bulkupdate.md @@ -9,7 +9,7 @@ Bulk Updates multiple SavedObject at once Signature: ```typescript -bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; +bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.create.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.create.md index ddb78a57e71bc6e..7f6fc117937cb3f 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.create.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.create.md @@ -9,7 +9,7 @@ Persists a SavedObject Signature: ```typescript -create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; +create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.find.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.find.md index f72691d3ce0c87d..c8804e2a9785181 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.find.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.find.md @@ -9,7 +9,7 @@ Find all SavedObjects matching the search query Signature: ```typescript -find(options: SavedObjectsFindOptions): Promise>; +find(options: SavedObjectsFindOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.get.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.get.md index 3906462184d4f9e..b48cef25ca3d10c 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.get.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.get.md @@ -9,7 +9,7 @@ Retrieves a single object Signature: ```typescript -get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; +get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.update.md b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.update.md index 2c71e518b7b05f1..ed6243c409fa476 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsclient.update.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsclient.update.md @@ -9,7 +9,7 @@ Updates an SavedObject Signature: ```typescript -update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; +update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md b/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md index efdc07cea88fdc8..a79a23db967ccc2 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsfindresponse.md @@ -11,7 +11,7 @@ Return type of the Saved Objects `find()` method. Signature: ```typescript -export interface SavedObjectsFindResponse +export interface SavedObjectsFindResponse ``` ## Properties diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkcreate.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkcreate.md index dfe9e51e62483cc..f0d8d9edfbe7999 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkcreate.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkcreate.md @@ -9,7 +9,7 @@ Creates multiple documents at once Signature: ```typescript -bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; +bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkget.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkget.md index 34b113bce5410ea..e27c5fc3bec9af4 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkget.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkget.md @@ -9,7 +9,7 @@ Returns an array of objects by id Signature: ```typescript -bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; +bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkupdate.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkupdate.md index 23c7a9262495738..5ad09d59f406113 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkupdate.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.bulkupdate.md @@ -9,7 +9,7 @@ Updates multiple objects in bulk Signature: ```typescript -bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; +bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.create.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.create.md index 29e3c3ab2465461..fd6495bd2d3c423 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.create.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.create.md @@ -9,7 +9,7 @@ Persists an object Signature: ```typescript -create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; +create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.find.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.find.md index dbf6d59e78d85fa..ccb9feca1669e91 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.find.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.find.md @@ -7,7 +7,7 @@ Signature: ```typescript -find({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, }: SavedObjectsFindOptions): Promise>; +find({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, }: SavedObjectsFindOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.get.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.get.md index 930a4647ca1750f..b3ccbc7277b4e0f 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.get.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.get.md @@ -9,7 +9,7 @@ Gets a single object Signature: ```typescript -get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; +get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.update.md b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.update.md index 5e9f69ecc567bbd..bb215cdb97af54f 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.update.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsrepository.update.md @@ -9,7 +9,7 @@ Updates an object Signature: ```typescript -update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; +update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; ``` ## Parameters diff --git a/docs/development/core/server/kibana-plugin-server.savedobjectsupdateresponse.md b/docs/development/core/server/kibana-plugin-server.savedobjectsupdateresponse.md index 64c90377353585b..130b0b4faaa0712 100644 --- a/docs/development/core/server/kibana-plugin-server.savedobjectsupdateresponse.md +++ b/docs/development/core/server/kibana-plugin-server.savedobjectsupdateresponse.md @@ -8,7 +8,7 @@ Signature: ```typescript -export interface SavedObjectsUpdateResponse extends Omit, 'attributes' | 'references'> +export interface SavedObjectsUpdateResponse extends Omit, 'attributes' | 'references'> ``` ## Properties diff --git a/package.json b/package.json index cb87c48ab7f2a71..c3fe290e7934f80 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "@babel/core": "^7.5.5", "@babel/register": "^7.7.0", "@elastic/apm-rum": "^4.6.0", - "@elastic/charts": "^17.0.2", + "@elastic/charts": "^17.1.1", "@elastic/datemath": "5.0.2", "@elastic/ems-client": "7.6.0", "@elastic/eui": "19.0.0", diff --git a/packages/kbn-ui-shared-deps/package.json b/packages/kbn-ui-shared-deps/package.json index acb2b48e12278d6..e9ad227b235faf1 100644 --- a/packages/kbn-ui-shared-deps/package.json +++ b/packages/kbn-ui-shared-deps/package.json @@ -9,7 +9,7 @@ "kbn:watch": "node scripts/build --watch" }, "devDependencies": { - "@elastic/charts": "^17.0.2", + "@elastic/charts": "^17.1.1", "abortcontroller-polyfill": "^1.4.0", "@elastic/eui": "19.0.0", "@kbn/babel-preset": "1.0.0", diff --git a/src/core/public/public.api.md b/src/core/public/public.api.md index ca2f6789bebeee1..ba1988b85738546 100644 --- a/src/core/public/public.api.md +++ b/src/core/public/public.api.md @@ -932,7 +932,7 @@ export type RecursiveReadonly = T extends (...args: any[]) => any ? T : T ext }> : T; // @public (undocumented) -export interface SavedObject { +export interface SavedObject { attributes: T; // (undocumented) error?: { @@ -975,13 +975,13 @@ export interface SavedObjectsBaseOptions { } // @public (undocumented) -export interface SavedObjectsBatchResponse { +export interface SavedObjectsBatchResponse { // (undocumented) savedObjects: Array>; } // @public (undocumented) -export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions { +export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions { // (undocumented) attributes: T; // (undocumented) @@ -994,7 +994,7 @@ export interface SavedObjectsBulkCreateOptions { } // @public (undocumented) -export interface SavedObjectsBulkUpdateObject { +export interface SavedObjectsBulkUpdateObject { // (undocumented) attributes: T; // (undocumented) @@ -1017,17 +1017,17 @@ export interface SavedObjectsBulkUpdateOptions { export class SavedObjectsClient { // @internal constructor(http: HttpSetup); - bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; + bulkCreate: (objects?: SavedObjectsBulkCreateObject[], options?: SavedObjectsBulkCreateOptions) => Promise>; bulkGet: (objects?: { id: string; type: string; - }[]) => Promise>; - bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; - create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; + }[]) => Promise>; + bulkUpdate(objects?: SavedObjectsBulkUpdateObject[]): Promise>; + create: (type: string, attributes: T, options?: SavedObjectsCreateOptions) => Promise>; delete: (type: string, id: string) => Promise<{}>; - find: (options: Pick) => Promise>; - get: (type: string, id: string) => Promise>; - update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; + find: (options: Pick) => Promise>; + get: (type: string, id: string) => Promise>; + update(type: string, id: string, attributes: T, { version, migrationVersion, references }?: SavedObjectsUpdateOptions): Promise>; } // @public @@ -1069,7 +1069,7 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { } // @public -export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { // (undocumented) page: number; // (undocumented) @@ -1176,7 +1176,7 @@ export interface SavedObjectsUpdateOptions { } // @public -export class SimpleSavedObject { +export class SimpleSavedObject { constructor(client: SavedObjectsClientContract, { id, type, version, attributes, error, references, migrationVersion }: SavedObject); // (undocumented) attributes: T; diff --git a/src/core/public/saved_objects/saved_objects_client.ts b/src/core/public/saved_objects/saved_objects_client.ts index ccb23793a85349b..afc77806afb914b 100644 --- a/src/core/public/saved_objects/saved_objects_client.ts +++ b/src/core/public/saved_objects/saved_objects_client.ts @@ -22,7 +22,6 @@ import { resolve as resolveUrl } from 'url'; import { SavedObject, - SavedObjectAttributes, SavedObjectReference, SavedObjectsClientContract as SavedObjectsApi, SavedObjectsFindOptions as SavedObjectFindOptionsServer, @@ -61,9 +60,7 @@ export interface SavedObjectsCreateOptions { * * @public */ -export interface SavedObjectsBulkCreateObject< - T extends SavedObjectAttributes = SavedObjectAttributes -> extends SavedObjectsCreateOptions { +export interface SavedObjectsBulkCreateObject extends SavedObjectsCreateOptions { type: string; attributes: T; } @@ -75,9 +72,7 @@ export interface SavedObjectsBulkCreateOptions { } /** @public */ -export interface SavedObjectsBulkUpdateObject< - T extends SavedObjectAttributes = SavedObjectAttributes -> { +export interface SavedObjectsBulkUpdateObject { type: string; id: string; attributes: T; @@ -99,9 +94,7 @@ export interface SavedObjectsUpdateOptions { } /** @public */ -export interface SavedObjectsBatchResponse< - T extends SavedObjectAttributes = SavedObjectAttributes -> { +export interface SavedObjectsBatchResponse { savedObjects: Array>; } @@ -113,9 +106,7 @@ export interface SavedObjectsBatchResponse< * * @public */ -export interface SavedObjectsFindResponsePublic< - T extends SavedObjectAttributes = SavedObjectAttributes -> extends SavedObjectsBatchResponse { +export interface SavedObjectsFindResponsePublic extends SavedObjectsBatchResponse { total: number; perPage: number; page: number; @@ -124,7 +115,7 @@ export interface SavedObjectsFindResponsePublic< interface BatchQueueEntry { type: string; id: string; - resolve: (value: SimpleSavedObject | SavedObject) => void; + resolve: (value: SimpleSavedObject | SavedObject) => void; reject: (reason?: any) => void; } @@ -207,7 +198,7 @@ export class SavedObjectsClient { * @param options * @returns */ - public create = ( + public create = ( type: string, attributes: T, options: SavedObjectsCreateOptions = {} @@ -300,7 +291,7 @@ export class SavedObjectsClient { * @property {object} [options.hasReference] - { type, id } * @returns A find result with objects matching the specified search. */ - public find = ( + public find = ( options: SavedObjectsFindOptions ): Promise> => { const path = this.getPath(['_find']); @@ -348,10 +339,7 @@ export class SavedObjectsClient { * @param {string} id * @returns The saved object for the given type and id. */ - public get = ( - type: string, - id: string - ): Promise> => { + public get = (type: string, id: string): Promise> => { if (!type || !id) { return Promise.reject(new Error('requires type and id')); } @@ -402,7 +390,7 @@ export class SavedObjectsClient { * @prop {object} options.migrationVersion - The optional migrationVersion of this document * @returns */ - public update( + public update( type: string, id: string, attributes: T, @@ -434,7 +422,7 @@ export class SavedObjectsClient { * @param {array} objects - [{ type, id, attributes, options: { version, references } }] * @returns The result of the update operation containing both failed and updated saved objects. */ - public bulkUpdate(objects: SavedObjectsBulkUpdateObject[] = []) { + public bulkUpdate(objects: SavedObjectsBulkUpdateObject[] = []) { const path = this.getPath(['_bulk_update']); return this.savedObjectsFetch(path, { @@ -449,9 +437,7 @@ export class SavedObjectsClient { }); } - private createSavedObject( - options: SavedObject - ): SimpleSavedObject { + private createSavedObject(options: SavedObject): SimpleSavedObject { return new SimpleSavedObject(this, options); } diff --git a/src/core/public/saved_objects/simple_saved_object.ts b/src/core/public/saved_objects/simple_saved_object.ts index 8e464680bcf1749..d3ba506b865a474 100644 --- a/src/core/public/saved_objects/simple_saved_object.ts +++ b/src/core/public/saved_objects/simple_saved_object.ts @@ -18,7 +18,7 @@ */ import { get, has, set } from 'lodash'; -import { SavedObject as SavedObjectType, SavedObjectAttributes } from '../../server'; +import { SavedObject as SavedObjectType } from '../../server'; import { SavedObjectsClientContract } from './saved_objects_client'; /** @@ -30,7 +30,7 @@ import { SavedObjectsClientContract } from './saved_objects_client'; * * @public */ -export class SimpleSavedObject { +export class SimpleSavedObject { public attributes: T; // We want to use the same interface this class had in JS public _version?: SavedObjectType['version']; @@ -46,7 +46,7 @@ export class SimpleSavedObject { ) { this.id = id; this.type = type; - this.attributes = attributes || {}; + this.attributes = attributes || ({} as T); this.references = references || []; this._version = version; this.migrationVersion = migrationVersion; diff --git a/src/core/server/saved_objects/import/collect_saved_objects.ts b/src/core/server/saved_objects/import/collect_saved_objects.ts index 65ffd4d9a1d5756..1a8ede41d0b2cb6 100644 --- a/src/core/server/saved_objects/import/collect_saved_objects.ts +++ b/src/core/server/saved_objects/import/collect_saved_objects.ts @@ -42,10 +42,10 @@ export async function collectSavedObjects({ supportedTypes, }: CollectSavedObjectsOptions) { const errors: SavedObjectsImportError[] = []; - const collectedObjects: SavedObject[] = await createPromiseFromStreams([ + const collectedObjects: Array> = await createPromiseFromStreams([ readStream, createLimitStream(objectLimit), - createFilterStream(obj => { + createFilterStream>(obj => { if (supportedTypes.includes(obj.type)) { return true; } diff --git a/src/core/server/saved_objects/import/extract_errors.ts b/src/core/server/saved_objects/import/extract_errors.ts index 725e935f6e21db2..5728ce8b7b59f68 100644 --- a/src/core/server/saved_objects/import/extract_errors.ts +++ b/src/core/server/saved_objects/import/extract_errors.ts @@ -20,11 +20,12 @@ import { SavedObject } from '../types'; import { SavedObjectsImportError } from './types'; export function extractErrors( - savedObjectResults: SavedObject[], - savedObjectsToImport: SavedObject[] + // TODO: define saved object type + savedObjectResults: Array>, + savedObjectsToImport: Array> ) { const errors: SavedObjectsImportError[] = []; - const originalSavedObjectsMap = new Map(); + const originalSavedObjectsMap = new Map>(); for (const savedObject of savedObjectsToImport) { originalSavedObjectsMap.set(`${savedObject.type}:${savedObject.id}`, savedObject); } diff --git a/src/core/server/saved_objects/import/validate_references.ts b/src/core/server/saved_objects/import/validate_references.ts index 4d9ee59f9df159e..f0c033c1d00b451 100644 --- a/src/core/server/saved_objects/import/validate_references.ts +++ b/src/core/server/saved_objects/import/validate_references.ts @@ -77,7 +77,7 @@ export async function getNonExistingReferenceAsKeys( } export async function validateReferences( - savedObjects: SavedObject[], + savedObjects: Array>, savedObjectsClient: SavedObjectsClientContract, namespace?: string ) { diff --git a/src/core/server/saved_objects/management/management.ts b/src/core/server/saved_objects/management/management.ts index 7b5274da91fc891..b7dce2c087c5f5b 100644 --- a/src/core/server/saved_objects/management/management.ts +++ b/src/core/server/saved_objects/management/management.ts @@ -23,9 +23,9 @@ interface SavedObjectsManagementTypeDefinition { isImportableAndExportable?: boolean; defaultSearchField?: string; icon?: string; - getTitle?: (savedObject: SavedObject) => string; - getEditUrl?: (savedObject: SavedObject) => string; - getInAppUrl?: (savedObject: SavedObject) => { path: string; uiCapabilitiesPath: string }; + getTitle?: (savedObject: SavedObject) => string; + getEditUrl?: (savedObject: SavedObject) => string; + getInAppUrl?: (savedObject: SavedObject) => { path: string; uiCapabilitiesPath: string }; } export interface SavedObjectsManagementDefinition { diff --git a/src/core/server/saved_objects/serialization/types.ts b/src/core/server/saved_objects/serialization/types.ts index aaf6f45c244ec08..524c2c8ffae7ae6 100644 --- a/src/core/server/saved_objects/serialization/types.ts +++ b/src/core/server/saved_objects/serialization/types.ts @@ -50,7 +50,7 @@ export interface SavedObjectsRawDocSource { * scenario out of the box. */ interface SavedObjectDoc { - attributes: object; + attributes: unknown; id?: string; // NOTE: SavedObjectDoc is used for uncreated objects where `id` is optional type: string; namespace?: string; diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index b485b8dfe398cbe..72a7867854b60f7 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -48,7 +48,6 @@ import { } from '../saved_objects_client'; import { SavedObject, - SavedObjectAttributes, SavedObjectsBaseOptions, SavedObjectsFindOptions, SavedObjectsMigrationVersion, @@ -213,7 +212,7 @@ export class SavedObjectsRepository { * @property {array} [options.references=[]] - [{ name, type, id }] * @returns {promise} - { id, type, version, attributes } */ - public async create( + public async create( type: string, attributes: T, options: SavedObjectsCreateOptions = {} @@ -254,7 +253,7 @@ export class SavedObjectsRepository { body: raw._source, }); - return this._rawToSavedObject({ + return this._rawToSavedObject({ ...raw, ...response, }); @@ -277,7 +276,7 @@ export class SavedObjectsRepository { * @property {string} [options.namespace] * @returns {promise} - {saved_objects: [[{ id, type, version, references, attributes, error: { message } }]} */ - async bulkCreate( + async bulkCreate( objects: Array>, options: SavedObjectsCreateOptions = {} ): Promise> { @@ -464,7 +463,7 @@ export class SavedObjectsRepository { * @property {object} [options.hasReference] - { type, id } * @returns {promise} - { saved_objects: [{ id, type, version, attributes }], total, per_page, page } */ - async find({ + async find({ search, defaultSearchOperator = 'OR', searchFields, @@ -577,7 +576,7 @@ export class SavedObjectsRepository { * { id: 'foo', type: 'index-pattern' } * ]) */ - async bulkGet( + async bulkGet( objects: SavedObjectsBulkGetObject[] = [], options: SavedObjectsBaseOptions = {} ): Promise> { @@ -648,7 +647,7 @@ export class SavedObjectsRepository { * @property {string} [options.namespace] * @returns {promise} - { id, type, version, attributes } */ - async get( + async get( type: string, id: string, options: SavedObjectsBaseOptions = {} @@ -696,7 +695,7 @@ export class SavedObjectsRepository { * @property {array} [options.references] - [{ name, type, id }] * @returns {promise} */ - async update( + async update( type: string, id: string, attributes: Partial, @@ -753,7 +752,7 @@ export class SavedObjectsRepository { * @property {string} [options.namespace] * @returns {promise} - {saved_objects: [[{ id, type, version, references, attributes, error: { message } }]} */ - async bulkUpdate( + async bulkUpdate( objects: Array>, options: SavedObjectsBulkUpdateOptions = {} ): Promise> { @@ -972,7 +971,7 @@ export class SavedObjectsRepository { // includes the namespace, and we use this for migrating documents. However, we don't // want the namespace to be returned from the repository, as the repository scopes each // method transparently to the specified namespace. - private _rawToSavedObject(raw: SavedObjectsRawDoc): SavedObject { + private _rawToSavedObject(raw: SavedObjectsRawDoc): SavedObject { const savedObject = this._serializer.rawToSavedObject(raw); return omit(savedObject, 'namespace'); } diff --git a/src/core/server/saved_objects/service/saved_objects_client.ts b/src/core/server/saved_objects/service/saved_objects_client.ts index b0b2633646e10d9..70d69374ba8fe4d 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -20,7 +20,6 @@ import { ISavedObjectsRepository } from './lib'; import { SavedObject, - SavedObjectAttributes, SavedObjectReference, SavedObjectsMigrationVersion, SavedObjectsBaseOptions, @@ -49,7 +48,7 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions { * * @public */ -export interface SavedObjectsBulkCreateObject { +export interface SavedObjectsBulkCreateObject { id?: string; type: string; attributes: T; @@ -62,7 +61,7 @@ export interface SavedObjectsBulkCreateObject +export interface SavedObjectsBulkUpdateObject extends Pick { /** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */ id: string; @@ -76,7 +75,7 @@ export interface SavedObjectsBulkUpdateObject { +export interface SavedObjectsBulkResponse { saved_objects: Array>; } @@ -88,7 +87,7 @@ export interface SavedObjectsBulkResponse * * @public */ -export interface SavedObjectsFindResponse { +export interface SavedObjectsFindResponse { saved_objects: Array>; total: number; per_page: number; @@ -141,7 +140,7 @@ export interface SavedObjectsBulkGetObject { * * @public */ -export interface SavedObjectsBulkResponse { +export interface SavedObjectsBulkResponse { saved_objects: Array>; } @@ -149,7 +148,7 @@ export interface SavedObjectsBulkResponse * * @public */ -export interface SavedObjectsBulkUpdateResponse { +export interface SavedObjectsBulkUpdateResponse { saved_objects: Array>; } @@ -157,7 +156,7 @@ export interface SavedObjectsBulkUpdateResponse +export interface SavedObjectsUpdateResponse extends Omit, 'attributes' | 'references'> { attributes: Partial; references: SavedObjectReference[] | undefined; @@ -185,11 +184,7 @@ export class SavedObjectsClient { * @param attributes * @param options */ - async create( - type: string, - attributes: T, - options?: SavedObjectsCreateOptions - ) { + async create(type: string, attributes: T, options?: SavedObjectsCreateOptions) { return await this._repository.create(type, attributes, options); } @@ -199,7 +194,7 @@ export class SavedObjectsClient { * @param objects * @param options */ - async bulkCreate( + async bulkCreate( objects: Array>, options?: SavedObjectsCreateOptions ) { @@ -222,9 +217,7 @@ export class SavedObjectsClient { * * @param options */ - async find( - options: SavedObjectsFindOptions - ): Promise> { + async find(options: SavedObjectsFindOptions): Promise> { return await this._repository.find(options); } @@ -239,7 +232,7 @@ export class SavedObjectsClient { * { id: 'foo', type: 'index-pattern' } * ]) */ - async bulkGet( + async bulkGet( objects: SavedObjectsBulkGetObject[] = [], options: SavedObjectsBaseOptions = {} ): Promise> { @@ -253,7 +246,7 @@ export class SavedObjectsClient { * @param id - The ID of the SavedObject to retrieve * @param options */ - async get( + async get( type: string, id: string, options: SavedObjectsBaseOptions = {} @@ -268,7 +261,7 @@ export class SavedObjectsClient { * @param id * @param options */ - async update( + async update( type: string, id: string, attributes: Partial, @@ -282,7 +275,7 @@ export class SavedObjectsClient { * * @param objects */ - async bulkUpdate( + async bulkUpdate( objects: Array>, options?: SavedObjectsBulkUpdateOptions ): Promise> { diff --git a/src/core/server/saved_objects/types.ts b/src/core/server/saved_objects/types.ts index a4fde1765b7d333..9c204784b0aeb37 100644 --- a/src/core/server/saved_objects/types.ts +++ b/src/core/server/saved_objects/types.ts @@ -33,7 +33,6 @@ export { SavedObjectsImportRetry, } from './import/types'; -import { SavedObjectAttributes } from '../../types'; import { LegacyConfig } from '../legacy'; export { SavedObjectAttributes, @@ -64,7 +63,7 @@ export interface SavedObjectsMigrationVersion { * * @public */ -export interface SavedObject { +export interface SavedObject { /** The ID of this Saved Object, guaranteed to be unique for all objects of the same `type` */ id: string; /** The type of Saved Object. Each plugin can define it's own custom Saved Object types. */ diff --git a/src/core/server/server.api.md b/src/core/server/server.api.md index 053a60028fc5ff9..f717f30fdb0cfd3 100644 --- a/src/core/server/server.api.md +++ b/src/core/server/server.api.md @@ -1462,7 +1462,7 @@ export interface RouteValidatorOptions { } // @public (undocumented) -export interface SavedObject { +export interface SavedObject { attributes: T; // (undocumented) error?: { @@ -1524,7 +1524,7 @@ export interface SavedObjectsBaseOptions { } // @public (undocumented) -export interface SavedObjectsBulkCreateObject { +export interface SavedObjectsBulkCreateObject { // (undocumented) attributes: T; // (undocumented) @@ -1546,19 +1546,19 @@ export interface SavedObjectsBulkGetObject { } // @public (undocumented) -export interface SavedObjectsBulkResponse { +export interface SavedObjectsBulkResponse { // (undocumented) saved_objects: Array>; } // @public (undocumented) -export interface SavedObjectsBulkResponse { +export interface SavedObjectsBulkResponse { // (undocumented) saved_objects: Array>; } // @public (undocumented) -export interface SavedObjectsBulkUpdateObject extends Pick { +export interface SavedObjectsBulkUpdateObject extends Pick { attributes: Partial; id: string; type: string; @@ -1570,7 +1570,7 @@ export interface SavedObjectsBulkUpdateOptions extends SavedObjectsBaseOptions { } // @public (undocumented) -export interface SavedObjectsBulkUpdateResponse { +export interface SavedObjectsBulkUpdateResponse { // (undocumented) saved_objects: Array>; } @@ -1579,18 +1579,18 @@ export interface SavedObjectsBulkUpdateResponse(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; - bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; - bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; - create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; + bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; + bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; + bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; + create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>; // (undocumented) static errors: typeof SavedObjectsErrorHelpers; // (undocumented) errors: typeof SavedObjectsErrorHelpers; - find(options: SavedObjectsFindOptions): Promise>; - get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; - update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; + find(options: SavedObjectsFindOptions): Promise>; + get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; + update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; } // @public @@ -1772,7 +1772,7 @@ export interface SavedObjectsFindOptions extends SavedObjectsBaseOptions { } // @public -export interface SavedObjectsFindResponse { +export interface SavedObjectsFindResponse { // (undocumented) page: number; // (undocumented) @@ -1951,10 +1951,10 @@ export interface SavedObjectsRawDoc { // @public (undocumented) export class SavedObjectsRepository { - bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; - bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; - bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; - create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; + bulkCreate(objects: Array>, options?: SavedObjectsCreateOptions): Promise>; + bulkGet(objects?: SavedObjectsBulkGetObject[], options?: SavedObjectsBaseOptions): Promise>; + bulkUpdate(objects: Array>, options?: SavedObjectsBulkUpdateOptions): Promise>; + create(type: string, attributes: T, options?: SavedObjectsCreateOptions): Promise>; // Warning: (ae-forgotten-export) The symbol "KibanaMigrator" needs to be exported by the entry point index.d.ts // // @internal @@ -1962,8 +1962,8 @@ export class SavedObjectsRepository { delete(type: string, id: string, options?: SavedObjectsDeleteOptions): Promise<{}>; deleteByNamespace(namespace: string, options?: SavedObjectsDeleteByNamespaceOptions): Promise; // (undocumented) - find({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, }: SavedObjectsFindOptions): Promise>; - get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; + find({ search, defaultSearchOperator, searchFields, hasReference, page, perPage, sortField, sortOrder, fields, namespace, type, filter, }: SavedObjectsFindOptions): Promise>; + get(type: string, id: string, options?: SavedObjectsBaseOptions): Promise>; incrementCounter(type: string, id: string, counterFieldName: string, options?: SavedObjectsIncrementCounterOptions): Promise<{ id: string; type: string; @@ -1972,7 +1972,7 @@ export class SavedObjectsRepository { version: string; attributes: any; }>; - update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; + update(type: string, id: string, attributes: Partial, options?: SavedObjectsUpdateOptions): Promise>; } // @public @@ -2062,7 +2062,7 @@ export interface SavedObjectsUpdateOptions extends SavedObjectsBaseOptions { } // @public (undocumented) -export interface SavedObjectsUpdateResponse extends Omit, 'attributes' | 'references'> { +export interface SavedObjectsUpdateResponse extends Omit, 'attributes' | 'references'> { // (undocumented) attributes: Partial; // (undocumented) diff --git a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts index 0544a1806e09a2f..55e32b1e3bb3752 100644 --- a/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts +++ b/src/core/server/ui_settings/create_or_upgrade_saved_config/create_or_upgrade_saved_config.ts @@ -45,7 +45,10 @@ export async function createOrUpgradeSavedConfig( }); // default to the attributes of the upgradeableConfig if available - const attributes = defaults({ buildNum }, upgradeableConfig ? upgradeableConfig.attributes : {}); + const attributes = defaults( + { buildNum }, + upgradeableConfig ? (upgradeableConfig.attributes as any) : {} + ); try { // create the new SavedConfig diff --git a/src/core/server/ui_settings/ui_settings_client.ts b/src/core/server/ui_settings/ui_settings_client.ts index 3c9c232bff28061..a7e55d2b2da65ef 100644 --- a/src/core/server/ui_settings/ui_settings_client.ts +++ b/src/core/server/ui_settings/ui_settings_client.ts @@ -185,7 +185,7 @@ export class UiSettingsClient implements IUiSettingsClient { autoCreateOrUpgradeIfMissing = true, }: ReadOptions = {}): Promise> { try { - const resp = await this.savedObjectsClient.get(this.type, this.id); + const resp = await this.savedObjectsClient.get>(this.type, this.id); return resp.attributes; } catch (error) { if (SavedObjectsErrorHelpers.isNotFoundError(error) && autoCreateOrUpgradeIfMissing) { diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/_discover.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/_discover.scss index 0da28e41579aed3..62e7a96ed80cf73 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/_discover.scss +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/_discover.scss @@ -206,7 +206,7 @@ discover-app { background-color: transparent; } -.dscField--noResults { +.dscFieldName--noResults { color: $euiColorDarkShade; } diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/__snapshots__/field_name.test.tsx.snap b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/__snapshots__/field_name.test.tsx.snap index bdb003771619c14..23288fc5feb5971 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/__snapshots__/field_name.test.tsx.snap +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/__snapshots__/field_name.test.tsx.snap @@ -1,73 +1,109 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`FieldName renders a geo field, useShortDots is set to true 1`] = ` - - - - t.t.test - - + + + + +
+ + t.t.test + +
+ `; exports[`FieldName renders a number field by providing a field record, useShortDots is set to false 1`] = ` - - - + + + + +
- test.test.test - - + + test.test.test + +
+ `; exports[`FieldName renders a string field by providing fieldType and fieldName 1`] = ` - - - + + + + +
- test - - + + test + +
+ `; diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx index 95720bee38df8d8..54e1c1706a856aa 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/angular/directives/field_name/field_name.tsx @@ -18,7 +18,9 @@ */ import React from 'react'; import classNames from 'classnames'; -import { FieldIcon } from '../../../../../../../../../plugins/kibana_react/public'; +import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; + +import { FieldIcon, FieldIconProps } from '../../../../../../../../../plugins/kibana_react/public'; import { shortenDottedString } from '../../../../../../../../../plugins/data/common/utils'; import { getFieldTypeName } from './field_type_name'; @@ -35,25 +37,35 @@ interface Props { fieldName?: string; fieldType?: string; useShortDots?: boolean; + fieldIconProps?: Omit; } -export function FieldName({ field, fieldName, fieldType, useShortDots }: Props) { +export function FieldName({ field, fieldName, fieldType, useShortDots, fieldIconProps }: Props) { const type = field ? String(field.type) : String(fieldType); const typeName = getFieldTypeName(type); const name = field ? String(field.name) : String(fieldName); const displayName = useShortDots ? shortenDottedString(name) : name; - const className = classNames({ - 'dscField--noResults': field ? !field.rowCount && !field.scripted : false, - // this is currently not styled, should display an icon - scripted: field ? field.scripted : false, + const noResults = field ? !field.rowCount && !field.scripted : false; + + const className = classNames('dscFieldName', { + 'dscFieldName--noResults': noResults, }); return ( - - - {displayName} - + + + + + + {displayName} + + ); } diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_field_chooser.scss b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_field_chooser.scss index fe13ac2fafa01fc..b05775c4ee95cac 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_field_chooser.scss +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/_field_chooser.scss @@ -10,7 +10,6 @@ .dscFieldName { color: $euiColorDarkShade; - padding-left: $euiSizeS; } diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.test.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.test.tsx index 96b8cc383888e35..b6fd5ee60b8e2c7 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.test.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.test.tsx @@ -31,14 +31,14 @@ const indexPattern1 = { attributes: { title: 'test1 title', }, -} as SavedObject; +} as SavedObject; const indexPattern2 = { id: 'test2', attributes: { title: 'test2 title', }, -} as SavedObject; +} as SavedObject; const defaultProps = { indexPatternList: [indexPattern1, indexPattern2], diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx index a4e8ee2ca3d8aaf..cca523ee2c1bda8 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/field_chooser/discover_index_pattern.tsx @@ -18,6 +18,7 @@ */ import React, { useState } from 'react'; import { SavedObject } from 'kibana/server'; +import { IndexPatternAttributes } from 'src/plugins/data/public'; import { I18nProvider } from '@kbn/i18n/react'; import { IndexPatternRef } from './types'; @@ -26,11 +27,11 @@ export interface DiscoverIndexPatternProps { /** * list of available index patterns, if length > 1, component offers a "change" link */ - indexPatternList: SavedObject[]; + indexPatternList: Array>; /** * currently selected index pattern, due to angular issues it's undefined at first rendering */ - selectedIndexPattern: SavedObject; + selectedIndexPattern: SavedObject; /** * triggered when user selects a new index pattern */ diff --git a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx index 7a78e8941636130..5b13f6b3655c399 100644 --- a/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx +++ b/src/legacy/core_plugins/kibana/public/discover/np_ready/components/table/table_row.tsx @@ -87,7 +87,12 @@ export function DocViewTableRow({ )} - + {isCollapsible && ( diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx index 7cfc7c4dbc81cb6..bbb6bf26e5b3112 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.tsx @@ -24,6 +24,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { indexPatterns, DataPublicPluginStart, + IndexPatternAttributes, } from '../../../../../../../../../../plugins/data/public'; import { SavedObjectsClient, IUiSettingsClient } from '../../../../../../../../../../core/public'; import { MAX_SEARCH_SIZE } from '../../constants'; @@ -96,7 +97,7 @@ export class StepIndexPattern extends Component { - const { savedObjects } = await this.props.savedObjectsClient.find({ + const { savedObjects } = await this.props.savedObjectsClient.find({ type: 'index-pattern', fields: ['title'], perPage: 10000, diff --git a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts index 95e01f9c8db5b38..ea9532964d6fe46 100644 --- a/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts +++ b/src/legacy/core_plugins/vis_type_timelion/public/helpers/arg_value_suggestions.ts @@ -20,7 +20,10 @@ import { get } from 'lodash'; import { getIndexPatterns, getSavedObjectsClient } from './plugin_services'; import { TimelionFunctionArgs } from '../../../../../plugins/timelion/common/types'; -import { indexPatterns as indexPatternsUtils } from '../../../../../plugins/data/public'; +import { + indexPatterns as indexPatternsUtils, + IndexPatternAttributes, +} from '../../../../../plugins/data/public'; export interface Location { min: number; @@ -53,7 +56,7 @@ export function getArgValueSuggestions() { } const indexPatternTitle = get(indexPatternArg, 'value.text'); - const { savedObjects } = await savedObjectsClient.find({ + const { savedObjects } = await savedObjectsClient.find({ type: 'index-pattern', fields: ['title'], search: `"${indexPatternTitle}"`, @@ -84,7 +87,7 @@ export function getArgValueSuggestions() { es: { async index(partial: string) { const search = partial ? `${partial}*` : '*'; - const resp = await savedObjectsClient.find({ + const resp = await savedObjectsClient.find({ type: 'index-pattern', fields: ['title', 'type'], search: `${search}`, diff --git a/src/legacy/core_plugins/visualizations/public/embeddable/get_index_pattern.ts b/src/legacy/core_plugins/visualizations/public/embeddable/get_index_pattern.ts index 25aa77ec7357923..cfb2960cfbb7cd0 100644 --- a/src/legacy/core_plugins/visualizations/public/embeddable/get_index_pattern.ts +++ b/src/legacy/core_plugins/visualizations/public/embeddable/get_index_pattern.ts @@ -18,7 +18,11 @@ */ import { VisSavedObject } from './visualize_embeddable'; -import { indexPatterns, IIndexPattern } from '../../../../../plugins/data/public'; +import { + indexPatterns, + IIndexPattern, + IndexPatternAttributes, +} from '../../../../../plugins/data/public'; import { getUISettings, getSavedObjects } from '../np_ready/public/services'; export async function getIndexPattern( @@ -32,7 +36,7 @@ export async function getIndexPattern( const defaultIndex = getUISettings().get('defaultIndex'); if (savedVis.vis.params.index_pattern) { - const indexPatternObjects = await savedObjectsClient.find({ + const indexPatternObjects = await savedObjectsClient.find({ type: 'index-pattern', fields: ['title', 'fields'], search: `"${savedVis.vis.params.index_pattern}"`, @@ -42,6 +46,9 @@ export async function getIndexPattern( return indexPattern; } - const savedObject = await savedObjectsClient.get('index-pattern', defaultIndex); + const savedObject = await savedObjectsClient.get( + 'index-pattern', + defaultIndex + ); return indexPatterns.getFromSavedObject(savedObject); } diff --git a/src/plugins/data/common/index_patterns/types.ts b/src/plugins/data/common/index_patterns/types.ts index 98cdd20ea4b8463..698edbf9cd6a8ea 100644 --- a/src/plugins/data/common/index_patterns/types.ts +++ b/src/plugins/data/common/index_patterns/types.ts @@ -34,3 +34,15 @@ export interface IIndexPattern { } >; } + +/** + * Use data plugin interface instead + * @deprecated + */ +export interface IndexPatternAttributes { + type: string; + fields: string; + title: string; + typeMeta: string; + timeFieldName?: string; +} diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index cbd4bfd348797d4..978f140eb1d2632 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -263,6 +263,7 @@ export { IFieldSubType, ES_FIELD_TYPES, KBN_FIELD_TYPES, + IndexPatternAttributes, } from '../common'; /* diff --git a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts index 5f95b101302ef67..acce5ed57683c55 100644 --- a/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts +++ b/src/plugins/data/public/index_patterns/index_patterns/index_patterns.ts @@ -50,7 +50,7 @@ export class IndexPatternsService { private async refreshSavedObjectsCache() { this.savedObjectsCache = ( - await this.savedObjectsClient.find({ + await this.savedObjectsClient.find>({ type: 'index-pattern', fields: ['title'], perPage: 10000, diff --git a/src/plugins/data/public/index_patterns/lib/get_from_saved_object.ts b/src/plugins/data/public/index_patterns/lib/get_from_saved_object.ts index 60b2023f2560968..1630a4547b7a14c 100644 --- a/src/plugins/data/public/index_patterns/lib/get_from_saved_object.ts +++ b/src/plugins/data/public/index_patterns/lib/get_from_saved_object.ts @@ -17,17 +17,20 @@ * under the License. */ +import { SavedObject } from 'src/core/public'; import { get } from 'lodash'; -import { IIndexPattern } from '../..'; +import { IIndexPattern, IndexPatternAttributes } from '../..'; -export function getFromSavedObject(savedObject: any): IIndexPattern | undefined { +export function getFromSavedObject( + savedObject: SavedObject +): IIndexPattern | undefined { if (get(savedObject, 'attributes.fields') === undefined) { return; } return { id: savedObject.id, - fields: JSON.parse(savedObject.attributes.fields), + fields: JSON.parse(savedObject.attributes.fields!), title: savedObject.attributes.title, }; } diff --git a/src/plugins/data/public/ui/query_string_input/fetch_index_patterns.ts b/src/plugins/data/public/ui/query_string_input/fetch_index_patterns.ts index 6bef11e4fc46cfc..1e01d2452ce040a 100644 --- a/src/plugins/data/public/ui/query_string_input/fetch_index_patterns.ts +++ b/src/plugins/data/public/ui/query_string_input/fetch_index_patterns.ts @@ -18,7 +18,7 @@ */ import { isEmpty } from 'lodash'; import { IUiSettingsClient, SavedObjectsClientContract } from 'src/core/public'; -import { indexPatterns } from '../..'; +import { indexPatterns, IndexPatternAttributes } from '../..'; export async function fetchIndexPatterns( savedObjectsClient: SavedObjectsClientContract, @@ -30,7 +30,7 @@ export async function fetchIndexPatterns( } const searchString = indexPatternStrings.map(string => `"${string}"`).join(' | '); - const indexPatternsFromSavedObjects = await savedObjectsClient.find({ + const indexPatternsFromSavedObjects = await savedObjectsClient.find({ type: 'index-pattern', fields: ['title', 'fields'], search: searchString, @@ -38,7 +38,7 @@ export async function fetchIndexPatterns( }); const exactMatches = indexPatternsFromSavedObjects.savedObjects.filter(savedObject => { - return indexPatternStrings.includes(savedObject.attributes.title as string); + return indexPatternStrings.includes(savedObject.attributes.title); }); const defaultIndex = uiSettings.get('defaultIndex'); @@ -46,7 +46,10 @@ export async function fetchIndexPatterns( const allMatches = exactMatches.length === indexPatternStrings.length ? exactMatches - : [...exactMatches, await savedObjectsClient.get('index-pattern', defaultIndex)]; + : [ + ...exactMatches, + await savedObjectsClient.get('index-pattern', defaultIndex), + ]; return allMatches.map(indexPatterns.getFromSavedObject); } diff --git a/src/plugins/data/server/index.ts b/src/plugins/data/server/index.ts index 40d367138b60d74..020c3c4c1192df6 100644 --- a/src/plugins/data/server/index.ts +++ b/src/plugins/data/server/index.ts @@ -142,6 +142,7 @@ export { IFieldSubType, ES_FIELD_TYPES, KBN_FIELD_TYPES, + IndexPatternAttributes, } from '../common'; /** diff --git a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts index 29cf2289fc5b346..bfe99730039d2a8 100644 --- a/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts +++ b/src/plugins/home/server/services/sample_data/lib/sample_dataset_registry_types.ts @@ -67,7 +67,7 @@ export interface AppLinkSchema { label: string; } -export interface SampleDatasetSchema { +export interface SampleDatasetSchema { id: string; name: string; description: string; @@ -83,7 +83,7 @@ export interface SampleDatasetSchema { // Kibana saved objects (index patter, visualizations, dashboard, ...) // Should provide a nice demo of Kibana's functionality with the sample data set - savedObjects: SavedObject[]; + savedObjects: Array>; dataIndices: DataIndexSchema[]; status?: string | undefined; statusMsg?: unknown; diff --git a/src/plugins/home/server/services/sample_data/sample_data_registry.ts b/src/plugins/home/server/services/sample_data/sample_data_registry.ts index aac680211e52e4b..b6d04c5c0b6a315 100644 --- a/src/plugins/home/server/services/sample_data/sample_data_registry.ts +++ b/src/plugins/home/server/services/sample_data/sample_data_registry.ts @@ -137,9 +137,9 @@ export class SampleDataRegistry { throw new Error(`Unable to find sample dataset with id: ${sampleDataId}`); } - const dashboard = sampleDataset.savedObjects.find((savedObject: SavedObject) => { + const dashboard = sampleDataset.savedObjects.find(savedObject => { return savedObject.id === dashboardId && savedObject.type === 'dashboard'; - }); + }) as SavedObject<{ panelsJSON: string }>; if (!dashboard) { throw new Error(`Unable to find dashboard with id: ${dashboardId}`); } diff --git a/src/plugins/kibana_react/public/field_icon/__snapshots__/field_icon.test.tsx.snap b/src/plugins/kibana_react/public/field_icon/__snapshots__/field_icon.test.tsx.snap index 870dbdc53326761..cde6a625ac8e865 100644 --- a/src/plugins/kibana_react/public/field_icon/__snapshots__/field_icon.test.tsx.snap +++ b/src/plugins/kibana_react/public/field_icon/__snapshots__/field_icon.test.tsx.snap @@ -1,37 +1,159 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`FieldIcon renders a blackwhite icon for a string 1`] = ` - `; -exports[`FieldIcon renders a colored icon for a number 1`] = ` - `; -exports[`FieldIcon renders an icon for an unknown type 1`] = ` - +`; + +exports[`FieldIcon renders known field types boolean is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types conflict is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types date is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types geo_point is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types geo_shape is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types ip is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types murmur3 is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types nested is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types number is rendered 1`] = ` + +`; + +exports[`FieldIcon renders known field types string is rendered 1`] = ` + `; exports[`FieldIcon renders with className if provided 1`] = ` - +`; + +exports[`FieldIcon supports same props as EuiToken 1`] = ` + `; diff --git a/src/plugins/kibana_react/public/field_icon/field_icon.test.tsx b/src/plugins/kibana_react/public/field_icon/field_icon.test.tsx index 90a858e31b4f3dc..51ff5f603ea377b 100644 --- a/src/plugins/kibana_react/public/field_icon/field_icon.test.tsx +++ b/src/plugins/kibana_react/public/field_icon/field_icon.test.tsx @@ -18,24 +18,44 @@ */ import React from 'react'; import { shallow } from 'enzyme'; -import { FieldIcon } from './field_icon'; +import { FieldIcon, typeToEuiIconMap } from './field_icon'; -test('FieldIcon renders a blackwhite icon for a string', () => { - const component = shallow(); +const availableTypes = Object.keys(typeToEuiIconMap); + +describe('FieldIcon renders known field types', () => { + availableTypes.forEach(type => { + test(`${type} is rendered`, () => { + const component = shallow(); + expect(component).toMatchSnapshot(); + }); + }); +}); + +test('FieldIcon renders an icon for an unknown type', () => { + const component = shallow(); expect(component).toMatchSnapshot(); }); -test('FieldIcon renders a colored icon for a number', () => { - const component = shallow(); +test('FieldIcon supports same props as EuiToken', () => { + const component = shallow( + + ); expect(component).toMatchSnapshot(); }); -test('FieldIcon renders an icon for an unknown type', () => { - const component = shallow(); +test('FieldIcon changes fill when scripted is true', () => { + const component = shallow(); expect(component).toMatchSnapshot(); }); test('FieldIcon renders with className if provided', () => { - const component = shallow(); + const component = shallow(); expect(component).toMatchSnapshot(); }); diff --git a/src/plugins/kibana_react/public/field_icon/field_icon.tsx b/src/plugins/kibana_react/public/field_icon/field_icon.tsx index 2e199a7471a642b..2da1eba31e254dc 100644 --- a/src/plugins/kibana_react/public/field_icon/field_icon.tsx +++ b/src/plugins/kibana_react/public/field_icon/field_icon.tsx @@ -17,14 +17,10 @@ * under the License. */ import React from 'react'; -import { euiPaletteColorBlind, EuiIcon } from '@elastic/eui'; -import { IconSize } from '@elastic/eui/src/components/icon/icon'; +import classNames from 'classnames'; +import { EuiToken, EuiTokenProps } from '@elastic/eui'; -interface IconMapEntry { - icon: string; - color: string; -} -interface FieldIconProps { +export interface FieldIconProps extends Omit { type: | 'boolean' | 'conflict' @@ -39,51 +35,50 @@ interface FieldIconProps { | string | 'nested'; label?: string; - size?: IconSize; - useColor?: boolean; - className?: string; + scripted?: boolean; } -const colors = euiPaletteColorBlind(); - // defaultIcon => a unknown datatype -const defaultIcon = { icon: 'questionInCircle', color: colors[0] }; +const defaultIcon = { iconType: 'questionInCircle', color: 'gray' }; -export const typeToEuiIconMap: Partial> = { - boolean: { icon: 'invert', color: colors[5] }, +export const typeToEuiIconMap: Partial> = { + boolean: { iconType: 'tokenBoolean' }, // icon for an index pattern mapping conflict in discover - conflict: { icon: 'alert', color: colors[8] }, - date: { icon: 'calendar', color: colors[7] }, - geo_point: { icon: 'globe', color: colors[2] }, - geo_shape: { icon: 'globe', color: colors[2] }, - ip: { icon: 'storage', color: colors[8] }, + conflict: { iconType: 'alert', color: 'euiVisColor9' }, + date: { iconType: 'tokenDate' }, + geo_point: { iconType: 'tokenGeo' }, + geo_shape: { iconType: 'tokenGeo' }, + ip: { iconType: 'tokenIP' }, // is a plugin's data type https://www.elastic.co/guide/en/elasticsearch/plugins/current/mapper-murmur3-usage.html - murmur3: { icon: 'document', color: colors[1] }, - number: { icon: 'number', color: colors[0] }, - _source: { icon: 'editorCodeBlock', color: colors[3] }, - string: { icon: 'string', color: colors[4] }, - nested: { icon: 'nested', color: colors[2] }, + murmur3: { iconType: 'tokenFile' }, + number: { iconType: 'tokenNumber' }, + _source: { iconType: 'editorCodeBlock', color: 'gray' }, + string: { iconType: 'tokenString' }, + nested: { iconType: 'tokenNested' }, }; /** - * Field icon used across the app + * Field token icon used across the app */ export function FieldIcon({ type, label, size = 's', - useColor = false, - className = undefined, + scripted, + className, + ...rest }: FieldIconProps) { - const euiIcon = typeToEuiIconMap[type] || defaultIcon; + const token = typeToEuiIconMap[type] || defaultIcon; return ( - ); } diff --git a/src/plugins/saved_objects/public/finder/saved_object_finder.tsx b/src/plugins/saved_objects/public/finder/saved_object_finder.tsx index b503392c9827fae..81600e9f6863452 100644 --- a/src/plugins/saved_objects/public/finder/saved_object_finder.tsx +++ b/src/plugins/saved_objects/public/finder/saved_object_finder.tsx @@ -43,14 +43,13 @@ import { Direction } from '@elastic/eui/src/services/sort/sort_direction'; import { i18n } from '@kbn/i18n'; import { - SavedObjectAttributes, SimpleSavedObject, CoreStart, IUiSettingsClient, SavedObjectsStart, -} from '../../../../core/public'; +} from 'src/core/public'; -export interface SavedObjectMetaData { +export interface SavedObjectMetaData { type: string; name: string; getIconForSavedObject(savedObject: SimpleSavedObject): IconType; @@ -59,12 +58,17 @@ export interface SavedObjectMetaData { includeFields?: string[]; } +interface FinderAttributes { + title?: string; + type: string; +} + interface SavedObjectFinderState { items: Array<{ title: string | null; - id: SimpleSavedObject['id']; - type: SimpleSavedObject['type']; - savedObject: SimpleSavedObject; + id: SimpleSavedObject['id']; + type: SimpleSavedObject['type']; + savedObject: SimpleSavedObject; }>; query: string; isFetchingItems: boolean; @@ -78,13 +82,13 @@ interface SavedObjectFinderState { interface BaseSavedObjectFinder { onChoose?: ( - id: SimpleSavedObject['id'], - type: SimpleSavedObject['type'], + id: SimpleSavedObject['id'], + type: SimpleSavedObject['type'], name: string, - savedObject: SimpleSavedObject + savedObject: SimpleSavedObject ) => void; noItemsMessage?: React.ReactNode; - savedObjectMetaData: Array>; + savedObjectMetaData: Array>; showFilter?: boolean; } @@ -128,7 +132,7 @@ class SavedObjectFinderUi extends React.Component< .reduce((allFields, currentFields) => allFields.concat(currentFields), ['title']); const perPage = this.props.uiSettings.get('savedObjects:listingLimit'); - const resp = await this.props.savedObjects.client.find({ + const resp = await this.props.savedObjects.client.find({ type: Object.keys(metaDataMap), fields: [...new Set(fields)], search: query ? `${query}*` : undefined, @@ -163,6 +167,7 @@ class SavedObjectFinderUi extends React.Component< id, type, } = savedObject; + return { title: typeof title === 'string' ? title : '', id, @@ -208,7 +213,7 @@ class SavedObjectFinderUi extends React.Component< ); } - private getSavedObjectMetaDataMap(): Record> { + private getSavedObjectMetaDataMap(): Record { return this.props.savedObjectMetaData.reduce( (map, metaData) => ({ ...map, [metaData.type]: metaData }), {} @@ -470,7 +475,7 @@ class SavedObjectFinderUi extends React.Component< currentSavedObjectMetaData || ({ getIconForSavedObject: () => 'document', - } as Pick, 'getIconForSavedObject'>) + } as Pick, 'getIconForSavedObject'>) ).getIconForSavedObject(item.savedObject); return ( >({ type: this.lowercaseType, search: search ? `${search}*` : undefined, perPage: size, diff --git a/src/plugins/share/server/routes/lib/short_url_lookup.test.ts b/src/plugins/share/server/routes/lib/short_url_lookup.test.ts index 87e2b7b726e599a..2b33489eb27c950 100644 --- a/src/plugins/share/server/routes/lib/short_url_lookup.test.ts +++ b/src/plugins/share/server/routes/lib/short_url_lookup.test.ts @@ -17,9 +17,10 @@ * under the License. */ -import { shortUrlLookupProvider, ShortUrlLookupService } from './short_url_lookup'; -import { SavedObjectsClientContract, Logger } from 'kibana/server'; -import { SavedObjectsClient } from '../../../../../core/server'; +import { shortUrlLookupProvider, ShortUrlLookupService, UrlAttributes } from './short_url_lookup'; +import { SavedObjectsClientContract, SavedObject } from 'kibana/server'; + +import { savedObjectsClientMock, loggingServiceMock } from '../../../../../core/server/mocks'; describe('shortUrlLookupProvider', () => { const ID = 'bf00ad16941fc51420f91a93428b27a0'; @@ -31,15 +32,10 @@ describe('shortUrlLookupProvider', () => { let shortUrl: ShortUrlLookupService; beforeEach(() => { - savedObjects = ({ - get: jest.fn(), - create: jest.fn(() => Promise.resolve({ id: ID })), - update: jest.fn(), - errors: SavedObjectsClient.errors, - } as unknown) as jest.Mocked; - + savedObjects = savedObjectsClientMock.create(); + savedObjects.create.mockResolvedValue({ id: ID } as SavedObject); deps = { savedObjects }; - shortUrl = shortUrlLookupProvider({ logger: ({ warn: () => {} } as unknown) as Logger }); + shortUrl = shortUrlLookupProvider({ logger: loggingServiceMock.create().get() }); }); describe('generateUrlId', () => { @@ -55,13 +51,13 @@ describe('shortUrlLookupProvider', () => { const [type, attributes, options] = savedObjects.create.mock.calls[0]; expect(type).toEqual(TYPE); - expect(Object.keys(attributes).sort()).toEqual([ + expect(Object.keys(attributes as UrlAttributes).sort()).toEqual([ 'accessCount', 'accessDate', 'createDate', 'url', ]); - expect(attributes.url).toEqual(URL); + expect((attributes as UrlAttributes).url).toEqual(URL); expect(options!.id).toEqual(ID); }); @@ -72,13 +68,13 @@ describe('shortUrlLookupProvider', () => { const [type, attributes] = savedObjects.create.mock.calls[0]; expect(type).toEqual(TYPE); - expect(Object.keys(attributes).sort()).toEqual([ + expect(Object.keys(attributes as UrlAttributes).sort()).toEqual([ 'accessCount', 'accessDate', 'createDate', 'url', ]); - expect(attributes.url).toEqual(URL); + expect((attributes as UrlAttributes).url).toEqual(URL); }); it('gracefully handles version conflict', async () => { @@ -119,7 +115,7 @@ describe('shortUrlLookupProvider', () => { expect(type).toEqual(TYPE); expect(id).toEqual(ID); expect(Object.keys(attributes).sort()).toEqual(['accessCount', 'accessDate']); - expect(attributes.accessCount).toEqual(3); + expect((attributes as UrlAttributes).accessCount).toEqual(3); }); }); }); diff --git a/src/plugins/share/server/routes/lib/short_url_lookup.ts b/src/plugins/share/server/routes/lib/short_url_lookup.ts index 0d8a9c86621de39..65fa33a940facda 100644 --- a/src/plugins/share/server/routes/lib/short_url_lookup.ts +++ b/src/plugins/share/server/routes/lib/short_url_lookup.ts @@ -27,13 +27,20 @@ export interface ShortUrlLookupService { getUrl(url: string, deps: { savedObjects: SavedObjectsClientContract }): Promise; } +export interface UrlAttributes { + url: string; + accessCount: number; + createDate: number; + accessDate: number; +} + export function shortUrlLookupProvider({ logger }: { logger: Logger }): ShortUrlLookupService { async function updateMetadata( - doc: SavedObject, + doc: SavedObject, { savedObjects }: { savedObjects: SavedObjectsClientContract } ) { try { - await savedObjects.update('url', doc.id, { + await savedObjects.update('url', doc.id, { accessDate: new Date().valueOf(), accessCount: get(doc, 'attributes.accessCount', 0) + 1, }); @@ -53,7 +60,7 @@ export function shortUrlLookupProvider({ logger }: { logger: Logger }): ShortUrl const { isConflictError } = savedObjects.errors; try { - const doc = await savedObjects.create( + const doc = await savedObjects.create( 'url', { url, @@ -75,7 +82,7 @@ export function shortUrlLookupProvider({ logger }: { logger: Logger }): ShortUrl }, async getUrl(id, { savedObjects }) { - const doc = await savedObjects.get('url', id); + const doc = await savedObjects.get('url', id); updateMetadata(doc, { savedObjects }); return doc.attributes.url; diff --git a/x-pack/legacy/plugins/canvas/public/lib/es_service.ts b/x-pack/legacy/plugins/canvas/public/lib/es_service.ts index 2fa1bf94ad66902..32f4fe041423c22 100644 --- a/x-pack/legacy/plugins/canvas/public/lib/es_service.ts +++ b/x-pack/legacy/plugins/canvas/public/lib/es_service.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import { IndexPatternAttributes } from 'src/plugins/data/public'; + import { API_ROUTE } from '../../common/lib/constants'; // @ts-ignore untyped local import { fetch } from '../../common/lib/fetch'; @@ -44,7 +46,7 @@ export const getFields = (index = '_all') => { export const getIndices = () => getSavedObjectsClient() - .find({ + .find({ type: 'index-pattern', fields: ['title'], searchFields: ['title'], @@ -62,7 +64,7 @@ export const getDefaultIndex = () => { return defaultIndexId ? getSavedObjectsClient() - .get('index-pattern', defaultIndexId) + .get('index-pattern', defaultIndexId) .then(defaultIndex => defaultIndex.attributes.title) .catch(err => notify.error(err, { title: strings.getDefaultIndexFetchErrorMessage() })) : Promise.resolve(''); diff --git a/x-pack/legacy/plugins/file_upload/index.js b/x-pack/legacy/plugins/file_upload/index.js index d29226c802b0692..23e1e1d98aa7fb4 100644 --- a/x-pack/legacy/plugins/file_upload/index.js +++ b/x-pack/legacy/plugins/file_upload/index.js @@ -8,9 +8,10 @@ import { mappings } from './mappings'; export const fileUpload = kibana => { return new kibana.Plugin({ - require: ['elasticsearch', 'xpack_main'], + require: ['elasticsearch'], name: 'file_upload', id: 'file_upload', + // TODO: uiExports and savedObjectSchemas to be removed on migration uiExports: { mappings, }, @@ -22,23 +23,14 @@ export const fileUpload = kibana => { init(server) { const coreSetup = server.newPlatform.setup.core; + const coreStart = server.newPlatform.start.core; const { usageCollection } = server.newPlatform.setup.plugins; - const pluginsSetup = { + const pluginsStart = { usageCollection, }; - - // legacy dependencies - const __LEGACY = { - route: server.route.bind(server), - plugins: { - elasticsearch: server.plugins.elasticsearch, - }, - savedObjects: { - getSavedObjectsRepository: server.savedObjects.getSavedObjectsRepository, - }, - }; - - new FileUploadPlugin().setup(coreSetup, pluginsSetup, __LEGACY); + const fileUploadPlugin = new FileUploadPlugin(); + fileUploadPlugin.setup(coreSetup); + fileUploadPlugin.start(coreStart, pluginsStart); }, }); }; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts deleted file mode 100644 index 9c1000db8cb5692..000000000000000 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -export function callWithInternalUserFactory(elasticsearchPlugin: any): any; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js deleted file mode 100644 index 2e5431bdd6ce2d1..000000000000000 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.js +++ /dev/null @@ -1,18 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { once } from 'lodash'; - -const _callWithInternalUser = once(elasticsearchPlugin => { - const { callWithInternalUser } = elasticsearchPlugin.getCluster('admin'); - return callWithInternalUser; -}); - -export const callWithInternalUserFactory = elasticsearchPlugin => { - return (...args) => { - return _callWithInternalUser(elasticsearchPlugin)(...args); - }; -}; diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts b/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts deleted file mode 100644 index 04c5013ed8e67c1..000000000000000 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_internal_user_factory.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { callWithInternalUserFactory } from './call_with_internal_user_factory'; - -describe('call_with_internal_user_factory', () => { - describe('callWithInternalUserFactory', () => { - it('should use internal user "admin"', () => { - const callWithInternalUser: any = jest.fn(); - const elasticsearchPlugin: any = { - getCluster: jest.fn(() => ({ callWithInternalUser })), - }; - const callWithInternalUserInstance = callWithInternalUserFactory(elasticsearchPlugin); - callWithInternalUserInstance(); - - expect(elasticsearchPlugin.getCluster).toHaveBeenCalledWith('admin'); - }); - }); -}); diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js b/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js index a0b0d2d1c7ce357..bef6c369fd9acbe 100644 --- a/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js +++ b/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js @@ -5,14 +5,17 @@ */ import { once } from 'lodash'; +import { getDataClient } from '../kibana_server_services'; -const callWithRequest = once(elasticsearchPlugin => { - const cluster = elasticsearchPlugin.getCluster('data'); - return cluster.callWithRequest; -}); +const callWithRequest = once(() => getDataClient()); -export const callWithRequestFactory = (elasticsearchPlugin, request) => { +export const callWithRequestFactory = request => { return (...args) => { - return callWithRequest(elasticsearchPlugin)(request, ...args); + return ( + callWithRequest() + .asScoped(request) + // @ts-ignore + .callAsCurrentUser(...args) + ); }; }; diff --git a/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js b/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js new file mode 100644 index 000000000000000..104e49015ba807f --- /dev/null +++ b/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js @@ -0,0 +1,18 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +let dataClient; + +export const setElasticsearchClientServices = elasticsearch => { + ({ dataClient } = elasticsearch); +}; +export const getDataClient = () => dataClient; + +let internalRepository; +export const setInternalRepository = createInternalRepository => { + internalRepository = createInternalRepository(); +}; +export const getInternalRepository = () => internalRepository; diff --git a/x-pack/legacy/plugins/file_upload/server/plugin.js b/x-pack/legacy/plugins/file_upload/server/plugin.js index 23fb8bda897f0f2..c448676f813eac1 100644 --- a/x-pack/legacy/plugins/file_upload/server/plugin.js +++ b/x-pack/legacy/plugins/file_upload/server/plugin.js @@ -5,19 +5,23 @@ */ import { initRoutes } from './routes/file_upload'; +import { setElasticsearchClientServices, setInternalRepository } from './kibana_server_services'; import { registerFileUploadUsageCollector } from './telemetry'; export class FileUploadPlugin { - setup(core, plugins, __LEGACY) { - const elasticsearchPlugin = __LEGACY.plugins.elasticsearch; - const getSavedObjectsRepository = __LEGACY.savedObjects.getSavedObjectsRepository; - const router = core.http.createRouter(); + constructor() { + this.router = null; + } + + setup(core) { + setElasticsearchClientServices(core.elasticsearch); + this.router = core.http.createRouter(); + } - initRoutes(router, elasticsearchPlugin, getSavedObjectsRepository); + start(core, plugins) { + initRoutes(this.router, core.savedObjects.getSavedObjectsRepository); + setInternalRepository(core.savedObjects.createInternalRepository); - registerFileUploadUsageCollector(plugins.usageCollection, { - elasticsearchPlugin, - getSavedObjectsRepository, - }); + registerFileUploadUsageCollector(plugins.usageCollection); } } diff --git a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js b/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js index 1c27c2d7d68e9d7..acbc907729d9589 100644 --- a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js +++ b/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js @@ -75,7 +75,7 @@ export const idConditionalValidation = (body, boolHasId) => ) .validate(body); -const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepository) => { +const finishValidationAndProcessReq = () => { return async (con, req, { ok, badRequest }) => { const { query: { id }, @@ -86,7 +86,7 @@ const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepos let resp; try { const validIdReqData = idConditionalValidation(body, boolHasId); - const callWithRequest = callWithRequestFactory(elasticsearchPlugin, req); + const callWithRequest = callWithRequestFactory(req); const { importData: importDataFunc } = importDataProvider(callWithRequest); const { index, settings, mappings, ingestPipeline, data } = validIdReqData; @@ -103,7 +103,7 @@ const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepos resp = ok({ body: processedReq }); // If no id's been established then this is a new index, update telemetry if (!boolHasId) { - await updateTelemetry({ elasticsearchPlugin, getSavedObjectsRepository }); + await updateTelemetry(); } } else { resp = badRequest(`Error processing request 1: ${processedReq.error.message}`, ['body']); @@ -115,7 +115,7 @@ const finishValidationAndProcessReq = (elasticsearchPlugin, getSavedObjectsRepos }; }; -export const initRoutes = (router, esPlugin, getSavedObjectsRepository) => { +export const initRoutes = router => { router.post( { path: `${IMPORT_ROUTE}{id?}`, @@ -125,6 +125,6 @@ export const initRoutes = (router, esPlugin, getSavedObjectsRepository) => { }, options, }, - finishValidationAndProcessReq(esPlugin, getSavedObjectsRepository) + finishValidationAndProcessReq() ); }; diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts index a2b359ae11638a5..2c2b1183fd5bf3c 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts @@ -9,19 +9,11 @@ import { getTelemetry, initTelemetry } from './telemetry'; const TELEMETRY_TYPE = 'fileUploadTelemetry'; -export function registerFileUploadUsageCollector( - usageCollection: UsageCollectionSetup, - deps: { - elasticsearchPlugin: any; - getSavedObjectsRepository: any; - } -): void { - const { elasticsearchPlugin, getSavedObjectsRepository } = deps; +export function registerFileUploadUsageCollector(usageCollection: UsageCollectionSetup): void { const fileUploadUsageCollector = usageCollection.makeUsageCollector({ type: TELEMETRY_TYPE, isReady: () => true, - fetch: async () => - (await getTelemetry(elasticsearchPlugin, getSavedObjectsRepository)) || initTelemetry(), + fetch: async () => (await getTelemetry()) || initTelemetry(), }); usageCollection.registerCollector(fileUploadUsageCollector); diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts index 1c785d8e7b61c60..fadad307c0710cd 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts @@ -6,8 +6,6 @@ import { getTelemetry, updateTelemetry } from './telemetry'; -const elasticsearchPlugin: any = null; -const getSavedObjectsRepository: any = null; const internalRepository = () => ({ get: jest.fn(() => null), create: jest.fn(() => ({ attributes: 'test' })), @@ -25,7 +23,7 @@ describe('file upload plugin telemetry', () => { describe('getTelemetry', () => { it('should get existing telemetry', async () => { const internalRepo = mockInit(); - await getTelemetry(elasticsearchPlugin, getSavedObjectsRepository, internalRepo); + await getTelemetry(internalRepo); expect(internalRepo.update.mock.calls.length).toBe(0); expect(internalRepo.get.mock.calls.length).toBe(1); expect(internalRepo.create.mock.calls.length).toBe(0); @@ -40,11 +38,7 @@ describe('file upload plugin telemetry', () => { }, }); - await updateTelemetry({ - elasticsearchPlugin, - getSavedObjectsRepository, - internalRepo, - }); + await updateTelemetry(internalRepo); expect(internalRepo.update.mock.calls.length).toBe(1); expect(internalRepo.get.mock.calls.length).toBe(1); expect(internalRepo.create.mock.calls.length).toBe(0); diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts index 5ffa735f4c83a81..2978dec7aa68da3 100644 --- a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts +++ b/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts @@ -5,7 +5,8 @@ */ import _ from 'lodash'; -import { callWithInternalUserFactory } from '../client/call_with_internal_user_factory'; +// @ts-ignore +import { getInternalRepository } from '../kibana_server_services'; export const TELEMETRY_DOC_ID = 'file-upload-telemetry'; @@ -17,27 +18,14 @@ export interface TelemetrySavedObject { attributes: Telemetry; } -export function getInternalRepository( - elasticsearchPlugin: any, - getSavedObjectsRepository: any -): any { - const callWithInternalUser = callWithInternalUserFactory(elasticsearchPlugin); - return getSavedObjectsRepository(callWithInternalUser); -} - export function initTelemetry(): Telemetry { return { filesUploadedTotalCount: 0, }; } -export async function getTelemetry( - elasticsearchPlugin: any, - getSavedObjectsRepository: any, - internalRepo?: object -): Promise { - const internalRepository = - internalRepo || getInternalRepository(elasticsearchPlugin, getSavedObjectsRepository); +export async function getTelemetry(internalRepo?: object): Promise { + const internalRepository = internalRepo || getInternalRepository(); let telemetrySavedObject; try { @@ -49,22 +37,9 @@ export async function getTelemetry( return telemetrySavedObject ? telemetrySavedObject.attributes : null; } -export async function updateTelemetry({ - elasticsearchPlugin, - getSavedObjectsRepository, - internalRepo, -}: { - elasticsearchPlugin: any; - getSavedObjectsRepository: any; - internalRepo?: any; -}) { - const internalRepository = - internalRepo || getInternalRepository(elasticsearchPlugin, getSavedObjectsRepository); - let telemetry = await getTelemetry( - elasticsearchPlugin, - getSavedObjectsRepository, - internalRepository - ); +export async function updateTelemetry(internalRepo?: any) { + const internalRepository = internalRepo || getInternalRepository(); + let telemetry = await getTelemetry(internalRepository); // Create if doesn't exist if (!telemetry || _.isEmpty(telemetry)) { const newTelemetrySavedObject = await internalRepository.create( diff --git a/x-pack/legacy/plugins/graph/public/components/field_manager/field_editor.tsx b/x-pack/legacy/plugins/graph/public/components/field_manager/field_editor.tsx index 6152f333509178a..f2a4c28afcdaec2 100644 --- a/x-pack/legacy/plugins/graph/public/components/field_manager/field_editor.tsx +++ b/x-pack/legacy/plugins/graph/public/components/field_manager/field_editor.tsx @@ -237,10 +237,18 @@ export function FieldEditor({ renderOption={(option, searchValue, contentClassName) => { const { type, label } = option; return ( - - {' '} - {label} - + + + + + + {label} + + ); }} compressed diff --git a/x-pack/legacy/plugins/graph/public/components/field_manager/field_icon.tsx b/x-pack/legacy/plugins/graph/public/components/field_manager/field_icon.tsx deleted file mode 100644 index 0c099135f631d4f..000000000000000 --- a/x-pack/legacy/plugins/graph/public/components/field_manager/field_icon.tsx +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React from 'react'; -import { ICON_TYPES, euiPaletteColorBlind, EuiIcon } from '@elastic/eui'; - -function stringToNum(s: string) { - return Array.from(s).reduce((acc, ch) => acc + ch.charCodeAt(0), 1); -} - -function getIconForDataType(dataType: string) { - const icons: Partial>> = { - boolean: 'invert', - date: 'calendar', - geo_point: 'globe', - ip: 'storage', - }; - return icons[dataType] || ICON_TYPES.find(t => t === dataType) || 'document'; -} - -export function getColorForDataType(type: string) { - const iconType = getIconForDataType(type); - const colors = euiPaletteColorBlind(); - const colorIndex = stringToNum(iconType) % colors.length; - return colors[colorIndex]; -} - -export type UnwrapArray = T extends Array ? P : T; - -export function FieldIcon({ type }: { type: string }) { - const iconType = getIconForDataType(type); - - return ; -} diff --git a/x-pack/legacy/plugins/graph/public/components/field_manager/field_picker.tsx b/x-pack/legacy/plugins/graph/public/components/field_manager/field_picker.tsx index b38e3f8430980e9..30f1fcffd4f6737 100644 --- a/x-pack/legacy/plugins/graph/public/components/field_manager/field_picker.tsx +++ b/x-pack/legacy/plugins/graph/public/components/field_manager/field_picker.tsx @@ -122,7 +122,7 @@ function toOptions( .filter(field => isExplorable(field) || field.selected) .map(field => ({ label: field.name, - prepend: , + prepend: , checked: field.selected ? 'on' : undefined, })) ); diff --git a/x-pack/legacy/plugins/graph/public/services/persistence/saved_workspace_loader.ts b/x-pack/legacy/plugins/graph/public/services/persistence/saved_workspace_loader.ts index 184fbc01eb96f50..d9bb119006e78a4 100644 --- a/x-pack/legacy/plugins/graph/public/services/persistence/saved_workspace_loader.ts +++ b/x-pack/legacy/plugins/graph/public/services/persistence/saved_workspace_loader.ts @@ -52,7 +52,7 @@ export function createSavedWorkspacesLoader( }, find: (searchString: string, size: number = 100) => { return savedObjectsClient - .find({ + .find>({ type: SavedWorkspace.type, search: searchString ? `${searchString}*` : undefined, perPage: size, diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__snapshots__/lens_field_icon.test.tsx.snap b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__snapshots__/lens_field_icon.test.tsx.snap index 5593a1af00d70c4..8bbe49b2e0d7f6c 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__snapshots__/lens_field_icon.test.tsx.snap +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/__snapshots__/lens_field_icon.test.tsx.snap @@ -1,10 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`LensFieldIcon accepts FieldIcon props 1`] = ` + +`; + exports[`LensFieldIcon renders properly 1`] = ` `; diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_datapanel.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_datapanel.scss index ed39beeb7d088b5..77d4b41a0413c19 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_datapanel.scss +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_datapanel.scss @@ -52,3 +52,16 @@ @include euiFormControlLayoutPadding(1, 'right'); @include euiFormControlLayoutPadding(1, 'left'); } + +.lnsInnerIndexPatternDataPanel__filterType { + padding: $euiSizeS; +} + +.lnsInnerIndexPatternDataPanel__filterTypeInner { + display: flex; + align-items: center; + + .lnsFieldListPanel__fieldIcon { + margin-right: $euiSizeS; + } +} diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_field_item.scss b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_field_item.scss index 54f9a3787466d32..89f6bbf9084194e 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_field_item.scss +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/_field_item.scss @@ -14,7 +14,7 @@ } .lnsFieldItem--missing { - background: lightOrDarkTheme(transparentize($euiColorMediumShade, .9), $euiColorEmptyShade); + background: lightOrDarkTheme(transparentize($euiColorMediumShade, 0.9), $euiColorEmptyShade); color: $euiColorDarkShade; } @@ -24,10 +24,10 @@ display: flex; align-items: flex-start; transition: box-shadow $euiAnimSpeedFast $euiAnimSlightResistance, - background-color $euiAnimSpeedFast $euiAnimSlightResistance; // sass-lint:disable-line indentation + background-color $euiAnimSpeedFast $euiAnimSlightResistance; // sass-lint:disable-line indentation .lnsFieldItem__name { - margin-left: $euiSizeXS; + margin-left: $euiSizeS; flex-grow: 1; } @@ -37,7 +37,8 @@ } .lnsFieldListPanel__fieldIcon { - margin-top: 2px; + margin-top: $euiSizeXS / 2; + margin-right: $euiSizeXS / 2; } .lnsFieldItem__infoIcon { diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.tsx index 3231ab7d7ff12c4..69982aed78b4068 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/datapanel.tsx @@ -384,6 +384,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({ data-test-subj="lnsIndexPatternTypeFilterOptions" items={(availableFieldTypes as DataType[]).map(type => ( - {fieldTypeNames[type]} + + {fieldTypeNames[type]} + ))} /> diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/field_select.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/field_select.tsx index 46d7233ba9587f3..77435fcdf3eeda3 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/field_select.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/dimension_panel/field_select.tsx @@ -169,6 +169,7 @@ export function FieldSelect({ diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.test.tsx deleted file mode 100644 index 6b12bb5feef1b5a..000000000000000 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.test.tsx +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { shallow } from 'enzyme'; -import React from 'react'; -import { FieldIcon } from './field_icon'; - -describe('FieldIcon', () => { - it('should render icons', () => { - expect(shallow()).toMatchInlineSnapshot(` - - `); - expect(shallow()).toMatchInlineSnapshot(` - - `); - expect(shallow()).toMatchInlineSnapshot(` - - `); - expect(shallow()).toMatchInlineSnapshot(` - - `); - expect(shallow()).toMatchInlineSnapshot(` - - `); - }); -}); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.tsx deleted file mode 100644 index 796f200bffd9728..000000000000000 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_icon.tsx +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import React from 'react'; -import { ICON_TYPES, euiPaletteColorBlind, EuiIcon } from '@elastic/eui'; -import classNames from 'classnames'; -import { DataType } from '../types'; - -function stringToNum(s: string) { - return Array.from(s).reduce((acc, ch) => acc + ch.charCodeAt(0), 1); -} - -function getIconForDataType(dataType: string) { - const icons: Partial>> = { - boolean: 'invert', - date: 'calendar', - ip: 'ip', - }; - return icons[dataType] || ICON_TYPES.find(t => t === dataType) || 'empty'; -} - -export function getColorForDataType(type: string) { - const iconType = getIconForDataType(type); - const colors = euiPaletteColorBlind(); - const colorIndex = stringToNum(iconType) % colors.length; - return colors[colorIndex]; -} - -export type UnwrapArray = T extends Array ? P : T; - -export function FieldIcon({ type }: { type: DataType }) { - const iconType = getIconForDataType(type); - - const classes = classNames( - 'lnsFieldListPanel__fieldIcon', - `lnsFieldListPanel__fieldIcon--${type}` - ); - - return ; -} diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.tsx index 0271d2ca021c578..94d644e6590e17a 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/field_item.tsx @@ -46,7 +46,7 @@ import { DragDrop } from '../drag_drop'; import { DatasourceDataPanelProps, DataType } from '../types'; import { BucketedAggregation, FieldStatsResponse } from '../../../../../plugins/lens/common'; import { IndexPattern, IndexPatternField } from './types'; -import { getColorForDataType, LensFieldIcon } from './lens_field_icon'; +import { LensFieldIcon } from './lens_field_icon'; import { trackUiEvent } from '../lens_ui_telemetry'; export interface FieldItemProps { @@ -294,11 +294,6 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { ); } - const euiButtonColor = - field.type === 'string' ? 'accent' : field.type === 'number' ? 'secondary' : 'primary'; - const euiTextColor = - field.type === 'string' ? 'accent' : field.type === 'number' ? 'secondary' : 'default'; - const fromDate = DateMath.parse(dateRange.fromDate); const toDate = DateMath.parse(dateRange.toDate); @@ -391,8 +386,6 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { const specId = i18n.translate('xpack.lens.indexPattern.fieldStatsCountLabel', { defaultMessage: 'Count', }); - const expectedColor = getColorForDataType(field.type); - const seriesColors = expectedColor ? [expectedColor] : undefined; if (field.type === 'date') { return wrapInPopover( @@ -429,7 +422,6 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { yAccessors={['count']} xScaleType={ScaleType.Time} yScaleType={ScaleType.Linear} - customSeriesColors={seriesColors} timeZone="local" /> @@ -453,7 +445,6 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { yAccessors={['count']} xScaleType={ScaleType.Linear} yScaleType={ScaleType.Linear} - customSeriesColors={seriesColors} /> ); @@ -486,7 +477,7 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { )} - + {Math.round((topValue.count / props.sampledValues!) * 100)}% @@ -497,7 +488,7 @@ function FieldItemPopoverContents(props: State & FieldItemProps) { value={topValue.count / props.sampledValues!} max={1} size="s" - color={euiButtonColor} + color="accent" /> ); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.test.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.test.tsx index 961e22380bdcafb..317ce8f032f94e6 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.test.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.test.tsx @@ -11,19 +11,14 @@ */ import React from 'react'; import { shallow } from 'enzyme'; -import { LensFieldIcon, getColorForDataType } from './lens_field_icon'; +import { LensFieldIcon } from './lens_field_icon'; test('LensFieldIcon renders properly', () => { const component = shallow(); expect(component).toMatchSnapshot(); }); -test('LensFieldIcon getColorForDataType for a valid type', () => { - const color = getColorForDataType('date'); - expect(color).toEqual('#DA8B45'); -}); - -test('LensFieldIcon getColorForDataType for an invalid type', () => { - const color = getColorForDataType('invalid'); - expect(color).toEqual('#54B399'); +test('LensFieldIcon accepts FieldIcon props', () => { + const component = shallow(); + expect(component).toMatchSnapshot(); }); diff --git a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.tsx b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.tsx index 2e6a5fcd8115fbc..06eda73748cef70 100644 --- a/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.tsx +++ b/x-pack/legacy/plugins/lens/public/indexpattern_datasource/lens_field_icon.tsx @@ -5,26 +5,16 @@ */ import React from 'react'; -import { euiPaletteColorBlind } from '@elastic/eui'; -import { FieldIcon, typeToEuiIconMap } from '../../../../../../src/plugins/kibana_react/public'; +import { FieldIcon, FieldIconProps } from '../../../../../../src/plugins/kibana_react/public'; import { DataType } from '../types'; import { normalizeOperationDataType } from './utils'; -export function getColorForDataType(type: string) { - const iconMap = typeToEuiIconMap[normalizeOperationDataType(type as DataType)]; - if (iconMap) { - return iconMap.color; - } - return euiPaletteColorBlind()[0]; -} - -export function LensFieldIcon({ type }: { type: DataType }) { +export function LensFieldIcon({ type, ...rest }: FieldIconProps & { type: DataType }) { return ( ); } diff --git a/x-pack/legacy/plugins/maps/public/components/__snapshots__/add_tooltip_field_popover.test.js.snap b/x-pack/legacy/plugins/maps/public/components/__snapshots__/add_tooltip_field_popover.test.js.snap index f37dfdd879c5bf8..d0cdbe7243abe46 100644 --- a/x-pack/legacy/plugins/maps/public/components/__snapshots__/add_tooltip_field_popover.test.js.snap +++ b/x-pack/legacy/plugins/maps/public/components/__snapshots__/add_tooltip_field_popover.test.js.snap @@ -23,7 +23,7 @@ exports[`Should remove selected fields from selectable 1`] = ` id="addTooltipFieldPopover" isOpen={false} ownFocus={true} - panelPaddingSize="m" + panelPaddingSize="none" > , "value": "@timestamp", }, ] } + searchProps={ + Object { + "compressed": true, + } + } searchable={true} singleSelection={false} > @@ -88,7 +93,7 @@ exports[`Should render 1`] = ` id="addTooltipFieldPopover" isOpen={false} ownFocus={true} - panelPaddingSize="m" + panelPaddingSize="none" > , "value": "@timestamp", }, Object { "label": "custom label for prop1", "prepend": , "value": "prop1", }, Object { "label": "prop2", "prepend": , "value": "prop2", }, ] } + searchProps={ + Object { + "compressed": true, + } + } searchable={true} singleSelection={false} > diff --git a/x-pack/legacy/plugins/maps/public/components/add_tooltip_field_popover.js b/x-pack/legacy/plugins/maps/public/components/add_tooltip_field_popover.js index bddb74596f4efd1..07bc54663c1d880 100644 --- a/x-pack/legacy/plugins/maps/public/components/add_tooltip_field_popover.js +++ b/x-pack/legacy/plugins/maps/public/components/add_tooltip_field_popover.js @@ -39,7 +39,10 @@ function getOptions(fields, selectedFields) { .map(field => { return { value: field.name, - prepend: 'type' in field ? : null, + prepend: + 'type' in field ? ( + + ) : null, label: 'label' in field ? field.label : field.name, }; }) @@ -127,7 +130,12 @@ export class AddTooltipFieldPopover extends Component { return ( - + {(list, search) => (
{search} @@ -161,6 +169,7 @@ export class AddTooltipFieldPopover extends Component { button={this._renderAddButton()} isOpen={this.state.isPopoverOpen} closePopover={this._closePopover} + panelPaddingSize="none" ownFocus > {this._renderContent()} diff --git a/x-pack/legacy/plugins/maps/public/components/single_field_select.js b/x-pack/legacy/plugins/maps/public/components/single_field_select.js index 7351ce7691a8276..98e33454b041b5e 100644 --- a/x-pack/legacy/plugins/maps/public/components/single_field_select.js +++ b/x-pack/legacy/plugins/maps/public/components/single_field_select.js @@ -8,7 +8,7 @@ import _ from 'lodash'; import PropTypes from 'prop-types'; import React from 'react'; -import { EuiComboBox, EuiHighlight } from '@elastic/eui'; +import { EuiComboBox, EuiHighlight, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { FieldIcon } from '../../../../../../src/plugins/kibana_react/public'; function fieldsToOptions(fields) { @@ -30,11 +30,14 @@ function fieldsToOptions(fields) { function renderOption(option, searchValue, contentClassName) { return ( - - -   - {option.label} - + + + + + + {option.label} + + ); } diff --git a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js index a32c2ce04d73557..cf0ec5589d6bcd4 100644 --- a/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js +++ b/x-pack/legacy/plugins/maps/public/layers/styles/vector/components/field_select.js @@ -7,18 +7,21 @@ import PropTypes from 'prop-types'; import React from 'react'; -import { EuiComboBox, EuiHighlight } from '@elastic/eui'; +import { EuiComboBox, EuiHighlight, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { FIELD_ORIGIN } from '../../../../../common/constants'; import { i18n } from '@kbn/i18n'; import { FieldIcon } from '../../../../../../../../../src/plugins/kibana_react/public'; function renderOption(option, searchValue, contentClassName) { return ( - - -   - {option.label} - + + + + + + {option.label} + + ); } diff --git a/x-pack/legacy/plugins/ml/common/types/kibana.ts b/x-pack/legacy/plugins/ml/common/types/kibana.ts index d647bd882162b7b..4a2edfebd1bac1e 100644 --- a/x-pack/legacy/plugins/ml/common/types/kibana.ts +++ b/x-pack/legacy/plugins/ml/common/types/kibana.ts @@ -6,7 +6,8 @@ // custom edits or fixes for default kibana types which are incomplete -import { SavedObjectAttributes, SimpleSavedObject } from 'kibana/public'; +import { SimpleSavedObject } from 'kibana/public'; +import { IndexPatternAttributes } from 'src/plugins/data/common'; export type IndexPatternTitle = string; @@ -17,8 +18,9 @@ export interface Route { k7Breadcrumbs: () => any; } -export type IndexPatternSavedObject = SimpleSavedObject; -export type SavedSearchSavedObject = SimpleSavedObject; +export type IndexPatternSavedObject = SimpleSavedObject; +// TODO define saved object type +export type SavedSearchSavedObject = SimpleSavedObject; export function isSavedSearchSavedObject( ss: SavedSearchSavedObject | null diff --git a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/recognize/resolvers.ts b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/recognize/resolvers.ts index fa0ed34dca622b6..9c60b84b16bdf32 100644 --- a/x-pack/legacy/plugins/ml/public/application/jobs/new_job/recognize/resolvers.ts +++ b/x-pack/legacy/plugins/ml/public/application/jobs/new_job/recognize/resolvers.ts @@ -61,7 +61,7 @@ export const checkForSavedObjects = async (objects: KibanaObjects): Promise { const acc = await prevPromise; - const { savedObjects } = await savedObjectsClient.find({ + const { savedObjects } = await savedObjectsClient.find({ type, perPage: 1000, }); diff --git a/x-pack/legacy/plugins/ml/public/application/util/index_utils.ts b/x-pack/legacy/plugins/ml/public/application/util/index_utils.ts index 88b56b2329ae6a0..220d707ddd665bc 100644 --- a/x-pack/legacy/plugins/ml/public/application/util/index_utils.ts +++ b/x-pack/legacy/plugins/ml/public/application/util/index_utils.ts @@ -5,11 +5,12 @@ */ import { i18n } from '@kbn/i18n'; -import { Query } from 'src/plugins/data/public'; import { IndexPattern, IIndexPattern, IndexPatternsContract, + Query, + IndexPatternAttributes, } from '../../../../../../../src/plugins/data/public'; import { getToastNotifications, getSavedObjectsClient } from './dependency_cache'; import { IndexPatternSavedObject, SavedSearchSavedObject } from '../../../common/types/kibana'; @@ -22,7 +23,7 @@ export function loadIndexPatterns(indexPatterns: IndexPatternsContract) { indexPatternsContract = indexPatterns; const savedObjectsClient = getSavedObjectsClient(); return savedObjectsClient - .find({ + .find({ type: 'index-pattern', fields: ['id', 'title', 'type', 'fields'], perPage: 10000, diff --git a/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.ts b/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.ts index b62e44c299a2d11..553de75e38e05d3 100644 --- a/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.ts +++ b/x-pack/legacy/plugins/ml/server/models/data_recognizer/data_recognizer.ts @@ -8,6 +8,7 @@ import fs from 'fs'; import Boom from 'boom'; import numeral from '@elastic/numeral'; import { CallAPIOptions, RequestHandlerContext, SavedObjectsClientContract } from 'kibana/server'; +import { IndexPatternAttributes } from 'src/plugins/data/server'; import { merge } from 'lodash'; import { MlJob } from '../../../common/types/jobs'; import { @@ -532,7 +533,10 @@ export class DataRecognizer { } async loadIndexPatterns() { - return await this.savedObjectsClient.find({ type: 'index-pattern', perPage: 1000 }); + return await this.savedObjectsClient.find({ + type: 'index-pattern', + perPage: 1000, + }); } // returns a id based on an index pattern name @@ -620,7 +624,8 @@ export class DataRecognizer { // find all existing savedObjects for a given type loadExistingSavedObjects(type: string) { - return this.savedObjectsClient.find({ type, perPage: 1000 }); + // TODO: define saved object type + return this.savedObjectsClient.find({ type, perPage: 1000 }); } // save the savedObjects if they do not exist already diff --git a/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/rollup.ts b/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/rollup.ts index 11b0802192e1f9b..1e9ce3d8d502257 100644 --- a/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/rollup.ts +++ b/x-pack/legacy/plugins/ml/server/models/job_service/new_job_caps/rollup.ts @@ -5,6 +5,7 @@ */ import { SavedObject } from 'src/core/server'; +import { IndexPatternAttributes } from 'src/plugins/data/server'; import { SavedObjectsClientContract } from 'kibana/server'; import { FieldId } from '../../../../common/types/fields'; import { ES_AGGREGATION } from '../../../../common/constants/aggregation_types'; @@ -58,8 +59,8 @@ export async function rollupServiceProvider( async function loadRollupIndexPattern( indexPattern: string, savedObjectsClient: SavedObjectsClientContract -): Promise { - const resp = await savedObjectsClient.find({ +): Promise | null> { + const resp = await savedObjectsClient.find({ type: 'index-pattern', fields: ['title', 'type', 'typeMeta'], perPage: 1000, diff --git a/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts b/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts index f968e90f70b2dac..9ef19e58bada71f 100644 --- a/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts +++ b/x-pack/legacy/plugins/monitoring/server/alerts/license_expiration.ts @@ -54,6 +54,7 @@ export const getLicenseExpiration = ( }), }, ], + defaultActionGroupId: 'default', async executor({ services, params, diff --git a/x-pack/legacy/plugins/siem/public/components/links/index.tsx b/x-pack/legacy/plugins/siem/public/components/links/index.tsx index 4f74f9ff2f5d606..b6548e3e950ba21 100644 --- a/x-pack/legacy/plugins/siem/public/components/links/index.tsx +++ b/x-pack/legacy/plugins/siem/public/components/links/index.tsx @@ -44,7 +44,10 @@ const CaseDetailsLinkComponent: React.FC<{ children?: React.ReactNode; detailNam children, detailName, }) => ( - + {children ? children : detailName} ); diff --git a/x-pack/legacy/plugins/siem/public/components/navigation/index.test.tsx b/x-pack/legacy/plugins/siem/public/components/navigation/index.test.tsx index 8eb08bd3d62f040..e1b3951a2317d9d 100644 --- a/x-pack/legacy/plugins/siem/public/components/navigation/index.test.tsx +++ b/x-pack/legacy/plugins/siem/public/components/navigation/index.test.tsx @@ -67,7 +67,7 @@ describe('SIEM Navigation', () => { detailName: undefined, navTabs: { case: { - disabled: true, + disabled: false, href: '#/link-to/case', id: 'case', name: 'Case', @@ -160,7 +160,7 @@ describe('SIEM Navigation', () => { filters: [], navTabs: { case: { - disabled: true, + disabled: false, href: '#/link-to/case', id: 'case', name: 'Case', diff --git a/x-pack/legacy/plugins/siem/public/containers/case/api.ts b/x-pack/legacy/plugins/siem/public/containers/case/api.ts index 830e00c70975e1b..bff3bfd62a85c05 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/api.ts +++ b/x-pack/legacy/plugins/siem/public/containers/case/api.ts @@ -5,12 +5,12 @@ */ import { KibanaServices } from '../../lib/kibana'; -import { AllCases, FetchCasesProps, Case, NewCase, SortFieldCase } from './types'; -import { Direction } from '../../graphql/types'; +import { FetchCasesProps, Case, NewCase, SortFieldCase, AllCases, CaseSnake } from './types'; import { throwIfNotOk } from '../../hooks/api/api'; import { CASES_URL } from './constants'; +import { convertToCamelCase, convertAllCasesToCamel } from './utils'; -export const getCase = async (caseId: string, includeComments: boolean) => { +export const getCase = async (caseId: string, includeComments: boolean): Promise => { const response = await KibanaServices.get().http.fetch(`${CASES_URL}/${caseId}`, { method: 'GET', asResponse: true, @@ -19,7 +19,7 @@ export const getCase = async (caseId: string, includeComments: boolean) => { }, }); await throwIfNotOk(response.response); - return response.body!; + return convertToCamelCase(response.body!); }; export const getCases = async ({ @@ -31,7 +31,7 @@ export const getCases = async ({ page: 1, perPage: 20, sortField: SortFieldCase.createdAt, - sortOrder: Direction.desc, + sortOrder: 'desc', }, }: FetchCasesProps): Promise => { const tags = [...(filterOptions.tags?.map(t => `case-workflow.attributes.tags: ${t}`) ?? [])]; @@ -46,7 +46,7 @@ export const getCases = async ({ asResponse: true, }); await throwIfNotOk(response.response); - return response.body!; + return convertAllCasesToCamel(response.body!); }; export const createCase = async (newCase: NewCase): Promise => { @@ -56,18 +56,19 @@ export const createCase = async (newCase: NewCase): Promise => { body: JSON.stringify(newCase), }); await throwIfNotOk(response.response); - return response.body!; + return convertToCamelCase(response.body!); }; export const updateCaseProperty = async ( caseId: string, - updatedCase: Partial + updatedCase: Partial, + version: string ): Promise> => { const response = await KibanaServices.get().http.fetch(`${CASES_URL}/${caseId}`, { method: 'PATCH', asResponse: true, - body: JSON.stringify(updatedCase), + body: JSON.stringify({ case: updatedCase, version }), }); await throwIfNotOk(response.response); - return response.body!; + return convertToCamelCase, Partial>(response.body!); }; diff --git a/x-pack/legacy/plugins/siem/public/containers/case/types.ts b/x-pack/legacy/plugins/siem/public/containers/case/types.ts index 0f80b2327a30c3a..1aea0b0f50a8936 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/types.ts +++ b/x-pack/legacy/plugins/siem/public/containers/case/types.ts @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Direction } from '../../graphql/types'; interface FormData { isNew?: boolean; } @@ -15,22 +14,35 @@ export interface NewCase extends FormData { title: string; } -export interface Case { +export interface CaseSnake { case_id: string; created_at: string; - created_by: ElasticUser; + created_by: ElasticUserSnake; description: string; state: string; tags: string[]; title: string; updated_at: string; + version?: string; +} + +export interface Case { + caseId: string; + createdAt: string; + createdBy: ElasticUser; + description: string; + state: string; + tags: string[]; + title: string; + updatedAt: string; + version?: string; } export interface QueryParams { page: number; perPage: number; sortField: SortFieldCase; - sortOrder: Direction; + sortOrder: 'asc' | 'desc'; } export interface FilterOptions { @@ -38,21 +50,33 @@ export interface FilterOptions { tags: string[]; } +export interface AllCasesSnake { + cases: CaseSnake[]; + page: number; + per_page: number; + total: number; +} + export interface AllCases { cases: Case[]; page: number; - per_page: number; + perPage: number; total: number; } export enum SortFieldCase { - createdAt = 'created_at', + createdAt = 'createdAt', state = 'state', - updatedAt = 'updated_at', + updatedAt = 'updatedAt', +} + +export interface ElasticUserSnake { + readonly username: string; + readonly full_name?: string | null; } export interface ElasticUser { readonly username: string; - readonly full_name?: string; + readonly fullName?: string | null; } export interface FetchCasesProps { diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_get_case.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_get_case.tsx index 8cc961c68fdf07c..bf76b69ef22d668 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_get_case.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_get_case.tsx @@ -50,16 +50,16 @@ const dataFetchReducer = (state: CaseState, action: Action): CaseState => { } }; const initialData: Case = { - case_id: '', - created_at: '', - created_by: { + caseId: '', + createdAt: '', + createdBy: { username: '', }, description: '', state: '', tags: [], title: '', - updated_at: '', + updatedAt: '', }; export const useGetCase = (caseId: string): [CaseState] => { diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx index db9c07747ba0447..4037823ccfc9406 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_get_cases.tsx @@ -17,7 +17,6 @@ import { } from './constants'; import { AllCases, SortFieldCase, FilterOptions, QueryParams } from './types'; import { getTypedPayload } from './utils'; -import { Direction } from '../../graphql/types'; import { errorToToaster } from '../../components/ml/api/error_to_toaster'; import { useStateToaster } from '../../components/toasters'; import * as i18n from './translations'; @@ -31,16 +30,9 @@ export interface UseGetCasesState { filterOptions: FilterOptions; } -export interface QueryArgs { - page?: number; - perPage?: number; - sortField?: SortFieldCase; - sortOrder?: Direction; -} - export interface Action { type: string; - payload?: AllCases | QueryArgs | FilterOptions; + payload?: AllCases | Partial | FilterOptions; } const dataFetchReducer = (state: UseGetCasesState, action: Action): UseGetCasesState => { switch (action.type) { @@ -83,13 +75,13 @@ const dataFetchReducer = (state: UseGetCasesState, action: Action): UseGetCasesS const initialData: AllCases = { page: 0, - per_page: 0, + perPage: 0, total: 0, cases: [], }; export const useGetCases = (): [ UseGetCasesState, - Dispatch>, + Dispatch>>, Dispatch> ] => { const [state, dispatch] = useReducer(dataFetchReducer, { @@ -104,11 +96,11 @@ export const useGetCases = (): [ page: DEFAULT_TABLE_ACTIVE_PAGE, perPage: DEFAULT_TABLE_LIMIT, sortField: SortFieldCase.createdAt, - sortOrder: Direction.desc, + sortOrder: 'desc', }, }); - const [queryParams, setQueryParams] = useState(state.queryParams as QueryArgs); - const [filterQuery, setFilters] = useState(state.filterOptions as FilterOptions); + const [queryParams, setQueryParams] = useState>(state.queryParams); + const [filterQuery, setFilters] = useState(state.filterOptions); const [, dispatchToaster] = useStateToaster(); useEffect(() => { diff --git a/x-pack/legacy/plugins/siem/public/containers/case/use_update_case.tsx b/x-pack/legacy/plugins/siem/public/containers/case/use_update_case.tsx index 68592c17e58dcc9..62e3d87b528c09e 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/use_update_case.tsx +++ b/x-pack/legacy/plugins/siem/public/containers/case/use_update_case.tsx @@ -96,7 +96,11 @@ export const useUpdateCase = ( const updateData = async (updateKey: keyof Case) => { dispatch({ type: FETCH_INIT }); try { - const response = await updateCaseProperty(caseId, { [updateKey]: state.data[updateKey] }); + const response = await updateCaseProperty( + caseId, + { [updateKey]: state.data[updateKey] }, + state.data.version ?? '' // saved object versions are typed as string | undefined, hope that's not true + ); dispatch({ type: FETCH_SUCCESS, payload: response }); } catch (error) { errorToToaster({ title: i18n.ERROR_TITLE, error, dispatchToaster }); diff --git a/x-pack/legacy/plugins/siem/public/containers/case/utils.ts b/x-pack/legacy/plugins/siem/public/containers/case/utils.ts index 8e6eaca1a8f0cf1..14a3819bdfdad69 100644 --- a/x-pack/legacy/plugins/siem/public/containers/case/utils.ts +++ b/x-pack/legacy/plugins/siem/public/containers/case/utils.ts @@ -4,4 +4,37 @@ * you may not use this file except in compliance with the Elastic License. */ +import { camelCase, isArray, isObject, set } from 'lodash'; +import { AllCases, AllCasesSnake, Case, CaseSnake } from './types'; + export const getTypedPayload = (a: unknown): T => a as T; + +export const convertArrayToCamelCase = (arrayOfSnakes: unknown[]): unknown[] => + arrayOfSnakes.reduce((acc: unknown[], value) => { + if (isArray(value)) { + return [...acc, convertArrayToCamelCase(value)]; + } else if (isObject(value)) { + return [...acc, convertToCamelCase(value)]; + } else { + return [...acc, value]; + } + }, []); + +export const convertToCamelCase = (snakeCase: T): U => + Object.entries(snakeCase).reduce((acc, [key, value]) => { + if (isArray(value)) { + set(acc, camelCase(key), convertArrayToCamelCase(value)); + } else if (isObject(value)) { + set(acc, camelCase(key), convertToCamelCase(value)); + } else { + set(acc, camelCase(key), value); + } + return acc; + }, {} as U); + +export const convertAllCasesToCamel = (snakeCases: AllCasesSnake): AllCases => ({ + cases: snakeCases.cases.map(snakeCase => convertToCamelCase(snakeCase)), + page: snakeCases.page, + perPage: snakeCases.per_page, + total: snakeCases.total, +}); diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/__mock__/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/__mock__/index.tsx new file mode 100644 index 000000000000000..98a67304fcf1f1d --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/__mock__/index.tsx @@ -0,0 +1,77 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SortFieldCase } from '../../../../../containers/case/types'; +import { UseGetCasesState } from '../../../../../containers/case/use_get_cases'; + +export const useGetCasesMockState: UseGetCasesState = { + data: { + cases: [ + { + caseId: '3c4ddcc0-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:23.627Z', + createdBy: { username: 'elastic' }, + description: 'Security banana Issue', + state: 'open', + tags: ['defacement'], + title: 'Another horrible breach', + updatedAt: '2020-02-13T19:44:23.627Z', + }, + { + caseId: '362a5c10-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:13.328Z', + createdBy: { username: 'elastic' }, + description: 'Security banana Issue', + state: 'open', + tags: ['phishing'], + title: 'Bad email', + updatedAt: '2020-02-13T19:44:13.328Z', + }, + { + caseId: '34f8b9e0-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:11.328Z', + createdBy: { username: 'elastic' }, + description: 'Security banana Issue', + state: 'open', + tags: ['phishing'], + title: 'Bad email', + updatedAt: '2020-02-13T19:44:11.328Z', + }, + { + caseId: '31890e90-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:05.563Z', + createdBy: { username: 'elastic' }, + description: 'Security banana Issue', + state: 'closed', + tags: ['phishing'], + title: 'Uh oh', + updatedAt: '2020-02-18T21:32:24.056Z', + }, + { + caseId: '2f5b3210-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:01.901Z', + createdBy: { username: 'elastic' }, + description: 'Security banana Issue', + state: 'open', + tags: ['phishing'], + title: 'Uh oh', + updatedAt: '2020-02-13T19:44:01.901Z', + }, + ], + page: 1, + perPage: 5, + total: 10, + }, + isLoading: false, + isError: false, + queryParams: { + page: 1, + perPage: 5, + sortField: SortFieldCase.createdAt, + sortOrder: 'desc', + }, + filterOptions: { search: '', tags: [] }, +}; diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx index 92cd16fd2000ed2..4c47bf605051d5b 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/columns.tsx @@ -14,14 +14,15 @@ import * as i18n from './translations'; export type CasesColumns = EuiTableFieldDataColumnType | EuiTableComputedColumnType; -const renderStringField = (field: string) => (field != null ? field : getEmptyTagValue()); +const renderStringField = (field: string, dataTestSubj: string) => + field != null ? {field} : getEmptyTagValue(); export const getCasesColumns = (): CasesColumns[] => [ { name: i18n.CASE_TITLE, render: (theCase: Case) => { - if (theCase.case_id != null && theCase.title != null) { - return {theCase.title}; + if (theCase.caseId != null && theCase.title != null) { + return {theCase.title}; } return getEmptyTagValue(); }, @@ -34,7 +35,11 @@ export const getCasesColumns = (): CasesColumns[] => [ return ( {tags.map((tag: string, i: number) => ( - + {tag} ))} @@ -46,28 +51,39 @@ export const getCasesColumns = (): CasesColumns[] => [ truncateText: true, }, { - field: 'created_at', + field: 'createdAt', name: i18n.CREATED_AT, sortable: true, - render: (createdAt: Case['created_at']) => { + render: (createdAt: Case['createdAt']) => { if (createdAt != null) { - return ; + return ( + + ); } return getEmptyTagValue(); }, }, { - field: 'created_by.username', + field: 'createdBy.username', name: i18n.REPORTER, - render: (createdBy: Case['created_by']['username']) => renderStringField(createdBy), + render: (createdBy: Case['createdBy']['username']) => + renderStringField(createdBy, `case-table-column-username`), }, { - field: 'updated_at', + field: 'updatedAt', name: i18n.LAST_UPDATED, sortable: true, - render: (updatedAt: Case['updated_at']) => { + render: (updatedAt: Case['updatedAt']) => { if (updatedAt != null) { - return ; + return ( + + ); } return getEmptyTagValue(); }, @@ -76,6 +92,6 @@ export const getCasesColumns = (): CasesColumns[] => [ field: 'state', name: i18n.STATE, sortable: true, - render: (state: Case['state']) => renderStringField(state), + render: (state: Case['state']) => renderStringField(state, `case-table-column-state`), }, ]; diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.test.tsx new file mode 100644 index 000000000000000..5a87cf53142f75e --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.test.tsx @@ -0,0 +1,97 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { mount } from 'enzyme'; +import moment from 'moment-timezone'; +import { AllCases } from './'; +import { TestProviders } from '../../../../mock'; +import { useGetCasesMockState } from './__mock__'; +import * as apiHook from '../../../../containers/case/use_get_cases'; + +describe('AllCases', () => { + const setQueryParams = jest.fn(); + const setFilters = jest.fn(); + beforeEach(() => { + jest.resetAllMocks(); + jest + .spyOn(apiHook, 'useGetCases') + .mockReturnValue([useGetCasesMockState, setQueryParams, setFilters]); + moment.tz.setDefault('UTC'); + }); + it('should render AllCases', () => { + const wrapper = mount( + + + + ); + expect( + wrapper + .find(`a[data-test-subj="case-details-link"]`) + .first() + .prop('href') + ).toEqual(`#/link-to/case/${useGetCasesMockState.data.cases[0].caseId}`); + expect( + wrapper + .find(`a[data-test-subj="case-details-link"]`) + .first() + .text() + ).toEqual(useGetCasesMockState.data.cases[0].title); + expect( + wrapper + .find(`[data-test-subj="case-table-column-state"]`) + .first() + .text() + ).toEqual(useGetCasesMockState.data.cases[0].state); + expect( + wrapper + .find(`span[data-test-subj="case-table-column-tags-0"]`) + .first() + .prop('title') + ).toEqual(useGetCasesMockState.data.cases[0].tags[0]); + expect( + wrapper + .find(`[data-test-subj="case-table-column-username"]`) + .first() + .text() + ).toEqual(useGetCasesMockState.data.cases[0].createdBy.username); + expect( + wrapper + .find(`[data-test-subj="case-table-column-createdAt"]`) + .first() + .prop('value') + ).toEqual(useGetCasesMockState.data.cases[0].createdAt); + expect( + wrapper + .find(`[data-test-subj="case-table-column-updatedAt"]`) + .first() + .prop('value') + ).toEqual(useGetCasesMockState.data.cases[0].updatedAt); + + expect( + wrapper + .find(`[data-test-subj="case-table-case-count"]`) + .first() + .text() + ).toEqual('Showing 10 cases'); + }); + it('should tableHeaderSortButton AllCases', () => { + const wrapper = mount( + + + + ); + wrapper + .find('[data-test-subj="tableHeaderCell_state_5"] [data-test-subj="tableHeaderSortButton"]') + .simulate('click'); + expect(setQueryParams).toBeCalledWith({ + page: 1, + perPage: 5, + sortField: 'state', + sortOrder: 'asc', + }); + }); +}); diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx index b1dd39c95e19109..3253a036c299053 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/all_cases/index.tsx @@ -18,7 +18,6 @@ import * as i18n from './translations'; import { getCasesColumns } from './columns'; import { SortFieldCase, Case, FilterOptions } from '../../../../containers/case/types'; -import { Direction } from '../../../../graphql/types'; import { useGetCases } from '../../../../containers/case/use_get_cases'; import { EuiBasicTableOnChange } from '../../../detection_engine/rules/types'; import { Panel } from '../../../../components/panel'; @@ -32,7 +31,16 @@ import { UtilityBarText, } from '../../../../components/detection_engine/utility_bar'; import { getCreateCaseUrl } from '../../../../components/link_to'; - +const getSortField = (field: string): SortFieldCase => { + if (field === SortFieldCase.createdAt) { + return SortFieldCase.createdAt; + } else if (field === SortFieldCase.state) { + return SortFieldCase.state; + } else if (field === SortFieldCase.updatedAt) { + return SortFieldCase.updatedAt; + } + return SortFieldCase.createdAt; +}; export const AllCases = React.memo(() => { const [ { data, isLoading, queryParams, filterOptions }, @@ -44,24 +52,10 @@ export const AllCases = React.memo(() => { ({ page, sort }: EuiBasicTableOnChange) => { let newQueryParams = queryParams; if (sort) { - let newSort; - switch (sort.field) { - case 'state': - newSort = SortFieldCase.state; - break; - case 'created_at': - newSort = SortFieldCase.createdAt; - break; - case 'updated_at': - newSort = SortFieldCase.updatedAt; - break; - default: - newSort = SortFieldCase.createdAt; - } newQueryParams = { ...newQueryParams, - sortField: newSort, - sortOrder: sort.direction as Direction, + sortField: getSortField(sort.field), + sortOrder: sort.direction, }; } if (page) { @@ -114,7 +108,9 @@ export const AllCases = React.memo(() => { - {i18n.SHOWING_CASES(data.total ?? 0)} + + {i18n.SHOWING_CASES(data.total ?? 0)} + diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/__mock__/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/__mock__/index.tsx new file mode 100644 index 000000000000000..7480c4fc4bb2a0e --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/__mock__/index.tsx @@ -0,0 +1,34 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { CaseProps } from '../index'; +import { Case } from '../../../../../containers/case/types'; + +export const caseProps: CaseProps = { + caseId: '3c4ddcc0-4e99-11ea-9290-35d05cb55c15', + initialData: { + caseId: '3c4ddcc0-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:23.627Z', + createdBy: { fullName: null, username: 'elastic' }, + description: 'Security banana Issue', + state: 'open', + tags: ['defacement'], + title: 'Another horrible breach!!', + updatedAt: '2020-02-19T15:02:57.995Z', + }, + isLoading: false, +}; + +export const data: Case = { + caseId: '3c4ddcc0-4e99-11ea-9290-35d05cb55c15', + createdAt: '2020-02-13T19:44:23.627Z', + createdBy: { username: 'elastic', fullName: null }, + description: 'Security banana Issue', + state: 'open', + tags: ['defacement'], + title: 'Another horrible breach!!', + updatedAt: '2020-02-19T15:02:57.995Z', +}; diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.test.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.test.tsx new file mode 100644 index 000000000000000..a9e694bad705dac --- /dev/null +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.test.tsx @@ -0,0 +1,82 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { mount } from 'enzyme'; +import { CaseComponent } from './'; +import * as apiHook from '../../../../containers/case/use_update_case'; +import { caseProps, data } from './__mock__'; +import { TestProviders } from '../../../../mock'; + +describe('CaseView ', () => { + const dispatchUpdateCaseProperty = jest.fn(); + + beforeEach(() => { + jest.resetAllMocks(); + jest.spyOn(apiHook, 'useUpdateCase').mockReturnValue([{ data }, dispatchUpdateCaseProperty]); + }); + + it('should render CaseComponent', () => { + const wrapper = mount( + + + + ); + expect( + wrapper + .find(`[data-test-subj="case-view-title"]`) + .first() + .prop('title') + ).toEqual(data.title); + expect( + wrapper + .find(`[data-test-subj="case-view-state"]`) + .first() + .text() + ).toEqual(data.state); + expect( + wrapper + .find(`[data-test-subj="case-view-tag-list"] .euiBadge__text`) + .first() + .text() + ).toEqual(data.tags[0]); + expect( + wrapper + .find(`[data-test-subj="case-view-username"]`) + .first() + .text() + ).toEqual(data.createdBy.username); + expect( + wrapper + .find(`[data-test-subj="case-view-createdAt"]`) + .first() + .prop('value') + ).toEqual(data.createdAt); + expect( + wrapper + .find(`[data-test-subj="case-view-description"]`) + .first() + .prop('raw') + ).toEqual(data.description); + }); + + it('should dispatch update state when button is toggled', () => { + const wrapper = mount( + + + + ); + + wrapper + .find('input[data-test-subj="toggle-case-state"]') + .simulate('change', { target: { value: false } }); + + expect(dispatchUpdateCaseProperty).toBeCalledWith({ + updateKey: 'state', + updateValue: 'closed', + }); + }); +}); diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.tsx index a92cf99097fcecb..5cd71c5855d34fa 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/case_view/index.tsx @@ -60,13 +60,13 @@ const BackgroundWrapper = styled.div` `} `; -interface CasesProps { +export interface CaseProps { caseId: string; initialData: Case; isLoading: boolean; } -export const Cases = React.memo(({ caseId, initialData, isLoading }) => { +export const CaseComponent = React.memo(({ caseId, initialData, isLoading }) => { const [{ data }, dispatchUpdateCaseProperty] = useUpdateCase(caseId, initialData); const [isEditDescription, setIsEditDescription] = useState(false); const [isEditTags, setIsEditTags] = useState(false); @@ -162,14 +162,14 @@ export const Cases = React.memo(({ caseId, initialData, isLoading }) ]; const userActions = [ { - avatarName: data.created_by.username, + avatarName: data.createdBy.username, title: (

- {`${data.created_by.username}`} + {`${data.createdBy.username}`} {` ${i18n.ADDED_DESCRIPTION} `}{' '} - + {/* STEPH FIX come back and add label `on` */}

@@ -206,7 +206,7 @@ export const Cases = React.memo(({ caseId, initialData, isLoading })
) : ( - + ), }, ]; @@ -229,6 +229,7 @@ export const Cases = React.memo(({ caseId, initialData, isLoading }) href: getCaseUrl(), text: i18n.BACK_TO_ALL, }} + data-test-subj="case-view-title" titleNode={titleNode} title={title} > @@ -239,13 +240,21 @@ export const Cases = React.memo(({ caseId, initialData, isLoading }) {i18n.STATUS} - {data.state} + + {data.state} + {i18n.CASE_OPENED} - + @@ -255,6 +264,7 @@ export const Cases = React.memo(({ caseId, initialData, isLoading }) (({ caseId, initialData, isLoading }) - + { ); } - return ; + return ; }); CaseView.displayName = 'CaseView'; diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/create/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/create/index.tsx index 9fd1525003b0b76..7d79e287b22e709 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/create/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/create/index.tsx @@ -48,8 +48,8 @@ export const Create = React.memo(() => { } }, [form]); - if (newCase && newCase.case_id) { - return ; + if (newCase && newCase.caseId) { + return ; } return ( diff --git a/x-pack/legacy/plugins/siem/public/pages/case/components/user_list/index.tsx b/x-pack/legacy/plugins/siem/public/pages/case/components/user_list/index.tsx index b80ee58f8abbfee..33e0a9541c5b45d 100644 --- a/x-pack/legacy/plugins/siem/public/pages/case/components/user_list/index.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/case/components/user_list/index.tsx @@ -42,7 +42,7 @@ const renderUsers = (users: ElasticUser[]) => {

- {username} + {username}

@@ -50,7 +50,7 @@ const renderUsers = (users: ElasticUser[]) => {
window.alert('Email clicked')} + onClick={() => {}} // TO DO iconType="email" aria-label="email" /> diff --git a/x-pack/legacy/plugins/siem/public/pages/home/home_navigations.tsx b/x-pack/legacy/plugins/siem/public/pages/home/home_navigations.tsx index 42d333f4f893e59..a087dca38de0025 100644 --- a/x-pack/legacy/plugins/siem/public/pages/home/home_navigations.tsx +++ b/x-pack/legacy/plugins/siem/public/pages/home/home_navigations.tsx @@ -55,7 +55,7 @@ export const navTabs: SiemNavTab = { id: SiemPageName.case, name: i18n.CASE, href: getCaseUrl(), - disabled: true, + disabled: false, urlKey: 'case', }, }; diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_filter.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_filter.ts index bcf091544e52a3c..d1f41efdddd14e5 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_filter.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_filter.ts @@ -51,6 +51,15 @@ interface GetFilterArgs { index: string[] | undefined | null; } +interface QueryAttributes { + // NOTE: doesn't match Query interface + query: { + query: string; + language: string; + }; + filters: PartialFilter[]; +} + export const getFilter = async ({ filters, index, @@ -72,7 +81,10 @@ export const getFilter = async ({ if (savedId != null && index != null) { try { // try to get the saved object first - const savedObject = await services.savedObjectsClient.get('query', savedId); + const savedObject = await services.savedObjectsClient.get( + 'query', + savedId + ); return getQueryFilter( savedObject.attributes.query.query, savedObject.attributes.query.language, diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_input_output_index.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_input_output_index.ts index 29d4d2182bd5351..c93990e25b52be7 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_input_output_index.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/get_input_output_index.ts @@ -16,7 +16,9 @@ export const getInputIndex = async ( if (inputIndex != null) { return inputIndex; } else { - const configuration = await services.savedObjectsClient.get('config', version); + const configuration = await services.savedObjectsClient.get<{ + 'siem:defaultIndex': string[]; + }>('config', version); if (configuration.attributes != null && configuration.attributes[DEFAULT_INDEX_KEY] != null) { return configuration.attributes[DEFAULT_INDEX_KEY]; } else { diff --git a/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts b/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts index 79337aa91b1fe19..f7fabfb9801958f 100644 --- a/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts +++ b/x-pack/legacy/plugins/siem/server/lib/detection_engine/signals/signal_rule_alert_type.ts @@ -22,7 +22,17 @@ import { SignalRuleAlertTypeDefinition } from './types'; import { getGapBetweenRuns } from './utils'; import { ruleStatusSavedObjectType } from '../rules/saved_object_mappings'; import { IRuleSavedAttributesSavedObjectAttributes } from '../rules/types'; - +interface AlertAttributes { + enabled: boolean; + name: string; + tags: string[]; + createdBy: string; + createdAt: string; + updatedBy: string; + schedule: { + interval: string; + }; +} export const signalRulesAlertType = ({ logger, version, @@ -41,6 +51,7 @@ export const signalRulesAlertType = ({ }), }, ], + defaultActionGroupId: 'default', validate: { params: schema.object({ description: schema.string(), @@ -82,7 +93,7 @@ export const signalRulesAlertType = ({ type, } = params; // TODO: Remove this hard extraction of name once this is fixed: https://github.com/elastic/kibana/issues/50522 - const savedObject = await services.savedObjectsClient.get('alert', alertId); + const savedObject = await services.savedObjectsClient.get('alert', alertId); const ruleStatusSavedObjects = await services.savedObjectsClient.find< IRuleSavedAttributesSavedObjectAttributes >({ @@ -123,15 +134,15 @@ export const signalRulesAlertType = ({ ); } - const name: string = savedObject.attributes.name; - const tags: string[] = savedObject.attributes.tags; + const name = savedObject.attributes.name; + const tags = savedObject.attributes.tags; - const createdBy: string = savedObject.attributes.createdBy; - const createdAt: string = savedObject.attributes.createdAt; - const updatedBy: string = savedObject.attributes.updatedBy; - const updatedAt: string = savedObject.updated_at ?? ''; - const interval: string = savedObject.attributes.schedule.interval; - const enabled: boolean = savedObject.attributes.enabled; + const createdBy = savedObject.attributes.createdBy; + const createdAt = savedObject.attributes.createdAt; + const updatedBy = savedObject.attributes.updatedBy; + const updatedAt = savedObject.updated_at ?? ''; + const interval = savedObject.attributes.schedule.interval; + const enabled = savedObject.attributes.enabled; const gap = getGapBetweenRuns({ previousStartedAt: previousStartedAt != null ? moment(previousStartedAt) : null, // TODO: Remove this once previousStartedAt is no longer a string interval, diff --git a/x-pack/legacy/plugins/task_manager/server/migrations.ts b/x-pack/legacy/plugins/task_manager/server/migrations.ts index 7dce763ddf309fd..97c4f97f59c586e 100644 --- a/x-pack/legacy/plugins/task_manager/server/migrations.ts +++ b/x-pack/legacy/plugins/task_manager/server/migrations.ts @@ -7,7 +7,7 @@ import { SavedObject } from '../../../../../src/core/server'; export const migrations = { task: { - '7.4.0': (doc: SavedObject) => ({ + '7.4.0': (doc: SavedObject>) => ({ ...doc, updated_at: new Date().toISOString(), }), @@ -18,7 +18,7 @@ export const migrations = { function moveIntervalIntoSchedule({ attributes: { interval, ...attributes }, ...doc -}: SavedObject) { +}: SavedObject>) { return { ...doc, attributes: { diff --git a/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts b/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts index aba61766b5d2bcc..aa4cd21281e22e9 100644 --- a/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts +++ b/x-pack/legacy/plugins/transform/public/app/lib/kibana/common.ts @@ -9,6 +9,7 @@ import { IndexPattern, esQuery, IndexPatternsContract, + IndexPatternAttributes, } from '../../../../../../../../src/plugins/data/public'; import { matchAllQuery } from '../../common'; @@ -29,7 +30,7 @@ export function loadIndexPatterns( ) { fullIndexPatterns = indexPatterns; return savedObjectsClient - .find({ + .find({ type: 'index-pattern', fields: ['id', 'title', 'type', 'fields'], perPage: 10000, diff --git a/x-pack/legacy/plugins/upgrade_assistant/server/np_ready/lib/telemetry/usage_collector.ts b/x-pack/legacy/plugins/upgrade_assistant/server/np_ready/lib/telemetry/usage_collector.ts index 99c0441063ce62b..1d24d190fa9f251 100644 --- a/x-pack/legacy/plugins/upgrade_assistant/server/np_ready/lib/telemetry/usage_collector.ts +++ b/x-pack/legacy/plugins/upgrade_assistant/server/np_ready/lib/telemetry/usage_collector.ts @@ -24,7 +24,12 @@ async function getSavedObjectAttributesFromRepo( docID: string ) { try { - return (await savedObjectsRepository.get(docType, docID)).attributes; + return ( + await savedObjectsRepository.get( + docType, + docID + ) + ).attributes; } catch (e) { return null; } diff --git a/x-pack/plugins/actions/server/actions_client.ts b/x-pack/plugins/actions/server/actions_client.ts index 7ac8ea24b5218f0..a06048953b62cce 100644 --- a/x-pack/plugins/actions/server/actions_client.ts +++ b/x-pack/plugins/actions/server/actions_client.ts @@ -10,7 +10,7 @@ import { SavedObjectsClientContract, SavedObjectAttributes, SavedObject, -} from '../../../../src/core/server'; +} from 'src/core/server'; import { ActionTypeRegistry } from './action_type_registry'; import { validateConfig, validateSecrets } from './lib'; @@ -118,7 +118,7 @@ export class ActionsClient { * Update action */ public async update({ id, action }: UpdateOptions): Promise { - const existingObject = await this.savedObjectsClient.get('action', id); + const existingObject = await this.savedObjectsClient.get('action', id); const { actionTypeId } = existingObject.attributes; const { name, config, secrets } = action; const actionType = this.actionTypeRegistry.get(actionTypeId); @@ -144,13 +144,13 @@ export class ActionsClient { * Get an action */ public async get({ id }: { id: string }): Promise { - const result = await this.savedObjectsClient.get('action', id); + const result = await this.savedObjectsClient.get('action', id); return { id, - actionTypeId: result.attributes.actionTypeId as string, - name: result.attributes.name as string, - config: result.attributes.config as Record, + actionTypeId: result.attributes.actionTypeId, + name: result.attributes.name, + config: result.attributes.config, }; } diff --git a/x-pack/plugins/actions/server/create_execute_function.ts b/x-pack/plugins/actions/server/create_execute_function.ts index c2e8795b5f133d4..5316e833f33d938 100644 --- a/x-pack/plugins/actions/server/create_execute_function.ts +++ b/x-pack/plugins/actions/server/create_execute_function.ts @@ -6,7 +6,7 @@ import { SavedObjectsClientContract } from '../../../../src/core/server'; import { TaskManagerStartContract } from '../../task_manager/server'; -import { GetBasePathFunction } from './types'; +import { GetBasePathFunction, RawAction } from './types'; interface CreateExecuteFunctionOptions { taskManager: TaskManagerStartContract; @@ -59,7 +59,7 @@ export function createExecuteFunction({ }; const savedObjectsClient = getScopedSavedObjectsClient(fakeRequest); - const actionSavedObject = await savedObjectsClient.get('action', id); + const actionSavedObject = await savedObjectsClient.get('action', id); const actionTaskParamsRecord = await savedObjectsClient.create('action_task_params', { actionId: id, params, diff --git a/x-pack/plugins/alerting/common/index.ts b/x-pack/plugins/alerting/common/index.ts index 03b3487f10f1d99..8c6969cded85ad7 100644 --- a/x-pack/plugins/alerting/common/index.ts +++ b/x-pack/plugins/alerting/common/index.ts @@ -7,3 +7,8 @@ export * from './alert'; export * from './alert_instance'; export * from './alert_task_instance'; + +export interface ActionGroup { + id: string; + name: string; +} diff --git a/x-pack/plugins/alerting/server/alert_type_registry.test.ts b/x-pack/plugins/alerting/server/alert_type_registry.test.ts index 1a820d55af8a40d..f4749772c70040d 100644 --- a/x-pack/plugins/alerting/server/alert_type_registry.test.ts +++ b/x-pack/plugins/alerting/server/alert_type_registry.test.ts @@ -27,7 +27,13 @@ describe('has()', () => { registry.register({ id: 'foo', name: 'Foo', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', executor: jest.fn(), }); expect(registry.has('foo')).toEqual(true); @@ -39,7 +45,13 @@ describe('register()', () => { const alertType = { id: 'test', name: 'Test', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', executor: jest.fn(), }; // eslint-disable-next-line @typescript-eslint/no-var-requires @@ -64,14 +76,26 @@ describe('register()', () => { registry.register({ id: 'test', name: 'Test', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', executor: jest.fn(), }); expect(() => registry.register({ id: 'test', name: 'Test', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', executor: jest.fn(), }) ).toThrowErrorMatchingInlineSnapshot(`"Alert type \\"test\\" is already registered."`); @@ -84,13 +108,25 @@ describe('get()', () => { registry.register({ id: 'test', name: 'Test', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', executor: jest.fn(), }); const alertType = registry.get('test'); expect(alertType).toMatchInlineSnapshot(` Object { - "actionGroups": Array [], + "actionGroups": Array [ + Object { + "id": "default", + "name": "Default", + }, + ], + "defaultActionGroupId": "default", "executor": [MockFunction], "id": "test", "name": "Test", @@ -124,6 +160,7 @@ describe('list()', () => { name: 'Test Action Group', }, ], + defaultActionGroupId: 'testActionGroup', executor: jest.fn(), }); const result = registry.list(); @@ -136,6 +173,7 @@ describe('list()', () => { "name": "Test Action Group", }, ], + "defaultActionGroupId": "testActionGroup", "id": "test", "name": "Test", }, diff --git a/x-pack/plugins/alerting/server/alert_type_registry.ts b/x-pack/plugins/alerting/server/alert_type_registry.ts index b0976d67c70a000..d9045fb986745f9 100644 --- a/x-pack/plugins/alerting/server/alert_type_registry.ts +++ b/x-pack/plugins/alerting/server/alert_type_registry.ts @@ -70,6 +70,7 @@ export class AlertTypeRegistry { id: alertTypeId, name: alertType.name, actionGroups: alertType.actionGroups, + defaultActionGroupId: alertType.defaultActionGroupId, })); } } diff --git a/x-pack/plugins/alerting/server/alerts_client.test.ts b/x-pack/plugins/alerting/server/alerts_client.test.ts index 629bd05a8c76aea..ed6e7562e3acd00 100644 --- a/x-pack/plugins/alerting/server/alerts_client.test.ts +++ b/x-pack/plugins/alerting/server/alerts_client.test.ts @@ -87,6 +87,7 @@ describe('create()', () => { id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', async executor() {}, }); }); @@ -522,7 +523,13 @@ describe('create()', () => { alertTypeRegistry.get.mockReturnValue({ id: '123', name: 'Test', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', validate: { params: schema.object({ param1: schema.string(), @@ -1885,6 +1892,7 @@ describe('update()', () => { id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', async executor() {}, }); }); @@ -2415,6 +2423,7 @@ describe('update()', () => { id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', validate: { params: schema.object({ param1: schema.string(), @@ -2647,6 +2656,7 @@ describe('update()', () => { id: '123', name: 'Test', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', async executor() {}, }); savedObjectsClient.bulkGet.mockResolvedValueOnce({ diff --git a/x-pack/plugins/alerting/server/alerts_client.ts b/x-pack/plugins/alerting/server/alerts_client.ts index ad308f819da340f..9a56781aa1d7d8f 100644 --- a/x-pack/plugins/alerting/server/alerts_client.ts +++ b/x-pack/plugins/alerting/server/alerts_client.ts @@ -203,7 +203,7 @@ export class AlertsClient { } public async get({ id }: { id: string }): Promise { - const result = await this.savedObjectsClient.get('alert', id); + const result = await this.savedObjectsClient.get('alert', id); return this.getAlertFromRaw(result.id, result.attributes, result.updated_at, result.references); } diff --git a/x-pack/plugins/alerting/server/index.ts b/x-pack/plugins/alerting/server/index.ts index 58b77f0f510f722..727e38d9ba56b0d 100644 --- a/x-pack/plugins/alerting/server/index.ts +++ b/x-pack/plugins/alerting/server/index.ts @@ -12,6 +12,7 @@ export type AlertsClient = PublicMethodsOf; export { AlertType, + ActionGroup, AlertingPlugin, AlertExecutorOptions, AlertActionParams, diff --git a/x-pack/plugins/alerting/server/lib/validate_alert_type_params.test.ts b/x-pack/plugins/alerting/server/lib/validate_alert_type_params.test.ts index e9a61354001f121..67820e44f567ec5 100644 --- a/x-pack/plugins/alerting/server/lib/validate_alert_type_params.test.ts +++ b/x-pack/plugins/alerting/server/lib/validate_alert_type_params.test.ts @@ -12,7 +12,13 @@ test('should return passed in params when validation not defined', () => { { id: 'my-alert-type', name: 'My description', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', async executor() {}, }, { @@ -27,7 +33,13 @@ test('should validate and apply defaults when params is valid', () => { { id: 'my-alert-type', name: 'My description', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', validate: { params: schema.object({ param1: schema.string(), @@ -50,7 +62,13 @@ test('should validate and throw error when params is invalid', () => { { id: 'my-alert-type', name: 'My description', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', validate: { params: schema.object({ param1: schema.string(), diff --git a/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts b/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts index 3e9f57d55122d7c..96ee8c571745319 100644 --- a/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts +++ b/x-pack/plugins/alerting/server/routes/list_alert_types.test.ts @@ -40,7 +40,13 @@ describe('listAlertTypesRoute', () => { { id: '1', name: 'name', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', }, ]; @@ -50,7 +56,13 @@ describe('listAlertTypesRoute', () => { Object { "body": Array [ Object { - "actionGroups": Array [], + "actionGroups": Array [ + Object { + "id": "default", + "name": "Default", + }, + ], + "defaultActionGroupId": "default", "id": "1", "name": "name", }, @@ -128,7 +140,13 @@ describe('listAlertTypesRoute', () => { { id: '1', name: 'name', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', }, ]; diff --git a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts index 1b3a9ed8d7b0676..32299680a1f8cf4 100644 --- a/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/create_execution_handler.test.ts @@ -15,6 +15,7 @@ const alertType: AlertType = { { id: 'default', name: 'Default' }, { id: 'other-group', name: 'Other Group' }, ], + defaultActionGroupId: 'default', executor: jest.fn(), }; diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts index af0e7b658240a79..d1bc0de3ae0e218 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts @@ -17,6 +17,7 @@ const alertType = { id: 'test', name: 'My test alert', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', executor: jest.fn(), }; let fakeTimer: sinon.SinonFakeTimers; diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.ts index 34278ee62dbc4e3..c2a3fbcf38069ea 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.ts @@ -5,8 +5,7 @@ */ import { pick, mapValues, omit } from 'lodash'; -import { Logger } from '../../../../../src/core/server'; -import { SavedObject } from '../../../../../src/core/server'; +import { Logger, SavedObject } from '../../../../../src/core/server'; import { TaskRunnerContext } from './task_runner_factory'; import { ConcreteTaskInstance } from '../../../../plugins/task_manager/server'; import { createExecutionHandler } from './create_execution_handler'; diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts index 4dad46ef32f214b..f885b0bdbd046b8 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts @@ -14,6 +14,7 @@ const alertType = { id: 'test', name: 'My test alert', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', executor: jest.fn(), }; let fakeTimer: sinon.SinonFakeTimers; diff --git a/x-pack/plugins/alerting/server/types.ts b/x-pack/plugins/alerting/server/types.ts index 202a73f076859f9..90bc7996729a6c6 100644 --- a/x-pack/plugins/alerting/server/types.ts +++ b/x-pack/plugins/alerting/server/types.ts @@ -8,7 +8,7 @@ import { AlertInstance } from './alert_instance'; import { AlertTypeRegistry as OrigAlertTypeRegistry } from './alert_type_registry'; import { PluginSetupContract, PluginStartContract } from './plugin'; import { SavedObjectAttributes, SavedObjectsClientContract } from '../../../../src/core/server'; -import { Alert, AlertActionParams } from '../common'; +import { Alert, AlertActionParams, ActionGroup } from '../common'; import { AlertsClient } from './alerts_client'; export * from '../common'; @@ -52,11 +52,6 @@ export interface AlertExecutorOptions { updatedBy: string | null; } -export interface ActionGroup { - id: string; - name: string; -} - export interface AlertType { id: string; name: string; @@ -64,6 +59,7 @@ export interface AlertType { params?: { validate: (object: any) => any }; }; actionGroups: ActionGroup[]; + defaultActionGroupId: ActionGroup['id']; executor: ({ services, params, state }: AlertExecutorOptions) => Promise; } diff --git a/x-pack/plugins/canvas/server/routes/workpad/update.ts b/x-pack/plugins/canvas/server/routes/workpad/update.ts index 0d4809a9ee168e1..83b8fef48e9bed6 100644 --- a/x-pack/plugins/canvas/server/routes/workpad/update.ts +++ b/x-pack/plugins/canvas/server/routes/workpad/update.ts @@ -6,8 +6,7 @@ import { schema, TypeOf } from '@kbn/config-schema'; import { omit } from 'lodash'; -import { KibanaResponseFactory } from 'src/core/server'; -import { SavedObjectsClientContract } from 'src/core/server'; +import { KibanaResponseFactory, SavedObjectsClientContract } from 'src/core/server'; import { RouteInitializerDeps } from '../'; import { CANVAS_TYPE, diff --git a/x-pack/plugins/case/server/config.ts b/x-pack/plugins/case/server/config.ts index a7cb117198f9b7a..8ff9a793b17dc5a 100644 --- a/x-pack/plugins/case/server/config.ts +++ b/x-pack/plugins/case/server/config.ts @@ -7,9 +7,7 @@ import { schema, TypeOf } from '@kbn/config-schema'; export const ConfigSchema = schema.object({ - enabled: schema.boolean({ defaultValue: false }), - indexPattern: schema.string({ defaultValue: '.case-test-2' }), - secret: schema.string({ defaultValue: 'Cool secret huh?' }), + enabled: schema.boolean({ defaultValue: true }), }); export type ConfigType = TypeOf; diff --git a/x-pack/plugins/case/server/plugin.ts b/x-pack/plugins/case/server/plugin.ts index 37d087433a2ed10..5ca640f0b25c389 100644 --- a/x-pack/plugins/case/server/plugin.ts +++ b/x-pack/plugins/case/server/plugin.ts @@ -34,6 +34,7 @@ export class CasePlugin { if (!config.enabled) { return; } + const service = new CaseService(this.log); this.log.debug( diff --git a/x-pack/plugins/case/server/routes/api/__tests__/update_case.test.ts b/x-pack/plugins/case/server/routes/api/__tests__/update_case.test.ts index 23283d7f8a5be34..25d5cafb4bb06e3 100644 --- a/x-pack/plugins/case/server/routes/api/__tests__/update_case.test.ts +++ b/x-pack/plugins/case/server/routes/api/__tests__/update_case.test.ts @@ -27,7 +27,8 @@ describe('UPDATE case', () => { id: 'mock-id-1', }, body: { - state: 'closed', + case: { state: 'closed' }, + version: 'WzAsMV0=', }, }); @@ -38,6 +39,42 @@ describe('UPDATE case', () => { expect(typeof response.payload.updated_at).toBe('string'); expect(response.payload.state).toEqual('closed'); }); + it(`Fails with 409 if version does not match`, async () => { + const request = httpServerMock.createKibanaRequest({ + path: '/api/cases/{id}', + method: 'patch', + params: { + id: 'mock-id-1', + }, + body: { + case: { state: 'closed' }, + version: 'badv=', + }, + }); + + const theContext = createRouteContext(createMockSavedObjectsRepository(mockCases)); + + const response = await routeHandler(theContext, request, kibanaResponseFactory); + expect(response.status).toEqual(409); + }); + it(`Fails with 406 if updated field is unchanged`, async () => { + const request = httpServerMock.createKibanaRequest({ + path: '/api/cases/{id}', + method: 'patch', + params: { + id: 'mock-id-1', + }, + body: { + case: { state: 'open' }, + version: 'WzAsMV0=', + }, + }); + + const theContext = createRouteContext(createMockSavedObjectsRepository(mockCases)); + + const response = await routeHandler(theContext, request, kibanaResponseFactory); + expect(response.status).toEqual(406); + }); it(`Returns an error if updateCase throws`, async () => { const request = httpServerMock.createKibanaRequest({ path: '/api/cases/{id}', diff --git a/x-pack/plugins/case/server/routes/api/get_all_cases.ts b/x-pack/plugins/case/server/routes/api/get_all_cases.ts index 09075a32ac3771e..ba26a07dc239492 100644 --- a/x-pack/plugins/case/server/routes/api/get_all_cases.ts +++ b/x-pack/plugins/case/server/routes/api/get_all_cases.ts @@ -6,7 +6,7 @@ import { schema } from '@kbn/config-schema'; import { RouteDeps } from '.'; -import { formatAllCases, wrapError } from './utils'; +import { formatAllCases, sortToSnake, wrapError } from './utils'; import { SavedObjectsFindOptionsSchema } from './schema'; import { AllCases } from './types'; @@ -23,7 +23,10 @@ export function initGetAllCasesApi({ caseService, router }: RouteDeps) { const args = request.query ? { client: context.core.savedObjects.client, - options: request.query, + options: { + ...request.query, + sortField: sortToSnake(request.query.sortField ?? ''), + }, } : { client: context.core.savedObjects.client, diff --git a/x-pack/plugins/case/server/routes/api/schema.ts b/x-pack/plugins/case/server/routes/api/schema.ts index 962dc474254f0e5..468abc8e7226f79 100644 --- a/x-pack/plugins/case/server/routes/api/schema.ts +++ b/x-pack/plugins/case/server/routes/api/schema.ts @@ -41,6 +41,11 @@ export const UpdatedCaseSchema = schema.object({ title: schema.maybe(schema.string()), }); +export const UpdateCaseArguments = schema.object({ + case: UpdatedCaseSchema, + version: schema.string(), +}); + export const SavedObjectsFindOptionsSchema = schema.object({ defaultSearchOperator: schema.maybe(schema.oneOf([schema.literal('AND'), schema.literal('OR')])), fields: schema.maybe(schema.arrayOf(schema.string())), diff --git a/x-pack/plugins/case/server/routes/api/types.ts b/x-pack/plugins/case/server/routes/api/types.ts index 2d1a88bcf14298f..5f1c207bf98297e 100644 --- a/x-pack/plugins/case/server/routes/api/types.ts +++ b/x-pack/plugins/case/server/routes/api/types.ts @@ -32,12 +32,14 @@ export interface CaseAttributes extends NewCaseType, SavedObjectAttributes { export type FlattenedCaseSavedObject = CaseAttributes & { case_id: string; + version: string; comments: FlattenedCommentSavedObject[]; }; export type FlattenedCasesSavedObject = Array< CaseAttributes & { case_id: string; + version: string; // TO DO it is partial because we need to add it the commentCount commentCount?: number; } @@ -52,6 +54,7 @@ export interface AllCases { export type FlattenedCommentSavedObject = CommentAttributes & { comment_id: string; + version: string; // TO DO We might want to add the case_id where this comment is related too }; @@ -69,3 +72,13 @@ export interface UpdatedCaseType { title?: UpdatedCaseTyped['title']; updated_at: string; } + +export enum SortFieldCase { + createdAt = 'created_at', + state = 'state', + updatedAt = 'updated_at', +} + +export type Writable = { + -readonly [K in keyof T]: T[K]; +}; diff --git a/x-pack/plugins/case/server/routes/api/update_case.ts b/x-pack/plugins/case/server/routes/api/update_case.ts index 2a814c7259e4a60..1c1a56dfe9b3a75 100644 --- a/x-pack/plugins/case/server/routes/api/update_case.ts +++ b/x-pack/plugins/case/server/routes/api/update_case.ts @@ -5,9 +5,17 @@ */ import { schema } from '@kbn/config-schema'; +import { SavedObject } from 'kibana/server'; +import Boom from 'boom'; +import { difference } from 'lodash'; import { wrapError } from './utils'; import { RouteDeps } from '.'; -import { UpdatedCaseSchema } from './schema'; +import { UpdateCaseArguments } from './schema'; +import { CaseAttributes, UpdatedCaseTyped, Writable } from './types'; + +interface UpdateCase extends Writable { + [key: string]: any; +} export function initUpdateCaseApi({ caseService, router }: RouteDeps) { router.patch( @@ -17,23 +25,70 @@ export function initUpdateCaseApi({ caseService, router }: RouteDeps) { params: schema.object({ id: schema.string(), }), - body: UpdatedCaseSchema, + body: UpdateCaseArguments, }, }, async (context, request, response) => { + let theCase: SavedObject; try { - const updatedCase = await caseService.updateCase({ + theCase = await caseService.getCase({ client: context.core.savedObjects.client, caseId: request.params.id, - updatedAttributes: { - ...request.body, - updated_at: new Date().toISOString(), - }, }); - return response.ok({ body: updatedCase.attributes }); } catch (error) { return response.customError(wrapError(error)); } + + if (request.body.version !== theCase.version) { + return response.customError( + wrapError( + Boom.conflict( + 'This case has been updated. Please refresh before saving additional updates.' + ) + ) + ); + } + const currentCase = theCase.attributes; + const updateCase: Partial = Object.entries(request.body.case).reduce( + (acc, [key, value]) => { + const currentValue = currentCase[key]; + if ( + Array.isArray(value) && + Array.isArray(currentValue) && + difference(value, currentValue).length !== 0 + ) { + return { + ...acc, + [key]: value, + }; + } else if (value !== currentCase[key]) { + return { + ...acc, + [key]: value, + }; + } + return acc; + }, + {} + ); + if (Object.keys(updateCase).length > 0) { + try { + const updatedCase = await caseService.updateCase({ + client: context.core.savedObjects.client, + caseId: request.params.id, + updatedAttributes: { + ...updateCase, + updated_at: new Date().toISOString(), + }, + }); + return response.ok({ body: { ...updatedCase.attributes, version: updatedCase.version } }); + } catch (error) { + return response.customError(wrapError(error)); + } + } + return response.customError( + wrapError(Boom.notAcceptable('All update fields are identical to current version.')) + ); } ); } diff --git a/x-pack/plugins/case/server/routes/api/utils.ts b/x-pack/plugins/case/server/routes/api/utils.ts index 51944b04836ab68..32de41e1c01c5a7 100644 --- a/x-pack/plugins/case/server/routes/api/utils.ts +++ b/x-pack/plugins/case/server/routes/api/utils.ts @@ -20,6 +20,7 @@ import { AllCases, NewCaseType, NewCommentType, + SortFieldCase, UserType, } from './types'; @@ -80,6 +81,7 @@ export const flattenCaseSavedObject = ( comments: Array> ): FlattenedCaseSavedObject => ({ case_id: savedObject.id, + version: savedObject.version ? savedObject.version : '0', comments: flattenCommentSavedObjects(comments), ...savedObject.attributes, }); @@ -107,5 +109,21 @@ export const flattenCommentSavedObject = ( savedObject: SavedObject ): FlattenedCommentSavedObject => ({ comment_id: savedObject.id, + version: savedObject.version ? savedObject.version : '0', ...savedObject.attributes, }); + +export const sortToSnake = (sortField: string): SortFieldCase => { + switch (sortField) { + case 'state': + return SortFieldCase.state; + case 'createdAt': + case 'created_at': + return SortFieldCase.createdAt; + case 'updatedAt': + case 'updated_at': + return SortFieldCase.updatedAt; + default: + return SortFieldCase.createdAt; + } +}; diff --git a/x-pack/plugins/case/server/services/tags/read_tags.ts b/x-pack/plugins/case/server/services/tags/read_tags.ts index 58ab99b164cfba9..da5905fe4ea3583 100644 --- a/x-pack/plugins/case/server/services/tags/read_tags.ts +++ b/x-pack/plugins/case/server/services/tags/read_tags.ts @@ -52,7 +52,7 @@ export const readRawTags = async ({ page: 1, perPage, }); - const tags = await client.find({ + const tags = await client.find({ type: CASE_SAVED_OBJECT, fields: ['tags'], page: 1, diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts index 1e439b68f8c30db..849bfda2bc86fa9 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.ts @@ -7,7 +7,6 @@ import uuid from 'uuid'; import { SavedObject, - SavedObjectAttributes, SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkGetObject, @@ -42,7 +41,7 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon public readonly errors = options.baseClient.errors ) {} - public async create( + public async create( type: string, attributes: T = {} as T, options: SavedObjectsCreateOptions = {} @@ -66,15 +65,15 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon type, await this.options.service.encryptAttributes( { type, id, namespace: options.namespace }, - attributes + attributes as Record ), { ...options, id } ) - ); + ) as SavedObject; } - public async bulkCreate( - objects: SavedObjectsBulkCreateObject[], + public async bulkCreate( + objects: Array>, options?: SavedObjectsBaseOptions ) { // We encrypt attributes for every object in parallel and that can potentially exhaust libuv or @@ -101,14 +100,14 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon id, attributes: await this.options.service.encryptAttributes( { type: object.type, id, namespace: options && options.namespace }, - object.attributes + object.attributes as Record ), - }; + } as SavedObjectsBulkCreateObject; }) ); return this.stripEncryptedAttributesFromBulkResponse( - await this.options.baseClient.bulkCreate(encryptedObjects, options) + await this.options.baseClient.bulkCreate(encryptedObjects, options) ); } @@ -144,28 +143,28 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon return await this.options.baseClient.delete(type, id, options); } - public async find(options: SavedObjectsFindOptions) { + public async find(options: SavedObjectsFindOptions) { return this.stripEncryptedAttributesFromBulkResponse( - await this.options.baseClient.find(options) + await this.options.baseClient.find(options) ); } - public async bulkGet( + public async bulkGet( objects: SavedObjectsBulkGetObject[] = [], options?: SavedObjectsBaseOptions ) { return this.stripEncryptedAttributesFromBulkResponse( - await this.options.baseClient.bulkGet(objects, options) + await this.options.baseClient.bulkGet(objects, options) ); } - public async get(type: string, id: string, options?: SavedObjectsBaseOptions) { + public async get(type: string, id: string, options?: SavedObjectsBaseOptions) { return this.stripEncryptedAttributesFromResponse( - await this.options.baseClient.get(type, id, options) + await this.options.baseClient.get(type, id, options) ); } - public async update( + public async update( type: string, id: string, attributes: Partial, @@ -199,7 +198,7 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon if (this.options.service.isRegistered(response.type)) { response.attributes = this.options.service.stripEncryptedAttributes( response.type, - response.attributes + response.attributes as Record ); } @@ -218,7 +217,7 @@ export class EncryptedSavedObjectsClientWrapper implements SavedObjectsClientCon if (this.options.service.isRegistered(savedObject.type)) { savedObject.attributes = this.options.service.stripEncryptedAttributes( savedObject.type, - savedObject.attributes + savedObject.attributes as Record ); } } diff --git a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts index 80bd2ab7b5171bb..0dbdc2f3ac7e3ab 100644 --- a/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts +++ b/x-pack/plugins/encrypted_saved_objects/server/saved_objects/index.ts @@ -4,12 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - CoreSetup, - SavedObject, - SavedObjectAttributes, - SavedObjectsBaseOptions, -} from 'src/core/server'; +import { CoreSetup, SavedObject, SavedObjectsBaseOptions } from 'src/core/server'; import { EncryptedSavedObjectsService } from '../crypto'; import { EncryptedSavedObjectsClientWrapper } from './encrypted_saved_objects_client_wrapper'; @@ -20,7 +15,7 @@ interface SetupSavedObjectsParams { } export interface SavedObjectsSetup { - getDecryptedAsInternalUser: ( + getDecryptedAsInternalUser: ( type: string, id: string, options?: SavedObjectsBaseOptions @@ -47,7 +42,7 @@ export function setupSavedObjects({ core.savedObjects.createInternalRepository() ); return { - getDecryptedAsInternalUser: async ( + getDecryptedAsInternalUser: async ( type: string, id: string, options?: SavedObjectsBaseOptions @@ -56,10 +51,10 @@ export function setupSavedObjects({ const savedObject = await internalRepository.get(type, id, options); return { ...savedObject, - attributes: await service.decryptAttributes( + attributes: (await service.decryptAttributes( { type, id, namespace: options && options.namespace }, - savedObject.attributes - ), + savedObject.attributes as Record + )) as T, }; }, }; diff --git a/x-pack/plugins/infra/public/hooks/use_bulk_get_saved_object.tsx b/x-pack/plugins/infra/public/hooks/use_bulk_get_saved_object.tsx index 80d1b67e5979894..2c553b57dcd4854 100644 --- a/x-pack/plugins/infra/public/hooks/use_bulk_get_saved_object.tsx +++ b/x-pack/plugins/infra/public/hooks/use_bulk_get_saved_object.tsx @@ -5,12 +5,13 @@ */ import { useState, useCallback } from 'react'; -import { SavedObjectAttributes, SavedObjectsBatchResponse } from 'src/core/public'; +import { SavedObjectsBatchResponse } from 'src/core/public'; import { useKibana } from '../../../../../src/plugins/kibana_react/public'; export const useBulkGetSavedObject = (type: string) => { const kibana = useKibana(); - const [data, setData] = useState | null>(null); + // TODO: define saved object type + const [data, setData] = useState | null>(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); diff --git a/x-pack/plugins/lens/server/routes/existing_fields.test.ts b/x-pack/plugins/lens/server/routes/existing_fields.test.ts index 1f19671826807a1..9bd11b6863d93be 100644 --- a/x-pack/plugins/lens/server/routes/existing_fields.test.ts +++ b/x-pack/plugins/lens/server/routes/existing_fields.test.ts @@ -91,6 +91,8 @@ describe('buildFieldList', () => { type: 'indexpattern', attributes: { title: 'testpattern', + type: 'type', + typeMeta: 'typemeta', fields: JSON.stringify([ { name: 'foo', scripted: true, lang: 'painless', script: '2+2' }, { name: 'bar' }, diff --git a/x-pack/plugins/lens/server/routes/existing_fields.ts b/x-pack/plugins/lens/server/routes/existing_fields.ts index a059e325859094a..40b2766a647cf71 100644 --- a/x-pack/plugins/lens/server/routes/existing_fields.ts +++ b/x-pack/plugins/lens/server/routes/existing_fields.ts @@ -9,7 +9,10 @@ import { schema } from '@kbn/config-schema'; import { IScopedClusterClient, SavedObject, RequestHandlerContext } from 'src/core/server'; import { CoreSetup } from 'src/core/server'; import { BASE_API_URL } from '../../common'; -import { IndexPatternsFetcher } from '../../../../../src/plugins/data/server'; +import { + IndexPatternsFetcher, + IndexPatternAttributes, +} from '../../../../../src/plugins/data/server'; /** * The number of docs to sample to determine field empty status. @@ -125,7 +128,10 @@ async function fetchFieldExistence({ async function fetchIndexPatternDefinition(indexPatternId: string, context: RequestHandlerContext) { const savedObjectsClient = context.core.savedObjects.client; const requestClient = context.core.elasticsearch.dataClient; - const indexPattern = await savedObjectsClient.get('index-pattern', indexPatternId); + const indexPattern = await savedObjectsClient.get( + 'index-pattern', + indexPatternId + ); const indexPatternTitle = indexPattern.attributes.title; // TODO: maybe don't use IndexPatternsFetcher at all, since we're only using it // to look up field values in the resulting documents. We can accomplish the same @@ -155,7 +161,7 @@ async function fetchIndexPatternDefinition(indexPatternId: string, context: Requ * Exported only for unit tests. */ export function buildFieldList( - indexPattern: SavedObject, + indexPattern: SavedObject, mappings: MappingResult, fieldDescriptors: FieldDescriptor[] ): Field[] { diff --git a/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.ts b/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.ts index 03b1d770fa77069..2209e7fb66fcb46 100644 --- a/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.ts +++ b/x-pack/plugins/security/server/saved_objects/secure_saved_objects_client_wrapper.ts @@ -5,7 +5,6 @@ */ import { - SavedObjectAttributes, SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkGetObject, @@ -46,7 +45,7 @@ export class SecureSavedObjectsClientWrapper implements SavedObjectsClientContra this.checkSavedObjectsPrivilegesAsCurrentUser = checkSavedObjectsPrivilegesAsCurrentUser; } - public async create( + public async create( type: string, attributes: T = {} as T, options: SavedObjectsCreateOptions = {} @@ -56,8 +55,8 @@ export class SecureSavedObjectsClientWrapper implements SavedObjectsClientContra return await this.baseClient.create(type, attributes, options); } - public async bulkCreate( - objects: SavedObjectsBulkCreateObject[], + public async bulkCreate( + objects: Array>, options: SavedObjectsBaseOptions = {} ) { await this.ensureAuthorized( @@ -76,13 +75,13 @@ export class SecureSavedObjectsClientWrapper implements SavedObjectsClientContra return await this.baseClient.delete(type, id, options); } - public async find(options: SavedObjectsFindOptions) { + public async find(options: SavedObjectsFindOptions) { await this.ensureAuthorized(options.type, 'find', options.namespace, { options }); - return this.baseClient.find(options); + return this.baseClient.find(options); } - public async bulkGet( + public async bulkGet( objects: SavedObjectsBulkGetObject[] = [], options: SavedObjectsBaseOptions = {} ) { @@ -91,16 +90,16 @@ export class SecureSavedObjectsClientWrapper implements SavedObjectsClientContra options, }); - return await this.baseClient.bulkGet(objects, options); + return await this.baseClient.bulkGet(objects, options); } - public async get(type: string, id: string, options: SavedObjectsBaseOptions = {}) { + public async get(type: string, id: string, options: SavedObjectsBaseOptions = {}) { await this.ensureAuthorized(type, 'get', options.namespace, { type, id, options }); - return await this.baseClient.get(type, id, options); + return await this.baseClient.get(type, id, options); } - public async update( + public async update( type: string, id: string, attributes: Partial, @@ -116,8 +115,8 @@ export class SecureSavedObjectsClientWrapper implements SavedObjectsClientContra return await this.baseClient.update(type, id, attributes, options); } - public async bulkUpdate( - objects: SavedObjectsBulkUpdateObject[] = [], + public async bulkUpdate( + objects: Array> = [], options: SavedObjectsBaseOptions = {} ) { await this.ensureAuthorized( @@ -127,7 +126,7 @@ export class SecureSavedObjectsClientWrapper implements SavedObjectsClientContra { objects, options } ); - return await this.baseClient.bulkUpdate(objects, options); + return await this.baseClient.bulkUpdate(objects, options); } private async checkPrivileges(actions: string | string[], namespace?: string) { diff --git a/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts b/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts index 62a78679175b3de..534d79712394011 100644 --- a/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts +++ b/x-pack/plugins/spaces/server/lib/saved_objects_client/spaces_saved_objects_client.ts @@ -5,7 +5,6 @@ */ import { - SavedObjectAttributes, SavedObjectsBaseOptions, SavedObjectsBulkCreateObject, SavedObjectsBulkGetObject, @@ -65,14 +64,14 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * @property {string} [options.namespace] * @returns {promise} - { id, type, version, attributes } */ - public async create( + public async create( type: string, attributes: T = {} as T, options: SavedObjectsCreateOptions = {} ) { throwErrorIfNamespaceSpecified(options); - return await this.client.create(type, attributes, { + return await this.client.create(type, attributes, { ...options, namespace: spaceIdToNamespace(this.spaceId), }); @@ -87,8 +86,8 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * @property {string} [options.namespace] * @returns {promise} - { saved_objects: [{ id, type, version, attributes, error: { message } }]} */ - public async bulkCreate( - objects: SavedObjectsBulkCreateObject[], + public async bulkCreate( + objects: Array>, options: SavedObjectsBaseOptions = {} ) { throwErrorIfNamespaceSpecified(options); @@ -133,10 +132,10 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * @property {object} [options.hasReference] - { type, id } * @returns {promise} - { saved_objects: [{ id, type, version, attributes }], total, per_page, page } */ - public async find(options: SavedObjectsFindOptions) { + public async find(options: SavedObjectsFindOptions) { throwErrorIfNamespaceSpecified(options); - return await this.client.find({ + return await this.client.find({ ...options, type: (options.type ? coerceToArray(options.type) : this.types).filter( type => type !== 'space' @@ -159,13 +158,13 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * { id: 'foo', type: 'index-pattern' } * ]) */ - public async bulkGet( + public async bulkGet( objects: SavedObjectsBulkGetObject[] = [], options: SavedObjectsBaseOptions = {} ) { throwErrorIfNamespaceSpecified(options); - return await this.client.bulkGet(objects, { + return await this.client.bulkGet(objects, { ...options, namespace: spaceIdToNamespace(this.spaceId), }); @@ -180,10 +179,10 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * @property {string} [options.namespace] * @returns {promise} - { id, type, version, attributes } */ - public async get(type: string, id: string, options: SavedObjectsBaseOptions = {}) { + public async get(type: string, id: string, options: SavedObjectsBaseOptions = {}) { throwErrorIfNamespaceSpecified(options); - return await this.client.get(type, id, { + return await this.client.get(type, id, { ...options, namespace: spaceIdToNamespace(this.spaceId), }); @@ -199,7 +198,7 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * @property {string} [options.namespace] * @returns {promise} */ - public async update( + public async update( type: string, id: string, attributes: Partial, @@ -225,8 +224,8 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract { * { id: 'foo', type: 'index-pattern', attributes: {} } * ]) */ - public async bulkUpdate( - objects: SavedObjectsBulkUpdateObject[] = [], + public async bulkUpdate( + objects: Array> = [], options: SavedObjectsBaseOptions = {} ) { throwErrorIfNamespaceSpecified(options); diff --git a/x-pack/plugins/task_manager/server/task_store.test.ts b/x-pack/plugins/task_manager/server/task_store.test.ts index 6ed6ae16fa0f922..97794311fb3d25a 100644 --- a/x-pack/plugins/task_manager/server/task_store.test.ts +++ b/x-pack/plugins/task_manager/server/task_store.test.ts @@ -18,11 +18,7 @@ import { } from './task'; import { StoreOpts, OwnershipClaimingOpts, TaskStore, SearchOpts } from './task_store'; import { savedObjectsRepositoryMock } from '../../../../src/core/server/mocks'; -import { - SavedObjectsSerializer, - SavedObjectTypeRegistry, - SavedObjectAttributes, -} from '../../../../src/core/server'; +import { SavedObjectsSerializer, SavedObjectTypeRegistry } from '../../../../src/core/server'; import { SavedObjectsErrorHelpers } from '../../../../src/core/server/saved_objects/service/lib/errors'; import { asTaskClaimEvent, TaskEvent } from './task_events'; import { asOk, asErr } from './lib/result_type'; @@ -64,15 +60,13 @@ describe('TaskStore', () => { describe('schedule', () => { async function testSchedule(task: TaskInstance) { const callCluster = jest.fn(); - savedObjectsClient.create.mockImplementation( - async (type: string, attributes: SavedObjectAttributes) => ({ - id: 'testid', - type, - attributes, - references: [], - version: '123', - }) - ); + savedObjectsClient.create.mockImplementation(async (type: string, attributes: any) => ({ + id: 'testid', + type, + attributes, + references: [], + version: '123', + })); const store = new TaskStore({ index: 'tasky', taskManagerId: '', @@ -155,14 +149,14 @@ describe('TaskStore', () => { test('sets runAt to now if not specified', async () => { await testSchedule({ taskType: 'dernstraight', params: {}, state: {} }); expect(savedObjectsClient.create).toHaveBeenCalledTimes(1); - const attributes = savedObjectsClient.create.mock.calls[0][1]; + const attributes: any = savedObjectsClient.create.mock.calls[0][1]; expect(new Date(attributes.runAt as string).getTime()).toEqual(mockedDate.getTime()); }); test('ensures params and state are not null', async () => { await testSchedule({ taskType: 'yawn' } as any); expect(savedObjectsClient.create).toHaveBeenCalledTimes(1); - const attributes = savedObjectsClient.create.mock.calls[0][1]; + const attributes: any = savedObjectsClient.create.mock.calls[0][1]; expect(attributes.params).toEqual('{}'); expect(attributes.state).toEqual('{}'); }); @@ -751,7 +745,7 @@ if (doc['task.runAt'].size()!=0) { }; savedObjectsClient.update.mockImplementation( - async (type: string, id: string, attributes: SavedObjectAttributes) => { + async (type: string, id: string, attributes: any) => { return { id, type, diff --git a/x-pack/plugins/task_manager/server/task_store.ts b/x-pack/plugins/task_manager/server/task_store.ts index 3915eeffc55197c..0e487386eb04d27 100644 --- a/x-pack/plugins/task_manager/server/task_store.ts +++ b/x-pack/plugins/task_manager/server/task_store.ts @@ -428,7 +428,8 @@ function taskInstanceToAttributes(doc: TaskInstance): SavedObjectAttributes { } export function savedObjectToConcreteTaskInstance( - savedObject: Omit + // TODO: define saved object type + savedObject: Omit, 'references'> ): ConcreteTaskInstance { return { ...savedObject.attributes, diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.test.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.test.ts index 93a46862f4cd2cd..1e53e7d9838480b 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.test.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.test.ts @@ -40,6 +40,7 @@ describe('loadAlertTypes', () => { name: 'Test', actionVariables: ['var1'], actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', }, ]; http.get.mockResolvedValueOnce(resolvedValue); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.test.tsx index ce524ed8178eeec..aa71621f1a914ed 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.test.tsx @@ -158,6 +158,7 @@ describe('alert_form', () => { alertTypeRegistry.has.mockReturnValue(true); actionTypeRegistry.list.mockReturnValue([actionType]); actionTypeRegistry.has.mockReturnValue(true); + actionTypeRegistry.get.mockReturnValue(actionType); const initialAlert = ({ name: 'test', diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.tsx index 95c049f32436aa6..18dc88f54e90706 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_add/alert_form.tsx @@ -40,7 +40,6 @@ import { ActionTypeIndex, ActionConnector, AlertTypeIndex, - ActionGroup, } from '../../../types'; import { SectionLoading } from '../../components/section_loading'; import { ConnectorAddModal } from '../action_connector_form/connector_add_modal'; @@ -119,7 +118,7 @@ export const AlertForm = ({ const [alertThrottleUnit, setAlertThrottleUnit] = useState('m'); const [isAddActionPanelOpen, setIsAddActionPanelOpen] = useState(true); const [connectors, setConnectors] = useState([]); - const [defaultActionGroup, setDefaultActionGroup] = useState(undefined); + const [defaultActionGroupId, setDefaultActionGroupId] = useState(undefined); const [activeActionItem, setActiveActionItem] = useState( undefined ); @@ -166,13 +165,14 @@ export const AlertForm = ({ ], name: 'threshold', actionVariables: ['ctx.metadata.name', 'ctx.metadata.test'], + defaultActionGroupId: 'alert', }); const index: AlertTypeIndex = {}; for (const alertTypeItem of alertTypes) { index[alertTypeItem.id] = alertTypeItem; } - if (alert.alertTypeId) { - setDefaultActionGroup(index[alert.alertTypeId].actionGroups[0]); + if (alert.alertTypeId && index[alert.alertTypeId]) { + setDefaultActionGroupId(index[alert.alertTypeId].defaultActionGroupId); } setAlertTypesIndex(index); } catch (e) { @@ -251,6 +251,14 @@ export const AlertForm = ({ : null; function addActionType(actionTypeModel: ActionTypeModel) { + if (!defaultActionGroupId) { + toastNotifications!.addDanger({ + title: i18n.translate('xpack.triggersActionsUI.sections.alertForm.unableToAddAction', { + defaultMessage: 'Unable to add action, because default action group is not defined', + }), + }); + return; + } setIsAddActionPanelOpen(false); const actionTypeConnectors = connectors.filter( field => field.actionTypeId === actionTypeModel.id @@ -266,7 +274,7 @@ export const AlertForm = ({ alert.actions.push({ id: '', actionTypeId: actionTypeModel.id, - group: defaultActionGroup?.id ?? 'Alert', + group: defaultActionGroupId, params: {}, }); setActionProperty('id', freeConnectors[0].id, alert.actions.length - 1); @@ -278,7 +286,7 @@ export const AlertForm = ({ alert.actions.push({ id: '', actionTypeId: actionTypeModel.id, - group: defaultActionGroup?.id ?? 'Alert', + group: defaultActionGroupId, params: {}, }); setActionProperty('id', alert.actions.length, alert.actions.length - 1); @@ -294,12 +302,8 @@ export const AlertForm = ({ onClick={() => { setAlertProperty('alertTypeId', item.id); setAlertTypeModel(item); - if ( - alertTypesIndex && - alertTypesIndex[item.id] && - alertTypesIndex[item.id].actionGroups.length > 0 - ) { - setDefaultActionGroup(alertTypesIndex[item.id].actionGroups[0]); + if (alertTypesIndex && alertTypesIndex[item.id]) { + setDefaultActionGroupId(alertTypesIndex[item.id].defaultActionGroupId); } }} > @@ -356,7 +360,7 @@ export const AlertForm = ({ id, })); const actionTypeRegisterd = actionTypeRegistry.get(actionConnector.actionTypeId); - if (actionTypeRegisterd === null || actionItem.group !== defaultActionGroup?.id) return null; + if (!actionTypeRegisterd || actionItem.group !== defaultActionGroupId) return null; const ParamsFieldsComponent = actionTypeRegisterd.actionParamsFields; const actionParamsErrors: { errors: IErrorObject } = Object.keys(actionsErrors).length > 0 ? actionsErrors[actionItem.id] : { errors: {} }; @@ -368,7 +372,7 @@ export const AlertForm = ({ id={index.toString()} className="euiAccordionForm" buttonContentClassName="euiAccordionForm__button" - data-test-subj="alertActionAccordion" + data-test-subj={`alertActionAccordion-${defaultActionGroupId}`} buttonContent={ @@ -465,7 +469,9 @@ export const AlertForm = ({ errors={actionParamsErrors.errors} editAction={setActionParamsProperty} messageVariables={ - alertTypesIndex ? alertTypesIndex[alert.alertTypeId].actionVariables : undefined + alertTypesIndex && alertTypesIndex[alert.alertTypeId] + ? alertTypesIndex[alert.alertTypeId].actionVariables + : undefined } defaultMessage={alertTypeModel?.defaultActionMessage ?? undefined} /> @@ -479,7 +485,7 @@ export const AlertForm = ({ ? actionTypesIndex[actionItem.actionTypeId].name : actionItem.actionTypeId; const actionTypeRegisterd = actionTypeRegistry.get(actionItem.actionTypeId); - if (actionTypeRegisterd === null || actionItem.group !== defaultActionGroup?.id) return null; + if (!actionTypeRegisterd || actionItem.group !== defaultActionGroupId) return null; return ( diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx index c67954bdc44fd8d..d2cf2decc4a1602 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx @@ -45,6 +45,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -65,6 +66,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -92,6 +94,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -141,6 +144,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; const actionTypes: ActionType[] = [ @@ -191,6 +195,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -215,6 +220,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -239,6 +245,7 @@ describe('alert_details', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -268,6 +275,7 @@ describe('enable button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -293,6 +301,7 @@ describe('enable button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -318,6 +327,7 @@ describe('enable button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -352,6 +362,7 @@ describe('enable button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -389,6 +400,7 @@ describe('mute button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -415,6 +427,7 @@ describe('mute button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -441,6 +454,7 @@ describe('mute button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -476,6 +490,7 @@ describe('mute button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; @@ -511,6 +526,7 @@ describe('mute button', () => { id: '.noop', name: 'No Op', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', actionVariables: [], }; diff --git a/x-pack/plugins/triggers_actions_ui/public/types.ts b/x-pack/plugins/triggers_actions_ui/public/types.ts index aa1d3d068ed77b1..2119c08bedc31bf 100644 --- a/x-pack/plugins/triggers_actions_ui/public/types.ts +++ b/x-pack/plugins/triggers_actions_ui/public/types.ts @@ -3,6 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { ActionGroup } from '../../alerting/common'; import { ActionType } from '../../actions/common'; import { TypeRegistry } from './application/type_registry'; import { @@ -70,17 +71,16 @@ export interface ActionConnectorTableItem extends ActionConnector { actionType: ActionType['name']; } -export interface ActionGroup { - id: string; - name: string; -} export interface AlertType { id: string; name: string; actionGroups: ActionGroup[]; actionVariables: string[]; + defaultActionGroupId: ActionGroup['id']; } +export type SanitizedAlertType = Omit; + export type AlertWithoutId = Omit; export interface AlertTableItem extends Alert { diff --git a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts index b06e0c9e0f8cdda..2e7674f2b3eb7d5 100644 --- a/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts +++ b/x-pack/test/alerting_api_integration/common/fixtures/plugins/alerts/index.ts @@ -206,6 +206,7 @@ export default function(kibana: any) { { id: 'default', name: 'Default' }, { id: 'other', name: 'Other' }, ], + defaultActionGroupId: 'default', async executor(alertExecutorOptions: AlertExecutorOptions) { const { services, @@ -260,6 +261,7 @@ export default function(kibana: any) { { id: 'default', name: 'Default' }, { id: 'other', name: 'Other' }, ], + defaultActionGroupId: 'default', async executor(alertExecutorOptions: AlertExecutorOptions) { const { services, state } = alertExecutorOptions; const group = 'default'; @@ -281,7 +283,13 @@ export default function(kibana: any) { const neverFiringAlertType: AlertType = { id: 'test.never-firing', name: 'Test: Never firing', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', async executor({ services, params, state }: AlertExecutorOptions) { await services.callCluster('index', { index: params.index, @@ -301,7 +309,13 @@ export default function(kibana: any) { const failingAlertType: AlertType = { id: 'test.failing', name: 'Test: Failing', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', async executor({ services, params, state }: AlertExecutorOptions) { await services.callCluster('index', { index: params.index, @@ -319,7 +333,13 @@ export default function(kibana: any) { const authorizationAlertType: AlertType = { id: 'test.authorization', name: 'Test: Authorization', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', validate: { params: schema.object({ callClusterAuthorizationIndex: schema.string(), @@ -378,7 +398,13 @@ export default function(kibana: any) { const validationAlertType: AlertType = { id: 'test.validation', name: 'Test: Validation', - actionGroups: [], + actionGroups: [ + { + id: 'default', + name: 'Default', + }, + ], + defaultActionGroupId: 'default', validate: { params: schema.object({ param1: schema.string(), @@ -390,6 +416,7 @@ export default function(kibana: any) { id: 'test.noop', name: 'Test: Noop', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', async executor({ services, params, state }: AlertExecutorOptions) {}, }; server.newPlatform.setup.plugins.alerting.registerType(alwaysFiringAlertType); diff --git a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts index 517a60f77849e08..30c1548b7db2a53 100644 --- a/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts +++ b/x-pack/test/alerting_api_integration/security_and_spaces/tests/alerting/list_alert_types.ts @@ -41,6 +41,7 @@ export default function listAlertTypes({ getService }: FtrProviderContext) { ); expect(fixtureAlertType).to.eql({ actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', id: 'test.noop', name: 'Test: Noop', }); diff --git a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts index 55570744f6af95d..590de1ea7ce0b72 100644 --- a/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts +++ b/x-pack/test/alerting_api_integration/spaces_only/tests/alerting/list_alert_types.ts @@ -21,6 +21,7 @@ export default function listAlertTypes({ getService }: FtrProviderContext) { const fixtureAlertType = response.body.find((alertType: any) => alertType.id === 'test.noop'); expect(fixtureAlertType).to.eql({ actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', id: 'test.noop', name: 'Test: Noop', }); diff --git a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/index.ts b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/index.ts index 678707af40bae58..9069044b83ed9fe 100644 --- a/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/index.ts +++ b/x-pack/test/functional_with_es_ssl/fixtures/plugins/alerts/index.ts @@ -23,6 +23,7 @@ function createNoopAlertType(setupContract: any) { id: 'test.noop', name: 'Test: Noop', actionGroups: [{ id: 'default', name: 'Default' }], + defaultActionGroupId: 'default', async executor() {}, }; setupContract.registerType(noopAlertType); diff --git a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts index 071067ffa85cbd9..3529d8f3ae9c97f 100644 --- a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts +++ b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts @@ -59,7 +59,9 @@ export function resolveCopyToSpaceConflictsSuite( .then((response: any) => response.body); }; - const getObjectsAtSpace = async (spaceId: string): Promise<[SavedObject, SavedObject]> => { + const getObjectsAtSpace = async ( + spaceId: string + ): Promise<[SavedObject, SavedObject]> => { const dashboard = await getDashboardAtSpace(spaceId); const visualization = await getVisualizationAtSpace(spaceId); return [dashboard, visualization]; diff --git a/yarn.lock b/yarn.lock index 2caaac974dfaded..8ea23c17b8b8b22 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1680,7 +1680,7 @@ dependencies: regenerator-runtime "^0.13.2" -"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.3.1", "@babel/runtime@^7.4.0", "@babel/runtime@^7.4.2", "@babel/runtime@^7.4.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.1", "@babel/runtime@^7.5.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.0", "@babel/runtime@^7.6.2", "@babel/runtime@^7.6.3", "@babel/runtime@^7.7.2": +"@babel/runtime@^7.0.0", "@babel/runtime@^7.1.2", "@babel/runtime@^7.4.0", "@babel/runtime@^7.4.2", "@babel/runtime@^7.4.4", "@babel/runtime@^7.4.5", "@babel/runtime@^7.5.0", "@babel/runtime@^7.5.1", "@babel/runtime@^7.5.4", "@babel/runtime@^7.5.5", "@babel/runtime@^7.6.0", "@babel/runtime@^7.6.2", "@babel/runtime@^7.6.3", "@babel/runtime@^7.7.2": version "7.7.6" resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.7.6.tgz#d18c511121aff1b4f2cd1d452f1bac9601dd830f" integrity sha512-BWAJxpNVa0QlE5gZdWjSxXtemZyZ9RmrmVozxt3NUXeZhVIJ5ANyqmMc0JDrivBZyxUuQvFxlvH4OWWOogGfUw== @@ -1880,10 +1880,10 @@ dependencies: "@elastic/apm-rum-core" "^4.7.0" -"@elastic/charts@^17.0.2": - version "17.0.2" - resolved "https://registry.yarnpkg.com/@elastic/charts/-/charts-17.0.2.tgz#0bd2cb7b78bd60255eed2a9b0ce5049a62dc5d8a" - integrity sha512-hz31Yma/HSdu9tRS/05xNXY+YuaHOadD9Gd+eh7ankNlJJOFI4IRV6F8BMnloeWYedNXBSTp4susFLwJNQQ+0w== +"@elastic/charts@^17.1.1": + version "17.1.1" + resolved "https://registry.yarnpkg.com/@elastic/charts/-/charts-17.1.1.tgz#28df3d1be445aa4951fac59dec0831760a1ea034" + integrity sha512-zI3ZHy51tqlsEenDbHFWlL6qbDMvrQXeuV+UFleILtVcfI0r4Lk7DtSbx4GQlHcBuVvvAk1MRdYKNGA0IYWP6w== dependencies: "@types/d3-shape" "^1.3.1" classnames "^2.2.6" @@ -1892,14 +1892,11 @@ d3-color "^1.4.0" d3-scale "^1.0.7" d3-shape "^1.3.4" - fast-deep-equal "^3.1.1" - konva "^4.0.18" newtype-ts "^0.2.4" + path2d-polyfill "^0.4.2" prop-types "^15.7.2" re-reselect "^3.4.0" - react-konva "16.10.1-0" react-redux "^7.1.0" - react-spring "^8.0.8" redux "^4.0.4" reselect "^4.0.0" resize-observer-polyfill "^1.5.1" @@ -19008,11 +19005,6 @@ known-css-properties@^0.3.0: resolved "https://registry.yarnpkg.com/known-css-properties/-/known-css-properties-0.3.0.tgz#a3d135bbfc60ee8c6eacf2f7e7e6f2d4755e49a4" integrity sha512-QMQcnKAiQccfQTqtBh/qwquGZ2XK/DXND1jrcN9M8gMMy99Gwla7GQjndVUsEqIaRyP6bsFRuhwRj5poafBGJQ== -konva@^4.0.18: - version "4.0.18" - resolved "https://registry.yarnpkg.com/konva/-/konva-4.0.18.tgz#43e614c9b22827183506d4a6b3b474f90187b469" - integrity sha512-Tlq0v7QHr8q73xr1cKjHdQl41oHC06IOldPO+ukjt99G74NgoU0TVouvPIFpW2whA9t3xNk/+/VJcc3XPcboOw== - kopy@^8.2.0: version "8.2.5" resolved "https://registry.yarnpkg.com/kopy/-/kopy-8.2.5.tgz#6c95f312e981ab917680d7e5de3cdf29a1bf221f" @@ -22917,6 +22909,11 @@ path-type@^4.0.0: resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b" integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw== +path2d-polyfill@^0.4.2: + version "0.4.2" + resolved "https://registry.yarnpkg.com/path2d-polyfill/-/path2d-polyfill-0.4.2.tgz#594d3103838ef6b9dd4a7fd498fe9a88f1f28531" + integrity sha512-JSeAnUfkFjl+Ml/EZL898ivMSbGHrOH63Mirx5EQ1ycJiryHDmj1Q7Are+uEPvenVGCUN9YbolfGfyUewJfJEg== + pathval@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" @@ -24504,14 +24501,6 @@ react-is@~16.3.0: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.3.2.tgz#f4d3d0e2f5fbb6ac46450641eb2e25bf05d36b22" integrity sha512-ybEM7YOr4yBgFd6w8dJqwxegqZGJNBZl6U27HnGKuTZmDvVrD5quWOK/wAnMywiZzW+Qsk+l4X2c70+thp/A8Q== -react-konva@16.10.1-0: - version "16.10.1-0" - resolved "https://registry.yarnpkg.com/react-konva/-/react-konva-16.10.1-0.tgz#f8cc2c95374933069e891a6c714c70d0fdc77e68" - integrity sha512-N0Zi3TcWmUxb2d7y1DUDQhRA+WIcqk54DQmmUmJSadj+fS0bg6iZDebQSEQC8dMbjnLHc/338xRT4a4718PEiw== - dependencies: - react-reconciler "^0.22.1" - scheduler "^0.16.1" - react-lib-adler32@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/react-lib-adler32/-/react-lib-adler32-1.0.3.tgz#63df1aed274eabcc1c5067077ea281ec30888ba7" @@ -24647,16 +24636,6 @@ react-portal@^3.2.0: dependencies: prop-types "^15.5.8" -react-reconciler@^0.22.1: - version "0.22.2" - resolved "https://registry.yarnpkg.com/react-reconciler/-/react-reconciler-0.22.2.tgz#e8a10374fec8fee7c5cd0cf3cd05626f1b134d3e" - integrity sha512-MLX5Y2pNLsdXzWz/GLNhhYkdLOvxEtw2IGqVCzkiRdSFSHRjujI9gfTOQ3rV5z8toTBxSZ2qrRkRUo97mmEdhA== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - prop-types "^15.6.2" - scheduler "^0.16.2" - react-redux@^5.0.7, react-redux@^5.1.2: version "5.1.2" resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-5.1.2.tgz#b19cf9e21d694422727bf798e934a916c4080f57" @@ -24798,14 +24777,6 @@ react-sizeme@^2.6.7: shallowequal "^1.1.0" throttle-debounce "^2.1.0" -react-spring@^8.0.8: - version "8.0.20" - resolved "https://registry.yarnpkg.com/react-spring/-/react-spring-8.0.20.tgz#e25967f6059364b09cf0339168d73014e87c9d17" - integrity sha512-40ZUQ5uI5YHsoQWLPchWNcEUh6zQ6qvcVDeTI2vW10ldoCN3PvDsII9wBH2xEbMl+BQvYmHzGdfLTQxPxJWGnQ== - dependencies: - "@babel/runtime" "^7.3.1" - prop-types "^15.5.8" - react-sticky@^6.0.3: version "6.0.3" resolved "https://registry.yarnpkg.com/react-sticky/-/react-sticky-6.0.3.tgz#7a18b643e1863da113d7f7036118d2a75d9ecde4" @@ -26570,14 +26541,6 @@ saxes@^3.1.9: dependencies: xmlchars "^2.1.1" -scheduler@^0.16.1, scheduler@^0.16.2: - version "0.16.2" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.16.2.tgz#f74cd9d33eff6fc554edfb79864868e4819132c1" - integrity sha512-BqYVWqwz6s1wZMhjFvLfVR5WXP7ZY32M/wYPo04CcuPM7XZEbV2TBNW7Z0UkguPTl0dWMA59VbNXxK6q+pHItg== - dependencies: - loose-envify "^1.1.0" - object-assign "^4.1.1" - scheduler@^0.18.0: version "0.18.0" resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.18.0.tgz#5901ad6659bc1d8f3fdaf36eb7a67b0d6746b1c4"