Skip to content

Commit

Permalink
Merge branch 'main' into chart_expressions-xy-extended_layers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuznietsov authored May 3, 2022
2 parents c407547 + 71f2099 commit 168b032
Show file tree
Hide file tree
Showing 117 changed files with 2,617 additions and 413 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Import saved objects from given stream. See the [options](./kibana-plugin-core-s
<b>Signature:</b>

```typescript
import({ readStream, createNewCopies, namespace, overwrite, }: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse>;
import({ readStream, createNewCopies, namespace, overwrite, refresh, }: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| { readStream, createNewCopies, namespace, overwrite, } | SavedObjectsImportOptions | |
| { readStream, createNewCopies, namespace, overwrite, refresh, } | SavedObjectsImportOptions | |

<b>Returns:</b>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ export declare class SavedObjectsImporter

| Method | Modifiers | Description |
| --- | --- | --- |
| [import({ readStream, createNewCopies, namespace, overwrite, })](./kibana-plugin-core-server.savedobjectsimporter.import.md) | | Import saved objects from given stream. See the [options](./kibana-plugin-core-server.savedobjectsimportoptions.md) for more detailed information. |
| [import({ readStream, createNewCopies, namespace, overwrite, refresh, })](./kibana-plugin-core-server.savedobjectsimporter.import.md) | | Import saved objects from given stream. See the [options](./kibana-plugin-core-server.savedobjectsimportoptions.md) for more detailed information. |
| [resolveImportErrors({ readStream, createNewCopies, namespace, retries, })](./kibana-plugin-core-server.savedobjectsimporter.resolveimporterrors.md) | | Resolve and return saved object import errors. See the [options](./kibana-plugin-core-server.savedobjectsresolveimporterrorsoptions.md) for more detailed information. |

Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface SavedObjectsImportOptions
| [namespace?](./kibana-plugin-core-server.savedobjectsimportoptions.namespace.md) | string | <i>(Optional)</i> if specified, will import in given namespace, else will import as global object |
| [overwrite](./kibana-plugin-core-server.savedobjectsimportoptions.overwrite.md) | boolean | If true, will override existing object if present. Note: this has no effect when used with the <code>createNewCopies</code> option. |
| [readStream](./kibana-plugin-core-server.savedobjectsimportoptions.readstream.md) | Readable | The stream of [saved objects](./kibana-plugin-core-server.savedobject.md) to import |
| [refresh?](./kibana-plugin-core-server.savedobjectsimportoptions.refresh.md) | boolean \| 'wait\_for' | <i>(Optional)</i> Refresh setting, defaults to <code>wait_for</code> |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsImportOptions](./kibana-plugin-core-server.savedobjectsimportoptions.md) &gt; [refresh](./kibana-plugin-core-server.savedobjectsimportoptions.refresh.md)

## SavedObjectsImportOptions.refresh property

Refresh setting, defaults to `wait_for`

<b>Signature:</b>

```typescript
refresh?: boolean | 'wait_for';
```
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pageLoadAssetSize:
sessionView: 77750
cloudSecurityPosture: 19109
visTypeGauge: 24113
unifiedSearch: 104869
unifiedSearch: 71059
data: 454087
eventAnnotation: 19334
screenshotting: 22870
Expand Down
4 changes: 4 additions & 0 deletions src/core/server/saved_objects/import/import_saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export interface ImportSavedObjectsOptions {
objectLimit: number;
/** If true, will override existing object if present. Note: this has no effect when used with the `createNewCopies` option. */
overwrite: boolean;
/** Refresh setting, defaults to `wait_for` */
refresh?: boolean | 'wait_for';
/** {@link SavedObjectsClientContract | client} to use to perform the import operation */
savedObjectsClient: SavedObjectsClientContract;
/** The registry of all known saved object types */
Expand Down Expand Up @@ -62,6 +64,7 @@ export async function importSavedObjectsFromStream({
typeRegistry,
importHooks,
namespace,
refresh,
}: ImportSavedObjectsOptions): Promise<SavedObjectsImportResponse> {
let errorAccumulator: SavedObjectsImportFailure[] = [];
const supportedTypes = typeRegistry.getImportableAndExportableTypes().map((type) => type.name);
Expand Down Expand Up @@ -141,6 +144,7 @@ export async function importSavedObjectsFromStream({
importStateMap,
overwrite,
namespace,
refresh,
};
const createSavedObjectsResult = await createSavedObjects(createSavedObjectsParams);
errorAccumulator = [...errorAccumulator, ...createSavedObjectsResult.errors];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface CreateSavedObjectsParams<T> {
importStateMap: ImportStateMap;
namespace?: string;
overwrite?: boolean;
refresh?: boolean | 'wait_for';
}
export interface CreateSavedObjectsResult<T> {
createdObjects: Array<CreatedObject<T>>;
Expand All @@ -35,6 +36,7 @@ export const createSavedObjects = async <T>({
importStateMap,
namespace,
overwrite,
refresh,
}: CreateSavedObjectsParams<T>): Promise<CreateSavedObjectsResult<T>> => {
// filter out any objects that resulted in errors
const errorSet = accumulatedErrors.reduce(
Expand Down Expand Up @@ -87,6 +89,7 @@ export const createSavedObjects = async <T>({
const bulkCreateResponse = await savedObjectsClient.bulkCreate(objectsToCreate, {
namespace,
overwrite,
refresh,
});
expectedResults = bulkCreateResponse.saved_objects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ export class SavedObjectsImporter {
createNewCopies,
namespace,
overwrite,
refresh,
}: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse> {
return importSavedObjectsFromStream({
readStream,
createNewCopies,
namespace,
overwrite,
refresh,
objectLimit: this.#importSizeLimit,
savedObjectsClient: this.#savedObjectsClient,
typeRegistry: this.#typeRegistry,
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/import/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ export interface SavedObjectsImportOptions {
namespace?: string;
/** If true, will create new copies of import objects, each with a random `id` and undefined `originId`. */
createNewCopies: boolean;
/** Refresh setting, defaults to `wait_for` */
refresh?: boolean | 'wait_for';
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/core/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2541,7 +2541,7 @@ export class SavedObjectsImporter {
typeRegistry: ISavedObjectTypeRegistry;
importSizeLimit: number;
});
import({ readStream, createNewCopies, namespace, overwrite, }: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse>;
import({ readStream, createNewCopies, namespace, overwrite, refresh, }: SavedObjectsImportOptions): Promise<SavedObjectsImportResponse>;
resolveImportErrors({ readStream, createNewCopies, namespace, retries, }: SavedObjectsResolveImportErrorsOptions): Promise<SavedObjectsImportResponse>;
}

Expand Down Expand Up @@ -2604,6 +2604,7 @@ export interface SavedObjectsImportOptions {
namespace?: string;
overwrite: boolean;
readStream: Readable;
refresh?: boolean | 'wait_for';
}

// @public
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { chartPluginMock } from '@kbn/charts-plugin/public/mocks';
import { dataPluginMock } from '@kbn/data-plugin/public/mocks';
import { fieldFormatsServiceMock } from '@kbn/field-formats-plugin/public/mocks';
import type { Datatable } from '@kbn/expressions-plugin/public';
import { shallow, mount } from 'enzyme';
import { shallow } from 'enzyme';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { findTestSubject } from '@elastic/eui/lib/test';
import { act } from 'react-dom/test-utils';
import PartitionVisComponent, { PartitionVisComponentProps } from './partition_vis_component';
Expand Down Expand Up @@ -143,7 +144,7 @@ describe('PartitionVisComponent', function () {
});

it('renders the legend toggle component', async () => {
const component = mount(<PartitionVisComponent {...wrapperProps} />);
const component = mountWithIntl(<PartitionVisComponent {...wrapperProps} />);
await actWithTimeout(async () => {
await component.update();
});
Expand All @@ -154,7 +155,7 @@ describe('PartitionVisComponent', function () {
});

it('hides the legend if the legend toggle is clicked', async () => {
const component = mount(<PartitionVisComponent {...wrapperProps} />);
const component = mountWithIntl(<PartitionVisComponent {...wrapperProps} />);
await actWithTimeout(async () => {
await component.update();
});
Expand Down Expand Up @@ -233,7 +234,7 @@ describe('PartitionVisComponent', function () {
],
} as unknown as Datatable;
const newProps = { ...wrapperProps, visData: newVisData };
const component = mount(<PartitionVisComponent {...newProps} />);
const component = mountWithIntl(<PartitionVisComponent {...newProps} />);
expect(findTestSubject(component, 'partitionVisEmptyValues').text()).toEqual(
'No results found'
);
Expand Down Expand Up @@ -264,7 +265,7 @@ describe('PartitionVisComponent', function () {
],
} as unknown as Datatable;
const newProps = { ...wrapperProps, visData: newVisData };
const component = mount(<PartitionVisComponent {...newProps} />);
const component = mountWithIntl(<PartitionVisComponent {...newProps} />);
expect(findTestSubject(component, 'partitionVisNegativeValues').text()).toEqual(
"Pie chart can't render with negative values."
);
Expand Down
1 change: 1 addition & 0 deletions src/plugins/embeddable/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type {
EmbeddableStateWithType,
PanelState,
EmbeddablePersistableStateService,
EmbeddableRegistryDefinition,
} from './types';
export { ViewMode } from './types';
export type { SavedObjectEmbeddableInput } from './lib';
Expand Down
12 changes: 11 additions & 1 deletion src/plugins/embeddable/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

import type { SerializableRecord } from '@kbn/utility-types';
import type { KibanaExecutionContext } from '@kbn/core/public';
import { PersistableStateService, PersistableState } from '@kbn/kibana-utils-plugin/common';
import type {
PersistableStateService,
PersistableState,
PersistableStateDefinition,
} from '@kbn/kibana-utils-plugin/common';

export enum ViewMode {
EDIT = 'edit',
Expand Down Expand Up @@ -74,6 +78,12 @@ export interface PanelState<E extends EmbeddableInput & { id: string } = { id: s

export type EmbeddableStateWithType = EmbeddableInput & { type: string };

export interface EmbeddableRegistryDefinition<
P extends EmbeddableStateWithType = EmbeddableStateWithType
> extends PersistableStateDefinition<P> {
id: string;
}

export type EmbeddablePersistableStateService = PersistableStateService<EmbeddableStateWithType>;

export interface CommonEmbeddableStartContract {
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/embeddable/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { EmbeddableServerPlugin, EmbeddableSetup, EmbeddableStart } from './plug

export type { EmbeddableSetup, EmbeddableStart };

export type { EnhancementRegistryDefinition, EmbeddableRegistryDefinition } from './types';
export type { EnhancementRegistryDefinition } from './types';

export type { EmbeddableRegistryDefinition } from '../common';

export const plugin = () => new EmbeddableServerPlugin();
7 changes: 5 additions & 2 deletions src/plugins/embeddable/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ import {
EnhancementsRegistry,
EnhancementRegistryDefinition,
EnhancementRegistryItem,
EmbeddableRegistryDefinition,
} from './types';
import {
getExtractFunction,
getInjectFunction,
getMigrateFunction,
getTelemetryFunction,
} from '../common/lib';
import { EmbeddableStateWithType, CommonEmbeddableStartContract } from '../common/types';
import {
EmbeddableStateWithType,
CommonEmbeddableStartContract,
EmbeddableRegistryDefinition,
} from '../common/types';
import { getAllMigrations } from '../common/lib/get_all_migrations';

export interface EmbeddableSetup extends PersistableStateService<EmbeddableStateWithType> {
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/embeddable/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ export interface EnhancementRegistryItem<P extends SerializableRecord = Serializ
id: string;
}

export interface EmbeddableRegistryDefinition<
P extends EmbeddableStateWithType = EmbeddableStateWithType
> extends PersistableStateDefinition<P> {
id: string;
}

export interface EmbeddableRegistryItem<P extends EmbeddableStateWithType = EmbeddableStateWithType>
extends PersistableState<P> {
id: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { IFieldType, indexPatterns as indexPatternsUtils } from '@kbn/data-plugin/public';
import { flatten } from 'lodash';
import { escapeKuery } from './lib/escape_kuery';
import { sortPrefixFirst } from './sort_prefix_first';
import { QuerySuggestionField, QuerySuggestionTypes } from '../query_suggestion_provider';
import { KqlQuerySuggestionProvider } from './types';
Expand All @@ -27,7 +26,7 @@ const keywordComparator = (first: IFieldType, second: IFieldType) => {
export const setupGetFieldSuggestions: KqlQuerySuggestionProvider<QuerySuggestionField> = (
core
) => {
return ({ indexPatterns }, { start, end, prefix, suffix, nestedPath = '' }) => {
return async ({ indexPatterns }, { start, end, prefix, suffix, nestedPath = '' }) => {
const allFields = flatten(
indexPatterns.map((indexPattern) => {
return indexPattern.fields.filter(indexPatternsUtils.isFilterable);
Expand All @@ -42,7 +41,7 @@ export const setupGetFieldSuggestions: KqlQuerySuggestionProvider<QuerySuggestio
);
});
const sortedFields = sortPrefixFirst(matchingFields.sort(keywordComparator), search, 'name');

const { escapeKuery } = await import('@kbn/es-query');
const suggestions: QuerySuggestionField[] = sortedFields.map((field) => {
const remainingPath =
field.subType && field.subType.nested
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { CoreSetup } from '@kbn/core/public';
import { $Keys } from 'utility-types';
import { flatten, uniqBy } from 'lodash';
import { fromKueryExpression } from '@kbn/es-query';
import { setupGetFieldSuggestions } from './field';
import { setupGetValueSuggestions } from './value';
import { setupGetOperatorSuggestions } from './operator';
Expand Down Expand Up @@ -38,11 +37,12 @@ export const setupKqlQuerySuggestionProvider = (
conjunction: setupGetConjunctionSuggestions(core),
};

const getSuggestionsByType = (
const getSuggestionsByType = async (
cursoredQuery: string,
querySuggestionsArgs: QuerySuggestionGetFnArgs
): Array<Promise<QuerySuggestion[]>> | [] => {
): Promise<Array<Promise<QuerySuggestion[]>> | []> => {
try {
const { fromKueryExpression } = await import('@kbn/es-query');
const cursorNode = fromKueryExpression(cursoredQuery, {
cursorSymbol,
parseCursor: true,
Expand All @@ -56,13 +56,13 @@ export const setupKqlQuerySuggestionProvider = (
}
};

return (querySuggestionsArgs) => {
return async (querySuggestionsArgs): Promise<QuerySuggestion[]> => {
const { query, selectionStart, selectionEnd } = querySuggestionsArgs;
const cursoredQuery = `${query.substr(0, selectionStart)}${cursorSymbol}${query.substr(
selectionEnd
)}`;

return Promise.all(getSuggestionsByType(cursoredQuery, querySuggestionsArgs)).then(
return Promise.all(await getSuggestionsByType(cursoredQuery, querySuggestionsArgs)).then(
(suggestionsByType) => dedup(flatten(suggestionsByType))
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@
* Side Public License, v 1.
*/

import { escapeKuery } from '@kbn/es-query';

/**
* Escapes backslashes and double-quotes. (Useful when putting a string in quotes to use as a value
* in a KQL expression. See the QuotedCharacter rule in kuery.peg.)
*/
export function escapeQuotes(str: string) {
return str.replace(/[\\"]/g, '\\$&');
}

// Re-export this function from the @kbn/es-query package to avoid refactoring
export { escapeKuery };
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
* Side Public License, v 1.
*/

import { CoreSetup } from '@kbn/core/public';
import { KueryNode } from '@kbn/es-query';
import type { KueryNode } from '@kbn/es-query';
import type { CoreSetup } from '@kbn/core/public';
import type { UnifiedSearchPublicPluginStart } from '../../../types';
import { QuerySuggestionBasic, QuerySuggestionGetFnArgs } from '../query_suggestion_provider';
import type { QuerySuggestionBasic, QuerySuggestionGetFnArgs } from '../query_suggestion_provider';

export type KqlQuerySuggestionProvider<T = QuerySuggestionBasic> = (
core: CoreSetup<object, UnifiedSearchPublicPluginStart>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { CoreSetup } from '@kbn/core/public';
import dateMath from '@kbn/datemath';
import { buildQueryFromFilters } from '@kbn/es-query';
import { memoize } from 'lodash';
import {
IIndexPattern,
Expand Down Expand Up @@ -124,6 +123,7 @@ export const setupValueSuggestionProvider = (
const timeFilter = useTimeRange
? getAutocompleteTimefilter(timefilter, indexPattern)
: undefined;
const { buildQueryFromFilters } = await import('@kbn/es-query');
const filterQuery = timeFilter ? buildQueryFromFilters([timeFilter], indexPattern).filter : [];
const filters = [...(boolFilter ? boolFilter : []), ...filterQuery];
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,6 @@ export function FilterItem(props: FilterItemProps) {
</EuiPopover>
);
}

// Needed for React.lazy
// eslint-disable-next-line import/no-default-export
export default FilterItem;
Loading

0 comments on commit 168b032

Please sign in to comment.