Skip to content

Commit

Permalink
Merge branch 'main' into data-view-updated-warn-in-view-alert-route
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jun 28, 2022
2 parents d9f734c + 1aba542 commit b3041e4
Show file tree
Hide file tree
Showing 74 changed files with 948 additions and 583 deletions.
2 changes: 0 additions & 2 deletions packages/kbn-shared-ux-services/src/services/editors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ type DataView = unknown;
interface DataViewEditorOptions {
/** Handler to be invoked when the Data View Editor completes a save operation. */
onSave: (dataView: DataView) => void;
/** If set to false, will skip empty prompt in data view editor. */
showEmptyPrompt?: boolean;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions packages/shared-ux/page/kibana_no_data/src/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type DataView = unknown;
interface DataViewEditorOptions {
/** Handler to be invoked when the Data View Editor completes a save operation. */
onSave: (dataView: DataView) => void;
/** If set to false, will skip empty prompt in data view editor. */
showEmptyPrompt?: boolean;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const NoDataViewsPrompt = ({
onClick={onClickCreate}
iconType="plusInCircle"
fill={true}
data-test-subj="createDataViewButtonFlyout"
data-test-subj="createDataViewButton"
>
{createDataViewText}
</EuiButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const NoDataViewsPrompt = ({ onDataViewCreated }: Props) => {
onSave: (dataView) => {
onDataViewCreated(dataView);
},
showEmptyPrompt: false,
});

if (setDataViewEditorRef) {
Expand Down
2 changes: 0 additions & 2 deletions packages/shared-ux/prompt/no_data_views/src/services.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ type DataView = unknown;
interface DataViewEditorOptions {
/** Handler to be invoked when the Data View Editor completes a save operation. */
onSave: (dataView: DataView) => void;
/** If set to false, will skip empty prompt in data view editor. */
showEmptyPrompt?: boolean;
}

/**
Expand Down
32 changes: 32 additions & 0 deletions src/core/server/ui_settings/settings/announcements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { UiSettingsParams } from '../../../types';
import { getAnnouncementsSettings } from './announcements';

describe('announcements settings', () => {
const state = getAnnouncementsSettings();

const getValidationFn = (setting: UiSettingsParams) => (value: any) =>
setting.schema.validate(value);

describe('hideAnnouncements', () => {
const validate = getValidationFn(state.hideAnnouncements);

it('should only accept boolean values', () => {
expect(() => validate(true)).not.toThrow();
expect(() => validate(false)).not.toThrow();
expect(() => validate('foo')).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [boolean] but got [string]"`
);
expect(() => validate(12)).toThrowErrorMatchingInlineSnapshot(
`"expected value of type [boolean] but got [number]"`
);
});
});
});
26 changes: 26 additions & 0 deletions src/core/server/ui_settings/settings/announcements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { schema } from '@kbn/config-schema';
import { i18n } from '@kbn/i18n';
import { UiSettingsParams } from '../../../types';

export const getAnnouncementsSettings = (): Record<string, UiSettingsParams> => {
return {
hideAnnouncements: {
name: i18n.translate('core.ui_settings.params.hideAnnouncements', {
defaultMessage: 'Hide announcements',
}),
value: false,
description: i18n.translate('core.ui_settings.params.hideAnnouncementsText', {
defaultMessage: 'Stop showing messages and tours that highlight new features.',
}),
schema: schema.boolean(),
},
};
};
2 changes: 2 additions & 0 deletions src/core/server/ui_settings/settings/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import { getNotificationsSettings } from './notifications';
import { getThemeSettings } from './theme';
import { getCoreSettings } from '.';
import { getStateSettings } from './state';
import { getAnnouncementsSettings } from './announcements';

describe('getCoreSettings', () => {
it('should not have setting overlaps', () => {
const coreSettingsLength = Object.keys(getCoreSettings()).length;
const summedLength = [
getAccessibilitySettings(),
getAnnouncementsSettings(),
getDateFormatSettings(),
getMiscUiSettings(),
getNavigationSettings(),
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/ui_settings/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getNavigationSettings } from './navigation';
import { getNotificationsSettings } from './notifications';
import { getThemeSettings } from './theme';
import { getStateSettings } from './state';
import { getAnnouncementsSettings } from './announcements';

interface GetCoreSettingsOptions {
isDist?: boolean;
Expand All @@ -24,6 +25,7 @@ export const getCoreSettings = (
): Record<string, UiSettingsParams> => {
return {
...getAccessibilitySettings(),
...getAnnouncementsSettings(),
...getDateFormatSettings(),
...getMiscUiSettings(),
...getNavigationSettings(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ export const createSearchSource = (

// hydrating index pattern
if (searchSourceFields.index) {
fields.index = await indexPatterns.get(searchSourceFields.index);
if (typeof searchSourceFields.index === 'string') {
fields.index = await indexPatterns.get(searchSourceFields.index);
} else {
fields.index = await indexPatterns.create(searchSourceFields.index);
}
}

if (searchSourceFields.parent) {
Expand Down
33 changes: 20 additions & 13 deletions src/plugins/data/common/search/search_source/extract_references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import { SavedObjectReference } from '@kbn/core/types';
import { Filter } from '@kbn/es-query';
import { DataViewPersistableStateService } from '@kbn/data-views-plugin/common';
import { SerializedSearchSourceFields } from './types';

import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../..';

export const extractReferences = (
Expand All @@ -18,18 +18,25 @@ export const extractReferences = (
let searchSourceFields: SerializedSearchSourceFields & { indexRefName?: string } = { ...state };
const references: SavedObjectReference[] = [];
if (searchSourceFields.index) {
const indexId = searchSourceFields.index;
const refName = 'kibanaSavedObjectMeta.searchSourceJSON.index';
references.push({
name: refName,
type: DATA_VIEW_SAVED_OBJECT_TYPE,
id: indexId,
});
searchSourceFields = {
...searchSourceFields,
indexRefName: refName,
index: undefined,
};
if (typeof searchSourceFields.index === 'string') {
const indexId = searchSourceFields.index;
const refName = 'kibanaSavedObjectMeta.searchSourceJSON.index';
references.push({
name: refName,
type: DATA_VIEW_SAVED_OBJECT_TYPE,
id: indexId,
});
searchSourceFields = {
...searchSourceFields,
indexRefName: refName,
index: undefined,
};
} else {
const { state: dataViewState, references: dataViewReferences } =
DataViewPersistableStateService.extract(searchSourceFields.index);
searchSourceFields.index = dataViewState;
references.push(...dataViewReferences);
}
}

if (searchSourceFields.filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { SavedObjectReference } from '@kbn/core/types';
import { DataViewPersistableStateService } from '@kbn/data-views-plugin/common';
import { SerializedSearchSourceFields } from './types';

export const injectReferences = (
Expand All @@ -26,6 +27,13 @@ export const injectReferences = (
delete searchSourceReturnFields.indexRefName;
}

if (searchSourceFields.index && typeof searchSourceFields.index !== 'string') {
searchSourceFields.index = DataViewPersistableStateService.inject(
searchSourceFields.index,
references
);
}

if (searchSourceReturnFields.filter && Array.isArray(searchSourceReturnFields.filter)) {
searchSourceReturnFields.filter.forEach((filterRow: any) => {
if (!filterRow.meta || !filterRow.meta.indexRefName) {
Expand Down
23 changes: 19 additions & 4 deletions src/plugins/data/common/search/search_source/search_source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,15 +808,31 @@ describe('SearchSource', () => {
});

describe('#serialize', () => {
const indexPattern123 = { id: '123', isPersisted: () => true } as DataView;
test('should reference index patterns', () => {
const indexPattern123 = { id: '123' } as DataView;
searchSource.setField('index', indexPattern123);
const { searchSourceJSON, references } = searchSource.serialize();
expect(references[0].id).toEqual('123');
expect(references[0].type).toEqual('index-pattern');
expect(JSON.parse(searchSourceJSON).indexRefName).toEqual(references[0].name);
});

test('should contain persisted data view by value', () => {
const localDataView = {
id: 'local-123',
isPersisted: () => false,
toSpec: () => ({ id: 'local-123' }),
} as DataView;
searchSource.setField('index', localDataView);
const { searchSourceJSON, references } = searchSource.serialize();
expect(references.length).toEqual(0);
expect(JSON.parse(searchSourceJSON).index).toMatchInlineSnapshot(`
Object {
"id": "local-123",
}
`);
});

test('should add other fields', () => {
searchSource.setField('highlightAll', true);
searchSource.setField('from', 123456);
Expand Down Expand Up @@ -851,7 +867,6 @@ describe('SearchSource', () => {
});

test('should reference index patterns in filters separately from index field', () => {
const indexPattern123 = { id: '123' } as DataView;
searchSource.setField('index', indexPattern123);
const filter = [
{
Expand Down Expand Up @@ -908,8 +923,9 @@ describe('SearchSource', () => {
},
];

const indexPattern123 = { id: '123', isPersisted: () => true } as DataView;

test('should return serialized fields', () => {
const indexPattern123 = { id: '123' } as DataView;
searchSource.setField('index', indexPattern123);
searchSource.setField('filter', () => {
return filter;
Expand Down Expand Up @@ -941,7 +957,6 @@ describe('SearchSource', () => {
});

test('should support nested search sources', () => {
const indexPattern123 = { id: '123' } as DataView;
searchSource.setField('index', indexPattern123);
searchSource.setField('from', 123);
const childSearchSource = searchSource.createChild();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ export class SearchSource {
...searchSourceFields,
};
if (index) {
serializedSearchSourceFields.index = index.id;
serializedSearchSourceFields.index = index.isPersisted() ? index.id : index.toSpec();
}
if (sort) {
serializedSearchSourceFields.sort = !Array.isArray(sort) ? [sort] : sort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
mergeMigrationFunctionMaps,
MigrateFunctionsObject,
} from '@kbn/kibana-utils-plugin/common';
import { DataViewsContract } from '@kbn/data-views-plugin/common';
import { DataViewPersistableStateService, DataViewsContract } from '@kbn/data-views-plugin/common';
import {
createSearchSource,
extractReferences,
Expand All @@ -34,7 +34,20 @@ const getAllMigrations = (): MigrateFunctionsObject => {
});
});

return mergeMigrationFunctionMaps(searchSourceMigrations, filterMigrations);
const dataviewsMigrations = mapValues(
DataViewPersistableStateService.getAllMigrations(),
(migrate) => {
return (state: SerializedSearchSourceFields) => ({
...state,
index: migrate(state.index),
});
}
);

return mergeMigrationFunctionMaps(
mergeMigrationFunctionMaps(searchSourceMigrations, filterMigrations),
dataviewsMigrations
);
};

export class SearchSourceService {
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/search/search_source/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { SerializableRecord } from '@kbn/utility-types';
import { PersistableStateService } from '@kbn/kibana-utils-plugin/common';
import type { Filter } from '@kbn/es-query';
import type { DataView } from '@kbn/data-views-plugin/common';
import type { DataView, DataViewSpec } from '@kbn/data-views-plugin/common';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { AggConfigSerialized, IAggConfigs } from '../../../public';
import { Query } from '../..';
Expand Down Expand Up @@ -159,7 +159,7 @@ export type SerializedSearchSourceFields = {
/**
* {@link IndexPatternService}
*/
index?: string;
index?: string | DataViewSpec;
searchAfter?: EsQuerySearchAfter;
timeout?: string;
terminate_after?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const DataViewEditor = ({
defaultTypeIsRollup = false,
requireTimestampField = false,
editData,
showEmptyPrompt = true,
}: DataViewEditorPropsWithServices) => {
const { Provider: KibanaReactContextProvider } =
createKibanaReactContext<DataViewEditorContext>(services);
Expand All @@ -38,7 +37,6 @@ export const DataViewEditor = ({
defaultTypeIsRollup={defaultTypeIsRollup}
requireTimestampField={requireTimestampField}
editData={editData}
showEmptyPrompt={showEmptyPrompt}
/>
</EuiFlyout>
</KibanaReactContextProvider>
Expand Down
Loading

0 comments on commit b3041e4

Please sign in to comment.