/** * JavaScript code for the "Edit" section integration of the "Table Features for Site Visitors". * * @package TablePress * @subpackage Views JavaScript * @author Tobias Bäthge * @since 3.0.0 */ /** * WordPress dependencies. */ import { useState } from 'react'; import { CheckboxControl, __experimentalHStack as HStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis __experimentalNumberControl as NumberControl, // eslint-disable-line @wordpress/no-unsafe-wp-apis TextareaControl, __experimentalVStack as VStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis } from '@wordpress/components'; import { createInterpolateElement } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; /** * Internal dependencies. */ import { initializeReactComponentInPortal } from '../common/react-loader'; import { Alert } from '../common/alert'; // Wrap the "Custom Commands" in a separate component, to keep internal states at a lower level. const CustomCommandsControl = ( { tableOptionCustomCommands, dataTablesEnabled, updateTableOptions } ) => { const [ customCommands, setCustomCommands ] = useState( tableOptionCustomCommands ); const [ customCommandsExpanded, setCustomCommandsExpanded ] = useState( false ); /* // Updating the state variable when the table option changes is not necessary, as it's never modified externally. useEffect( () => { setCustomCommands( tableOptionCustomCommands ); }, [ tableOptionCustomCommands ] ); */ return ( setCustomCommands( newCustomCommands ) } onBlur={ () => { if ( customCommands !== tableOptionCustomCommands ) { updateTableOptions( { datatables_custom_commands: customCommands } ); } } } onFocus={ () => setCustomCommandsExpanded( true ) } help={ createInterpolateElement( __( 'Additional parameters from the DataTables documentation to be added to the JS call.', 'tablepress' ) + ' ' + __( 'For advanced use only.', 'tablepress' ), { a: , // eslint-disable-line jsx-a11y/anchor-has-content }, ) } /> ); }; const Section = ( { tableOptions, updateTableOptions } ) => { const [ alertEnableDataTablesMergedCellsIsShown, setAlertEnableDataTablesMergedCellsIsShown ] = useState( false ); const tableHeadEnabled = ( tableOptions.table_head > 0 ); const dataTablesEnabled = ( tableHeadEnabled && tableOptions.use_datatables ); return ( { ( ! tableHeadEnabled ) && ( { sprintf( __( 'These features and options are only available when the “%1$s” setting in the “%2$s” section is used.', 'tablepress' ), __( 'Table Header', 'tablepress' ), __( 'Table Options', 'tablepress' ), ) } ) } { ( tp.screenOptions.showCustomCommands ) && ( ) }
{ __( 'Enable Visitor Features', 'tablepress' ) }: { // Don't turn on "Enable Visitor Features" if the table has merged cells. if ( use_datatables ) { tp.helpers.visibility.update(); // Update information about hidden rows and columns. if ( tp.helpers.editor.has_merged_body_cells() ) { setAlertEnableDataTablesMergedCellsIsShown( true ); return; } } updateTableOptions( { use_datatables } ); } } /> { alertEnableDataTablesMergedCellsIsShown && ( setAlertEnableDataTablesMergedCellsIsShown( false ) } modalProps={ { size: 'medium', } } /> ) }
{ __( 'Sorting', 'tablepress' ) }: updateTableOptions( { datatables_sort } ) } />
{ __( 'Search/Filtering', 'tablepress' ) }: updateTableOptions( { datatables_filter } ) } />
{ __( 'Pagination', 'tablepress' ) }: updateTableOptions( { datatables_paginate } ) } />
{ __( 'Pagination Length Change', 'tablepress' ) }: updateTableOptions( { datatables_lengthchange } ) } />
{ __( 'Info', 'tablepress' ) }: updateTableOptions( { datatables_info } ) } />
{ __( 'Horizontal Scrolling', 'tablepress' ) }: updateTableOptions( { datatables_scrollx } ) } />
); }; initializeReactComponentInPortal( 'datatables-features', 'edit', Section, );