Skip to content

Commit

Permalink
Merge branch 'master' into metric-dropdown-loading-state
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 27, 2021
2 parents 5fb18c4 + d6f9adf commit 0756bbe
Show file tree
Hide file tree
Showing 38 changed files with 232 additions and 125 deletions.
2 changes: 1 addition & 1 deletion docs/api/dashboard-api.asciidoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[[dashboard-api]]
== Import and export dashboard APIs

deprecated::[7.15.0,Both of these APIs have been deprecated in favor of <<saved-objects-api-import>> and <<saved-objects-api-export>>.]
deprecated::[7.15.0,These experimental APIs have been deprecated in favor of <<saved-objects-api-import>> and <<saved-objects-api-export>>.]

Import and export dashboards with the corresponding saved objects, such as visualizations, saved
searches, and index patterns.
Expand Down
2 changes: 1 addition & 1 deletion docs/api/dashboard/export-dashboard.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

deprecated::[7.15.0,Use <<saved-objects-api-export>> instead.]

Export dashboards and corresponding saved objects.
experimental[] Export dashboards and corresponding saved objects.

[[dashboard-api-export-request]]
==== Request
Expand Down
2 changes: 1 addition & 1 deletion docs/api/dashboard/import-dashboard.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

deprecated::[7.15.0,Use <<saved-objects-api-import>> instead.]

Import dashboards and corresponding saved objects.
experimental[] Import dashboards and corresponding saved objects.

