From 716ab2374dde594a1eea2af05622d099544ccf59 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Wed, 20 Jan 2021 12:37:44 -0500 Subject: [PATCH 1/9] Implemented actions and selectors --- .../components/relevance_tuning/index.ts | 1 + .../relevance_tuning_logic.test.ts | 296 ++++++++++++++++++ .../relevance_tuning_logic.ts | 155 +++++++++ .../components/relevance_tuning/types.ts | 26 ++ 4 files changed, 478 insertions(+) create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/index.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/index.ts index 55070255ac81b..d61834b73c6dd 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/index.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/index.ts @@ -6,3 +6,4 @@ export { RELEVANCE_TUNING_TITLE } from './constants'; export { RelevanceTuning } from './relevance_tuning'; +export { RelevanceTuningLogic } from './relevance_tuning_logic'; diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts new file mode 100644 index 0000000000000..4d64e82ca534b --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts @@ -0,0 +1,296 @@ +/* + * 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 { LogicMounter } from '../../../__mocks__'; + +import { IBoostType } from './types'; + +import { RelevanceTuningLogic } from './relevance_tuning_logic'; + +describe('RelevanceTuningLogic', () => { + const searchSettings = { + boosts: { + foo: [ + { + type: 'value' as IBoostType, + factor: 5, + }, + ], + }, + search_fields: {}, + }; + const schema = {}; + const schemaConflicts = {}; + const searchSettingProps = { + searchSettings, + schema, + schemaConflicts, + }; + const searchResults = [{}, {}]; + + const { mount } = new LogicMounter(RelevanceTuningLogic); + + const DEFAULT_VALUES = { + dataLoading: true, + schema: {}, + schemaConflicts: {}, + searchSettings: {}, + unsavedChanges: false, + filterInputValue: '', + query: '', + resultsLoading: false, + searchResults: null, + showSchemaConflictCallout: true, + engineHasSchemaFields: false, + schemaFields: [], + schemaFieldsWithConflicts: [], + filteredSchemaFields: [], + filteredSchemaFieldsWithConflicts: [], + }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + it('has expected default values', () => { + mount(); + expect(RelevanceTuningLogic.values).toEqual(DEFAULT_VALUES); + }); + + describe('actions', () => { + describe('onInitializeSearchSettings', () => { + it('should set state', () => { + mount({ + dataLoading: true, + }); + RelevanceTuningLogic.actions.onInitializeSearchSettings(searchSettingProps); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + searchSettings, + schema, + dataLoading: false, + schemaConflicts, + }); + }); + }); + + describe('setSearchSettings', () => { + it('should set state', () => { + mount({ + unsavedChanges: false, + }); + RelevanceTuningLogic.actions.setSearchSettings(searchSettings); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + searchSettings, + unsavedChanges: true, + }); + }); + }); + + describe('setFilterValue', () => { + it('should set state', () => { + mount(); + RelevanceTuningLogic.actions.setFilterValue('foo'); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + filterInputValue: 'foo', + }); + }); + }); + + describe('setSearchQuery', () => { + it('should set state', () => { + mount(); + RelevanceTuningLogic.actions.setSearchQuery('foo'); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + query: 'foo', + }); + }); + }); + + describe('setSearchResults', () => { + it('should set state', () => { + mount({ + resultsLoading: true, + }); + RelevanceTuningLogic.actions.setSearchResults(searchResults); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + searchResults, + resultsLoading: false, + }); + }); + }); + + describe('setResultsLoading', () => { + it('should set state', () => { + mount({ + resultsLoading: false, + }); + RelevanceTuningLogic.actions.setResultsLoading(true); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + resultsLoading: true, + }); + }); + }); + + describe('clearSearchResults', () => { + it('should set state', () => { + mount({ + searchResults: [{}], + }); + RelevanceTuningLogic.actions.clearSearchResults(); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + searchResults: null, + }); + }); + }); + + describe('resetSearchSettingsState', () => { + it('should set state', () => { + mount({ + dataLoading: false, + }); + RelevanceTuningLogic.actions.resetSearchSettingsState(); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + dataLoading: true, + }); + }); + }); + + describe('dismissSchemaConflictCallout', () => { + it('should set state', () => { + mount({ + showSchemaConflictCallout: true, + }); + RelevanceTuningLogic.actions.dismissSchemaConflictCallout(); + + expect(RelevanceTuningLogic.values).toEqual({ + ...DEFAULT_VALUES, + showSchemaConflictCallout: false, + }); + }); + }); + }); + + describe('selectors', () => { + describe('engineHasSchemaFields', () => { + it('should false if there is only a single field in a schema', () => { + // I believe this is because schemas *always* have an ID, and we don't consider that + // a tunable field + mount({ + schema: { + id: 'foo', + }, + }); + expect(RelevanceTuningLogic.values.engineHasSchemaFields).toEqual(false); + }); + + it('should return true otherwise', () => { + mount({ + schema: { + id: 'foo', + bar: 'bar', + }, + }); + expect(RelevanceTuningLogic.values.engineHasSchemaFields).toEqual(true); + }); + }); + + describe('schemaFields', () => { + it('should return the list of field names from the schema', () => { + mount({ + schema: { + id: 'foo', + bar: 'bar', + }, + }); + expect(RelevanceTuningLogic.values.schemaFields).toEqual(['id', 'bar']); + }); + }); + + describe('schemaFieldsWithConflicts', () => { + it('should return the list of field names that have schema conflicts', () => { + mount({ + schemaConflicts: { + foo: { + text: ['source_engine_1'], + number: ['source_engine_2'], + }, + }, + }); + expect(RelevanceTuningLogic.values.schemaFieldsWithConflicts).toEqual(['foo']); + }); + }); + + describe('filteredSchemaFields', () => { + it('should return a list of schema field names that contain the text from filterInputValue ', () => { + mount({ + filterInputValue: 'ba', + schema: { + id: 'string', + foo: 'string', + bar: 'string', + baz: 'string', + }, + }); + expect(RelevanceTuningLogic.values.filteredSchemaFields).toEqual(['bar', 'baz']); + }); + + it('should return all schema fields if there is no filter applied', () => { + mount({ + filterTerm: '', + schema: { + id: 'string', + foo: 'string', + bar: 'string', + baz: 'string', + }, + }); + expect(RelevanceTuningLogic.values.filteredSchemaFields).toEqual([ + 'id', + 'foo', + 'bar', + 'baz', + ]); + }); + }); + + describe('filteredSchemaFieldsWithConflicts', () => { + it('should return a list of schema field names that contain the text from filterInputValue, and if that field has a schema conflict', () => { + mount({ + filterInputValue: 'ba', + schema: { + id: 'string', + foo: 'string', + bar: 'string', + baz: 'string', + }, + schemaConflicts: { + bar: { + text: ['source_engine_1'], + number: ['source_engine_2'], + }, + }, + }); + expect(RelevanceTuningLogic.values.filteredSchemaFieldsWithConflicts).toEqual(['bar']); + }); + }); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts new file mode 100644 index 0000000000000..00947f7d0fb00 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts @@ -0,0 +1,155 @@ +/* + * 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 { kea, MakeLogicType } from 'kea'; + +import { Schema, SchemaConflicts } from '../../../shared/types'; +import { ISearchSettings } from './types'; + +interface ISearchSettingsProps { + searchSettings: ISearchSettings; + schema: Schema; + schemaConflicts: SchemaConflicts; +} + +interface ISearchSettingsActions { + onInitializeSearchSettings(props: ISearchSettingsProps): ISearchSettingsProps; + setSearchSettings(searchSettings: ISearchSettings): { searchSettings: ISearchSettings }; + setFilterValue(value: string): string; + setSearchQuery(value: string): string; + setSearchResults(searchResults: object[]): object[]; + setResultsLoading(resultsLoading: boolean): boolean; + clearSearchResults(): void; + resetSearchSettingsState(): void; + dismissSchemaConflictCallout(): void; +} + +interface ISearchSettingsValues { + searchSettings: Partial; + schema: Schema; + dataLoading: boolean; + schemaConflicts: SchemaConflicts; + unsavedChanges: boolean; + filterInputValue: string; + query: string; + searchResults: object[] | null; + resultsLoading: boolean; + showSchemaConflictCallout: boolean; + engineHasSchemaFields: boolean; + schemaFields: string[]; + schemaFieldsWithConflicts: string[]; + filteredSchemaFields: string[]; + filteredSchemaFieldsWithConflicts: string[]; +} + +// If the user hasn't entered a filter, then we can skip filtering the array entirely +const filterIfTerm = (array: string[], filterTerm: string): string[] => { + return filterTerm === '' ? array : array.filter((item) => item.includes(filterTerm)); +}; + +export const RelevanceTuningLogic = kea< + MakeLogicType +>({ + path: ['enterprise_search', 'app_search', 'relevance_tuning_logic'], + actions: () => ({ + onInitializeSearchSettings: (props) => props, + setSearchSettings: (searchSettings) => ({ searchSettings }), + setFilterValue: (value) => value, + setSearchQuery: (query) => query, + setSearchResults: (searchResults) => searchResults, + setResultsLoading: (resultsLoading) => resultsLoading, + clearSearchResults: true, + resetSearchSettingsState: true, + dismissSchemaConflictCallout: true, + }), + reducers: () => ({ + searchSettings: [ + {}, + { + onInitializeSearchSettings: (_, { searchSettings }) => searchSettings, + setSearchSettings: (_, { searchSettings }) => searchSettings, + }, + ], + schema: [ + {}, + { + onInitializeSearchSettings: (_, { schema }) => schema, + }, + ], + dataLoading: [ + true, + { + onInitializeSearchSettings: () => false, + resetSearchSettingsState: () => true, + }, + ], + schemaConflicts: [ + {}, + { + onInitializeSearchSettings: (_, { schemaConflicts }) => schemaConflicts, + }, + ], + unsavedChanges: [ + false, + { + setSearchSettings: () => true, + }, + ], + filterInputValue: [ + '', + { + setFilterValue: (_, filterInputValue) => filterInputValue, + }, + ], + query: [ + '', + { + setSearchQuery: (_, query) => query, + }, + ], + resultsLoading: [ + false, + { + setResultsLoading: (_, resultsLoading) => resultsLoading, + setSearchResults: () => false, + }, + ], + searchResults: [ + null, + { + clearSearchResults: () => null, + setSearchResults: (_, searchResults) => searchResults, + }, + ], + showSchemaConflictCallout: [ + true, + { + dismissSchemaConflictCallout: () => false, + }, + ], + }), + selectors: ({ selectors }) => ({ + engineHasSchemaFields: [ + () => [selectors.schema], + (schema: Schema): boolean => Object.keys(schema).length >= 2, + ], + schemaFields: [() => [selectors.schema], (schema: Schema) => Object.keys(schema)], + schemaFieldsWithConflicts: [ + () => [selectors.schemaConflicts], + (schemaConflicts: SchemaConflicts) => Object.keys(schemaConflicts), + ], + filteredSchemaFields: [ + () => [selectors.schemaFields, selectors.filterInputValue], + (schemaFields: string[], filterInputValue: string): string[] => + filterIfTerm(schemaFields, filterInputValue), + ], + filteredSchemaFieldsWithConflicts: [ + () => [selectors.schemaFieldsWithConflicts, selectors.filterInputValue], + (schemaFieldsWithConflicts: string[], filterInputValue: string): string[] => + filterIfTerm(schemaFieldsWithConflicts, filterInputValue), + ], + }), +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts new file mode 100644 index 0000000000000..caf7ffd31aefd --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts @@ -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; + * you may not use this file except in compliance with the Elastic License. + */ + +export type IBoostType = 'value' | 'functional' | 'proximity'; + +export interface IBoost { + type: IBoostType; + operation?: string; + function?: string; + newBoost?: boolean; + center?: string | number; + value?: string | number | string[] | number[]; + factor: number; +} + +export interface IBoostObject { + [key: string]: IBoost[]; +} + +export interface ISearchSettings { + boosts: IBoostObject; + search_fields: object; +} From 074190a72d8e4684ad384973c6ba46083dfe17c9 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Tue, 26 Jan 2021 11:11:59 -0500 Subject: [PATCH 2/9] Targeted renaming of SearchSettings --- .../relevance_tuning_logic.test.ts | 10 +++---- .../relevance_tuning_logic.ts | 29 ++++++++++--------- .../components/relevance_tuning/types.ts | 10 +++---- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts index 4d64e82ca534b..903532285a8c9 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts @@ -6,7 +6,7 @@ import { LogicMounter } from '../../../__mocks__'; -import { IBoostType } from './types'; +import { BoostType } from './types'; import { RelevanceTuningLogic } from './relevance_tuning_logic'; @@ -15,7 +15,7 @@ describe('RelevanceTuningLogic', () => { boosts: { foo: [ { - type: 'value' as IBoostType, + type: 'value' as BoostType, factor: 5, }, ], @@ -24,7 +24,7 @@ describe('RelevanceTuningLogic', () => { }; const schema = {}; const schemaConflicts = {}; - const searchSettingProps = { + const relevanceTuningProps = { searchSettings, schema, schemaConflicts, @@ -61,12 +61,12 @@ describe('RelevanceTuningLogic', () => { }); describe('actions', () => { - describe('onInitializeSearchSettings', () => { + describe('onInitializeRelevanceTuning', () => { it('should set state', () => { mount({ dataLoading: true, }); - RelevanceTuningLogic.actions.onInitializeSearchSettings(searchSettingProps); + RelevanceTuningLogic.actions.onInitializeRelevanceTuning(relevanceTuningProps); expect(RelevanceTuningLogic.values).toEqual({ ...DEFAULT_VALUES, diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts index 00947f7d0fb00..4a4e535720a0a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts @@ -7,17 +7,18 @@ import { kea, MakeLogicType } from 'kea'; import { Schema, SchemaConflicts } from '../../../shared/types'; -import { ISearchSettings } from './types'; -interface ISearchSettingsProps { - searchSettings: ISearchSettings; +import { SearchSettings } from './types'; + +interface RelevanceTuningProps { + searchSettings: SearchSettings; schema: Schema; schemaConflicts: SchemaConflicts; } -interface ISearchSettingsActions { - onInitializeSearchSettings(props: ISearchSettingsProps): ISearchSettingsProps; - setSearchSettings(searchSettings: ISearchSettings): { searchSettings: ISearchSettings }; +interface RelevanceTuningActions { + onInitializeRelevanceTuning(props: RelevanceTuningProps): RelevanceTuningProps; + setSearchSettings(searchSettings: SearchSettings): { searchSettings: SearchSettings }; setFilterValue(value: string): string; setSearchQuery(value: string): string; setSearchResults(searchResults: object[]): object[]; @@ -27,8 +28,8 @@ interface ISearchSettingsActions { dismissSchemaConflictCallout(): void; } -interface ISearchSettingsValues { - searchSettings: Partial; +interface RelevanceTuningValues { + searchSettings: Partial; schema: Schema; dataLoading: boolean; schemaConflicts: SchemaConflicts; @@ -51,11 +52,11 @@ const filterIfTerm = (array: string[], filterTerm: string): string[] => { }; export const RelevanceTuningLogic = kea< - MakeLogicType + MakeLogicType >({ path: ['enterprise_search', 'app_search', 'relevance_tuning_logic'], actions: () => ({ - onInitializeSearchSettings: (props) => props, + onInitializeRelevanceTuning: (props) => props, setSearchSettings: (searchSettings) => ({ searchSettings }), setFilterValue: (value) => value, setSearchQuery: (query) => query, @@ -69,27 +70,27 @@ export const RelevanceTuningLogic = kea< searchSettings: [ {}, { - onInitializeSearchSettings: (_, { searchSettings }) => searchSettings, + onInitializeRelevanceTuning: (_, { searchSettings }) => searchSettings, setSearchSettings: (_, { searchSettings }) => searchSettings, }, ], schema: [ {}, { - onInitializeSearchSettings: (_, { schema }) => schema, + onInitializeRelevanceTuning: (_, { schema }) => schema, }, ], dataLoading: [ true, { - onInitializeSearchSettings: () => false, + onInitializeRelevanceTuning: () => false, resetSearchSettingsState: () => true, }, ], schemaConflicts: [ {}, { - onInitializeSearchSettings: (_, { schemaConflicts }) => schemaConflicts, + onInitializeRelevanceTuning: (_, { schemaConflicts }) => schemaConflicts, }, ], unsavedChanges: [ diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts index caf7ffd31aefd..31e0d72b89b8c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts @@ -4,10 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -export type IBoostType = 'value' | 'functional' | 'proximity'; +export type BoostType = 'value' | 'functional' | 'proximity'; export interface IBoost { - type: IBoostType; + type: BoostType; operation?: string; function?: string; newBoost?: boolean; @@ -16,11 +16,11 @@ export interface IBoost { factor: number; } -export interface IBoostObject { +export interface BoostObject { [key: string]: IBoost[]; } -export interface ISearchSettings { - boosts: IBoostObject; +export interface SearchSettings { + boosts: BoostObject; search_fields: object; } From 2ff1eefbfff697ef6c8c16fa80c5d4b8b207830e Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Tue, 26 Jan 2021 14:58:46 -0500 Subject: [PATCH 3/9] Renamed Iboost --- .../app_search/components/relevance_tuning/types.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts index 31e0d72b89b8c..2d7b36084c1c5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts @@ -6,7 +6,7 @@ export type BoostType = 'value' | 'functional' | 'proximity'; -export interface IBoost { +export interface Boost { type: BoostType; operation?: string; function?: string; @@ -17,7 +17,7 @@ export interface IBoost { } export interface BoostObject { - [key: string]: IBoost[]; + [key: string]: Boost[]; } export interface SearchSettings { From 62e9598c1f2b21bfcbd01c8954c0e0d274c50b5b Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Wed, 3 Feb 2021 07:28:47 -0500 Subject: [PATCH 4/9] Updated comment --- .../relevance_tuning/relevance_tuning_logic.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts index 903532285a8c9..03576ec2b8d72 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts @@ -191,9 +191,9 @@ describe('RelevanceTuningLogic', () => { describe('selectors', () => { describe('engineHasSchemaFields', () => { - it('should false if there is only a single field in a schema', () => { - // I believe this is because schemas *always* have an ID, and we don't consider that - // a tunable field + it('should return false if there is only a single field in a schema', () => { + // This is because if a schema only has a single field, it is "id", which we do not + // consider a tunable field. mount({ schema: { id: 'foo', From f2db188b187a8ccc670eb4d39744a6ad44e1a92c Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 4 Feb 2021 12:07:52 -0500 Subject: [PATCH 5/9] Use Record type --- .../app_search/components/relevance_tuning/types.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts index 2d7b36084c1c5..25187df89d64c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/types.ts @@ -1,7 +1,8 @@ /* * 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. + * 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. */ export type BoostType = 'value' | 'functional' | 'proximity'; @@ -16,11 +17,7 @@ export interface Boost { factor: number; } -export interface BoostObject { - [key: string]: Boost[]; -} - export interface SearchSettings { - boosts: BoostObject; + boosts: Record; search_fields: object; } From 2eb1d3712039a769a24e0404a1b8c4eff6d7a617 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 4 Feb 2021 12:10:09 -0500 Subject: [PATCH 6/9] Move destructured constant --- .../relevance_tuning/relevance_tuning_logic.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts index 03576ec2b8d72..960b5cfd8d819 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts @@ -1,7 +1,8 @@ /* * 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. + * 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 { LogicMounter } from '../../../__mocks__'; @@ -11,6 +12,8 @@ import { BoostType } from './types'; import { RelevanceTuningLogic } from './relevance_tuning_logic'; describe('RelevanceTuningLogic', () => { + const { mount } = new LogicMounter(RelevanceTuningLogic); + const searchSettings = { boosts: { foo: [ @@ -31,8 +34,6 @@ describe('RelevanceTuningLogic', () => { }; const searchResults = [{}, {}]; - const { mount } = new LogicMounter(RelevanceTuningLogic); - const DEFAULT_VALUES = { dataLoading: true, schema: {}, From 021aea4013e8d2c2300fd630e584583e2598d2a9 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 4 Feb 2021 12:30:04 -0500 Subject: [PATCH 7/9] Updated test descriptions --- .../relevance_tuning_logic.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts index 960b5cfd8d819..586a845ce382a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.test.ts @@ -63,7 +63,7 @@ describe('RelevanceTuningLogic', () => { describe('actions', () => { describe('onInitializeRelevanceTuning', () => { - it('should set state', () => { + it('should set searchSettings, schema, & schemaConflicts from the API response, and set dataLoading to false', () => { mount({ dataLoading: true, }); @@ -80,7 +80,7 @@ describe('RelevanceTuningLogic', () => { }); describe('setSearchSettings', () => { - it('should set state', () => { + it('should set setSearchSettings and set unsavedChanges to true', () => { mount({ unsavedChanges: false, }); @@ -95,7 +95,7 @@ describe('RelevanceTuningLogic', () => { }); describe('setFilterValue', () => { - it('should set state', () => { + it('should set filterInputValue', () => { mount(); RelevanceTuningLogic.actions.setFilterValue('foo'); @@ -107,7 +107,7 @@ describe('RelevanceTuningLogic', () => { }); describe('setSearchQuery', () => { - it('should set state', () => { + it('should set query', () => { mount(); RelevanceTuningLogic.actions.setSearchQuery('foo'); @@ -119,7 +119,7 @@ describe('RelevanceTuningLogic', () => { }); describe('setSearchResults', () => { - it('should set state', () => { + it('should set searchResults and set resultLoading to false', () => { mount({ resultsLoading: true, }); @@ -134,7 +134,7 @@ describe('RelevanceTuningLogic', () => { }); describe('setResultsLoading', () => { - it('should set state', () => { + it('should set resultsLoading', () => { mount({ resultsLoading: false, }); @@ -148,7 +148,7 @@ describe('RelevanceTuningLogic', () => { }); describe('clearSearchResults', () => { - it('should set state', () => { + it('should set searchResults', () => { mount({ searchResults: [{}], }); @@ -162,7 +162,7 @@ describe('RelevanceTuningLogic', () => { }); describe('resetSearchSettingsState', () => { - it('should set state', () => { + it('should set dataLoading', () => { mount({ dataLoading: false, }); @@ -176,7 +176,7 @@ describe('RelevanceTuningLogic', () => { }); describe('dismissSchemaConflictCallout', () => { - it('should set state', () => { + it('should set showSchemaConflictCallout to false', () => { mount({ showSchemaConflictCallout: true, }); From 55dfa7057d80d9d9400d88e9a5fa9920d9abf7df Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 4 Feb 2021 12:34:06 -0500 Subject: [PATCH 8/9] Updated license --- .../components/relevance_tuning/relevance_tuning_logic.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts index 4a4e535720a0a..4abaae5b287f5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts @@ -1,7 +1,8 @@ /* * 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. + * 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 { kea, MakeLogicType } from 'kea'; From c69b184a5f24aa2eabb52ea5f45e14fa33761a17 Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Thu, 4 Feb 2021 12:39:26 -0500 Subject: [PATCH 9/9] Reorganized logic --- .../relevance_tuning_logic.ts | 57 ++++++++++--------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts index 4abaae5b287f5..d4ec5e37f6ce5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/relevance_tuning/relevance_tuning_logic.ts @@ -32,19 +32,19 @@ interface RelevanceTuningActions { interface RelevanceTuningValues { searchSettings: Partial; schema: Schema; - dataLoading: boolean; + schemaFields: string[]; + schemaFieldsWithConflicts: string[]; + filteredSchemaFields: string[]; + filteredSchemaFieldsWithConflicts: string[]; schemaConflicts: SchemaConflicts; - unsavedChanges: boolean; + showSchemaConflictCallout: boolean; + engineHasSchemaFields: boolean; filterInputValue: string; query: string; + unsavedChanges: boolean; + dataLoading: boolean; searchResults: object[] | null; resultsLoading: boolean; - showSchemaConflictCallout: boolean; - engineHasSchemaFields: boolean; - schemaFields: string[]; - schemaFieldsWithConflicts: string[]; - filteredSchemaFields: string[]; - filteredSchemaFieldsWithConflicts: string[]; } // If the user hasn't entered a filter, then we can skip filtering the array entirely @@ -81,23 +81,16 @@ export const RelevanceTuningLogic = kea< onInitializeRelevanceTuning: (_, { schema }) => schema, }, ], - dataLoading: [ - true, - { - onInitializeRelevanceTuning: () => false, - resetSearchSettingsState: () => true, - }, - ], schemaConflicts: [ {}, { onInitializeRelevanceTuning: (_, { schemaConflicts }) => schemaConflicts, }, ], - unsavedChanges: [ - false, + showSchemaConflictCallout: [ + true, { - setSearchSettings: () => true, + dismissSchemaConflictCallout: () => false, }, ], filterInputValue: [ @@ -112,11 +105,18 @@ export const RelevanceTuningLogic = kea< setSearchQuery: (_, query) => query, }, ], - resultsLoading: [ + unsavedChanges: [ false, { - setResultsLoading: (_, resultsLoading) => resultsLoading, - setSearchResults: () => false, + setSearchSettings: () => true, + }, + ], + + dataLoading: [ + true, + { + onInitializeRelevanceTuning: () => false, + resetSearchSettingsState: () => true, }, ], searchResults: [ @@ -126,18 +126,15 @@ export const RelevanceTuningLogic = kea< setSearchResults: (_, searchResults) => searchResults, }, ], - showSchemaConflictCallout: [ - true, + resultsLoading: [ + false, { - dismissSchemaConflictCallout: () => false, + setResultsLoading: (_, resultsLoading) => resultsLoading, + setSearchResults: () => false, }, ], }), selectors: ({ selectors }) => ({ - engineHasSchemaFields: [ - () => [selectors.schema], - (schema: Schema): boolean => Object.keys(schema).length >= 2, - ], schemaFields: [() => [selectors.schema], (schema: Schema) => Object.keys(schema)], schemaFieldsWithConflicts: [ () => [selectors.schemaConflicts], @@ -153,5 +150,9 @@ export const RelevanceTuningLogic = kea< (schemaFieldsWithConflicts: string[], filterInputValue: string): string[] => filterIfTerm(schemaFieldsWithConflicts, filterInputValue), ], + engineHasSchemaFields: [ + () => [selectors.schema], + (schema: Schema): boolean => Object.keys(schema).length >= 2, + ], }), });