-
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.
[Discover] Update document explorer callout wording (#128556)
- Adding a new callout when Document explorer is active, linking to documentation Co-authored-by: Matthias Wilhelm <[email protected]>
- Loading branch information
Showing
7 changed files
with
239 additions
and
30 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
60 changes: 60 additions & 0 deletions
60
...ation/main/components/document_explorer_callout/document_explorer_update_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,60 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { KibanaContextProvider } from '../../../../../../kibana_react/public'; | ||
import { | ||
CALLOUT_STATE_KEY, | ||
DocumentExplorerUpdateCallout, | ||
} from './document_explorer_update_callout'; | ||
import { LocalStorageMock } from '../../../../__mocks__/local_storage_mock'; | ||
import { DiscoverServices } from '../../../../build_services'; | ||
|
||
const defaultServices = { | ||
addBasePath: () => '', | ||
docLinks: { links: { discover: { documentExplorer: '' } } }, | ||
capabilities: { advancedSettings: { save: true } }, | ||
storage: new LocalStorageMock({ [CALLOUT_STATE_KEY]: false }), | ||
} as unknown as DiscoverServices; | ||
|
||
const mount = (services: DiscoverServices) => { | ||
return mountWithIntl( | ||
<KibanaContextProvider services={services}> | ||
<DocumentExplorerUpdateCallout /> | ||
</KibanaContextProvider> | ||
); | ||
}; | ||
|
||
describe('Document Explorer Update callout', () => { | ||
it('should render callout', () => { | ||
const result = mount(defaultServices); | ||
|
||
expect(result.find('.dscDocumentExplorerCallout').exists()).toBeTruthy(); | ||
}); | ||
|
||
it('should not render callout for user without permissions', () => { | ||
const services = { | ||
...defaultServices, | ||
capabilities: { advancedSettings: { save: false } }, | ||
} as unknown as DiscoverServices; | ||
const result = mount(services); | ||
|
||
expect(result.find('.dscDocumentExplorerCallout').exists()).toBeFalsy(); | ||
}); | ||
|
||
it('should not render callout of it was closed', () => { | ||
const services = { | ||
...defaultServices, | ||
storage: new LocalStorageMock({ [CALLOUT_STATE_KEY]: true }), | ||
} as unknown as DiscoverServices; | ||
const result = mount(services); | ||
|
||
expect(result.find('.dscDocumentExplorerCallout').exists()).toBeFalsy(); | ||
}); | ||
}); |
124 changes: 124 additions & 0 deletions
124
...pplication/main/components/document_explorer_callout/document_explorer_update_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,124 @@ | ||
/* | ||
* 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 React, { useCallback, useMemo, useState } from 'react'; | ||
import './document_explorer_callout.scss'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { | ||
EuiButton, | ||
EuiButtonIcon, | ||
EuiCallOut, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
useEuiTheme, | ||
} from '@elastic/eui'; | ||
import { css } from '@emotion/react'; | ||
import { useDiscoverServices } from '../../../../utils/use_discover_services'; | ||
import { Storage } from '../../../../../../kibana_utils/public'; | ||
|
||
export const CALLOUT_STATE_KEY = 'discover:docExplorerUpdateCalloutClosed'; | ||
|
||
const getStoredCalloutState = (storage: Storage): boolean => { | ||
const calloutClosed = storage.get(CALLOUT_STATE_KEY); | ||
return Boolean(calloutClosed); | ||
}; | ||
const updateStoredCalloutState = (newState: boolean, storage: Storage) => { | ||
storage.set(CALLOUT_STATE_KEY, newState); | ||
}; | ||
|
||
/** | ||
* The callout that's displayed when Document explorer is enabled | ||
*/ | ||
export const DocumentExplorerUpdateCallout = () => { | ||
const { euiTheme } = useEuiTheme(); | ||
const { storage, capabilities, docLinks } = useDiscoverServices(); | ||
const [calloutClosed, setCalloutClosed] = useState(getStoredCalloutState(storage)); | ||
|
||
const semiBoldStyle = useMemo( | ||
() => css` | ||
font-weight: ${euiTheme.font.weight.semiBold}; | ||
`, | ||
[euiTheme.font.weight.semiBold] | ||
); | ||
|
||
const onCloseCallout = useCallback(() => { | ||
updateStoredCalloutState(true, storage); | ||
setCalloutClosed(true); | ||
}, [storage]); | ||
|
||
if (calloutClosed || !capabilities.advancedSettings.save) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<EuiCallOut | ||
className="dscDocumentExplorerCallout" | ||
title={<CalloutTitle onCloseCallout={onCloseCallout} />} | ||
iconType="search" | ||
> | ||
<p> | ||
<FormattedMessage | ||
id="discover.docExplorerUpdateCallout.bodyMessage" | ||
defaultMessage="Experience the new {documentExplorer}. Understand the shape of your data with {fieldStatistics}." | ||
values={{ | ||
fieldStatistics: ( | ||
<span css={semiBoldStyle}> | ||
<FormattedMessage | ||
id="discover.docExplorerUpdateCallout.fieldStatistics" | ||
defaultMessage="Field Statistics" | ||
/> | ||
</span> | ||
), | ||
documentExplorer: ( | ||
<span css={semiBoldStyle}> | ||
<FormattedMessage | ||
id="discover.docExplorerUpdateCallout.documentExplorer" | ||
defaultMessage="Document Explorer" | ||
/> | ||
</span> | ||
), | ||
}} | ||
/> | ||
</p> | ||
<EuiButton | ||
iconType="tableDensityNormal" | ||
size="s" | ||
href={docLinks.links.discover.documentExplorer} | ||
> | ||
<FormattedMessage | ||
id="discover.docExplorerUpdateCallout.learnMore" | ||
defaultMessage="Learn more" | ||
/> | ||
</EuiButton> | ||
</EuiCallOut> | ||
); | ||
}; | ||
|
||
function CalloutTitle({ onCloseCallout }: { onCloseCallout: () => void }) { | ||
return ( | ||
<EuiFlexGroup justifyContent="spaceBetween" gutterSize="none" responsive={false}> | ||
<EuiFlexItem grow={false}> | ||
<FormattedMessage | ||
id="discover.docExplorerUpdateCallout.headerMessage" | ||
defaultMessage="A better way to explore" | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButtonIcon | ||
aria-label={i18n.translate('discover.docExplorerUpdateCallout.closeButtonAriaLabel', { | ||
defaultMessage: 'Close', | ||
})} | ||
onClick={onCloseCallout} | ||
type="button" | ||
iconType="cross" | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
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