-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into 113808-ccr-view
- Loading branch information
Showing
19 changed files
with
426 additions
and
13 deletions.
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
1 change: 1 addition & 0 deletions
1
x-pack/plugins/canvas/canvas_plugin_src/renderers/embeddable/embeddable.scss
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
77 changes: 77 additions & 0 deletions
77
...blic/applications/app_search/components/curations/components/suggestions_callout.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,77 @@ | ||
/* | ||
* 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__/react_router'; | ||
|
||
jest.mock('../../../../shared/use_local_storage', () => ({ | ||
useLocalStorage: jest.fn(), | ||
})); | ||
|
||
import React from 'react'; | ||
|
||
import { useLocation } from 'react-router-dom'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { EuiButtonEmpty, EuiCallOut } from '@elastic/eui'; | ||
|
||
import { EuiButtonTo } from '../../../../shared/react_router_helpers'; | ||
import { useLocalStorage } from '../../../../shared/use_local_storage'; | ||
|
||
import { SuggestionsCallout } from './suggestions_callout'; | ||
|
||
const props = { | ||
title: 'Title', | ||
description: 'A description.', | ||
buttonTo: '/suggestions', | ||
}; | ||
|
||
const now = '2021-01-01T00:30:00Z'; | ||
const tenMinutesAgo = '2021-01-01T00:20:00Z'; | ||
const twentyMinutesAgo = '2021-01-01T00:10:00Z'; | ||
|
||
describe('SuggestionsCallout', () => { | ||
const mockSetLastDismissedTimestamp = jest.fn(); | ||
const setMockLastDismissedTimestamp = (lastDismissedTimestamp: string) => { | ||
(useLocalStorage as jest.Mock).mockImplementation(() => [ | ||
lastDismissedTimestamp, | ||
mockSetLastDismissedTimestamp, | ||
]); | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockLastDismissedTimestamp(tenMinutesAgo); | ||
(useLocation as jest.Mock).mockImplementationOnce(() => ({ | ||
pathname: '/engines/some-engine', | ||
})); | ||
}); | ||
|
||
it('renders a callout with a link to the suggestions', () => { | ||
const wrapper = shallow(<SuggestionsCallout {...props} lastUpdatedTimestamp={now} />); | ||
|
||
expect(wrapper.find(EuiCallOut)); | ||
expect(wrapper.find(EuiButtonTo).prop('to')).toEqual('/suggestions'); | ||
}); | ||
|
||
it('is empty is it was updated before it was last dismissed', () => { | ||
const wrapper = shallow( | ||
<SuggestionsCallout {...props} lastUpdatedTimestamp={twentyMinutesAgo} /> | ||
); | ||
|
||
expect(wrapper.isEmptyRender()).toBe(true); | ||
}); | ||
|
||
it('clicking the dismiss button updates the timestamp in local storage', () => { | ||
jest.spyOn(global.Date.prototype, 'toISOString').mockImplementation(() => now); | ||
|
||
const wrapper = shallow(<SuggestionsCallout {...props} lastUpdatedTimestamp={now} />); | ||
wrapper.find(EuiButtonEmpty).simulate('click'); | ||
|
||
expect(mockSetLastDismissedTimestamp).toHaveBeenCalledWith(now); | ||
}); | ||
}); |
86 changes: 86 additions & 0 deletions
86
...ch/public/applications/app_search/components/curations/components/suggestions_callout.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 React from 'react'; | ||
|
||
import { useLocation } from 'react-router-dom'; | ||
|
||
import { | ||
EuiButtonEmpty, | ||
EuiCallOut, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { LightbulbIcon } from '../../../../shared/icons'; | ||
import { EuiButtonTo } from '../../../../shared/react_router_helpers'; | ||
import { useLocalStorage } from '../../../../shared/use_local_storage'; | ||
|
||
interface SuggestionsCalloutProps { | ||
title: string; | ||
description: string; | ||
buttonTo: string; | ||
lastUpdatedTimestamp: string; // ISO string like '2021-10-04T18:53:02.784Z' | ||
} | ||
|
||
export const SuggestionsCallout: React.FC<SuggestionsCalloutProps> = ({ | ||
title, | ||
description, | ||
buttonTo, | ||
lastUpdatedTimestamp, | ||
}) => { | ||
const { pathname } = useLocation(); | ||
|
||
const [lastDismissedTimestamp, setLastDismissedTimestamp] = useLocalStorage<string>( | ||
`suggestions-callout--${pathname}`, | ||
new Date(0).toISOString() | ||
); | ||
|
||
if (new Date(lastDismissedTimestamp) >= new Date(lastUpdatedTimestamp)) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<EuiCallOut color="success" iconType={LightbulbIcon} title={title}> | ||
<EuiText size="s"> | ||
<p>{description}</p> | ||
</EuiText> | ||
<EuiSpacer size="m" /> | ||
<EuiFlexGroup gutterSize="s"> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonTo to={buttonTo} color="success" fill size="s"> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.curations.suggestionsCallout.reviewSuggestionsButtonLabel', | ||
{ defaultMessage: 'Review suggestions' } | ||
)} | ||
</EuiButtonTo> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonEmpty | ||
color="success" | ||
iconType="eyeClosed" | ||
size="s" | ||
onClick={() => { | ||
setLastDismissedTimestamp(new Date().toISOString()); | ||
}} | ||
> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.curations.suggestionsCallout.hideForNowLabel', | ||
{ defaultMessage: 'Hide this for now' } | ||
)} | ||
</EuiButtonEmpty> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiCallOut> | ||
<EuiSpacer /> | ||
</> | ||
); | ||
}; |
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
58 changes: 58 additions & 0 deletions
58
...pplications/app_search/components/curations/curation/suggested_documents_callout.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,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 '../../../__mocks__/engine_logic.mock'; | ||
|
||
import { setMockValues } from '../../../../__mocks__/kea_logic'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
import { set } from 'lodash/fp'; | ||
|
||
import { SuggestionsCallout } from '../components/suggestions_callout'; | ||
|
||
import { SuggestedDocumentsCallout } from './suggested_documents_callout'; | ||
|
||
const MOCK_VALUES = { | ||
// CurationLogic | ||
curation: { | ||
suggestion: { | ||
status: 'pending', | ||
updated_at: '2021-01-01T00:30:00Z', | ||
}, | ||
queries: ['some query'], | ||
}, | ||
}; | ||
|
||
describe('SuggestedDocumentsCallout', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(MOCK_VALUES); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<SuggestedDocumentsCallout />); | ||
|
||
expect(wrapper.is(SuggestionsCallout)); | ||
}); | ||
|
||
it('is empty when the suggested is undefined', () => { | ||
setMockValues({ ...MOCK_VALUES, curation: {} }); | ||
|
||
const wrapper = shallow(<SuggestedDocumentsCallout />); | ||
|
||
expect(wrapper.isEmptyRender()).toBe(true); | ||
}); | ||
|
||
it('is empty when curation status is not pending', () => { | ||
const values = set('curation.suggestion.status', 'applied', MOCK_VALUES); | ||
setMockValues(values); | ||
const wrapper = shallow(<SuggestedDocumentsCallout />); | ||
|
||
expect(wrapper.isEmptyRender()).toBe(true); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
...lic/applications/app_search/components/curations/curation/suggested_documents_callout.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,48 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { useValues } from 'kea'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { ENGINE_CURATION_SUGGESTION_PATH } from '../../../routes'; | ||
import { generateEnginePath } from '../../engine'; | ||
|
||
import { SuggestionsCallout } from '../components/suggestions_callout'; | ||
|
||
import { CurationLogic } from '.'; | ||
|
||
export const SuggestedDocumentsCallout: React.FC = () => { | ||
const { | ||
curation: { suggestion, queries }, | ||
} = useValues(CurationLogic); | ||
|
||
if (typeof suggestion === 'undefined' || suggestion.status !== 'pending') { | ||
return null; | ||
} | ||
|
||
return ( | ||
<SuggestionsCallout | ||
title={i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.curation.suggestedDocumentsCallout.title', | ||
{ defaultMessage: 'New suggested documents for this query' } | ||
)} | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.curation.suggestedDocumentsCallout.description', | ||
{ | ||
defaultMessage: | ||
"Based on your engine's analytics, there are new suggested document promotions ready to review.", | ||
} | ||
)} | ||
buttonTo={generateEnginePath(ENGINE_CURATION_SUGGESTION_PATH, { | ||
query: queries[0], | ||
})} | ||
lastUpdatedTimestamp={suggestion.updated_at} | ||
/> | ||
); | ||
}; |
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
Oops, something went wrong.