| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { Button, Flex, FlexItem } from '@wordpress/components'; |
| 5 |
import { useCopyToClipboard } from '@wordpress/compose'; |
| 6 |
import { WPElement } from '@wordpress/element'; |
| 7 |
import { __ } from '@wordpress/i18n'; |
| 8 |
|
| 9 |
/** |
| 10 |
* Internal dependencies. |
| 11 |
*/ |
| 12 |
import Report from './reports/report'; |
| 13 |
import { useSettingsScreen } from '../../settings-screen'; |
| 14 |
|
| 15 |
/** |
| 16 |
* Styles. |
| 17 |
*/ |
| 18 |
import '../style.css'; |
| 19 |
|
| 20 |
/** |
| 21 |
* Reports component. |
| 22 |
* |
| 23 |
* @param {object} props Component props. |
| 24 |
* @param {string} props.plainTextReport Plain text report. |
| 25 |
* @param {object} props.reports Status reports. |
| 26 |
* @returns {WPElement} Reports component. |
| 27 |
*/ |
| 28 |
export default ({ plainTextReport, reports }) => { |
| 29 |
const { createNotice } = useSettingsScreen(); |
| 30 |
|
| 31 |
const downloadUrl = `data:text/plain;charset=utf-8,${encodeURIComponent(plainTextReport)}`; |
| 32 |
|
| 33 |
/** |
| 34 |
* Copy to clipboard button ref. |
| 35 |
* |
| 36 |
* @type {object} |
| 37 |
*/ |
| 38 |
const ref = useCopyToClipboard(plainTextReport, () => { |
| 39 |
createNotice('info', __('Copied status report to clipboard.', 'elasticpress')); |
| 40 |
}); |
| 41 |
|
| 42 |
return ( |
| 43 |
<> |
| 44 |
<p> |
| 45 |
{__( |
| 46 |
'This screen provides a list of information related to ElasticPress and synced content that can be helpful during troubleshooting. This list can also be copy/pasted and shared as needed.', |
| 47 |
'elasticpress', |
| 48 |
)} |
| 49 |
</p> |
| 50 |
<p> |
| 51 |
<Flex justify="start"> |
| 52 |
<FlexItem> |
| 53 |
<Button |
| 54 |
download="elasticpress-report.txt" |
| 55 |
href={downloadUrl} |
| 56 |
variant="primary" |
| 57 |
> |
| 58 |
{__('Download status report', 'elasticpress')} |
| 59 |
</Button> |
| 60 |
</FlexItem> |
| 61 |
<FlexItem> |
| 62 |
<Button ref={ref} variant="secondary"> |
| 63 |
{__('Copy status report to clipboard', 'elasticpress')} |
| 64 |
</Button> |
| 65 |
</FlexItem> |
| 66 |
</Flex> |
| 67 |
</p> |
| 68 |
{Object.entries(reports).map(([key, { actions, groups, messages, title }]) => ( |
| 69 |
<Report |
| 70 |
actions={actions} |
| 71 |
groups={groups} |
| 72 |
id={key} |
| 73 |
key={key} |
| 74 |
messages={messages} |
| 75 |
title={title} |
| 76 |
/> |
| 77 |
))} |
| 78 |
</> |
| 79 |
); |
| 80 |
}; |
| 81 |
|