PK ! …Ô˜1. 1.
screen.jsxnu „[µü¤ /**
* JavaScript code for the "Import Screen" component.
*
* @package TablePress
* @subpackage Import Screen
* @author Tobias Bäthge
* @since 2.2.0
*/
/**
* WordPress dependencies.
*/
import { useEffect, useRef, useState } from 'react';
import {
Button,
__experimentalHStack as HStack, // eslint-disable-line @wordpress/no-unsafe-wp-apis
Icon,
RadioControl,
ComboboxControl,
Disabled,
TextareaControl,
TextControl,
} from '@wordpress/components';
import { info } from '@wordpress/icons';
import { __, _n, _x, sprintf } from '@wordpress/i18n';
// Details for the available import sources.
const importSources = {
'file-upload': {
label: __( 'File Upload', 'tablepress' ),
instruction: __( 'Select files', 'tablepress' ),
},
url: {
label: __( 'URL', 'tablepress' ),
instruction: __( 'File URL', 'tablepress' ),
},
server: {
label: __( 'File on server', 'tablepress' ),
instruction: __( 'Server Path to file', 'tablepress' ),
},
'form-field': {
label: __( 'Manual Input', 'tablepress' ),
instruction: __( 'Import data', 'tablepress' ),
},
};
if ( ! tp.import.showImportSourceUrl ) {
delete importSources.url;
}
if ( ! tp.import.showImportSourceServer ) {
delete importSources.server;
}
const importSourcesRadioOptions = Object.entries( importSources ).map( ( [ importSource, importSourceData ] ) => ( { value: importSource, label: importSourceData.label } ) );
// Number of tables.
const tablesCount = Object.keys( tp.import.tables ).length;
const tablesSelectOptions = Object.entries( tp.import.tables ).map( ( [ tableId, tableName ] ) => {
if ( '' === tableName.trim() ) {
tableName = __( '(no name)', 'tablepress' );
}
const optionText = sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), tableId, tableName );
return { value: tableId, label: optionText };
} );
// Custom component to conditionally disable its children, used for the ComboboxControl.
const ConditionalDisabled = ( { condition, children } ) => (
condition ? (
{ __( 'Import Source', 'tablepress' ) }: |
|
---|---|
{
/*
* Always add the "File Upload" UI to the DOM, but hide it using `style="display: none;"` below.
* This ensures that the field works, as that is "uncontrolled" in React, and setting its value (files) is not possible.
*/
}
( event.target.files && updateScreenData( { importFileUpload: event.target.files } ) ) }
onDragEnter={ () => fileUploadDropzone.current.classList.add( 'dragover' ) }
onDragLeave={ () => fileUploadDropzone.current.classList.remove( 'dragover' ) }
/>
{ tp.import.showImportSourceUrl && 'url' === screenData.importSource &&
{ 0 === screenData.importFileUpload.length && __( 'Click to select files, or drag them here.', 'tablepress' ) }
{ 0 < screenData.importFileUpload.length && sprintf( _n( 'You have selected %1$d file:', 'You have selected %1$d files:', screenData.importFileUpload.length, 'tablepress' ), screenData.importFileUpload.length ) }
{
[ ...screenData.importFileUpload ].map( ( file ) =>
{ file.name }
)
}
|
|
{ __( 'Add, Replace, or Append?', 'tablepress' ) }: |
|
|
|