/** * JavaScript code for the "Export Screen" component. * * @package TablePress * @subpackage Export Screen * @author Tobias Bäthge * @since 2.2.0 */ /* globals tp */ /** * WordPress dependencies. */ import { useState } from 'react'; import { Icon, } from '@wordpress/components'; import { info } from '@wordpress/icons'; import { __, _x, sprintf } from '@wordpress/i18n'; // Number of tables. const tablesCount = Object.keys( tp.export.tables ).length; // Show at least one empty row in the select, and between 3 and 12 total rows. let exportTablesSelectSize = tablesCount + 1; const maxExportTablesSelectSize = 12; exportTablesSelectSize = Math.max( exportTablesSelectSize, 3 ); exportTablesSelectSize = Math.min( exportTablesSelectSize, maxExportTablesSelectSize ); // The ; } ); const exportFormatsSelectOptions = Object.entries( tp.export.exportFormats ).map( ( [ exportFormat, exportFormatName ] ) => ); const csvDelimitersSelectOptions = Object.entries( tp.export.csvDelimiters ).map( ( [ csvDelimiter, csvDelimiterName ] ) => ); /** * Returns the "Export Screen" component's JSX markup. * * @return {Object} Export Screen component. */ const Screen = () => { const [ screenData, setScreenData ] = useState( { selectedTables: tp.export.selectedTables, exportFormat: tp.export.exportFormat, csvDelimiter: tp.export.csvDelimiter, createZipFile: false, reverseList: false, } ); // If more than one table is selected, force the ZIP file checkbox to checked. const zipFileRequired = screenData.selectedTables.length > 1; /** * Handles screen data state changes. * * @param {Object} updatedData Data in the screen data state that should be updated. */ const updateScreenData = ( updatedData ) => { const newScreenData = { ...screenData, ...updatedData, }; setScreenData( newScreenData ); }; return (
{ tp.export.zipSupportAvailable && <> { // Show a "Select all" checkbox to select all entries in the export tables dropdown. }

{ tablesCount > maxExportTablesSelectSize && <> { // Show a "Reverse List" checkbox if more tables are shown than what the height of the export tables dropdown holds. }

} }
{ tp.export.zipSupportAvailable && <>

{ sprintf( __( 'You can select multiple tables by holding down the “%1$s” key or the “%2$s” key for ranges.', 'tablepress' ), window?.navigator?.platform?.includes( 'Mac' ) ? _x( '⌘', 'keyboard shortcut modifier key on a Mac keyboard', 'tablepress' ) : _x( 'Ctrl', 'keyboard key', 'tablepress' ), _x( 'Shift', 'keyboard key', 'tablepress' ) ) }

}
{ 'csv' !== screenData.exportFormat && <> { ' ' } { __( '(Only needed for CSV export.)', 'tablepress' ) } }
{ __( 'ZIP file', 'tablepress' ) }: { tp.export.zipSupportAvailable && } { ! tp.export.zipSupportAvailable && __( 'Note: Support for ZIP file creation seems not to be available on this server.', 'tablepress' ) }
); }; export default Screen;