[[dashboard-api-import-request]]
==== Request
Expand Down
3 changes: 2 additions & 1 deletion test/examples/embeddables/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export default function ({ getService, getPageObjects }: PluginFunctionalProvide
const PageObjects = getPageObjects(['common', 'visChart']);
const monacoEditor = getService('monacoEditor');

describe('dashboard container', () => {
// FLAKY: https://github.com/elastic/kibana/issues/116414
describe.skip('dashboard container', () => {
before(async () => {
await esArchiver.loadIfNeeded('test/functional/fixtures/es_archiver/dashboard/current/data');
await esArchiver.loadIfNeeded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { PluginFunctionalProviderContext } from 'test/plugin_functional/services
export default function ({ getService }: PluginFunctionalProviderContext) {
const testSubjects = getService('testSubjects');

describe('', () => {
// FAILING: https://github.com/elastic/kibana/issues/116463
describe.skip('', () => {
it('finds an index pattern', async () => {
await testSubjects.existOrFail('indexPatternTitle');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const MOCK_VALUES = {

const MOCK_ACTIONS = {
// RelevanceTuningLogic
updatePrecision: jest.fn(),
setPrecision: jest.fn(),
};

describe('PrecisionSlider', () => {
Expand All @@ -49,12 +49,12 @@ describe('PrecisionSlider', () => {
expect(wrapper.find('[data-test-subj="PrecisionRange"]').prop('value')).toEqual(2);
});

it('calls updatePrecision on change', () => {
it('updates the precision on change', () => {
wrapper
.find('[data-test-subj="PrecisionRange"]')
.simulate('change', { target: { value: 10 } });

expect(MOCK_ACTIONS.updatePrecision).toHaveBeenCalledWith(10);
expect(MOCK_ACTIONS.setPrecision).toHaveBeenCalledWith(10);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const PrecisionSlider: React.FC = () => {
searchSettings: { precision },
} = useValues(RelevanceTuningLogic);

const { updatePrecision } = useActions(RelevanceTuningLogic);
const { setPrecision } = useActions(RelevanceTuningLogic);

const stepDescription = STEP_DESCRIPTIONS[precision];

Expand Down Expand Up @@ -102,7 +102,7 @@ export const PrecisionSlider: React.FC = () => {
data-test-subj="PrecisionRange"
value={precision}
onChange={(e) => {
updatePrecision(parseInt((e.target as HTMLInputElement).value, 10));
setPrecision(parseInt((e.target as HTMLInputElement).value, 10));
}}
min={1}
max={11}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ describe('RelevanceTuningLogic', () => {
});
});

describe('updatePrecision', () => {
describe('setPrecision', () => {
it('should set precision inside search settings and set unsavedChanges to true', () => {
mount();
RelevanceTuningLogic.actions.updatePrecision(9);
RelevanceTuningLogic.actions.setPrecision(9);

expect(RelevanceTuningLogic.values).toEqual({
...DEFAULT_VALUES,
Expand Down Expand Up @@ -1007,15 +1007,24 @@ describe('RelevanceTuningLogic', () => {
});
});

describe('updateSearchValue', () => {
it('should update the query then update search results', () => {
describe('setSearchQuery', () => {
it('shoulds update search results', () => {
mount();
jest.spyOn(RelevanceTuningLogic.actions, 'getSearchResults');

RelevanceTuningLogic.actions.setSearchQuery('foo');

expect(RelevanceTuningLogic.actions.getSearchResults).toHaveBeenCalled();
});
});

describe('setPrecision', () => {
it('shoulds update search results', () => {
mount();
jest.spyOn(RelevanceTuningLogic.actions, 'setSearchQuery');
jest.spyOn(RelevanceTuningLogic.actions, 'getSearchResults');

RelevanceTuningLogic.actions.updateSearchValue('foo');
RelevanceTuningLogic.actions.setPrecision(9);

expect(RelevanceTuningLogic.actions.setSearchQuery).toHaveBeenCalledWith('foo');
expect(RelevanceTuningLogic.actions.getSearchResults).toHaveBeenCalled();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ interface RelevanceTuningActions {
optionType: keyof Pick<Boost, 'operation' | 'function'>;
value: string;
};
updatePrecision(precision: number): { precision: number };
updateSearchValue(query: string): string;
setPrecision(precision: number): { precision: number };
}

interface RelevanceTuningValues {
Expand Down Expand Up @@ -144,8 +143,7 @@ export const RelevanceTuningLogic = kea<
optionType,
value,
}),
updatePrecision: (precision) => ({ precision }),
updateSearchValue: (query) => query,
setPrecision: (precision) => ({ precision }),
}),
reducers: () => ({
searchSettings: [
Expand All @@ -158,7 +156,7 @@ export const RelevanceTuningLogic = kea<
onInitializeRelevanceTuning: (_, { searchSettings }) => searchSettings,
setSearchSettings: (_, { searchSettings }) => searchSettings,
setSearchSettingsResponse: (_, { searchSettings }) => searchSettings,
updatePrecision: (currentSearchSettings, { precision }) => ({
setPrecision: (currentSearchSettings, { precision }) => ({
...currentSearchSettings,
precision,
}),
Expand Down Expand Up @@ -191,7 +189,7 @@ export const RelevanceTuningLogic = kea<
unsavedChanges: [
false,
{
updatePrecision: () => true,
setPrecision: () => true,
setSearchSettings: () => true,
setSearchSettingsResponse: () => false,
},
Expand Down Expand Up @@ -268,7 +266,11 @@ export const RelevanceTuningLogic = kea<

const { engineName } = EngineLogic.values;
const { http } = HttpLogic.values;
const { search_fields: searchFields, boosts } = removeBoostStateProps(values.searchSettings);
const {
search_fields: searchFields,
boosts,
precision,
} = removeBoostStateProps(values.searchSettings);
const url = `/internal/app_search/engines/${engineName}/search`;

actions.setResultsLoading(true);
Expand All @@ -283,6 +285,7 @@ export const RelevanceTuningLogic = kea<
body: JSON.stringify({
boosts: isEmpty(filteredBoosts) ? undefined : filteredBoosts,
search_fields: isEmpty(searchFields) ? undefined : searchFields,
precision,
}),
});

Expand Down Expand Up @@ -472,8 +475,10 @@ export const RelevanceTuningLogic = kea<
},
});
},
updateSearchValue: (query) => {
actions.setSearchQuery(query);
setSearchQuery: () => {
actions.getSearchResults();
},
setPrecision: () => {
actions.getSearchResults();
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('RelevanceTuningPreview', () => {
const result3 = { id: { raw: 3 } };

const actions = {
updateSearchValue: jest.fn(),
setSearchQuery: jest.fn(),
};

const values = {
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('RelevanceTuningPreview', () => {

wrapper.find(EuiFieldSearch).simulate('change', { target: { value: 'some search text' } });

expect(actions.updateSearchValue).toHaveBeenCalledWith('some search text');
expect(actions.setSearchQuery).toHaveBeenCalledWith('some search text');
});

it('will show user a prompt to enter a query if they have not entered one', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const noResultsCallout = (
);

export const RelevanceTuningPreview: React.FC = () => {
const { updateSearchValue } = useActions(RelevanceTuningLogic);
const { setSearchQuery } = useActions(RelevanceTuningLogic);
const { searchResults, schema } = useValues(RelevanceTuningLogic);
const { engineName, isMetaEngine } = useValues(EngineLogic);

Expand All @@ -59,7 +59,7 @@ export const RelevanceTuningPreview: React.FC = () => {
</EuiTitle>
<EuiSpacer />
<EuiFieldSearch
onChange={(e) => updateSearchValue(e.target.value)}
onChange={(e) => setSearchQuery(e.target.value)}
placeholder={i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.preview.searchPlaceholder',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const filterIfTerm = (array: string[], filterTerm: string): string[] => {
return filterTerm === '' ? array : array.filter((item) => item.includes(filterTerm));
};

export const removeBoostStateProps = (searchSettings: SearchSettings) => {
export const removeBoostStateProps = (searchSettings: SearchSettings): SearchSettings => {
const updatedSettings = cloneDeep(searchSettings);
const { boosts } = updatedSettings;
const keys = Object.keys(boosts);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ export const TimestampFromString = new rt.Type<number, string>(
export const sourceConfigurationConfigFilePropertiesRT = rt.type({
sources: rt.type({
default: rt.partial({
logAlias: rt.string, // Cannot be deprecated until 8.0.0. Will be converted to an indexName reference.
metricAlias: rt.string,
fields: rt.partial({
timestamp: rt.string,
message: rt.array(rt.string),
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/infra/server/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ export const configDeprecations: ConfigDeprecationProvider = ({ deprecate }) =>
return completeConfig;
}
),
deprecate('sources.default.logAlias', '8.0.0'),
deprecate('sources.default.metricAlias', '8.0.0'),
];

export const getInfraDeprecationsFactory =
Expand Down
21 changes: 1 addition & 20 deletions x-pack/plugins/infra/server/lib/sources/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,7 @@ export class InfraSources {
fold(constant({}), identity)
);

// NOTE: Legacy logAlias needs converting to a logIndices reference until we can remove
// config file sources in 8.0.0.
if (staticSourceConfiguration && staticSourceConfiguration.logAlias) {
const convertedStaticSourceConfiguration: InfraStaticSourceConfiguration & {
logAlias?: string;
} = {
...staticSourceConfiguration,
logIndices: {
type: 'index_name',
indexName: staticSourceConfiguration.logAlias,
},
};
delete convertedStaticSourceConfiguration.logAlias;
return mergeSourceConfiguration(
defaultSourceConfiguration,
convertedStaticSourceConfiguration
);
} else {
return mergeSourceConfiguration(defaultSourceConfiguration, staticSourceConfiguration);
}
return mergeSourceConfiguration(defaultSourceConfiguration, staticSourceConfiguration);
}

private async getSavedSourceConfiguration(
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/infra/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ export const config: PluginConfigDescriptor = {
schema.object({
default: schema.maybe(
schema.object({
logAlias: schema.maybe(schema.string()), // NOTE / TODO: Should be deprecated in 8.0.0
metricAlias: schema.maybe(schema.string()),
fields: schema.maybe(
schema.object({
timestamp: schema.maybe(schema.string()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export type AbstractSourceDescriptor = {
export type EMSTMSSourceDescriptor = AbstractSourceDescriptor & {
// id: EMS TMS layer id. Used when !isAutoSelect
isAutoSelect: boolean;
lightModeDefault: string;
};

export type EMSFileSourceDescriptor = AbstractSourceDescriptor & {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { setEmsTmsDefaultModes } from './set_ems_tms_default_modes';

describe('setEmsTmsDefaultModes', () => {
test('Should handle missing layerListJSON attribute', () => {
const attributes = {
title: 'my map',
};
expect(setEmsTmsDefaultModes({ attributes })).toEqual({
title: 'my map',
});
});

test('Should add lightModeDefault to existing EMS_TMS source descriptors', () => {
const layerListJSON = JSON.stringify([
{
sourceDescriptor: {
type: 'EMS_TMS',
},
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(setEmsTmsDefaultModes({ attributes })).toEqual({
title: 'my map',
layerListJSON: '[{"sourceDescriptor":{"type":"EMS_TMS","lightModeDefault":"road_map"}}]',
});
});

// test edge case where sample data maps set lightModeDefault but still run migration
test('Should not change lightModeDefault if provided', () => {
const layerListJSON = JSON.stringify([
{
sourceDescriptor: {
type: 'EMS_TMS',
lightModeDefault: 'road_map_desaturated',
},
},
]);
const attributes = {
title: 'my map',
layerListJSON,
};
expect(setEmsTmsDefaultModes({ attributes })).toEqual({
title: 'my map',
layerListJSON:
'[{"sourceDescriptor":{"type":"EMS_TMS","lightModeDefault":"road_map_desaturated"}}]',
});
});
});
Loading

0 comments on commit 0756bbe

Please sign in to comment.