-
Notifications
You must be signed in to change notification settings - Fork 8.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[App Search] Implement various Relevance Tuning states and form actions #92644
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
de4241a
Added save and reset buttons
JasonStoltz de595eb
Handle unsaved form changes
JasonStoltz a5a1479
Show invalid boosts message
JasonStoltz 3851eb9
Fix invalid boosts
JasonStoltz 6f3226c
Added unconfirmed fields message
JasonStoltz a8fb7dd
Added schema conflict message
JasonStoltz 23775c6
Added an empty message
JasonStoltz 86f1fe2
Lower cases some button text
JasonStoltz c5eea4b
Type fixes
JasonStoltz 2beccf9
Update x-pack/plugins/enterprise_search/public/applications/app_searc…
JasonStoltz 8b49284
Update x-pack/plugins/enterprise_search/public/applications/app_searc…
JasonStoltz 6d38048
Update x-pack/plugins/enterprise_search/public/applications/app_searc…
JasonStoltz c916abf
Update x-pack/plugins/enterprise_search/public/applications/app_searc…
JasonStoltz 9c20faf
[PR feedback] Remove old comment
JasonStoltz a948765
Extend engine_logic.mock
cee-chen dc7707d
Fix value boosts with long overflowing text
cee-chen 351fd33
[PR Feedback] Refactor
JasonStoltz 335eb1a
[PR Feedback] Show loading message
JasonStoltz 9e90845
Merge branch 'master' into relevance-tuning-6
kibanamachine 376fb36
Fix type errors
JasonStoltz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,67 +7,93 @@ | |
|
||
import React, { useEffect } from 'react'; | ||
|
||
import { useActions } from 'kea'; | ||
|
||
import { | ||
EuiPageHeader, | ||
EuiPageHeaderSection, | ||
EuiTitle, | ||
EuiText, | ||
EuiSpacer, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiTextColor, | ||
} from '@elastic/eui'; | ||
import { useActions, useValues } from 'kea'; | ||
|
||
import { EuiButton, EuiEmptyPrompt, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { FlashMessages } from '../../../shared/flash_messages'; | ||
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome'; | ||
import { Loading } from '../../../shared/loading'; | ||
import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt'; | ||
import { DOCS_PREFIX } from '../../routes'; | ||
|
||
import { RELEVANCE_TUNING_TITLE } from './constants'; | ||
import { RelevanceTuningForm } from './relevance_tuning_form'; | ||
import { RelevanceTuningLogic } from './relevance_tuning_logic'; | ||
import { RelevanceTuningLayout } from './relevance_tuning_layout'; | ||
|
||
import { RelevanceTuningLogic } from '.'; | ||
|
||
interface Props { | ||
engineBreadcrumb: string[]; | ||
} | ||
|
||
const EmptyCallout: React.FC = () => { | ||
return ( | ||
<EuiEmptyPrompt | ||
title={ | ||
<h2> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.emptyErrorMessageTitle', | ||
{ | ||
defaultMessage: 'Tuning requires schema fields', | ||
} | ||
)} | ||
</h2> | ||
} | ||
body={i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.emptyErrorMessage', | ||
{ | ||
defaultMessage: 'Index documents to tune relevance.', | ||
} | ||
)} | ||
actions={ | ||
<EuiButton | ||
size="s" | ||
color="primary" | ||
href={`${DOCS_PREFIX}/relevance-tuning-guide.html`} | ||
fill | ||
> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.emptyButtonLabel', | ||
{ | ||
defaultMessage: 'Read the relevance tuning guide', | ||
} | ||
)} | ||
</EuiButton> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export const RelevanceTuning: React.FC<Props> = ({ engineBreadcrumb }) => { | ||
const { dataLoading, engineHasSchemaFields, unsavedChanges } = useValues(RelevanceTuningLogic); | ||
const { initializeRelevanceTuning } = useActions(RelevanceTuningLogic); | ||
|
||
useEffect(() => { | ||
initializeRelevanceTuning(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<SetPageChrome trail={[...engineBreadcrumb, RELEVANCE_TUNING_TITLE]} /> | ||
<EuiPageHeader> | ||
<EuiPageHeaderSection> | ||
<EuiTitle size="l"> | ||
<h1>{RELEVANCE_TUNING_TITLE}</h1> | ||
</EuiTitle> | ||
<EuiText> | ||
<EuiTextColor color="subdued"> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.description', | ||
{ | ||
defaultMessage: 'Set field weights and boosts', | ||
} | ||
)} | ||
</EuiTextColor> | ||
</EuiText> | ||
</EuiPageHeaderSection> | ||
</EuiPageHeader> | ||
<EuiSpacer /> | ||
<FlashMessages /> | ||
const body = () => { | ||
if (dataLoading) { | ||
return <Loading />; | ||
} | ||
|
||
if (!engineHasSchemaFields) { | ||
return <EmptyCallout />; | ||
} | ||
|
||
return ( | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<RelevanceTuningForm /> | ||
</EuiFlexItem> | ||
<EuiFlexItem /> | ||
</EuiFlexGroup> | ||
</> | ||
); | ||
}; | ||
|
||
return ( | ||
<RelevanceTuningLayout engineBreadcrumb={engineBreadcrumb}> | ||
<UnsavedChangesPrompt hasUnsavedChanges={unsavedChanges} /> | ||
Comment on lines
+94
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [optional, not a blocker] I think you could probably bake |
||
{body()} | ||
</RelevanceTuningLayout> | ||
); | ||
}; |
86 changes: 86 additions & 0 deletions
86
...ic/applications/app_search/components/relevance_tuning/relevance_tuning_callouts.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* 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 '../../__mocks__/engine_logic.mock'; | ||
import { setMockValues } from '../../../__mocks__/kea.mock'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { RelevanceTuningCallouts } from './relevance_tuning_callouts'; | ||
|
||
describe('RelevanceTuningCallouts', () => { | ||
const values = { | ||
engineHasSchemaFields: true, | ||
engine: { | ||
invalidBoosts: false, | ||
unsearchedUnconfirmedFields: false, | ||
}, | ||
schemaFieldsWithConflicts: [], | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
}); | ||
|
||
const subject = () => shallow(<RelevanceTuningCallouts />); | ||
|
||
it('renders', () => { | ||
const wrapper = subject(); | ||
expect(wrapper.find('[data-test-subj="RelevanceTuningInvalidBoostsCallout"]').exists()).toBe( | ||
false | ||
); | ||
expect(wrapper.find('[data-test-subj="RelevanceTuningUnsearchedFieldsCallout"]').exists()).toBe( | ||
false | ||
); | ||
expect(subject().find('[data-test-subj="SchemaConflictsCallout"]').exists()).toBe(false); | ||
}); | ||
|
||
it('shows a message when there are invalid boosts', () => { | ||
// An invalid boost would be if a user creats a functional boost on a number field, then that | ||
// field later changes to text. At this point, the boost still exists but is invalid for | ||
// a text field. | ||
setMockValues({ | ||
...values, | ||
engine: { | ||
invalidBoosts: true, | ||
unsearchedUnconfirmedFields: false, | ||
}, | ||
}); | ||
expect(subject().find('[data-test-subj="RelevanceTuningInvalidBoostsCallout"]').exists()).toBe( | ||
true | ||
); | ||
}); | ||
|
||
it('shows a message when there are unconfirmed fields', () => { | ||
// An invalid boost would be if a user creats a functional boost on a number field, then that | ||
// field later changes to text. At this point, the boost still exists but is invalid for | ||
// a text field. | ||
setMockValues({ | ||
...values, | ||
engine: { | ||
invalidBoosts: false, | ||
unsearchedUnconfirmedFields: true, | ||
}, | ||
}); | ||
expect( | ||
subject().find('[data-test-subj="RelevanceTuningUnsearchedFieldsCallout"]').exists() | ||
).toBe(true); | ||
}); | ||
|
||
it('shows a message when there are schema field conflicts', () => { | ||
// Schema conflicts occur when a meta engine has fields in source engines with have differing types, | ||
// hence relevance tuning cannot be applied as we don't know the actual type | ||
setMockValues({ | ||
...values, | ||
schemaFieldsWithConflicts: ['fe', 'fi', 'fo'], | ||
}); | ||
expect(subject().find('[data-test-subj="SchemaConflictsCallout"]').exists()).toBe(true); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also optional, but I think Scotty stated a preference for single line returns. I'm fine with whatever though lol, not a big deal to me, we can yolo it and come back to returns later