Skip to content

Commit

Permalink
Merge branch 'master' into fix/112795
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Sep 30, 2021
2 parents 4b33f6c + bbf3d4b commit b0d5b4e
Show file tree
Hide file tree
Showing 172 changed files with 6,178 additions and 2,259 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
"js-levenshtein": "^1.1.6",
"js-search": "^1.4.3",
"js-sha256": "^0.9.0",
"js-sql-parser": "^1.4.1",
"js-yaml": "^3.14.0",
"json-stable-stringify": "^1.0.1",
"json-stringify-pretty-compact": "1.2.0",
Expand Down Expand Up @@ -298,7 +299,6 @@
"nock": "12.0.3",
"node-fetch": "^2.6.1",
"node-forge": "^0.10.0",
"node-sql-parser": "^3.6.1",
"nodemailer": "^6.6.2",
"normalize-path": "^3.0.0",
"object-hash": "^1.3.1",
Expand Down
22 changes: 17 additions & 5 deletions src/core/public/saved_objects/saved_objects_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ describe('SavedObjectsClient', () => {
});

describe('#resolve', () => {
beforeEach(() => {
function mockResolvedObjects(...objects: Array<Record<string, unknown>>) {
http.fetch.mockResolvedValue({
resolved_objects: [
{ saved_object: doc, outcome: 'conflict', alias_target_id: 'another-id' },
],
resolved_objects: objects.map((obj) => ({
saved_object: obj,
outcome: 'conflict',
alias_target_id: 'another-id',
})),
});
});
}

test('rejects if `type` parameter is undefined', () => {
return expect(
Expand All @@ -176,6 +178,7 @@ describe('SavedObjectsClient', () => {
});

test('makes HTTP call', async () => {
mockResolvedObjects(doc);
await savedObjectsClient.resolve(doc.type, doc.id);
expect(http.fetch.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Expand All @@ -191,10 +194,12 @@ describe('SavedObjectsClient', () => {

test('batches several #resolve calls into a single HTTP call', async () => {
// Await #resolve call to ensure batchQueue is empty and throttle has reset
mockResolvedObjects({ ...doc, type: 'type2' });
await savedObjectsClient.resolve('type2', doc.id);
http.fetch.mockClear();

// Make two #resolve calls right after one another
mockResolvedObjects({ ...doc, type: 'type1' }, { ...doc, type: 'type0' });
savedObjectsClient.resolve('type1', doc.id);
await savedObjectsClient.resolve('type0', doc.id);
expect(http.fetch.mock.calls).toMatchInlineSnapshot(`
Expand All @@ -213,9 +218,11 @@ describe('SavedObjectsClient', () => {

test('removes duplicates when calling `_bulk_resolve`', async () => {
// Await #resolve call to ensure batchQueue is empty and throttle has reset
mockResolvedObjects({ ...doc, type: 'type2' });
await savedObjectsClient.resolve('type2', doc.id);
http.fetch.mockClear();

mockResolvedObjects(doc, { ...doc, type: 'some-type', id: 'some-id' }); // the client will only request two objects, so we only mock two results
savedObjectsClient.resolve(doc.type, doc.id);
savedObjectsClient.resolve('some-type', 'some-id');
await savedObjectsClient.resolve(doc.type, doc.id);
Expand All @@ -235,9 +242,11 @@ describe('SavedObjectsClient', () => {

test('resolves with correct object when there are duplicates present', async () => {
// Await #resolve call to ensure batchQueue is empty and throttle has reset
mockResolvedObjects({ ...doc, type: 'type2' });
await savedObjectsClient.resolve('type2', doc.id);
http.fetch.mockClear();

mockResolvedObjects(doc);
const call1 = savedObjectsClient.resolve(doc.type, doc.id);
const objFromCall2 = await savedObjectsClient.resolve(doc.type, doc.id);
const objFromCall1 = await call1;
Expand All @@ -252,8 +261,10 @@ describe('SavedObjectsClient', () => {
test('do not share instances or references between duplicate callers', async () => {
// Await #resolve call to ensure batchQueue is empty and throttle has reset
await savedObjectsClient.resolve('type2', doc.id);
mockResolvedObjects({ ...doc, type: 'type2' });
http.fetch.mockClear();

mockResolvedObjects(doc);
const call1 = savedObjectsClient.resolve(doc.type, doc.id);
const objFromCall2 = await savedObjectsClient.resolve(doc.type, doc.id);
const objFromCall1 = await call1;
Expand All @@ -263,6 +274,7 @@ describe('SavedObjectsClient', () => {
});

test('resolves with ResolvedSimpleSavedObject instance', async () => {
mockResolvedObjects(doc);
const result = await savedObjectsClient.resolve(doc.type, doc.id);
expect(result.saved_object).toBeInstanceOf(SimpleSavedObject);
expect(result.saved_object.type).toBe(doc.type);
Expand Down
56 changes: 31 additions & 25 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ interface ObjectTypeAndId {
type: string;
}

const getObjectsToFetch = (
queue: Array<BatchGetQueueEntry | BatchResolveQueueEntry>
): ObjectTypeAndId[] => {
const getObjectsToFetch = (queue: BatchGetQueueEntry[]): ObjectTypeAndId[] => {
const objects: ObjectTypeAndId[] = [];
const inserted = new Set<string>();
queue.forEach(({ id, type }) => {
Expand All @@ -165,6 +163,24 @@ const getObjectsToFetch = (
return objects;
};

const getObjectsToResolve = (queue: BatchResolveQueueEntry[]) => {
const responseIndices: number[] = [];
const objectsToResolve: ObjectTypeAndId[] = [];
const inserted = new Map<string, number>();
queue.forEach(({ id, type }, currentIndex) => {
const key = `${type}|${id}`;
const indexForTypeAndId = inserted.get(key);
if (indexForTypeAndId === undefined) {
inserted.set(key, currentIndex);
objectsToResolve.push({ id, type });
responseIndices.push(currentIndex);
} else {
responseIndices.push(indexForTypeAndId);
}
});
return { objectsToResolve, responseIndices };
};

/**
* Saved Objects is Kibana's data persisentence mechanism allowing plugins to
* use Elasticsearch for storing plugin state. The client-side
Expand Down Expand Up @@ -224,28 +240,18 @@ export class SavedObjectsClient {
this.batchResolveQueue = [];

try {
const objectsToFetch = getObjectsToFetch(queue);
const { resolved_objects: savedObjects } = await this.performBulkResolve(objectsToFetch);

queue.forEach((queueItem) => {
const foundObject = savedObjects.find((resolveResponse) => {
return (
resolveResponse.saved_object.id === queueItem.id &&
resolveResponse.saved_object.type === queueItem.type
);
});

if (foundObject) {
// multiple calls may have been requested the same object.
// we need to clone to avoid sharing references between the instances
queueItem.resolve(this.createResolvedSavedObject(cloneDeep(foundObject)));
} else {
queueItem.resolve(
this.createResolvedSavedObject({
saved_object: pick(queueItem, ['id', 'type']),
} as SavedObjectsResolveResponse)
);
}
const { objectsToResolve, responseIndices } = getObjectsToResolve(queue);
const { resolved_objects: resolvedObjects } = await this.performBulkResolve(
objectsToResolve
);

queue.forEach((queueItem, i) => {
// This differs from the older processBatchGetQueue approach because the resolved object IDs are *not* guaranteed to be the same.
// Instead, we rely on the guarantee that the objects in the bulkResolve response will be in the same order as the requests.
// However, we still need to clone the response object because we deduplicate batched requests.
const responseIndex = responseIndices[i];
const clone = cloneDeep(resolvedObjects[responseIndex]);
queueItem.resolve(this.createResolvedSavedObject(clone));
});
} catch (err) {
queue.forEach((queueItem) => {
Expand Down
1 change: 0 additions & 1 deletion src/dev/license_checker/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ export const DEV_ONLY_LICENSE_ALLOWED = ['MPL-2.0'];
export const LICENSE_OVERRIDES = {
'jsts@1.6.2': ['Eclipse Distribution License - v 1.0'], // cf. https://github.com/bjornharrtell/jsts
'@mapbox/jsonlint-lines-primitives@2.0.2': ['MIT'], // license in readme https://github.com/tmcw/jsonlint
'node-sql-parser@3.6.1': ['(GPL-2.0 OR MIT)'], // GPL-2.0* https://github.com/taozhi8833998/node-sql-parser
'@elastic/ems-client@7.15.0': ['Elastic License 2.0'],
'@elastic/eui@38.0.1': ['SSPL-1.0 OR Elastic License 2.0'],

Expand Down
7 changes: 6 additions & 1 deletion src/plugins/custom_integrations/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ export const CATEGORY_DISPLAY = {

export type Category = keyof typeof CATEGORY_DISPLAY;

export interface CustomIntegrationIcon {
src: string;
type: 'eui' | 'svg';
}

export interface CustomIntegration {
id: string;
title: string;
description: string;
type: 'ui_link';
uiInternalPath: string;
isBeta: boolean;
icons: Array<{ src: string; type: string }>;
icons: CustomIntegrationIcon[];
categories: Category[];
shipper: string;
}
Expand Down
8 changes: 3 additions & 5 deletions src/plugins/custom_integrations/server/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
* Side Public License, v 1.
*/

import type { MockedKeys } from '@kbn/utility-types/jest';

import { CustomIntegrationsPluginSetup } from '../server';

function createCustomIntegrationsSetup(): MockedKeys<CustomIntegrationsPluginSetup> {
const mock = {
function createCustomIntegrationsSetup(): jest.Mocked<CustomIntegrationsPluginSetup> {
const mock: jest.Mocked<CustomIntegrationsPluginSetup> = {
registerCustomIntegration: jest.fn(),
getAppendCustomIntegrations: jest.fn(),
};

return mock as MockedKeys<CustomIntegrationsPluginSetup>;
return mock;
}

export const customIntegrationsMock = {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/dashboard/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"data",
"embeddable",
"inspector",
"kibanaLegacy",
"navigation",
"savedObjects",
"share",
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/dashboard/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import { createKbnUrlTracker } from './services/kibana_utils';
import { UsageCollectionSetup } from './services/usage_collection';
import { UiActionsSetup, UiActionsStart } from './services/ui_actions';
import { PresentationUtilPluginStart } from './services/presentation_util';
import { KibanaLegacySetup, KibanaLegacyStart } from './services/kibana_legacy';
import { FeatureCatalogueCategory, HomePublicPluginSetup } from './services/home';
import { NavigationPublicPluginStart as NavigationStart } from './services/navigation';
import { DataPublicPluginSetup, DataPublicPluginStart, esFilters } from './services/data';
Expand Down Expand Up @@ -98,7 +97,6 @@ export interface DashboardSetupDependencies {
data: DataPublicPluginSetup;
embeddable: EmbeddableSetup;
home?: HomePublicPluginSetup;
kibanaLegacy: KibanaLegacySetup;
urlForwarding: UrlForwardingSetup;
share?: SharePluginSetup;
uiActions: UiActionsSetup;
Expand All @@ -107,7 +105,6 @@ export interface DashboardSetupDependencies {

export interface DashboardStartDependencies {
data: DataPublicPluginStart;
kibanaLegacy: KibanaLegacyStart;
urlForwarding: UrlForwardingStart;
embeddable: EmbeddableStart;
inspector: InspectorStartContract;
Expand Down
9 changes: 0 additions & 9 deletions src/plugins/dashboard/public/services/kibana_legacy.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/plugins/dashboard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"references": [
{ "path": "../../core/tsconfig.json" },
{ "path": "../inspector/tsconfig.json" },
{ "path": "../kibana_legacy/tsconfig.json" },
{ "path": "../kibana_react/tsconfig.json" },
{ "path": "../kibana_utils/tsconfig.json" },
{ "path": "../share/tsconfig.json" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,18 +504,21 @@ export const useField = <T, FormType = FormData, I = T>(
const { resetValue = true, defaultValue: updatedDefaultValue } = resetOptions;

setPristine(true);
setIsModified(false);
setValidating(false);
setIsChangingValue(false);
setIsValidated(false);
setStateErrors([]);

if (resetValue) {
hasBeenReset.current = true;
const newValue = deserializeValue(updatedDefaultValue ?? defaultValue);
// updateStateIfMounted('value', newValue);
setValue(newValue);
return newValue;

if (isMounted.current) {
setIsModified(false);
setValidating(false);
setIsChangingValue(false);
setIsValidated(false);
setStateErrors([]);

if (resetValue) {
hasBeenReset.current = true;
const newValue = deserializeValue(updatedDefaultValue ?? defaultValue);
// updateStateIfMounted('value', newValue);
setValue(newValue);
return newValue;
}
}
},
[deserializeValue, defaultValue, setValue, setStateErrors]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b0d5b4e

Please sign in to comment.